diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index da5ba57..25ad2fb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ jobs: strategy: fail-fast: false matrix: - go-version: [1.22.x, 1.23.x] + go-version: [1.23.x, 1.24.x] venv: [windows-2019, windows-2022] fips: [1, 0] runs-on: ${{ matrix.venv }} diff --git a/cng/hash_test.go b/cng/hash_test.go index 67f88e4..33100dc 100644 --- a/cng/hash_test.go +++ b/cng/hash_test.go @@ -181,6 +181,61 @@ func TestHash_OneShot(t *testing.T) { } } +func TestHashAllocations(t *testing.T) { + msg := []byte("testing") + n := int(testing.AllocsPerRun(10, func() { + sink ^= cng.MD4(msg)[0] + sink ^= cng.MD5(msg)[0] + sink ^= cng.SHA1(msg)[0] + sink ^= cng.SHA256(msg)[0] + sink ^= cng.SHA384(msg)[0] + sink ^= cng.SHA512(msg)[0] + })) + want := 0 + if n > want { + t.Errorf("allocs = %d, want %d", n, want) + } +} + +func TestHashStructAllocations(t *testing.T) { + msg := []byte("testing") + + md4Hash := cng.NewMD4() + md5Hash := cng.NewMD5() + sha1Hash := cng.NewSHA1() + sha256Hash := cng.NewSHA256() + sha384Hash := cng.NewSHA384() + sha512Hash := cng.NewSHA512() + + sum := make([]byte, sha512Hash.Size()) + n := int(testing.AllocsPerRun(10, func() { + md4Hash.Write(msg) + md5Hash.Write(msg) + sha1Hash.Write(msg) + sha256Hash.Write(msg) + sha384Hash.Write(msg) + sha512Hash.Write(msg) + + md4Hash.Sum(sum[:0]) + md5Hash.Sum(sum[:0]) + sha1Hash.Sum(sum[:0]) + sha256Hash.Sum(sum[:0]) + sha384Hash.Sum(sum[:0]) + sha512Hash.Sum(sum[:0]) + + md4Hash.Reset() + md5Hash.Reset() + sha1Hash.Reset() + sha256Hash.Reset() + sha384Hash.Reset() + sha512Hash.Reset() + })) + want := 0 + if n > want { + t.Errorf("allocs = %d, want %d", n, want) + } +} + func BenchmarkSHA256_8Bytes(b *testing.B) { b.StopTimer() h := cng.NewSHA256()