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