Skip to content

Commit

Permalink
sm4: fix arm64 cbc 8 blocks decryption issue
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Aug 3, 2023
1 parent dba47d3 commit 71afa44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions cipher/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion sm4/cbc_cipher_asm_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 71afa44

Please sign in to comment.