Updates after code review
authorJon Spillett <jon.spillett@oracle.com>
Tue, 11 Apr 2017 23:45:54 +0000 (09:45 +1000)
committerMatt Caswell <matt@openssl.org>
Wed, 12 Apr 2017 09:05:14 +0000 (10:05 +0100)
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3179)

test/rsa_test.c

index af912eb1988192a52cad24ebb1d1c86e015f2c5c..d441a1d32faf79dfd4bb43e8f45598b2fd3b979e 100644 (file)
@@ -223,6 +223,24 @@ static int pad_unknown(void)
 static const char rnd_seed[] =
     "string to make the random number generator think it has entropy";
 
+static int rsa_setkey(RSA** key, unsigned char* ctext, int idx)
+{
+    int clen = 0;
+    *key = RSA_new();
+    switch (idx) {
+    case 0:
+        clen = key1(*key, ctext);
+        break;
+    case 1:
+        clen = key2(*key, ctext);
+        break;
+    case 2:
+        clen = key3(*key, ctext);
+        break;
+    }
+    return clen;
+}
+
 static int test_rsa_pkcs1(int idx)
 {
     int ret = 0;
@@ -236,19 +254,7 @@ static int test_rsa_pkcs1(int idx)
     int num;
 
     plen = sizeof(ptext_ex) - 1;
-
-    key = RSA_new();
-    switch (idx) {
-    case 0:
-        clen = key1(key, ctext_ex);
-        break;
-    case 1:
-        clen = key2(key, ctext_ex);
-        break;
-    case 2:
-        clen = key3(key, ctext_ex);
-        break;
-    }
+    clen = rsa_setkey(&key, ctext_ex, idx);
 
     num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
                              RSA_PKCS1_PADDING);
@@ -278,22 +284,8 @@ static int test_rsa_oaep(int idx)
     int num;
     int n;
 
-    RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
-
     plen = sizeof(ptext_ex) - 1;
-
-    key = RSA_new();
-    switch (idx) {
-    case 0:
-        clen = key1(key, ctext_ex);
-        break;
-    case 1:
-        clen = key2(key, ctext_ex);
-        break;
-    case 2:
-        clen = key3(key, ctext_ex);
-        break;
-    }
+    clen = rsa_setkey(&key, ctext_ex, idx);
 
     num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
                              RSA_PKCS1_OAEP_PADDING);