[rs-commit] r91 - /redwax-tool/trunk/redwax_openssl.c

rs-commit at redwax.eu rs-commit at redwax.eu
Fri Nov 26 20:20:39 CET 2021


Author: minfrin at redwax.eu
Date: Fri Nov 26 20:20:38 2021
New Revision: 91

Log:
Use the OSSL_PKEY_PARAM_RSA_COEFFICIENT1 label.

Ensure that any missing parameters are guarded for.

Modified:
    redwax-tool/trunk/redwax_openssl.c

Modified: redwax-tool/trunk/redwax_openssl.c
==============================================================================
--- redwax-tool/trunk/redwax_openssl.c	(original)
+++ redwax-tool/trunk/redwax_openssl.c	Fri Nov 26 20:20:38 2021
@@ -3125,7 +3125,7 @@
             EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_FACTOR2, &q);
             EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT1, &dmp1);
             EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT2, &dmq1);
-            EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_COEFFICIENT, &iqmp);
+            EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_COEFFICIENT1, &iqmp);
 #else
             RSA *rsa = EVP_PKEY_get1_RSA(pkey);
 
@@ -3142,46 +3142,62 @@
             key->rsa = apr_pcalloc(key->pool, sizeof(redwax_key_rsa_t));
 
             /* public */
-            key->rsa->modulus_len = BN_num_bytes(n);
-            key->rsa->modulus = apr_palloc(key->pool,
-                    key->rsa->modulus_len);
-            BN_bn2bin(n, key->rsa->modulus);
-
-            key->rsa->public_exponent_len = BN_num_bytes(e);
-            key->rsa->public_exponent = apr_palloc(key->pool,
-                    key->rsa->public_exponent_len);
-            BN_bn2bin(e, key->rsa->public_exponent);
+            if (n) {
+                key->rsa->modulus_len = BN_num_bytes(n);
+                key->rsa->modulus = apr_palloc(key->pool,
+                        key->rsa->modulus_len);
+                BN_bn2bin(n, key->rsa->modulus);
+            }
+
+            if (e) {
+                key->rsa->public_exponent_len = BN_num_bytes(e);
+                key->rsa->public_exponent = apr_palloc(key->pool,
+                        key->rsa->public_exponent_len);
+                BN_bn2bin(e, key->rsa->public_exponent);
+            }
 
             /* private */
-            key->rsa->private_exponent_len = BN_num_bytes(d);
-            key->rsa->private_exponent = apr_palloc(key->pool,
-                    key->rsa->private_exponent_len);
-            BN_bn2bin(d, key->rsa->private_exponent);
-
-            key->rsa->prime_1_len = BN_num_bytes(p);
-            key->rsa->prime_1 = apr_palloc(key->pool,
-                    key->rsa->prime_1_len);
-            BN_bn2bin(p, key->rsa->prime_1);
-
-            key->rsa->prime_2_len = BN_num_bytes(q);
-            key->rsa->prime_2 = apr_palloc(key->pool,
-                    key->rsa->prime_2_len);
-            BN_bn2bin(q, key->rsa->prime_2);
-
-            key->rsa->exponent_1_len = BN_num_bytes(dmp1);
-            key->rsa->exponent_1 = apr_palloc(key->pool,
-                    key->rsa->exponent_1_len);
-            BN_bn2bin(dmp1, key->rsa->exponent_1);
-
-            key->rsa->exponent_2_len = BN_num_bytes(dmq1);
-            key->rsa->exponent_2 = apr_palloc(key->pool,
-                    key->rsa->exponent_2_len);
-            BN_bn2bin(dmq1, key->rsa->exponent_2);
-
-            key->rsa->coefficient_len = BN_num_bytes(iqmp);
-            key->rsa->coefficient = apr_palloc(key->pool,
-                    key->rsa->coefficient_len);
-            BN_bn2bin(iqmp, key->rsa->coefficient);
+            if (d) {
+                key->rsa->private_exponent_len = BN_num_bytes(d);
+                key->rsa->private_exponent = apr_palloc(key->pool,
+                        key->rsa->private_exponent_len);
+                BN_bn2bin(d, key->rsa->private_exponent);
+            }
+
+            if (p) {
+                key->rsa->prime_1_len = BN_num_bytes(p);
+                key->rsa->prime_1 = apr_palloc(key->pool,
+                        key->rsa->prime_1_len);
+                BN_bn2bin(p, key->rsa->prime_1);
+            }
+
+            if (q) {
+                key->rsa->prime_2_len = BN_num_bytes(q);
+                key->rsa->prime_2 = apr_palloc(key->pool,
+                        key->rsa->prime_2_len);
+                BN_bn2bin(q, key->rsa->prime_2);
+            }
+
+            if (dmp1) {
+                key->rsa->exponent_1_len = BN_num_bytes(dmp1);
+                key->rsa->exponent_1 = apr_palloc(key->pool,
+                        key->rsa->exponent_1_len);
+                BN_bn2bin(dmp1, key->rsa->exponent_1);
+            }
+
+            if (dmq1) {
+                key->rsa->exponent_2_len = BN_num_bytes(dmq1);
+                key->rsa->exponent_2 = apr_palloc(key->pool,
+                        key->rsa->exponent_2_len);
+                BN_bn2bin(dmq1, key->rsa->exponent_2);
+            }
+
+            if (iqmp) {
+                key->rsa->coefficient_len = BN_num_bytes(iqmp);
+                key->rsa->coefficient = apr_palloc(key->pool,
+                        key->rsa->coefficient_len);
+                BN_bn2bin(iqmp, key->rsa->coefficient);
+            }
 
             /* key type is RSA */
             key->common.type = REDWAX_KEY_RSA;



More information about the rs-commit mailing list