Repository navigation
Expand file tree
/
Copy pathsimd_poly1305_vector_test.go
More file actions
81 lines (59 loc) · 1.65 KB
/
Copy pathsimd_poly1305_vector_test.go
File metadata and controls
81 lines (59 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: Apache-2.0 OR MIT
//go:build goexperiment.simd && amd64
package c2simd_test
import (
"bytes"
"crypto/rand"
"testing"
"code.hazyhaar.fr/devhoros/c2simd"
"golang.org/x/crypto/poly1305"
)
func TestKAT_Poly1305_AVX2_Vs_XCrypto_ExtendedSizes(t *testing.T) {
sizes := []int{0, 1, 15, 16, 17, 31, 32, 33, 63, 64, 65, 127, 128, 129, 255, 256, 511, 512, 1000, 1024, 4096}
key := make([]byte, 32)
rand.Read(key)
var keyArr [32]byte
copy(keyArr[:], key)
for _, sz := range sizes {
msg := make([]byte, sz)
if sz > 0 {
rand.Read(msg)
}
var expTag [16]byte
poly1305.Sum(&expTag, msg, &keyArr)
engine := c2simd.NewPoly1305AVX2(key)
engine.Update(msg)
var gotTag [16]byte
engine.Finish(&gotTag)
if !bytes.Equal(gotTag[:], expTag[:]) {
t.Fatalf("KAT DIVERGENCE taille %d:\n Got: %x\n Exp: %x", sz, gotTag, expTag)
}
}
}
// TestKAT_Poly1305_AVX2_CanonicalBoundary Edge-case test provoquant H >= 2^130 - 5
func TestKAT_Poly1305_AVX2_CanonicalBoundary(t *testing.T) {
var key [32]byte
key[0] = 1
msg := bytes.Repeat([]byte{0xff}, 16)
var expTag [16]byte
poly1305.Sum(&expTag, msg, &key)
engine := c2simd.NewPoly1305AVX2(key[:])
engine.Update(msg)
var gotTag [16]byte
engine.Finish(&gotTag)
if !bytes.Equal(gotTag[:], expTag[:]) {
t.Fatalf("DIVERGENCE CANONIQUE H >= 2^130-5:\n Got: %x\n Exp: %x", gotTag, expTag)
}
}
func BenchmarkPoly1305_AVX2_VPMULUDQ_1MB(b *testing.B) {
key := make([]byte, 32)
payload := make([]byte, 1024*1024)
rand.Read(key)
rand.Read(payload)
st := c2simd.NewPoly1305AVX2(key)
b.SetBytes(int64(len(payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
st.Update(payload)
}
}