From 4db3046001e67c43e358d87912c0e96d1758a46b Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Tue, 11 Jun 2024 11:01:05 +0800 Subject: [PATCH] pkcs7: support older CFCA integration #225 --- pkcs/cipher_sm4.go | 10 ++++++++++ pkcs7/encrypt_test.go | 1 + 2 files changed, 11 insertions(+) diff --git a/pkcs/cipher_sm4.go b/pkcs/cipher_sm4.go index 159d90e..6eb3aa5 100644 --- a/pkcs/cipher_sm4.go +++ b/pkcs/cipher_sm4.go @@ -53,3 +53,13 @@ var SM4GCM = &gcmBlockCipher{ }, nonceSize: 12, } + +// SM4 is the 128-bit key SM4 cipher in CBC mode, it's just for CFCA. +var SM4 = &cbcBlockCipher{ + baseBlockCipher: baseBlockCipher{ + keySize: 16, + newBlock: sm4.NewCipher, + oid: oidSM4, + }, + ivSize: sm4.BlockSize, +} diff --git a/pkcs7/encrypt_test.go b/pkcs7/encrypt_test.go index b288f3c..c316bd8 100644 --- a/pkcs7/encrypt_test.go +++ b/pkcs7/encrypt_test.go @@ -93,6 +93,7 @@ func TestEncryptSM(t *testing.T) { func TestEncryptCFCA(t *testing.T) { ciphers := []pkcs.Cipher{ + pkcs.SM4, pkcs.SM4CBC, pkcs.SM4GCM, }