Index: source/gnu/crypto/key/BaseKeyAgreementParty.java =================================================================== RCS file: /cvsroot/gnu-crypto/gnu-crypto/source/gnu/crypto/key/BaseKeyAgreementParty.java,v retrieving revision 1.1 diff -u -r1.1 BaseKeyAgreementParty.java --- source/gnu/crypto/key/BaseKeyAgreementParty.java 26 Sep 2003 23:50:48 -0000 1.1 +++ source/gnu/crypto/key/BaseKeyAgreementParty.java 24 Dec 2003 23:53:01 -0000 @@ -43,6 +43,8 @@ // do so, delete this exception statement from your version. // ---------------------------------------------------------------------------- +import gnu.crypto.prng.IRandom; +import gnu.crypto.prng.LimitReachedException; import gnu.crypto.util.PRNG; import java.math.BigInteger; @@ -77,6 +79,9 @@ /** The optional address@hidden SecureRandom} instance to use. */ protected SecureRandom rnd = null; + /** The option address@hidden IRandom} instance to use. */ + protected IRandom irnd = null; + // Constructor(s) // ------------------------------------------------------------------------- @@ -163,6 +168,13 @@ protected void nextRandomBytes(byte[] buffer) { if (rnd != null) { rnd.nextBytes(buffer); + } else if (irnd != null) { + try { + irnd.nextBytes(buffer, 0, buffer.length); + } catch (LimitReachedException lre) { + irnd = null; + PRNG.nextBytes(buffer); + } } else { PRNG.nextBytes(buffer); } Index: source/gnu/crypto/key/dh/DiffieHellmanSender.java =================================================================== RCS file: /cvsroot/gnu-crypto/gnu-crypto/source/gnu/crypto/key/dh/DiffieHellmanSender.java,v retrieving revision 1.1 diff -u -r1.1 DiffieHellmanSender.java --- source/gnu/crypto/key/dh/DiffieHellmanSender.java 26 Sep 2003 23:50:48 -0000 1.1 +++ source/gnu/crypto/key/dh/DiffieHellmanSender.java 24 Dec 2003 23:53:02 -0000 @@ -46,6 +46,7 @@ import gnu.crypto.key.KeyAgreementException; import gnu.crypto.key.IncomingMessage; import gnu.crypto.key.OutgoingMessage; +import gnu.crypto.prng.IRandom; import java.math.BigInteger; import java.security.SecureRandom; @@ -81,7 +82,14 @@ // implementation of abstract methods in base class ------------------------ protected void engineInit(Map attributes) throws KeyAgreementException { - rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS); + Object random = attributes.get(SOURCE_OF_RANDOMNESS); + rnd = null; + irnd = null; + if (random instanceof SecureRandom) { + rnd = (SecureRandom) random; + } else if (random instanceof IRandom) { + irnd = (IRandom) random; + } ownerKey = (DHPrivateKey) attributes.get(KA_DIFFIE_HELLMAN_OWNER_PRIVATE_KEY); if (ownerKey == null) { throw new KeyAgreementException("missing owner's private key"); @@ -111,7 +119,7 @@ do { nextRandomBytes(xBytes); x = new BigInteger(1, xBytes); - } while (x.compareTo(TWO) >= 0 && x.compareTo(p_minus_2) <= 0); + } while (!(x.compareTo(TWO) >= 0 && x.compareTo(p_minus_2) <= 0)); // A sends B the message: g^x mod p OutgoingMessage result = new OutgoingMessage(); Index: source/gnu/crypto/key/dh/DiffieHellmanReceiver.java =================================================================== RCS file: /cvsroot/gnu-crypto/gnu-crypto/source/gnu/crypto/key/dh/DiffieHellmanReceiver.java,v retrieving revision 1.1 diff -u -r1.1 DiffieHellmanReceiver.java --- source/gnu/crypto/key/dh/DiffieHellmanReceiver.java 26 Sep 2003 23:50:48 -0000 1.1 +++ source/gnu/crypto/key/dh/DiffieHellmanReceiver.java 24 Dec 2003 23:53:02 -0000 @@ -46,6 +46,7 @@ import gnu.crypto.key.KeyAgreementException; import gnu.crypto.key.IncomingMessage; import gnu.crypto.key.OutgoingMessage; +import gnu.crypto.prng.IRandom; import java.math.BigInteger; import java.security.SecureRandom; @@ -81,7 +82,14 @@ // implementation of abstract methods in base class ------------------------ protected void engineInit(Map attributes) throws KeyAgreementException { - rnd = (SecureRandom) attributes.get(SOURCE_OF_RANDOMNESS); + Object random = attributes.get(SOURCE_OF_RANDOMNESS); + rnd = null; + irnd = null; + if (random instanceof SecureRandom) { + rnd = (SecureRandom) random; + } else if (random instanceof IRandom) { + irnd = (IRandom) random; + } ownerKey = (DHPrivateKey) attributes.get(KA_DIFFIE_HELLMAN_OWNER_PRIVATE_KEY); if (ownerKey == null) { throw new KeyAgreementException("missing owner's private key"); @@ -115,7 +123,7 @@ do { nextRandomBytes(xBytes); y = new BigInteger(1, xBytes); - } while (y.compareTo(TWO) >= 0 && y.compareTo(p_minus_2) <= 0); + } while (!(y.compareTo(TWO) >= 0 && y.compareTo(p_minus_2) <= 0)); ZZ = m1.modPow(y, p); // ZZ = (yb ^ xa) mod p