Skip to content

Commit 5b2c47a

Browse files
authored
Merge pull request ethereum#19990 from karalabe/fix-blake2b-386
crypto/blake2b: fix non-amd64 builds
2 parents 22fdbee + 8517dd4 commit 5b2c47a

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

crypto/blake2b/blake2b_f_fuzz.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// +build gofuzz
2+
3+
package blake2b
4+
5+
import (
6+
"encoding/binary"
7+
)
8+
9+
func Fuzz(data []byte) int {
10+
// Make sure the data confirms to the input model
11+
if len(data) != 211 {
12+
return 0
13+
}
14+
// Parse everything and call all the implementations
15+
var (
16+
rounds = binary.BigEndian.Uint16(data[0:2])
17+
18+
h [8]uint64
19+
m [16]uint64
20+
t [2]uint64
21+
f uint64
22+
)
23+
for i := 0; i < 8; i++ {
24+
offset := 2 + i*8
25+
h[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
26+
}
27+
for i := 0; i < 16; i++ {
28+
offset := 66 + i*8
29+
m[i] = binary.LittleEndian.Uint64(data[offset : offset+8])
30+
}
31+
t[0] = binary.LittleEndian.Uint64(data[194:202])
32+
t[1] = binary.LittleEndian.Uint64(data[202:210])
33+
34+
if data[210]%2 == 1 { // Avoid spinning the fuzzer to hit 0/1
35+
f = 0xFFFFFFFFFFFFFFFF
36+
}
37+
// Run the blake2b compression on all instruction sets and cross reference
38+
want := h
39+
fGeneric(&want, &m, t[0], t[1], f, uint64(rounds))
40+
41+
have := h
42+
fSSE4(&have, &m, t[0], t[1], f, uint64(rounds))
43+
if have != want {
44+
panic("SSE4 mismatches generic algo")
45+
}
46+
have = h
47+
fAVX(&have, &m, t[0], t[1], f, uint64(rounds))
48+
if have != want {
49+
panic("AVX mismatches generic algo")
50+
}
51+
have = h
52+
fAVX2(&have, &m, t[0], t[1], f, uint64(rounds))
53+
if have != want {
54+
panic("AVX2 mismatches generic algo")
55+
}
56+
return 1
57+
}

crypto/blake2b/blake2b_ref.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
package blake2b
88

9-
func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) {
10-
hashBlocksGeneric(h, c, flag, blocks)
11-
}
12-
139
func f(h *[8]uint64, m [16]uint64, c0, c1 uint64, flag uint64, rounds int) {
1410
fGeneric(h, m, c0, c1, flag, rounds)
1511
}

0 commit comments

Comments
 (0)