I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit df8cd90b authored by zzz's avatar zzz
Browse files

* RandomSource: Add new method getBytes(buf, offset, length)

parent f3e2dfac
No related branches found
No related tags found
No related merge requests found
......@@ -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
*/
......
......@@ -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();
}
}
****/
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment