gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/sm4/cipher_asm_fuzzy_test.go (about)

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