From 71afa44b914da142d1d29b0c506977b5cf9c35d7 Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Thu, 3 Aug 2023 16:40:31 +0800 Subject: [PATCH] sm4: fix arm64 cbc 8 blocks decryption issue --- cipher/benchmark_test.go | 8 ++++---- sm4/cbc_cipher_asm_arm64.s | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cipher/benchmark_test.go b/cipher/benchmark_test.go index 334a2b3..f26035f 100644 --- a/cipher/benchmark_test.go +++ b/cipher/benchmark_test.go @@ -9,7 +9,7 @@ import ( "github.com/emmansun/gmsm/sm4" ) -func benchmarkEBCEncrypt1K(b *testing.B, block cipher.Block) { +func benchmarkECBEncrypt1K(b *testing.B, block cipher.Block) { buf := make([]byte, 1024) b.SetBytes(int64(len(buf))) @@ -19,16 +19,16 @@ func benchmarkEBCEncrypt1K(b *testing.B, block cipher.Block) { } } -func BenchmarkSM4EBCEncrypt1K(b *testing.B) { +func BenchmarkSM4ECBEncrypt1K(b *testing.B) { var key [16]byte c, _ := sm4.NewCipher(key[:]) - benchmarkEBCEncrypt1K(b, c) + benchmarkECBEncrypt1K(b, c) } func BenchmarkAES128EBCEncrypt1K(b *testing.B) { var key [16]byte c, _ := aes.NewCipher(key[:]) - benchmarkEBCEncrypt1K(b, c) + benchmarkECBEncrypt1K(b, c) } func benchmarkCBCEncrypt1K(b *testing.B, block cipher.Block) { diff --git a/sm4/cbc_cipher_asm_arm64.s b/sm4/cbc_cipher_asm_arm64.s index b5070cc..218c7aa 100644 --- a/sm4/cbc_cipher_asm_arm64.s +++ b/sm4/cbc_cipher_asm_arm64.s @@ -185,13 +185,14 @@ decrypt8BlocksLoop: VEOR V7.B16, t1.B16, t1.B16 VEOR V8.B16, t2.B16, t2.B16 VEOR V9.B16, t3.B16, t3.B16 - VST1.P [t0.S4, t1.S4, t2.S4, t3.S4], 64(R9) VLD1.P 64(R11), [V6.S4, V7.S4, V8.S4, V9.S4] VEOR V6.B16, t4.B16, t4.B16 VEOR V7.B16, t5.B16, t5.B16 VEOR V8.B16, t6.B16, t6.B16 VEOR V9.B16, t7.B16, t7.B16 + + VST1.P [t0.S4, t1.S4, t2.S4, t3.S4], 64(R9) VST1.P [t4.S4, t5.S4, t6.S4, t7.S4], 64(R9) RET