github.com/emmansun/gmsm@v0.29.1/sm4/cipher_asm_fuzzy_test.go (about) 1 //go:build (amd64 || arm64) && !purego 2 3 package sm4 4 5 import ( 6 "crypto/rand" 7 "io" 8 "reflect" 9 "testing" 10 "time" 11 ) 12 13 func TestExpandKey(t *testing.T) { 14 key := make([]byte, 16) 15 16 var encRes1 [rounds]uint32 17 var decRes1 [rounds]uint32 18 encRes2 := make([]uint32, 32) 19 decRes2 := make([]uint32, 32) 20 var timeout *time.Timer 21 22 if testing.Short() { 23 timeout = time.NewTimer(10 * time.Millisecond) 24 } else { 25 timeout = time.NewTimer(2 * time.Second) 26 } 27 28 for { 29 select { 30 case <-timeout.C: 31 return 32 default: 33 } 34 io.ReadFull(rand.Reader, key) 35 expandKeyGo(key, &encRes1, &decRes1) 36 expandKey(key, encRes2, decRes2) 37 if !reflect.DeepEqual(encRes1[:], encRes2) { 38 t.Errorf("expected=%x, result=%x\n", encRes1[:], encRes2) 39 } 40 if !reflect.DeepEqual(decRes1[:], decRes2) { 41 t.Errorf("expected=%x, result=%x\n", decRes1[:], decRes2) 42 } 43 } 44 }