File: fuzz_test.go

package info (click to toggle)
golang-github-pjbgf-sha1cd 0.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,576 kB
  • sloc: ansic: 2,188; asm: 1,527; makefile: 28
file content (36 lines) | stat: -rw-r--r-- 699 bytes parent folder | download
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)
		}
	})
}