1
2
3
4
5 package cryptotest
6
7 import (
8 "crypto/internal/boring"
9 "crypto/internal/fips140"
10 "hash"
11 "internal/testhash"
12 "io"
13 "math/rand"
14 "testing"
15 "time"
16 )
17
18 type MakeHash func() hash.Hash
19
20
21
22 func TestHash(t *testing.T, mh MakeHash) {
23 t.Run("OutOfBounds", func(t *testing.T) {
24 start, end := BoundarySlices(t, 1000)
25 h := mh()
26 for i := range len(start) + 1 {
27 h.Write(start[:i])
28 h.Write(start[len(start)-i:])
29 h.Write(end[:i])
30 h.Write(end[len(end)-i:])
31 }
32 start, end = BoundarySlices(t, h.Size())
33 h.Sum(start[:0])
34 h.Sum(end[:0])
35 })
36
37 if boring.Enabled || fips140.Version() == "v1.0.0" {
38 testhash.TestHashWithoutClone(t, testhash.MakeHash(mh))
39 return
40 }
41 testhash.TestHash(t, testhash.MakeHash(mh))
42 }
43
44 func newRandReader(t *testing.T) io.Reader {
45 seed := time.Now().UnixNano()
46 t.Logf("Deterministic RNG seed: 0x%x", seed)
47 return rand.New(rand.NewSource(seed))
48 }
49
View as plain text