From 8ea6262761029a1cccc0e0280ce8be198e687636 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 18 Oct 2001 00:05:29 +0000 Subject: 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 --- libjava/gnu/java/security/provider/SHA1PRNG.java | 43 +++++++++++------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'libjava/gnu/java/security') diff --git a/libjava/gnu/java/security/provider/SHA1PRNG.java b/libjava/gnu/java/security/provider/SHA1PRNG.java index bb34ef0..c5d31be 100644 --- a/libjava/gnu/java/security/provider/SHA1PRNG.java +++ b/libjava/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. @@ -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) -- cgit v1.1