Skip to content

Commit 4e45823

Browse files
authored
Revert "crypto/blake2b: put architecture-dependent features behind build-tag (ethereum#28381)"
This reverts commit 5e9d8bd.
1 parent 7ae5506 commit 4e45823

File tree

2 files changed

+58
-75
lines changed

2 files changed

+58
-75
lines changed

crypto/blake2b/blake2b_f_fuzz_test.go

Lines changed: 0 additions & 75 deletions
This file was deleted.

crypto/blake2b/blake2b_f_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package blake2b
22

33
import (
4+
"encoding/binary"
45
"fmt"
56
"reflect"
67
"testing"
@@ -57,3 +58,60 @@ var testVectorsF = []testVector{
5758
},
5859
},
5960
}
61+
62+
func Fuzz(f *testing.F) {
63+
f.Fuzz(func(t *testing.T, data []byte) {
64+
fuzz(data)
65+
})
66+
}
67+
68+
func fuzz(data []byte) {
69+
// Make sure the data confirms to the input model
70+
if len(data) != 211 {
71+
return
72+
}
73+
// Parse everything and call all the implementations
74+
var (
75+
rounds = binary.BigEndian.Uint16(data[0:2])
76+
77+
h [8]uint64
78+
m [16]uint64
79+
t [2]uint64
80+
f uint64
81+
)
82+
83+
for i := 0; i < 8; i++ {
84+
offset := 2 + i*8
85+
h[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
86+
}
87+
for i := 0; i < 16; i++ {
88+
offset := 66 + i*8
89+
m[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
90+
}
91+
t[0] = binary.LittleEndian.Uint64(data[194:202])
92+
t[1] = binary.LittleEndian.Uint64(data[202:210])
93+
94+
if data[210]%2 == 1 { // Avoid spinning the fuzzer to hit 0/1
95+
f = 0xFFFFFFFFFFFFFFFF
96+
}
97+
98+
// Run the blake2b compression on all instruction sets and cross reference
99+
want := h
100+
fGeneric(&want, &m, t[0], t[1], f, uint64(rounds))
101+
102+
have := h
103+
fSSE4(&have, &m, t[0], t[1], f, uint64(rounds))
104+
if have != want {
105+
panic("SSE4 mismatches generic algo")
106+
}
107+
have = h
108+
fAVX(&have, &m, t[0], t[1], f, uint64(rounds))
109+
if have != want {
110+
panic("AVX mismatches generic algo")
111+
}
112+
have = h
113+
fAVX2(&have, &m, t[0], t[1], f, uint64(rounds))
114+
if have != want {
115+
panic("AVX2 mismatches generic algo")
116+
}
117+
}

0 commit comments

Comments
 (0)