]> git.droids-corp.org - dpdk.git/commitdiff
crypto/openssl: fix 3.0 EVP_PKEY usage in RSA operations
authorKai Ji <kai.ji@intel.com>
Tue, 5 Jul 2022 13:16:25 +0000 (21:16 +0800)
committerAkhil Goyal <gakhil@marvell.com>
Tue, 5 Jul 2022 16:30:24 +0000 (18:30 +0200)
EVP_PKEY function need to be called twice for RSA sign
and verify operations in 3.0 EVP API. Original OpenSSL
1.x routines are untouched. The OPENSSL_API_COMPAT is
also removed as the driver now supports OpenSSL 3.0 lib
as well when it is detected on the host.

Fixes: d7bd42f6db19 ("crypto/openssl: update RSA routine with 3.0 EVP API")
Signed-off-by: Kai Ji <kai.ji@intel.com>
drivers/crypto/openssl/rte_openssl_pmd.c
drivers/crypto/openssl/rte_openssl_pmd_ops.c

index 84bca8689423edb351b7511cf0e9403153ebaa2d..e01dacc98d49ee6d1b5a7f296abdc10314ba7012 100644 (file)
@@ -1788,7 +1788,7 @@ process_openssl_dsa_sign_op_evp(struct rte_crypto_op *cop,
        if (key_ctx == NULL
                || EVP_PKEY_fromdata_init(key_ctx) <= 0
                || EVP_PKEY_fromdata(key_ctx, &pkey,
-                                               EVP_PKEY_PUBLIC_KEY, params) <= 0)
+                       EVP_PKEY_KEYPAIR, params) <= 0)
                goto err_dsa_sign;
 
        dsa_ctx = EVP_PKEY_CTX_new(pkey, NULL);
@@ -2478,6 +2478,14 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
                if (EVP_PKEY_CTX_set_rsa_padding(rsa_ctx, pad) <= 0)
                        goto err_rsa;
 
+               if (EVP_PKEY_sign(rsa_ctx, NULL, &outlen,
+                               op->rsa.message.data,
+                               op->rsa.message.length) <= 0)
+                       goto err_rsa;
+
+               if (outlen <= 0)
+                       goto err_rsa;
+
                if (EVP_PKEY_sign(rsa_ctx, op->rsa.sign.data, &outlen,
                                op->rsa.message.data,
                                op->rsa.message.length) <= 0)
@@ -2486,19 +2494,23 @@ process_openssl_rsa_op_evp(struct rte_crypto_op *cop,
                break;
 
        case RTE_CRYPTO_ASYM_OP_VERIFY:
-               tmp = rte_malloc(NULL, op->rsa.sign.length, 0);
-               if (tmp == NULL) {
-                       OPENSSL_LOG(ERR, "Memory allocation failed");
+               if (EVP_PKEY_verify_recover_init(rsa_ctx) <= 0)
                        goto err_rsa;
-               }
 
-               if (EVP_PKEY_verify_recover_init(rsa_ctx) <= 0) {
-                       rte_free(tmp);
+               if (EVP_PKEY_CTX_set_rsa_padding(rsa_ctx, pad) <= 0)
                        goto err_rsa;
-               }
 
-               if (EVP_PKEY_CTX_set_rsa_padding(rsa_ctx, pad) <= 0) {
-                       rte_free(tmp);
+               if (EVP_PKEY_verify_recover(rsa_ctx, NULL, &outlen,
+                               op->rsa.sign.data,
+                               op->rsa.sign.length) <= 0)
+                       goto err_rsa;
+
+               if ((outlen <= 0) || (outlen != op->rsa.sign.length))
+                       goto err_rsa;
+
+               tmp = OPENSSL_malloc(outlen);
+               if (tmp == NULL) {
+                       OPENSSL_LOG(ERR, "Memory allocation failed");
                        goto err_rsa;
                }
 
index 8d1f8e834a77ea9df71046b42573c23e6e27a63a..3e24ef94f7fe69aef86a03b516d36895b75cf4fb 100644 (file)
@@ -2,8 +2,6 @@
  * Copyright(c) 2016-2017 Intel Corporation
  */
 
-#define OPENSSL_API_COMPAT 0x10100000L
-
 #include <string.h>
 
 #include <rte_common.h>