DPDK usage discussions
 help / color / mirror / Atom feed
From: "Kusztal, ArkadiuszX" <arkadiuszx.kusztal@intel.com>
To: ossama ahmed <ossamaahmedmughal@hotmail.com>,
	"users@dpdk.org" <users@dpdk.org>
Cc: "Zhang, Roy Fan" <roy.fan.zhang@intel.com>, "Ji, Kai" <kai.ji@intel.com>
Subject: RE: OpenSSL Crypto Poll Mode Driver
Date: Fri, 1 Apr 2022 13:40:57 +0000
Message-ID: <PH0PR11MB50131EFB407F9C0BED35653D9FE09@PH0PR11MB5013.namprd11.prod.outlook.com> (raw)
In-Reply-To: <DB9P195MB12254755390BB7662CAB6873B2E09@DB9P195MB1225.EURP195.PROD.OUTLOOK.COM>

[-- Attachment #1: Type: text/plain, Size: 5874 bytes --]

Hi Ossama,

Please see answers inline with [Arek]

From: ossama ahmed <ossamaahmedmughal@hotmail.com>
Sent: Friday, April 1, 2022 1:18 PM
To: users@dpdk.org
Subject: Fw: OpenSSL Crypto Poll Mode Driver




Sent from Outlook<http://aka.ms/weboutlook>

________________________________
From: ossama ahmed
Sent: Friday, April 1, 2022 11:10 AM
To: users-request@dpdk.org<mailto:users-request@dpdk.org> <users-request@dpdk.org<mailto:users-request@dpdk.org>>
Subject: OpenSSL Crypto Poll Mode Driver

Hello,

I would like to highlight following issues in OpenSSL Crypto Poll Mode Driver and OpenSSL vdev related to RSA Sign and Verify operations.

ISSUES:
ISSUE1 (RSA_private_encrypt and RSA_public_decrypt)

With respect to https://www.openssl.org/docs/manmaster/man3/RSA_private_encrypt.html .Both of the functions are deprecated. Applications should instead use EVP_PKEY_sign_init_ex, EVP_PKEY_sign, EVP_PKEY_verify_recover_init, and EVP_PKEY_verify_recover.

Although I understand that due to compatibility reasons, DPDK is using native (in my case on Ubuntu 20.04.1 its 1.1.1f version of) OpenSSL but With respect
to OpenSSL's version 1.1.1f APIs "RSA_private_encrypt" and "RSA_public_decrypt" but in case of RSA_PKCS1_PADDING it is recomended that when generating or verifying
PKCS #1 signatures, RSA_sign(3) and RSA_verify(3) should be used.

POSSIBLE SOLUTION
1. Use RSA_sign, RSA_verify, EVP_DigestSignFinal, EVP_DigestSign etc instead.

[Arek] - RSA_sign and RSA_verify are now deprecated too.

2. Append algorithm identifier field to digest before signing. Details can be found in section EMSA-PKCS1-v1_5 availbel on https://datatracker.ietf.org/doc/html/rfc8017#section-9.2

For example in case if RSA is using SHA256 for digest generation then DigestInfo value is:
SHA-256: (0x)30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00 04 20 || H where H is the digest of data
Hence appropriate AIDs (i.e algorithm identifiers) must be appended to digest. Once this done then in case of RSA_PKCS1_PADDING, APIs RSA_private_encrypt and RSA_public_decrypt are compatible with RSA_sign, RSA_verify, EVP_DigestSignFinal, EVP_DigestSign and verify respectively.


[Arek] - yes, you are perfectly correct, this Is general Cryptodev API problem. Proposals to fix that were sent already:
https://patchwork.dpdk.org/project/dpdk/list/?series=22203.
When PKCS1 we should not worry about algorithmIdentifier from user perspective, although there was an option to do PKCS1 padding without it too (pre tls1.2 PKCS1.5 padding was used with 36 bytes hash concatenation for example), discussion was started on dev mailing list. As for OpenSSL PMD simultaneously we are working to fix that.


ISSUE2 (OpenSSL Crypto Poll Mode Driver vs RSA PSS Padding)
Current DPDK's OpenSSL Crypto Poll Mode Driver fails to verify signature generated using RSA PSS Padding. Also with respect to latest version of DPDK there is no handling available in OpenSSL Crypto Poll Mode Driver for RTE_CRYPTO_RSA_PADDING_PSS. Current implementation handles only RTE_CRYPTO_RSA_PADDING_NONE and
RTE_CRYPTO_RSA_PADDING_PKCS1_5 for signing and verification.

[Arek] - yes, PSS should be implemented too. Registration of openssl random engine should allow us to check known answer tests too not only PWCT, could you resend your proposal to dev list?

1. EVP_DigestSignFinal, EVP_DigestSign etc instead.

2. As coded in OpenSSL (crypto/rsa/rsa_pmeth.c +268):
else if (rctx->pad_mode == RSA_PKCS1_PSS_PADDING) {
            int ret;
            if (!setup_tbuf(rctx, ctx))
                return -1;
            ret = RSA_public_decrypt(siglen, sig, rctx->tbuf, rsa, RSA_NO_PADDING);

            if (ret <= 0)
                return 0;
            ret = RSA_verify_PKCS1_PSS_mgf1(rsa, tbs, rctx->md, rctx->mgf1md, rctx->tbuf, rctx->saltlen);
[Arek] - whole openssl low level api is deprecated now, these functions as well so we wont be using it.
            if (ret <= 0)
                return 0;
            return 1;
        }
However, in order to use above implementation changes are required in OpenSSL Crypto Poll Mode Driver (drivers/crypto/openssl/rte_openssl_pmd.c +1945) for example

       case RTE_CRYPTO_ASYM_OP_VERIFY:
                tmp = rte_malloc(NULL, op->rsa.sign.length, 0);
                if (tmp == NULL) {
                        OPENSSL_LOG(ERR, "Memory allocation failed");
                        cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
                        break;
                }
                ret = RSA_public_decrypt(op->rsa.sign.length,
                                op->rsa.sign.data,
                                tmp,
                                rsa,
                                pad);

                OPENSSL_LOG(DEBUG,
                                "Length of public_decrypt %d "
                                "length of message %zd\n",
                                ret, op->rsa.message.length);
                //FIXME
                if(pad == RSA_NO_PADDING && ret)
                        memcpy(op->rsa.message.data, tmp, op->rsa.sign.length);
                else if ((ret <= 0) || (CRYPTO_memcmp(tmp, op->rsa.message.data,
                                op->rsa.message.length))) {
                        OPENSSL_LOG(ERR, "RSA sign Verification failed");
                        cop->status = RTE_CRYPTO_OP_STATUS_ERROR;
                }
                //FIXME
                rte_free(tmp);
                break;

                Complete details are availble in section 8.1.2 of https://datatracker.ietf.org/doc/html/rfc8017#section-8.1.2


I have handled the above mentioned issues in DPDK using my own custom implementation. I would love to share details if required for further clarification

Regards,
Ossama Ahmed Mughal



[-- Attachment #2: Type: text/html, Size: 16070 bytes --]

  reply	other threads:[~2022-04-01 13:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <DB9P195MB12252F3886270BDBBE4047D2B2E09@DB9P195MB1225.EURP195.PROD.OUTLOOK.COM>
2022-04-01 11:17 ` Fw: " ossama ahmed
2022-04-01 13:40   ` Kusztal, ArkadiuszX [this message]
2022-04-01 14:20     ` Ji, Kai
2022-04-01 15:22       ` ossama ahmed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=PH0PR11MB50131EFB407F9C0BED35653D9FE09@PH0PR11MB5013.namprd11.prod.outlook.com \
    --to=arkadiuszx.kusztal@intel.com \
    --cc=kai.ji@intel.com \
    --cc=ossamaahmedmughal@hotmail.com \
    --cc=roy.fan.zhang@intel.com \
    --cc=users@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

DPDK usage discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.dpdk.org/users/0 users/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 users users/ http://inbox.dpdk.org/users \
		users@dpdk.org
	public-inbox-index users

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git