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 <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
Reviewed-by: Andreas Auernhammer <aead@mail.de>
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 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)