Add answers for EVP_PKEY_get_default_digest_name() in RSA and DSA keymgmt
authorRichard Levitte <levitte@openssl.org>
Mon, 13 Jan 2020 07:54:47 +0000 (08:54 +0100)
committerRichard Levitte <levitte@openssl.org>
Thu, 23 Jan 2020 16:59:12 +0000 (17:59 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10824)

providers/implementations/keymgmt/dsa_kmgmt.c
providers/implementations/keymgmt/rsa_kmgmt.c

index c2c3c22..5a53a43 100644 (file)
@@ -24,6 +24,8 @@ static OSSL_OP_keymgmt_importkey_fn dsa_importkey;
 static OSSL_OP_keymgmt_exportkey_fn dsa_exportkey;
 static OSSL_OP_keymgmt_get_key_params_fn dsa_get_key_params;
 
+#define DSA_DEFAULT_MD "SHA256"
+
 static int params_to_domparams(DSA *dsa, const OSSL_PARAM params[])
 {
     const OSSL_PARAM *param_p, *param_q, *param_g;
@@ -211,6 +213,9 @@ static ossl_inline int dsa_get_dpk_params(void *key, OSSL_PARAM params[])
     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL
         && !OSSL_PARAM_set_int(p, DSA_size(dsa)))
         return 0;
+    if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL
+        && !OSSL_PARAM_set_utf8_string(p, DSA_DEFAULT_MD))
+        return 0;
     return 1;
 }
 
index a1f8104..54e4c54 100644 (file)
@@ -10,7 +10,9 @@
 #include <openssl/core_numbers.h>
 #include <openssl/core_names.h>
 #include <openssl/bn.h>
+#include <openssl/err.h>
 #include <openssl/rsa.h>
+#include <openssl/evp.h>
 #include <openssl/params.h>
 #include <openssl/types.h>
 #include "internal/param_build.h"
@@ -22,6 +24,8 @@ static OSSL_OP_keymgmt_importkey_fn rsa_importkey;
 static OSSL_OP_keymgmt_exportkey_fn rsa_exportkey;
 static OSSL_OP_keymgmt_get_key_params_fn rsa_get_key_params;
 
+#define RSA_DEFAULT_MD "SHA256"
+
 DEFINE_STACK_OF(BIGNUM)
 DEFINE_SPECIAL_STACK_OF_CONST(BIGNUM_const, BIGNUM)
 
@@ -259,6 +263,28 @@ static int rsa_get_key_params(void *key, OSSL_PARAM params[])
     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL
         && !OSSL_PARAM_set_int(p, RSA_size(rsa)))
         return 0;
+
+# if 0                           /* PSS support pending */
+    if ((p = OSSL_PARAM_locate(params,
+                               OSSL_PKEY_PARAM_MANDATORY_DIGEST)) != NULL
+        && RSA_get0_pss_params(rsa) != NULL) {
+        const EVP_MD *md, *mgf1md;
+        int min_saltlen;
+
+        if (!rsa_pss_get_param(RSA_get0_pss_params(rsa),
+                               &md, &mgf1md, &min_saltlen)) {
+            ERR_raise(ERR_LIB_PROV, ERR_R_INTERNAL_ERROR);
+            return 0;
+        }
+        if (!OSSL_PARAM_set_utf8_string(p, EVP_MD_name(md)))
+            return 0;
+    }
+#endif
+    if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL
+        && RSA_get0_pss_params(rsa) == NULL)
+        if (!OSSL_PARAM_set_utf8_string(p, RSA_DEFAULT_MD))
+            return 0;
+
     return 1;
 }