diff options
| author | Tom Tromey <tromey@redhat.com> | 2001-10-17 23:58:04 +0000 |
|---|---|---|
| committer | Tom Tromey <tromey@redhat.com> | 2001-10-17 23:58:04 +0000 |
| commit | e7848cb67e50bc47ebc7ca536fbf9eb45d4643b7 (patch) | |
| tree | 04a332bb4f470912c4a2756199aedc288ac02895 /gnu/java/security/provider | |
| parent | 2dbbc8fcdb0ccf15a5177483b5e855f1c08bd603 (diff) | |
| download | classpath-e7848cb67e50bc47ebc7ca536fbf9eb45d4643b7.tar.gz | |
* gnu/java/security/provider/SHA1PRNG.java (engineNextBytes):
Rewrote.
* java/security/SecureRandom.java (setSeed(long)): Don't set seed
if secureRandomSpi is not initialized.
Diffstat (limited to 'gnu/java/security/provider')
| -rw-r--r-- | gnu/java/security/provider/SHA1PRNG.java | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/gnu/java/security/provider/SHA1PRNG.java b/gnu/java/security/provider/SHA1PRNG.java index 1c2f9e0db..c5d31be74 100644 --- a/gnu/java/security/provider/SHA1PRNG.java +++ b/gnu/java/security/provider/SHA1PRNG.java @@ -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. @@ -31,7 +31,6 @@ import java.util.Random; import java.security.SecureRandomSpi; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -//import SecureRandomSpi; import java.io.Serializable; public class SHA1PRNG extends SecureRandomSpi implements Serializable @@ -74,29 +73,26 @@ public class SHA1PRNG extends SecureRandomSpi implements Serializable public void engineNextBytes(byte[] bytes) { - - if( bytes.length < (20 - datapos) ) { - System.arraycopy( bytes, 0, data, datapos, bytes.length); - datapos += bytes.length; - return; - } - - int i, blen = bytes.length, bpos = 0; - byte digestdata[]; - while( bpos < blen ) { - i = 20 - datapos; - System.arraycopy( bytes, bpos, data, datapos, 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) |
