From 814723eff783c3281d914985cac5d548bfc96424 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 21 Oct 2016 16:39:25 -0400 Subject: [PATCH] blake2s: test all four 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: Icc9c3c1d15626e95f0446493b7fa3159bbe9567d Reviewed-on: https://go-review.googlesource.com/31712 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Minux Ma Reviewed-by: Andreas Auernhammer --- blake2s/blake2s_386.go | 6 ++++-- blake2s/blake2s_amd64.go | 6 ++++-- blake2s/blake2s_ref.go | 7 +++++++ blake2s/blake2s_test.go | 26 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/blake2s/blake2s_386.go b/blake2s/blake2s_386.go index e87da61..3ed0c8c 100644 --- a/blake2s/blake2s_386.go +++ b/blake2s/blake2s_386.go @@ -7,8 +7,10 @@ package blake2s var ( - useSSSE3 = supportSSSE3() - useSSE2 = supportSSE2() + useSSE4 = false + useSSSE3 = supportSSSE3() + useSSE2 = supportSSE2() + useGeneric = true ) //go:noescape diff --git a/blake2s/blake2s_amd64.go b/blake2s/blake2s_amd64.go index 6c5d830..c88f330 100644 --- a/blake2s/blake2s_amd64.go +++ b/blake2s/blake2s_amd64.go @@ -7,8 +7,10 @@ package blake2s var ( - useSSE4 = supportSSE4() - useSSSE3 = supportSSSE3() + useSSE4 = supportSSE4() + useSSSE3 = supportSSSE3() + useSSE2 = true // Always available on amd64 + useGeneric = false ) //go:noescape diff --git a/blake2s/blake2s_ref.go b/blake2s/blake2s_ref.go index eded925..9ce99f2 100644 --- a/blake2s/blake2s_ref.go +++ b/blake2s/blake2s_ref.go @@ -6,6 +6,13 @@ package blake2s +var ( + useSSE4 = false + useSSSE3 = false + useSSE2 = false + useGeneric = true +) + func hashBlocks(h *[8]uint32, c *[2]uint32, flag uint32, blocks []byte) { hashBlocksGeneric(h, c, flag, blocks) } diff --git a/blake2s/blake2s_test.go b/blake2s/blake2s_test.go index ab73bbb..e6f2eeb 100644 --- a/blake2s/blake2s_test.go +++ b/blake2s/blake2s_test.go @@ -11,6 +11,32 @@ import ( ) func TestHashes(t *testing.T) { + defer func(sse2, ssse3, sse4 bool) { + useSSE2, useSSSE3, useSSE4 = sse2, ssse3, sse4 + }(useSSE2, useSSSE3, useSSE4) + + if useSSE4 { + t.Log("SSE4 version") + testHashes(t) + useSSE4 = false + } + if useSSSE3 { + t.Log("SSSE3 version") + testHashes(t) + useSSSE3 = false + } + if useSSE2 { + t.Log("SSE2 version") + testHashes(t) + useSSE2 = false + } + if useGeneric { + t.Log("generic version") + testHashes(t) + } +} + +func testHashes(t *testing.T) { key, _ := hex.DecodeString("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f") input := make([]byte, 255)