diff --git a/core/java/src/net/i2p/util/FortunaRandomSource.java b/core/java/src/net/i2p/util/FortunaRandomSource.java index 1e201cb2c8524acc20fdbbce8e288dc13f00190a..6d57f1c6cc65107badad6f23bdea360a92c4c3e2 100644 --- a/core/java/src/net/i2p/util/FortunaRandomSource.java +++ b/core/java/src/net/i2p/util/FortunaRandomSource.java @@ -150,6 +150,16 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste _fortuna.nextBytes(buf); } + /** + * Not part of java.util.SecureRandom, but added for efficiency, since Fortuna supports it. + * + * @since 0.8.12 + */ + @Override + public synchronized void nextBytes(byte buf[], int offset, int length) { + _fortuna.nextBytes(buf, offset, length); + } + /** * Implementation from sun's java.util.Random javadocs */ diff --git a/core/java/src/net/i2p/util/RandomSource.java b/core/java/src/net/i2p/util/RandomSource.java index 558c01297c65b397e7aa75d87d18c00640145c59..c117f3458bcdc862b6861552c82d292c27ddfa22 100644 --- a/core/java/src/net/i2p/util/RandomSource.java +++ b/core/java/src/net/i2p/util/RandomSource.java @@ -59,6 +59,7 @@ public class RandomSource extends SecureRandom implements EntropyHarvester { * WTF. Ok, so we're going to have it return between 0 and n (including 0, excluding n), since * thats what it has been used for. * + * This code unused, see FortunaRandomSource override */ @Override public int nextInt(int n) { @@ -72,6 +73,8 @@ public class RandomSource extends SecureRandom implements EntropyHarvester { /** * Like the modified nextInt, nextLong(n) returns a random number from 0 through n, * including 0, excluding n. + * + * This code unused, see FortunaRandomSource override */ public long nextLong(long n) { long v = super.nextLong(); @@ -80,6 +83,24 @@ public class RandomSource extends SecureRandom implements EntropyHarvester { return v; } + /** + * Not part of java.util.SecureRandom, but added since Fortuna supports it. + * + * This code unused, see FortunaRandomSource override + * + * @since 0.8.12 + */ + public void nextBytes(byte buf[], int offset, int length) { + // inefficient, just in case anybody actually instantiates this + if (offset == 0 && buf.length == length) { + nextBytes(buf); + } else { + byte[] tmp = new byte[length]; + nextBytes(tmp); + System.arraycopy(tmp, 0, buf, offset, length); + } + } + /** * override as synchronized, for those JVMs that don't always pull via * nextBytes (cough ibm) @@ -188,6 +209,7 @@ public class RandomSource extends SecureRandom implements EntropyHarvester { return false; } +/**** public static void main(String args[]) { for (int j = 0; j < 2; j++) { RandomSource rs = new RandomSource(I2PAppContext.getGlobalContext()); @@ -208,4 +230,5 @@ public class RandomSource extends SecureRandom implements EntropyHarvester { rs.saveSeed(); } } +****/ }