mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-21 17:56:19 +08:00
cipher: xts asm, add random test
This commit is contained in:
parent
abbe36143c
commit
76635c4cf3
2
.github/workflows/test_qemu.yml
vendored
2
.github/workflows/test_qemu.yml
vendored
@ -30,7 +30,7 @@ jobs:
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Test
|
||||
run: go test -v -short ./cipher/...
|
||||
run: go test -v -short ./...
|
||||
env:
|
||||
DISABLE_SM3NI: 1
|
||||
DISABLE_SM4NI: 1
|
||||
|
@ -5,7 +5,9 @@ package cipher
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -45,6 +47,31 @@ func TestDoubleTweakGB(t *testing.T) {
|
||||
testDoubleTweak(t, true)
|
||||
}
|
||||
|
||||
func testDoubleTweakRandomly(t *testing.T, isGB bool) {
|
||||
var tweak, t1, t2 [16]byte
|
||||
io.ReadFull(rand.Reader, tweak[:])
|
||||
copy(t1[:], tweak[:])
|
||||
copy(t2[:], tweak[:])
|
||||
mul2(&t1, isGB)
|
||||
mul2Generic(&t2, isGB)
|
||||
|
||||
if !bytes.Equal(t1[:], t2[:]) {
|
||||
t.Errorf("tweak %x, expected %x, got %x", tweak[:], t2[:], t1[:])
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoubleTweakRandomly(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
testDoubleTweakRandomly(t, false)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoubleTweakGBRandomly(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
testDoubleTweakRandomly(t, true)
|
||||
}
|
||||
}
|
||||
|
||||
func testDoubleTweaks(t *testing.T, isGB bool) {
|
||||
for _, tk := range testTweakVector {
|
||||
tweak, _ := hex.DecodeString(tk)
|
||||
|
Loading…
x
Reference in New Issue
Block a user