From d808d59d064f1318b960b4f3c0e01268d22c1a90 Mon Sep 17 00:00:00 2001 From: emmansun Date: Sun, 2 Jan 2022 20:25:14 +0800 Subject: [PATCH] test gsmsm4data() --- sm4/sm4_gcm_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/sm4/sm4_gcm_test.go b/sm4/sm4_gcm_test.go index 814777c..5f8695e 100644 --- a/sm4/sm4_gcm_test.go +++ b/sm4/sm4_gcm_test.go @@ -8,7 +8,7 @@ import ( "testing" ) -func TestPrecomputeTableAsm(t *testing.T) { +func genPrecomputeTable() *gcmAsm { key := []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10} c := sm4CipherAsm{sm4Cipher{make([]uint32, rounds), make([]uint32, rounds)}} expandKeyAsm(&key[0], &ck[0], &c.enc[0], &c.dec[0]) @@ -19,6 +19,11 @@ func TestPrecomputeTableAsm(t *testing.T) { c1.Encrypt(key1[:], key1[:]) fmt.Printf("%v\n", key1) precomputeTableAsm(&g.bytesProductTable, &key1) + return g +} + +func TestPrecomputeTableAsm(t *testing.T) { + g := genPrecomputeTable() for i := 0; i < 16; i++ { for j := 0; j < 16; j++ { fmt.Printf("%02X ", g.bytesProductTable[i*16+j]) @@ -26,3 +31,14 @@ func TestPrecomputeTableAsm(t *testing.T) { fmt.Println() } } + +func TestGcmSm4Data(t *testing.T) { + g := genPrecomputeTable() + var counter [gcmBlockSize]byte + nonce := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} + gcmSm4Data(&g.bytesProductTable, nonce, &counter) + for j := 0; j < 16; j++ { + fmt.Printf("%02X ", counter[j]) + } + fmt.Println() +}