Skip to content

Commit 5ef86fb

Browse files
bdoole1Akhil Goyal
authored andcommitted
crypto/ipsec_mb: support SM4 algorithm
This patch introduces SM4 CBC, SM4 ECB and SM4 CTR algorithm support to the AESNI_MB PMD. SM4 CTR is available in the v2.0 release of Intel IPsec MB. Signed-off-by: Brian Dooley <[email protected]> Acked-by: Pablo de Lara <[email protected]>
1 parent 3629f7f commit 5ef86fb

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

doc/guides/cryptodevs/aesni_mb.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ Cipher algorithms:
3636
* RTE_CRYPTO_CIPHER_ZUC_EEA3
3737
* RTE_CRYPTO_CIPHER_SNOW3G_UEA2
3838
* RTE_CRYPTO_CIPHER_KASUMI_F8
39+
* RTE_CRYPTO_CIPHER_SM4_CBC
40+
* RTE_CRYPTO_CIPHER_SM4_ECB
41+
* RTE_CRYPTO_CIPHER_SM4_CTR
3942

4043
Hash algorithms:
4144

doc/guides/cryptodevs/features/aesni_mb.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ AES ECB (256) = Y
4242
ZUC EEA3 = Y
4343
SNOW3G UEA2 = Y
4444
KASUMI F8 = Y
45+
SM4 CBC = Y
46+
SM4 ECB = Y
47+
SM4 CTR = Y
4548

4649
;
4750
; Supported authentication algorithms of the 'aesni_mb' crypto driver.

doc/guides/rel_notes/release_24_11.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ New Features
7575
* **Updated IPsec_MB crypto driver.**
7676
* Added support for SM3 algorithm.
7777
* Added support for SM3 HMAC algorithm.
78+
* Added support for SM4 CBC, SM4 ECB and SM4 CTR algorithms.
7879

7980

8081
Removed Items

drivers/crypto/ipsec_mb/pmd_aesni_mb.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ aesni_mb_set_session_cipher_parameters(const IMB_MGR *mb_mgr,
451451
uint8_t is_zuc = 0;
452452
uint8_t is_snow3g = 0;
453453
uint8_t is_kasumi = 0;
454+
#if IMB_VERSION(1, 5, 0) <= IMB_VERSION_NUM
455+
uint8_t is_sm4 = 0;
456+
#endif
454457

455458
if (xform == NULL) {
456459
sess->template_job.cipher_mode = IMB_CIPHER_NULL;
@@ -521,6 +524,22 @@ aesni_mb_set_session_cipher_parameters(const IMB_MGR *mb_mgr,
521524
sess->iv.offset = xform->cipher.iv.offset;
522525
sess->template_job.iv_len_in_bytes = xform->cipher.iv.length;
523526
return 0;
527+
#if IMB_VERSION(1, 5, 0) <= IMB_VERSION_NUM
528+
case RTE_CRYPTO_CIPHER_SM4_CBC:
529+
sess->template_job.cipher_mode = IMB_CIPHER_SM4_CBC;
530+
is_sm4 = 1;
531+
break;
532+
case RTE_CRYPTO_CIPHER_SM4_ECB:
533+
sess->template_job.cipher_mode = IMB_CIPHER_SM4_ECB;
534+
is_sm4 = 1;
535+
break;
536+
#endif
537+
#if IMB_VERSION(1, 5, 0) < IMB_VERSION_NUM
538+
case RTE_CRYPTO_CIPHER_SM4_CTR:
539+
sess->template_job.cipher_mode = IMB_CIPHER_SM4_CNTR;
540+
is_sm4 = 1;
541+
break;
542+
#endif
524543
default:
525544
IPSEC_MB_LOG(ERR, "Unsupported cipher mode parameter");
526545
return -ENOTSUP;
@@ -655,6 +674,15 @@ aesni_mb_set_session_cipher_parameters(const IMB_MGR *mb_mgr,
655674
&sess->cipher.pKeySched_kasumi_cipher);
656675
sess->template_job.enc_keys = &sess->cipher.pKeySched_kasumi_cipher;
657676
sess->template_job.dec_keys = &sess->cipher.pKeySched_kasumi_cipher;
677+
#if IMB_VERSION(1, 5, 0) <= IMB_VERSION_NUM
678+
} else if (is_sm4) {
679+
sess->template_job.key_len_in_bytes = IMB_KEY_128_BYTES;
680+
IMB_SM4_KEYEXP(mb_mgr, xform->cipher.key.data,
681+
sess->cipher.expanded_sm4_keys.encode,
682+
sess->cipher.expanded_sm4_keys.decode);
683+
sess->template_job.enc_keys = sess->cipher.expanded_sm4_keys.encode;
684+
sess->template_job.dec_keys = sess->cipher.expanded_sm4_keys.decode;
685+
#endif
658686
} else {
659687
if (xform->cipher.key.length != 8) {
660688
IPSEC_MB_LOG(ERR, "Invalid cipher key length");

drivers/crypto/ipsec_mb/pmd_aesni_mb_priv.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,64 @@ static const struct rte_cryptodev_capabilities aesni_mb_capabilities[] = {
775775
}, }
776776
}, }
777777
},
778+
{ /* SM4 CBC */
779+
.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
780+
{.sym = {
781+
.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
782+
{.cipher = {
783+
.algo = RTE_CRYPTO_CIPHER_SM4_CBC,
784+
.block_size = 16,
785+
.key_size = {
786+
.min = 16,
787+
.max = 16,
788+
.increment = 0
789+
},
790+
.iv_size = {
791+
.min = 16,
792+
.max = 16,
793+
.increment = 0
794+
}
795+
}, }
796+
}, }
797+
},
798+
{ /* SM4 ECB */
799+
.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
800+
{.sym = {
801+
.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
802+
{.cipher = {
803+
.algo = RTE_CRYPTO_CIPHER_SM4_ECB,
804+
.block_size = 16,
805+
.key_size = {
806+
.min = 16,
807+
.max = 16,
808+
.increment = 0
809+
},
810+
.iv_size = { 0 }
811+
}, }
812+
}, }
813+
},
814+
#endif
815+
#if IMB_VERSION(1, 5, 0) < IMB_VERSION_NUM
816+
{ /* SM4 CTR */
817+
.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
818+
{.sym = {
819+
.xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
820+
{.cipher = {
821+
.algo = RTE_CRYPTO_CIPHER_SM4_CTR,
822+
.block_size = 16,
823+
.key_size = {
824+
.min = 16,
825+
.max = 16,
826+
.increment = 0
827+
},
828+
.iv_size = {
829+
.min = 16,
830+
.max = 16,
831+
.increment = 0
832+
}
833+
}, }
834+
}, }
835+
},
778836
#endif
779837
RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
780838
};
@@ -953,6 +1011,17 @@ struct __rte_cache_aligned aesni_mb_session {
9531011
/* *< SNOW3G scheduled cipher key */
9541012
kasumi_key_sched_t pKeySched_kasumi_cipher;
9551013
/* *< KASUMI scheduled cipher key */
1014+
#if IMB_VERSION(1, 5, 0) <= IMB_VERSION_NUM
1015+
struct {
1016+
alignas(16) uint32_t encode[IMB_SM4_KEY_SCHEDULE_ROUNDS];
1017+
/* *< encode key */
1018+
alignas(16) uint32_t decode[IMB_SM4_KEY_SCHEDULE_ROUNDS];
1019+
/* *< decode key */
1020+
} expanded_sm4_keys;
1021+
/* *< Expanded SM4 keys - Original 128 bit key is
1022+
* expanded into 32 round keys, each 32 bits.
1023+
*/
1024+
#endif
9561025
};
9571026
} cipher;
9581027

0 commit comments

Comments
 (0)