forked from I2P_Developers/i2p.i2p
* RandomSource: Add new method getBytes(buf, offset, length)
This commit is contained in:
@ -150,6 +150,16 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
|
|||||||
_fortuna.nextBytes(buf);
|
_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
|
* 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
|
* 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.
|
* thats what it has been used for.
|
||||||
*
|
*
|
||||||
|
* This code unused, see FortunaRandomSource override
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int nextInt(int n) {
|
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,
|
* Like the modified nextInt, nextLong(n) returns a random number from 0 through n,
|
||||||
* including 0, excluding n.
|
* including 0, excluding n.
|
||||||
|
*
|
||||||
|
* This code unused, see FortunaRandomSource override
|
||||||
*/
|
*/
|
||||||
public long nextLong(long n) {
|
public long nextLong(long n) {
|
||||||
long v = super.nextLong();
|
long v = super.nextLong();
|
||||||
@ -80,6 +83,24 @@ public class RandomSource extends SecureRandom implements EntropyHarvester {
|
|||||||
return v;
|
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
|
* override as synchronized, for those JVMs that don't always pull via
|
||||||
* nextBytes (cough ibm)
|
* nextBytes (cough ibm)
|
||||||
@ -188,6 +209,7 @@ public class RandomSource extends SecureRandom implements EntropyHarvester {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
for (int j = 0; j < 2; j++) {
|
for (int j = 0; j < 2; j++) {
|
||||||
RandomSource rs = new RandomSource(I2PAppContext.getGlobalContext());
|
RandomSource rs = new RandomSource(I2PAppContext.getGlobalContext());
|
||||||
@ -208,4 +230,5 @@ public class RandomSource extends SecureRandom implements EntropyHarvester {
|
|||||||
rs.saveSeed();
|
rs.saveSeed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user