2022-11-22 11:02:37 +08:00
|
|
|
//go:build (amd64 && !purego) || (arm64 && !purego)
|
2022-01-21 11:24:10 +08:00
|
|
|
|
|
|
|
package sm4
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
|
|
|
"io"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestExpandKey(t *testing.T) {
|
|
|
|
key := make([]byte, 16)
|
|
|
|
|
|
|
|
encRes1 := make([]uint32, 32)
|
|
|
|
decRes1 := make([]uint32, 32)
|
|
|
|
encRes2 := make([]uint32, 32)
|
|
|
|
decRes2 := make([]uint32, 32)
|
|
|
|
var timeout *time.Timer
|
|
|
|
|
|
|
|
if testing.Short() {
|
|
|
|
timeout = time.NewTimer(10 * time.Millisecond)
|
|
|
|
} else {
|
|
|
|
timeout = time.NewTimer(2 * time.Second)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-timeout.C:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
io.ReadFull(rand.Reader, key)
|
|
|
|
expandKeyGo(key, encRes1, decRes1)
|
2022-04-28 13:46:50 +08:00
|
|
|
expandKey(key, encRes2, decRes2)
|
2022-01-21 11:24:10 +08:00
|
|
|
if !reflect.DeepEqual(encRes1, encRes2) {
|
2023-03-30 11:26:34 +08:00
|
|
|
t.Errorf("expected=%x, result=%x\n", encRes1, encRes2)
|
2022-01-21 11:24:10 +08:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(decRes1, decRes2) {
|
2023-03-30 11:26:34 +08:00
|
|
|
t.Errorf("expected=%x, result=%x\n", encRes1, encRes2)
|
2022-01-21 11:24:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|