| 1 |
// Copyright 2025 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 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 |
// TestHash performs a set of tests on hash.Hash implementations, checking the |
| 21 |
// documented requirements of Write, Sum, Reset, Size, and BlockSize. |
| 22 |
func TestHash(t *testing.T, mh MakeHash) { |
| 23 |
if boring.Enabled || fips140.Version() == "v1.0.0" { |
| 24 |
testhash.TestHashWithoutClone(t, testhash.MakeHash(mh)) |
| 25 |
return |
| 26 |
} |
| 27 |
testhash.TestHash(t, testhash.MakeHash(mh)) |
| 28 |
} |
| 29 |
|
| 30 |
func newRandReader(t *testing.T) io.Reader { |
| 31 |
seed := time.Now().UnixNano() |
| 32 |
t.Logf("Deterministic RNG seed: 0x%x", seed) |
| 33 |
return rand.New(rand.NewSource(seed)) |
| 34 |
} |