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
|
//go:build gofuzz
// +build gofuzz
package test
import (
"bytes"
"encoding/hex"
"testing"
"github.com/pjbgf/sha1cd"
"github.com/pjbgf/sha1cd/cgo"
)
func FuzzDeviationDetection(f *testing.F) {
f.Add([]byte{})
g := sha1cd.New().(sha1cd.CollisionResistantHash)
c := cgo.New().(sha1cd.CollisionResistantHash)
f.Fuzz(func(t *testing.T, in []byte) {
g.Reset()
c.Reset()
g.Write(in)
c.Write(in)
gv, gc := g.CollisionResistantSum(nil)
cv, cc := c.CollisionResistantSum(nil)
if bytes.Compare(gv, cv) != 0 || gc != cc {
t.Fatalf("input: %q\n go result: %q %v\ncgo result: %q %v",
hex.EncodeToString(in), hex.EncodeToString(gv), gc, hex.EncodeToString(cv), cc)
}
})
}
|