From 5b075213c048b87fcd2014fd336cdebe72ea03a6 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Tue, 26 Jul 2022 08:30:24 +0800 Subject: [PATCH] sm4: add cbcEncAble interface --- sm4/cbc_cipher_asm.go | 4 ++-- sm4/modes.go | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sm4/cbc_cipher_asm.go b/sm4/cbc_cipher_asm.go index 7ec8155..5a65b02 100644 --- a/sm4/cbc_cipher_asm.go +++ b/sm4/cbc_cipher_asm.go @@ -10,8 +10,8 @@ import ( "github.com/emmansun/gmsm/internal/xor" ) -// Assert that sm4CipherAsm implements the cbcDecAble interfaces. -var _ cbcDecAble = (*sm4CipherAsm)(nil) +// Assert that sm4CipherAsm implements the cbcEncAble and cbcDecAble interfaces. +var _ cbcEncAble = (*sm4CipherAsm)(nil) var _ cbcDecAble = (*sm4CipherAsm)(nil) const cbcEncrypt = 1 diff --git a/sm4/modes.go b/sm4/modes.go index 93bfdd7..61e58e2 100644 --- a/sm4/modes.go +++ b/sm4/modes.go @@ -2,6 +2,13 @@ package sm4 import "crypto/cipher" +// cbcEncAble is implemented by cipher.Blocks that can provide an optimized +// implementation of CBC encryption through the cipher.BlockMode interface. +// See crypto/cipher/cbc.go. +type cbcEncAble interface { + NewCBCEncrypter(iv []byte) cipher.BlockMode +} + // cbcDecAble is implemented by cipher.Blocks that can provide an optimized // implementation of CBC decryption through the cipher.BlockMode interface. // See crypto/cipher/cbc.go.