@@ -0,0 +1,2584 @@
+package org.bouncycastle.crypto.prng;%0A%0A/**%0A * Takes bytes generated by an underling RandomGenerator and reverses the order in%0A * each small window (of configurable size).%0A * %3Cp%3E%0A * Access to internals is synchronized so a single one of these can be shared.%0A * %3C/p%3E%0A */%0Apublic class ReversedWindowGenerator%0A    implements RandomGenerator%0A%7B%0A    private final RandomGenerator generator;%0A%0A    private byte%5B%5D window;%0A    private int windowCount;%0A%0A    public ReversedWindowGenerator(%0A        RandomGenerator generator,%0A        int             windowSize)%0A    %7B%0A        if (generator == null)%0A            throw new IllegalArgumentException(%22generator cannot be null%22);%0A        if (windowSize %3C 2)%0A            throw new IllegalArgumentException(%22windowSize must be at least 2%22);%0A%0A        this.generator = generator;%0A        this.window = new byte%5BwindowSize%5D;%0A    %7D%0A%0A    /**%0A     * Add more seed material to the generator.%0A     *%0A     * @param seed a byte array to be mixed into the generator's state.%0A     */%0A    public void addSeedMaterial(%0A        byte%5B%5D seed)%0A    %7B%0A        synchronized (this)%0A        %7B%0A            windowCount = 0;%0A            generator.addSeedMaterial(seed);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Add more seed material to the generator.%0A     *%0A     * @param seed a long value to be mixed into the generator's state.%0A     */%0A    public void addSeedMaterial(%0A        long seed)%0A    %7B%0A        synchronized (this)%0A        %7B%0A            windowCount = 0;%0A            generator.addSeedMaterial(seed);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Fill bytes with random values.%0A     *%0A     * @param bytes byte array to be filled.%0A     */%0A    public void nextBytes(%0A        byte%5B%5D bytes)%0A    %7B%0A        doNextBytes(bytes, 0, bytes.length);%0A    %7D%0A%0A    /**%0A     * Fill part of bytes with random values.%0A     *%0A     * @param bytes byte array to be filled.%0A     * @param start index to start filling at.%0A     * @param len length of segment to fill.%0A     */%0A    public void nextBytes(%0A        byte%5B%5D  bytes,%0A        int     start,%0A        int     len)%0A    %7B%0A        doNextBytes(bytes, start, len);%0A    %7D%0A%0A    private void doNextBytes(%0A        byte%5B%5D  bytes,%0A        int     start,%0A        int     len)%0A    %7B%0A        synchronized (this)%0A        %7B%0A            int done = 0;%0A            while (done %3C len)%0A            %7B%0A                if (windowCount %3C 1)%0A                %7B%0A                    generator.nextBytes(window, 0, window.length);%0A                    windowCount = window.length;%0A                %7D%0A%0A                bytes%5Bstart + done++%5D = window%5B--windowCount%5D;%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add a generator that reverses the output of another generator over each short window.