From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C16D342BA9; Fri, 26 May 2023 11:12:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8F3E242D3A; Fri, 26 May 2023 11:12:15 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id C48CD42D0B for ; Fri, 26 May 2023 11:12:14 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34Q1qSRk031947; Fri, 26 May 2023 02:12:14 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=X81RC5HYuj8QPq9kD/hMngaFKCc1cflihn+L3BmOlTc=; b=XzDP5tutlYoa5Ha7dRH8BY3wFpUfR1k9sPDnPOlTfLw6L7e/FR9A1wEGJrWGOPh6Im1u gwiOa8m7zZLa5yXkZLggCSLiz+BCR30fLR+VVAcXEFjwsJa8glliAyc2LkHsUR52T8Zq O6KCerpQCjZEFybdjBJSwnkWQCaxm/bFb0735IGFMcck5jGfA9k8lFFGlDBCikmDAhtf X64jDJ4q5SAyi6h4ataxdcywRv9k8bwnRZ8wWD4ft+GPS4m1qrC/kyLDnGxTXhcPDJDD SoGF+/RJyDPyBDYPWkorqf+DdHMkJvjBFZKdPCcCv+q9xtT3n6gJSqnqpSPzVwlGleCj 9w== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3qtg6t24mu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 26 May 2023 02:12:13 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 26 May 2023 02:12:12 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 26 May 2023 02:12:12 -0700 Received: from BG-LT91401.marvell.com (unknown [10.193.69.246]) by maili.marvell.com (Postfix) with ESMTP id 416D63F7057; Fri, 26 May 2023 02:12:09 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Akhil Goyal , Fan Zhang , Gowrishankar Muthukrishnan Subject: [PATCH v2 1/3] cryptodev: add SM2 asymmetric crypto algorithm Date: Fri, 26 May 2023 14:42:02 +0530 Message-ID: <2c0f5049ca90891adb61b2bdfa3c96dbde0e95c2.1685091909.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: wR_5nGDhzvFIDHOlai4VMcSrOgBWC_5b X-Proofpoint-GUID: wR_5nGDhzvFIDHOlai4VMcSrOgBWC_5b X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-26_01,2023-05-25_03,2023-05-22_02 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org ShangMi 2 (SM2) is a encryption and digital signature algorithm used in the Chinese National Standard. Added support for asymmetric SM2 in cryptodev along with prime field curve, as referenced in RFC: https://datatracker.ietf.org/doc/html/draft-shen-sm2-ecdsa-02 Signed-off-by: Gowrishankar Muthukrishnan --- doc/guides/cryptodevs/features/default.ini | 1 + doc/guides/rel_notes/release_23_07.rst | 5 ++ lib/cryptodev/rte_crypto_asym.h | 77 ++++++++++++++++++++++ lib/cryptodev/rte_cryptodev.c | 1 + 4 files changed, 84 insertions(+) diff --git a/doc/guides/cryptodevs/features/default.ini b/doc/guides/cryptodevs/features/default.ini index 523da0cfa8..a69967bb9e 100644 --- a/doc/guides/cryptodevs/features/default.ini +++ b/doc/guides/cryptodevs/features/default.ini @@ -125,6 +125,7 @@ Diffie-hellman = ECDSA = ECPM = ECDH = +SM2 = ; ; Supported Operating systems of a default crypto driver. diff --git a/doc/guides/rel_notes/release_23_07.rst b/doc/guides/rel_notes/release_23_07.rst index a9b1293689..8b8e69d619 100644 --- a/doc/guides/rel_notes/release_23_07.rst +++ b/doc/guides/rel_notes/release_23_07.rst @@ -55,6 +55,11 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added SM2 asymmetric algorithm in cryptodev.** + + Added support for ShamMi 2 (SM2) asymmetric crypto algorithm + along with prime field curve support. + Removed Items ------------- diff --git a/lib/cryptodev/rte_crypto_asym.h b/lib/cryptodev/rte_crypto_asym.h index 989f38323f..35fa2c0a6d 100644 --- a/lib/cryptodev/rte_crypto_asym.h +++ b/lib/cryptodev/rte_crypto_asym.h @@ -119,6 +119,11 @@ enum rte_crypto_asym_xform_type { /**< Elliptic Curve Point Multiplication */ RTE_CRYPTO_ASYM_XFORM_ECFPM, /**< Elliptic Curve Fixed Point Multiplication */ + RTE_CRYPTO_ASYM_XFORM_SM2, + /**< ShangMi 2 + * Performs Encrypt, Decrypt, Sign and Verify. + * Refer to rte_crypto_asym_op_type. + */ RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END /**< End of list */ }; @@ -382,6 +387,20 @@ struct rte_crypto_ec_xform { /**< Pre-defined ec groups */ }; +/** + * Asymmetric SM2 transform data + * + * Structure describing SM2 xform params + * + */ +struct rte_crypto_sm2_xform { + rte_crypto_uint pkey; + /**< Private key of the signer for signature generation. */ + + struct rte_crypto_ec_point q; + /**< Public key of the signer for verification. */ +}; + /** * Operations params for modular operations: * exponentiation and multiplicative inverse @@ -637,9 +656,66 @@ struct rte_crypto_asym_xform { /**< EC xform parameters, used by elliptic curve based * operations. */ + + struct rte_crypto_sm2_xform sm2; + /**< SM2 xform parameters */ }; }; +/** + * SM2 operation params + */ +struct rte_crypto_sm2_op_param { + enum rte_crypto_asym_op_type op_type; + /**< Signature generation or verification */ + + rte_crypto_param message; + /**< + * Pointer to input data + * - to be encrypted for SM2 public encrypt. + * - to be signed for SM2 sign generation. + * - to be authenticated for SM2 sign verification. + * + * Pointer to output data + * - for SM2 private decrypt. + * In this case the underlying array should have been + * allocated with enough memory to hold plaintext output + * (at least encrypted text length). The message.length field + * will be overwritten by the PMD with the decrypted length. + */ + + rte_crypto_param cipher; + /**< + * Pointer to input data + * - to be decrypted for SM2 private decrypt. + * + * Pointer to output data + * - for SM2 public encrypt. + * In this case the underlying array should have been allocated + * with enough memory to hold ciphertext output (at least X bytes + * for prime field curve of N bytes and for message M bytes, + * where X = (C1 + C2 + C3) and computed based on SM2 RFC as + * C1 (1 + N + N), C2 = M, C3 = N. The cipher.length field will + * be overwritten by the PMD with the encrypted length. + */ + + rte_crypto_uint id; + /**< The SM2 id used by signer and verifier and is in interval (1, n-1). */ + + rte_crypto_uint r; + /**< r component of elliptic curve signature + * output : for signature generation (of at least N bytes + * where prime field length is N bytes) + * input : for signature verification + */ + rte_crypto_uint s; + /**< s component of elliptic curve signature + * output : for signature generation (of at least N bytes + * where prime field length is N bytes) + * input : for signature verification + */ +}; + /** * Asymmetric Cryptographic Operation. * @@ -665,6 +741,7 @@ struct rte_crypto_asym_op { struct rte_crypto_dsa_op_param dsa; struct rte_crypto_ecdsa_op_param ecdsa; struct rte_crypto_ecpm_op_param ecpm; + struct rte_crypto_sm2_op_param sm2; }; uint16_t flags; /**< diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c index a96114b2da..21cabc3ffd 100644 --- a/lib/cryptodev/rte_cryptodev.c +++ b/lib/cryptodev/rte_cryptodev.c @@ -299,6 +299,7 @@ crypto_asym_xform_strings[] = { [RTE_CRYPTO_ASYM_XFORM_DSA] = "dsa", [RTE_CRYPTO_ASYM_XFORM_ECDSA] = "ecdsa", [RTE_CRYPTO_ASYM_XFORM_ECPM] = "ecpm", + [RTE_CRYPTO_ASYM_XFORM_SM2] = "sm2", }; /** -- 2.25.1