@@ -93,17 +93,6 @@ public static RaiseException newDHError(Ruby runtime, String message) {
9393 return Utils .newError (runtime , _PKey (runtime ).getClass ("DHError" ), message );
9494 }
9595
96- private static SecureRandom _secureRandom ;
97-
98- private static SecureRandom getSecureRandom () {
99- SecureRandom rand ;
100- if ((rand = _secureRandom ) != null ) {
101- return rand ;
102- }
103- // FIXME: do we want a particular algorithm / provider? BC?
104- return _secureRandom = new SecureRandom ();
105- }
106-
10796 // transient because: we do not want these value serialized (insecure)
10897 // volatile because: permits unsynchronized reads in some cases
10998 private transient volatile BigInteger dh_p ;
@@ -201,7 +190,7 @@ public static BigInteger generateX(BigInteger p, int limit) {
201190 if (limit < 0 ) throw new IllegalArgumentException ("invalid limit" );
202191
203192 BigInteger x ;
204- SecureRandom secureRandom = getSecureRandom ();
193+ SecureRandom secureRandom = new SecureRandom ();
205194 // adapting algorithm from org.bouncycastle.crypto.generators.DHKeyGeneratorHelper,
206195 // which seems a little stronger (?) than OpenSSL's (OSSL just generates a random,
207196 // while BC generates a random potential prime [for limit > 0], though it's not
@@ -252,11 +241,11 @@ public synchronized IRubyObject generate_key() {
252241 @ JRubyMethod (name = "compute_key" )
253242 public synchronized IRubyObject compute_key (IRubyObject other_pub_key ) {
254243 BigInteger x , y , p ;
255- if ((y = BN .getBigInteger (other_pub_key )) == null ) {
244+ if ((y = BN .asBigInteger (other_pub_key )) == null ) {
256245 throw getRuntime ().newArgumentError ("invalid public key" );
257246 }
258247 if ((x = this .dh_x ) == null || (p = this .dh_p ) == null ) {
259- throw newDHError (getRuntime (), "can't compute key " );
248+ throw newDHError (getRuntime (), "incomplete DH " );
260249 }
261250 int plen ;
262251 if ((plen = p .bitLength ()) == 0 || plen > OPENSSL_DH_MAX_MODULUS_BITS ) {
0 commit comments