Commit 8ea62627 by Tom Tromey Committed by Tom Tromey

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
parent 9c48b4d1
2001-10-17 Tom Tromey <tromey@redhat.com>
* gnu/java/security/provider/SHA1PRNG.java (engineNextBytes):
Rewrote.
* java/security/SecureRandom.java (setSeed(long)): Don't set seed
if secureRandomSpi is not initialized.
* Makefile.in: Rebuilt.
* Makefile.am (secdir): New macro.
(install-data-local): Install new data files.
......
/* 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)
{
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;
int loc = 0;
while (loc < bytes.length)
{
int copy = Math.min (bytes.length - loc, 20 - datapos);
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)
......
/* SecureRandom.java --- Secure Random class implmentation
Copyright (C) 1999 Free Software Foundation, Inc.
Copyright (C) 1999, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
......@@ -52,7 +52,7 @@ public class SecureRandom extends Random
new SecureRandom by instantating the first SecureRandom
algorithm in the default security provier.
It is not seeded and should be seeded using setseed or else
It is not seeded and should be seeded using setSeed or else
on the first call to getnextBytes it will force a seed.
It is maintained for backwards compatability and programs
......@@ -267,12 +267,24 @@ public class SecureRandom extends Random
*/
public void setSeed(long seed)
{
byte tmp[] = { (byte) (0xff & (seed >> 56)), (byte) (0xff & (seed >> 48)),
(byte) (0xff & (seed >> 40)), (byte) (0xff & (seed >> 32)),
(byte) (0xff & (seed >> 24)), (byte) (0xff & (seed >> 16)),
(byte) (0xff & (seed >> 8)), (byte) (0xff & seed)
};
secureRandomSpi.engineSetSeed(tmp);
// This particular setSeed will be called by Random.Random(), via
// our own constructor, before secureRandomSpi is initialized. In
// this case we can't call a method on secureRandomSpi, and we
// definitely don't want to throw a NullPointerException.
// Therefore we test.
if (secureRandomSpi != null)
{
byte tmp[] = { (byte) (0xff & (seed >> 56)),
(byte) (0xff & (seed >> 48)),
(byte) (0xff & (seed >> 40)),
(byte) (0xff & (seed >> 32)),
(byte) (0xff & (seed >> 24)),
(byte) (0xff & (seed >> 16)),
(byte) (0xff & (seed >> 8)),
(byte) (0xff & seed)
};
secureRandomSpi.engineSetSeed(tmp);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment