diff --git a/sm4/cipher_asm.go b/sm4/cipher_asm.go index ca874445..0b65809c 100644 --- a/sm4/cipher_asm.go +++ b/sm4/cipher_asm.go @@ -71,6 +71,10 @@ func (c *sm4CipherAsm) Encrypt(dst, src []byte) { if alias.InexactOverlap(dst[:BlockSize], src[:BlockSize]) { panic("sm4: invalid buffer overlap") } + c.encrypt(dst, src) +} + +func (c *sm4CipherAsm) encrypt(dst, src []byte) { if useAESNI4SingleBlock { encryptBlockAsm(&c.enc[0], &dst[0], &src[0], INST_AES) } else { diff --git a/sm4/ctr_cipher_asm.go b/sm4/ctr_cipher_asm.go index d316bbea..3e5dd35a 100644 --- a/sm4/ctr_cipher_asm.go +++ b/sm4/ctr_cipher_asm.go @@ -66,7 +66,8 @@ func (x *ctr) refill() { copy(x.out, x.out[x.outUsed:]) x.out = x.out[:cap(x.out)] for remain <= len(x.out)-x.b.blocksSize { - x.b.EncryptBlocks(x.out[remain:], x.ctr) + encryptBlocksAsm(&x.b.enc[0], x.out[remain:], x.ctr, INST_AES) + remain += x.b.blocksSize // Generate complelte [x.b.batchBlocks] counters diff --git a/sm4/gcm_cipher_asm.go b/sm4/gcm_cipher_asm.go index f8106ccb..c5db35ce 100644 --- a/sm4/gcm_cipher_asm.go +++ b/sm4/gcm_cipher_asm.go @@ -93,7 +93,7 @@ func (g *gcm) Seal(dst, nonce, plaintext, data []byte) []byte { var counter, tagMask [gcmBlockSize]byte g.deriveCounter(&counter, nonce) - g.cipher.Encrypt(tagMask[:], counter[:]) + g.cipher.encrypt(tagMask[:], counter[:]) gcmInc32(&counter) g.counterCrypt(out, plaintext, &counter) @@ -130,7 +130,7 @@ func (g *gcm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) { var counter, tagMask [gcmBlockSize]byte g.deriveCounter(&counter, nonce) - g.cipher.Encrypt(tagMask[:], counter[:]) + g.cipher.encrypt(tagMask[:], counter[:]) gcmInc32(&counter) var expectedTag [gcmTagSize]byte diff --git a/sm4/sm4_gcm_asm.go b/sm4/sm4_gcm_asm.go index 236dce4d..c8645808 100644 --- a/sm4/sm4_gcm_asm.go +++ b/sm4/sm4_gcm_asm.go @@ -80,7 +80,7 @@ func (g *gcmAsm) Seal(dst, nonce, plaintext, data []byte) []byte { gcmSm4Finish(&g.bytesProductTable, &tagMask, &counter, uint64(len(nonce)), uint64(0)) } - g.cipher.Encrypt(tagMask[:], counter[:]) + g.cipher.encrypt(tagMask[:], counter[:]) var tagOut [gcmTagSize]byte gcmSm4Data(&g.bytesProductTable, data, &tagOut) @@ -134,7 +134,7 @@ func (g *gcmAsm) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) { gcmSm4Finish(&g.bytesProductTable, &tagMask, &counter, uint64(len(nonce)), uint64(0)) } - g.cipher.Encrypt(tagMask[:], counter[:]) + g.cipher.encrypt(tagMask[:], counter[:]) var expectedTag [gcmTagSize]byte gcmSm4Data(&g.bytesProductTable, data, &expectedTag) diff --git a/sm4/sm4ni_gcm_asm.go b/sm4/sm4ni_gcm_asm.go index 0c50fe93..937e2e3d 100644 --- a/sm4/sm4ni_gcm_asm.go +++ b/sm4/sm4ni_gcm_asm.go @@ -73,7 +73,7 @@ func (g *gcmNI) Seal(dst, nonce, plaintext, data []byte) []byte { gcmSm4Finish(&g.bytesProductTable, &tagMask, &counter, uint64(len(nonce)), uint64(0)) } - g.cipher.Encrypt(tagMask[:], counter[:]) + encryptBlockAsm(&g.cipher.enc[0], &tagMask[0], &counter[0], INST_SM4) var tagOut [gcmTagSize]byte gcmSm4Data(&g.bytesProductTable, data, &tagOut) @@ -127,7 +127,7 @@ func (g *gcmNI) Open(dst, nonce, ciphertext, data []byte) ([]byte, error) { gcmSm4Finish(&g.bytesProductTable, &tagMask, &counter, uint64(len(nonce)), uint64(0)) } - g.cipher.Encrypt(tagMask[:], counter[:]) + encryptBlockAsm(&g.cipher.enc[0], &tagMask[0], &counter[0], INST_SM4) var expectedTag [gcmTagSize]byte gcmSm4Data(&g.bytesProductTable, data, &expectedTag)