[rs-commit] r92 - /redwax-tool/trunk/redwax_p11kit.c

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


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

Log:
Pass the correct rsa key parameters in the pkcs11
case. Protect against missing parameters.

Modified:
    redwax-tool/trunk/redwax_p11kit.c

Modified: redwax-tool/trunk/redwax_p11kit.c
==============================================================================
--- redwax-tool/trunk/redwax_p11kit.c	(original)
+++ redwax-tool/trunk/redwax_p11kit.c	Fri Nov 26 20:38:01 2021
@@ -655,35 +655,52 @@
                 /* Do we support CKA_DERIVE or CKA_ALLOWED_MECHANISMS? */
 
                 /* public / private */
-                redwax_pkcs11_add_attribute(publicTemplate, CKA_MODULUS,
-                        (void*) &key->rsa->modulus, key->rsa->modulus_len);
-                redwax_pkcs11_add_attribute(privateTemplate, CKA_MODULUS,
-                        (void*) &key->rsa->modulus, key->rsa->modulus_len);
-                redwax_pkcs11_add_attribute(publicTemplate,
-                        CKA_PUBLIC_EXPONENT, (void*) &key->rsa->public_exponent,
-                        key->rsa->public_exponent_len);
-                redwax_pkcs11_add_attribute(privateTemplate,
-                        CKA_PUBLIC_EXPONENT, (void*) &key->rsa->public_exponent,
-                        key->rsa->public_exponent_len);
+                if (key->rsa->modulus_len) {
+                    redwax_pkcs11_add_attribute(publicTemplate, CKA_MODULUS,
+                            key->rsa->modulus, key->rsa->modulus_len);
+                }
+                if (key->rsa->modulus_len) {
+                    redwax_pkcs11_add_attribute(privateTemplate, CKA_MODULUS,
+                            key->rsa->modulus, key->rsa->modulus_len);
+                }
+                if (key->rsa->public_exponent_len) {
+                    redwax_pkcs11_add_attribute(publicTemplate,
+                    CKA_PUBLIC_EXPONENT, key->rsa->public_exponent,
+                            key->rsa->public_exponent_len);
+                }
+                if (key->rsa->public_exponent_len) {
+                    redwax_pkcs11_add_attribute(privateTemplate,
+                    CKA_PUBLIC_EXPONENT, key->rsa->public_exponent,
+                            key->rsa->public_exponent_len);
+                }
 
                 /* private only */
-                redwax_pkcs11_add_attribute(privateTemplate,
-                        CKA_PRIVATE_EXPONENT,
-                        (void*) &key->rsa->private_exponent,
-                        key->rsa->private_exponent_len);
-                redwax_pkcs11_add_attribute(privateTemplate, CKA_PRIME_1,
-                        (void*) &key->rsa->prime_1, key->rsa->prime_1_len);
-                redwax_pkcs11_add_attribute(privateTemplate, CKA_PRIME_2,
-                        (void*) &key->rsa->prime_2, key->rsa->prime_2_len);
-                redwax_pkcs11_add_attribute(privateTemplate, CKA_EXPONENT_1,
-                        (void*) &key->rsa->exponent_1,
-                        key->rsa->exponent_1_len);
-                redwax_pkcs11_add_attribute(privateTemplate, CKA_EXPONENT_2,
-                        (void*) &key->rsa->exponent_2,
-                        key->rsa->exponent_2_len);
-                redwax_pkcs11_add_attribute(privateTemplate, CKA_COEFFICIENT,
-                        (void*) &key->rsa->coefficient,
-                        key->rsa->coefficient_len);
+                if (key->rsa->private_exponent_len) {
+                    redwax_pkcs11_add_attribute(privateTemplate,
+                    CKA_PRIVATE_EXPONENT, key->rsa->private_exponent,
+                            key->rsa->private_exponent_len);
+                }
+                if (key->rsa->prime_1_len) {
+                    redwax_pkcs11_add_attribute(privateTemplate, CKA_PRIME_1,
+                            key->rsa->prime_1, key->rsa->prime_1_len);
+                }
+                if (key->rsa->prime_2_len) {
+                    redwax_pkcs11_add_attribute(privateTemplate, CKA_PRIME_2,
+                            key->rsa->prime_2, key->rsa->prime_2_len);
+                }
+                if (key->rsa->exponent_1_len) {
+                    redwax_pkcs11_add_attribute(privateTemplate, CKA_EXPONENT_1,
+                            key->rsa->exponent_1, key->rsa->exponent_1_len);
+                }
+                if (key->rsa->exponent_2_len) {
+                    redwax_pkcs11_add_attribute(privateTemplate, CKA_EXPONENT_2,
+                            key->rsa->exponent_2, key->rsa->exponent_2_len);
+                }
+                if (key->rsa->coefficient_len) {
+                    redwax_pkcs11_add_attribute(privateTemplate,
+                    CKA_COEFFICIENT, key->rsa->coefficient,
+                            key->rsa->coefficient_len);
+                }
 
             }
 



More information about the rs-commit mailing list