SHA1PRNG.java (engineNextBytes): Rewrote.

* gnu/java/security/provider/SHA1PRNG.java (engineNextBytes):
	Rewrote.
	* java/security/SecureRandom.java (setSeed(long)): Don't set seed
	if secureRandomSpi is not initialized.

From-SVN: r46327
This commit is contained in:
Tom Tromey 2001-10-18 00:05:29 +00:00 committed by Tom Tromey
parent 9c48b4d1e4
commit 8ea6262761
3 changed files with 44 additions and 30 deletions

View file

@ -1,5 +1,5 @@
/* SHA1PRNG.java --- Secure Random SPI SHA1PRNG
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -73,29 +73,26 @@ public class SHA1PRNG extends SecureRandomSpi implements Serializable
public void engineNextBytes(byte[] bytes)
{
int loc = 0;
while (loc < bytes.length)
{
int copy = Math.min (bytes.length - loc, 20 - datapos);
if( bytes.length < (20 - datapos) ) {
System.arraycopy( data, datapos, bytes, 0, bytes.length);
datapos += bytes.length;
return;
}
int i, blen = bytes.length, bpos = 0;
byte digestdata[];
while( bpos < blen ) {
i = 20 - datapos;
System.arraycopy( data, datapos, bytes, bpos, i);
bpos += i;
datapos += i;
if( datapos >= 20) {
//System.out.println( (0 + 20) + "\n" + (20 + 20) );
System.arraycopy( seed, 0, data, 20, 20);
digestdata = digest.digest( data );
System.arraycopy( digestdata, 0, data, 0, 20);
datapos = 0;
if (copy > 0)
{
System.arraycopy (data, datapos, bytes, loc, copy);
datapos += copy;
loc += copy;
}
else
{
// No data ready for copying, so refill our buffer.
System.arraycopy( seed, 0, data, 20, 20);
byte[] digestdata = digest.digest( data );
System.arraycopy( digestdata, 0, data, 0, 20);
datapos = 0;
}
}
}
}
public byte[] engineGenerateSeed(int numBytes)