fix error

This commit is contained in:
Sun Yimin 2023-03-30 11:26:34 +08:00 committed by GitHub
parent c52d700860
commit 3fed51e909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 9 deletions

View File

@ -108,6 +108,8 @@
WORD $0xcec084a8 \ //SM4E V8.4S, V5.4S WORD $0xcec084a8 \ //SM4E V8.4S, V5.4S
WORD $0xcec084c8 \ //SM4E V8.4S, V6.4S WORD $0xcec084c8 \ //SM4E V8.4S, V6.4S
WORD $0xcec084e8 \ //SM4E V8.4S, V7.4S WORD $0xcec084e8 \ //SM4E V8.4S, V7.4S
VREV64 V8.S4, V8.S4 \
VEXT $8, V8.B16, V8.B16, V8.B16 \
VREV32 V8.B16, V8.B16 \ VREV32 V8.B16, V8.B16 \
VST1.P [V8.B16], 16(R9) VST1.P [V8.B16], 16(R9)
@ -277,6 +279,8 @@ sm4niblock:
WORD $0xcec08428 //SM4E V8.4S, V1.4S WORD $0xcec08428 //SM4E V8.4S, V1.4S
WORD $0xcec08448 //SM4E V8.4S, V2.4S WORD $0xcec08448 //SM4E V8.4S, V2.4S
WORD $0xcec08468 //SM4E V8.4S, V3.4S WORD $0xcec08468 //SM4E V8.4S, V3.4S
VREV64 V8.S4, V8.S4
VEXT $8, V8.B16, V8.B16, V8.B16
VREV32 V8.B16, V8.B16 VREV32 V8.B16, V8.B16
VST1 [V8.B16], (R9) VST1 [V8.B16], (R9)
RET RET

View File

@ -36,10 +36,10 @@ func TestExpandKey(t *testing.T) {
expandKeyGo(key, encRes1, decRes1) expandKeyGo(key, encRes1, decRes1)
expandKey(key, encRes2, decRes2) expandKey(key, encRes2, decRes2)
if !reflect.DeepEqual(encRes1, encRes2) { if !reflect.DeepEqual(encRes1, encRes2) {
t.Errorf("expected=%v, result=%v\n", encRes1, encRes2) t.Errorf("expected=%x, result=%x\n", encRes1, encRes2)
} }
if !reflect.DeepEqual(decRes1, decRes2) { if !reflect.DeepEqual(decRes1, decRes2) {
t.Errorf("expected=%v, result=%v\n", encRes1, encRes2) t.Errorf("expected=%x, result=%x\n", encRes1, encRes2)
} }
} }
} }

View File

@ -30,11 +30,11 @@ func Test_sample1(t *testing.T) {
dst := make([]byte, 16) dst := make([]byte, 16)
c.Encrypt(dst, src) c.Encrypt(dst, src)
if !reflect.DeepEqual(dst, expected) { if !reflect.DeepEqual(dst, expected) {
t.Errorf("expected=%v, result=%v\n", expected, dst) t.Errorf("expected=%x, result=%x\n", expected, dst)
} }
c.Decrypt(dst, expected) c.Decrypt(dst, expected)
if !reflect.DeepEqual(dst, src) { if !reflect.DeepEqual(dst, src) {
t.Errorf("expected=%v, result=%v\n", src, dst) t.Errorf("expected=%x, result=%x\n", src, dst)
} }
} }
@ -56,7 +56,7 @@ func Test_sample2(t *testing.T) {
c.Encrypt(dst, dst) c.Encrypt(dst, dst)
} }
if !reflect.DeepEqual(dst, expected) { if !reflect.DeepEqual(dst, expected) {
t.Errorf("expected=%v, result=%v\n", expected, dst) t.Errorf("expected=%x, result=%x\n", expected, dst)
} }
} }

View File

@ -10,20 +10,21 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"log" "log"
"math/bits"
"os" "os"
) )
//SM4E <Vd>.4S, <Vn>.4S //SM4E <Vd>.4S, <Vn>.4S
func sm4e(Vd, Vn byte) uint32 { func sm4e(Vd, Vn byte) uint32 {
inst := uint32(0xcec08400) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 inst := uint32(0xcec08400) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5
return bits.ReverseBytes32(inst) // return bits.ReverseBytes32(inst)
return inst
} }
//SM4EKEY <Vd>.4S, <Vn>.4S, <Vm>.4S //SM4EKEY <Vd>.4S, <Vn>.4S, <Vm>.4S
func sm4ekey(Vd, Vn, Vm byte) uint32 { func sm4ekey(Vd, Vn, Vm byte) uint32 {
inst := uint32(0xce60c800) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | (uint32(Vm&0x1f) << 16) inst := uint32(0xce60c800) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | (uint32(Vm&0x1f) << 16)
return bits.ReverseBytes32(inst) // return bits.ReverseBytes32(inst)
return inst
} }
func sm4ekeyRound(buf *bytes.Buffer, d, n, m byte) { func sm4ekeyRound(buf *bytes.Buffer, d, n, m byte) {
@ -93,6 +94,8 @@ TEXT ·encryptBlockSM4E(SB),NOSPLIT,$0
sm4eRound(buf, 8, 2) sm4eRound(buf, 8, 2)
sm4eRound(buf, 8, 3) sm4eRound(buf, 8, 3)
fmt.Fprintf(buf, ` fmt.Fprintf(buf, `
VREV64 V8.S4, V8.S4
VEXT $8, V8.B16, V8.B16, V8.B16
VREV32 V8.B16, V8.B16 VREV32 V8.B16, V8.B16
VST1 [V8.B16], (R9) VST1 [V8.B16], (R9)
RET RET
@ -121,6 +124,8 @@ TEXT ·encryptBlocksSM4E(SB),NOSPLIT,$0
sm4eRound(buf, 8, 5) sm4eRound(buf, 8, 5)
sm4eRound(buf, 8, 6) sm4eRound(buf, 8, 6)
sm4eRound(buf, 8, 7) sm4eRound(buf, 8, 7)
fmt.Fprintf(buf, "\tVREV64 V8.S4, V8.S4\n")
fmt.Fprintf(buf, "\tVEXT $8, V8.B16, V8.B16, V8.B16\n")
fmt.Fprintf(buf, "\tVREV32 V8.B16, V8.B16\n") fmt.Fprintf(buf, "\tVREV32 V8.B16, V8.B16\n")
fmt.Fprintf(buf, "\tVST1.P [V8.B16], 16(R9)\n\n") fmt.Fprintf(buf, "\tVST1.P [V8.B16], 16(R9)\n\n")
} }