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 EEDF645E4C; Fri, 13 Dec 2024 13:58:56 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B905E409FA; Fri, 13 Dec 2024 13:58:56 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) by mails.dpdk.org (Postfix) with ESMTP id AD606402BB for ; Fri, 13 Dec 2024 13:58:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1734094735; x=1765630735; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=fTF9vigFelinvYY0qJXSqK79q5ftiE1dvSsMTzf1LCY=; b=IjgPoVqoT2UeCwpcc0mxtfImFmq2gShq0w+ATZwSD73Rneh4+JJuhSm3 NJ9UPBYNyinvlui6zhv+8pGFAde05By/98undWLZ4IFMqbBLdcLeo8D8R ErT+0n1F8rowKIe5PnsodQv/woeq7jXujZC9eXbTkpkWWd7gB2839Uzxe UrrCF18QXNACbNRZM43cNgvEMGovQsoFUk5a0ZTF8A9PHWRzG9oNzuoet SjoC6sYHEu22uA4ydbATCZsXv06xVfUYCxx7IMFEDtlBk708XdeBRKutF WyCvAFjXO15mfcFKRmOY8stl+O2m7TYpMQlxpCDpr16DXUDnSsC7nvrLr w==; X-CSE-ConnectionGUID: 9zgQcHsIQVK8pWvUPaennA== X-CSE-MsgGUID: A37IrbRKTHaitxsUO+8atw== X-IronPort-AV: E=McAfee;i="6700,10204,11285"; a="34275578" X-IronPort-AV: E=Sophos;i="6.12,231,1728975600"; d="scan'208";a="34275578" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2024 04:58:54 -0800 X-CSE-ConnectionGUID: m/cND8ZWRh6ELY9pI+6HdQ== X-CSE-MsgGUID: 3ihImw/CQcmAK5sXLlP9JQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,231,1728975600"; d="scan'208";a="101376278" Received: from silpixa00400886.ir.intel.com ([10.243.22.139]) by fmviesa004.fm.intel.com with ESMTP; 13 Dec 2024 04:58:52 -0800 From: Brian Dooley To: Kai Ji , Pablo de Lara , Akhil Goyal , Fan Zhang Cc: dev@dpdk.org, Brian Dooley Subject: [PATCH v1 1/2] crypto/ipsec_mb: add SM4 GCM support Date: Fri, 13 Dec 2024 12:58:48 +0000 Message-Id: <20241213125850.2714328-1-brian.dooley@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 This patch introduces SM4 GCM algorithm support to the AESNI_MB PMD. SM4 GCM is available in the v2.0 release of Intel IPsec MB. Signed-off-by: Brian Dooley --- doc/guides/cryptodevs/aesni_mb.rst | 1 + doc/guides/cryptodevs/features/aesni_mb.ini | 1 + doc/guides/cryptodevs/features/default.ini | 2 ++ doc/guides/rel_notes/release_25_03.rst | 4 +++ drivers/crypto/ipsec_mb/pmd_aesni_mb.c | 37 +++++++++++++++++++-- drivers/crypto/ipsec_mb/pmd_aesni_mb_priv.h | 30 +++++++++++++++++ lib/cryptodev/rte_crypto_sym.h | 4 ++- lib/cryptodev/rte_cryptodev.c | 3 +- 8 files changed, 78 insertions(+), 4 deletions(-) diff --git a/doc/guides/cryptodevs/aesni_mb.rst b/doc/guides/cryptodevs/aesni_mb.rst index 16d82147b2..8d7e221e79 100644 --- a/doc/guides/cryptodevs/aesni_mb.rst +++ b/doc/guides/cryptodevs/aesni_mb.rst @@ -67,6 +67,7 @@ AEAD algorithms: * RTE_CRYPTO_AEAD_AES_CCM * RTE_CRYPTO_AEAD_AES_GCM * RTE_CRYPTO_AEAD_CHACHA20_POLY1305 +* RTE_CRYPTO_AEAD_SM4_GCM Protocol offloads: diff --git a/doc/guides/cryptodevs/features/aesni_mb.ini b/doc/guides/cryptodevs/features/aesni_mb.ini index ebe00d075d..c648be62fb 100644 --- a/doc/guides/cryptodevs/features/aesni_mb.ini +++ b/doc/guides/cryptodevs/features/aesni_mb.ini @@ -80,6 +80,7 @@ AES GCM (128) = Y AES GCM (192) = Y AES GCM (256) = Y CHACHA20-POLY1305 = Y +SM4 GCM = Y ; ; Supported Asymmetric algorithms of the 'aesni_mb' crypto driver. ; diff --git a/doc/guides/cryptodevs/features/default.ini b/doc/guides/cryptodevs/features/default.ini index 592af48026..116ffce249 100644 --- a/doc/guides/cryptodevs/features/default.ini +++ b/doc/guides/cryptodevs/features/default.ini @@ -118,6 +118,8 @@ AES CCM (128) = AES CCM (192) = AES CCM (256) = CHACHA20-POLY1305 = +SM4 GCM = + ; ; Supported Asymmetric algorithms of a default crypto driver. ; diff --git a/doc/guides/rel_notes/release_25_03.rst b/doc/guides/rel_notes/release_25_03.rst index 426dfcd982..6f2b0bb5cb 100644 --- a/doc/guides/rel_notes/release_25_03.rst +++ b/doc/guides/rel_notes/release_25_03.rst @@ -55,6 +55,10 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +**Updated IPsec_MB crypto driver.** + + * Added support for the SM4 GCM algorithm. + Removed Items ------------- diff --git a/drivers/crypto/ipsec_mb/pmd_aesni_mb.c b/drivers/crypto/ipsec_mb/pmd_aesni_mb.c index 05dc1a039f..1bb47fb5ad 100644 --- a/drivers/crypto/ipsec_mb/pmd_aesni_mb.c +++ b/drivers/crypto/ipsec_mb/pmd_aesni_mb.c @@ -20,7 +20,8 @@ is_aead_algo(IMB_HASH_ALG hash_alg, IMB_CIPHER_MODE cipher_mode) { return (hash_alg == IMB_AUTH_CHACHA20_POLY1305 || hash_alg == IMB_AUTH_AES_CCM || - cipher_mode == IMB_CIPHER_GCM); + cipher_mode == IMB_CIPHER_GCM || + cipher_mode == IMB_CIPHER_SM4_GCM); } /** Set session authentication parameters */ @@ -602,7 +603,7 @@ aesni_mb_set_session_cipher_parameters(const IMB_MGR *mb_mgr, } static int -aesni_mb_set_session_aead_parameters(const IMB_MGR *mb_mgr, +aesni_mb_set_session_aead_parameters(IMB_MGR *mb_mgr, struct aesni_mb_session *sess, const struct rte_crypto_sym_xform *xform) { @@ -720,6 +721,21 @@ aesni_mb_set_session_aead_parameters(const IMB_MGR *mb_mgr, return -EINVAL; } break; + + case RTE_CRYPTO_AEAD_SM4_GCM: + sess->template_job.cipher_mode = IMB_CIPHER_SM4_GCM; + sess->template_job.hash_alg = IMB_AUTH_SM4_GCM; + sess->template_job.u.GCM.aad_len_in_bytes = xform->aead.aad_length; + + if (xform->aead.key.length != 16) { + IPSEC_MB_LOG(ERR, "Invalid key length"); + return -EINVAL; + } + sess->template_job.key_len_in_bytes = 16; + imb_sm4_gcm_pre(mb_mgr, xform->aead.key.data, &sess->cipher.gcm_key); + sess->template_job.enc_keys = &sess->cipher.gcm_key; + sess->template_job.dec_keys = &sess->cipher.gcm_key; + break; default: IPSEC_MB_LOG(ERR, "Unsupported aead mode parameter"); return -ENOTSUP; @@ -1559,6 +1575,9 @@ set_mb_job_params(IMB_JOB *job, struct ipsec_mb_qp *qp, imb_set_session(mb_mgr, job); } break; + case IMB_AUTH_SM4_GCM: + job->u.GCM.aad = op->sym->aead.aad.data; + break; default: break; } @@ -1687,6 +1706,17 @@ set_mb_job_params(IMB_JOB *job, struct ipsec_mb_qp *qp, job->iv = rte_crypto_op_ctod_offset(op, uint8_t *, session->iv.offset); break; + case IMB_AUTH_SM4_GCM: + job->hash_start_src_offset_in_bytes = 0; + /* + * Adding offset here as there is a bug in the ipsec mb library + */ + job->src += op->sym->aead.data.offset; + job->msg_len_to_hash_in_bytes = + op->sym->aead.data.length; + job->iv = rte_crypto_op_ctod_offset(op, uint8_t *, + session->iv.offset); + break; default: job->hash_start_src_offset_in_bytes = auth_start_offset(op, @@ -1732,6 +1762,9 @@ set_mb_job_params(IMB_JOB *job, struct ipsec_mb_qp *qp, job->msg_len_to_cipher_in_bytes = 0; job->cipher_start_src_offset_in_bytes = 0; break; + case IMB_CIPHER_SM4_GCM: + job->msg_len_to_cipher_in_bytes = op->sym->aead.data.length; + break; default: job->cipher_start_src_offset_in_bytes = op->sym->cipher.data.offset; diff --git a/drivers/crypto/ipsec_mb/pmd_aesni_mb_priv.h b/drivers/crypto/ipsec_mb/pmd_aesni_mb_priv.h index 468a1f35eb..bdb9ad815b 100644 --- a/drivers/crypto/ipsec_mb/pmd_aesni_mb_priv.h +++ b/drivers/crypto/ipsec_mb/pmd_aesni_mb_priv.h @@ -826,6 +826,36 @@ static const struct rte_cryptodev_capabilities aesni_mb_capabilities[] = { }, } }, } }, + { /* SM4 GCM */ + .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, + {.sym = { + .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD, + {.aead = { + .algo = RTE_CRYPTO_AEAD_SM4_GCM, + .block_size = 16, + .key_size = { + .min = 16, + .max = 16, + .increment = 0, + }, + .digest_size = { + .min = 16, + .max = 16, + .increment = 0, + }, + .aad_size = { + .min = 0, + .max = 65535, + .increment = 1, + }, + .iv_size = { + .min = 12, + .max = 12, + .increment = 0, + } + }, } + }, } + }, #endif RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() }; diff --git a/lib/cryptodev/rte_crypto_sym.h b/lib/cryptodev/rte_crypto_sym.h index 505356ff44..b47e52f63b 100644 --- a/lib/cryptodev/rte_crypto_sym.h +++ b/lib/cryptodev/rte_crypto_sym.h @@ -482,8 +482,10 @@ enum rte_crypto_aead_algorithm { /**< AES algorithm in CCM mode. */ RTE_CRYPTO_AEAD_AES_GCM, /**< AES algorithm in GCM mode. */ - RTE_CRYPTO_AEAD_CHACHA20_POLY1305 + RTE_CRYPTO_AEAD_CHACHA20_POLY1305, /**< Chacha20 cipher with poly1305 authenticator */ + RTE_CRYPTO_AEAD_SM4_GCM + /**< SM4 cipher with GCM mode */ }; /** Symmetric AEAD Operations */ diff --git a/lib/cryptodev/rte_cryptodev.c b/lib/cryptodev/rte_cryptodev.c index 85a4b46ac9..f6fc949785 100644 --- a/lib/cryptodev/rte_cryptodev.c +++ b/lib/cryptodev/rte_cryptodev.c @@ -168,7 +168,8 @@ static const char * crypto_aead_algorithm_strings[] = { [RTE_CRYPTO_AEAD_AES_CCM] = "aes-ccm", [RTE_CRYPTO_AEAD_AES_GCM] = "aes-gcm", - [RTE_CRYPTO_AEAD_CHACHA20_POLY1305] = "chacha20-poly1305" + [RTE_CRYPTO_AEAD_CHACHA20_POLY1305] = "chacha20-poly1305", + [RTE_CRYPTO_AEAD_SM4_GCM] = "sm4-gcm" }; -- 2.25.1