@@ -500,6 +500,7 @@ public void threadedRsaSignVerifyTest() throws InterruptedException {
500500
501501 Rsa priv = null ;
502502 Rsa pub = null ;
503+ Rng threadRng = null ;
503504
504505 byte [] n_out = new byte [256 ];
505506 byte [] e_out = new byte [3 ];
@@ -509,23 +510,27 @@ public void threadedRsaSignVerifyTest() throws InterruptedException {
509510 e_len [0 ] = e_out .length ;
510511
511512 try {
513+ /* Each thread needs its own RNG for FIPS */
514+ threadRng = new Rng ();
515+ threadRng .init ();
516+
512517 priv = new Rsa ();
513518 priv .decodePrivateKey (prvKey );
514519 priv .exportRawPublicKey (n_out , n_len , e_out , e_len );
515- priv .setRng (rng );
520+ priv .setRng (threadRng );
516521
517522 pub = new Rsa ();
518523 pub .decodeRawPublicKey (n_out , e_out );
519524
520- byte [] ciphertext = pub .encrypt (plaintext , rng );
525+ byte [] ciphertext = pub .encrypt (plaintext , threadRng );
521526
522527 if (!Arrays .equals (plaintext ,
523528 priv .decrypt (ciphertext ))) {
524529 failed = 1 ;
525530 }
526531
527532 if (failed == 0 ) {
528- byte [] signature = priv .sign (plaintext , rng );
533+ byte [] signature = priv .sign (plaintext , threadRng );
529534
530535 if (!Arrays .equals (plaintext ,
531536 pub .verify (signature ))) {
@@ -538,6 +543,10 @@ public void threadedRsaSignVerifyTest() throws InterruptedException {
538543 failed = 1 ;
539544
540545 } finally {
546+ if (threadRng != null ) {
547+ threadRng .free ();
548+ threadRng .releaseNativeStruct ();
549+ }
541550 priv .releaseNativeStruct ();
542551 pub .releaseNativeStruct ();
543552 latch .countDown ();
0 commit comments