From 8291fff38ab6f2928eca153913c3b5773aa0de98 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 21 Oct 2016 16:39:25 -0400 Subject: [PATCH] blake2b: test all three hashing implementations This adds use* flags for all arches so a common test can observe what implementations are supported and test all supported implementations. Change-Id: I0497b91294ed99309074ac4614ac996e006630c5 Reviewed-on: https://go-review.googlesource.com/31714 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Minux Ma Reviewed-by: Andreas Auernhammer --- blake2b/blake2b_amd64.go | 1 + blake2b/blake2b_ref.go | 3 +++ blake2b/blake2b_test.go | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/blake2b/blake2b_amd64.go b/blake2b/blake2b_amd64.go index 374b5f7..f11dcbc 100644 --- a/blake2b/blake2b_amd64.go +++ b/blake2b/blake2b_amd64.go @@ -6,6 +6,7 @@ package blake2b +var useAVX2 = false var useSSE4 = supportSSE4() //go:noescape diff --git a/blake2b/blake2b_ref.go b/blake2b/blake2b_ref.go index da156a1..2c3c68b 100644 --- a/blake2b/blake2b_ref.go +++ b/blake2b/blake2b_ref.go @@ -6,6 +6,9 @@ package blake2b +var useAVX2 = false +var useSSE4 = false + func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) { hashBlocksGeneric(h, c, flag, blocks) } diff --git a/blake2b/blake2b_test.go b/blake2b/blake2b_test.go index 54778d1..4607fda 100644 --- a/blake2b/blake2b_test.go +++ b/blake2b/blake2b_test.go @@ -21,6 +21,25 @@ func fromHex(s string) []byte { } func TestHashes(t *testing.T) { + defer func(sse4, avx2 bool) { + useSSE4, useAVX2 = sse4, avx2 + }(useSSE4, useAVX2) + + if useAVX2 { + t.Log("AVX2 version") + testHashes(t) + useAVX2 = false + } + if useSSE4 { + t.Log("SSE4 version") + testHashes(t) + useSSE4 = false + } + t.Log("generic version") + testHashes(t) +} + +func testHashes(t *testing.T) { key, _ := hex.DecodeString("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f") input := make([]byte, 255)