From 453249f01cfeb54c3d549ddb75ff152ca243f9d8 Mon Sep 17 00:00:00 2001 From: Adam Langley Date: Wed, 8 Feb 2017 12:51:15 -0800 Subject: [PATCH] poly1305: add burn-in test. This is the test that I use to sanity-check significant changes to the package, thus it's probably worth checking it in. Since it's very slow, it's disabled by default. (Note that while it stands a good chance of catching errors in 32-bit implementations, no amount of random testing is going to get useful coverage for 64-bit implementations. Thus it really is just a sanity check, despite the long run-time.) Change-Id: I95b321eec6f3026dafbbc157a7ef35a27e88d247 Reviewed-on: https://go-review.googlesource.com/36566 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- poly1305/poly1305_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/poly1305/poly1305_test.go b/poly1305/poly1305_test.go index 7b8ab2f..017027f 100644 --- a/poly1305/poly1305_test.go +++ b/poly1305/poly1305_test.go @@ -6,10 +6,14 @@ package poly1305 import ( "bytes" + "encoding/hex" + "flag" "testing" "unsafe" ) +var stressFlag = flag.Bool("stress", false, "run slow stress tests") + var testData = []struct { in, k, correct []byte }{ @@ -88,6 +92,39 @@ func testSum(t *testing.T, unaligned bool) { } } +func TestBurnin(t *testing.T) { + // This test can be used to sanity-check significant changes. It can + // take about many minutes to run, even on fast machines. It's disabled + // by default. + if !*stressFlag { + t.Skip("skipping without -stress") + } + + var key [32]byte + var input [25]byte + var output [16]byte + + for i := range key { + key[i] = 1 + } + for i := range input { + input[i] = 2 + } + + for i := uint64(0); i < 1e10; i++ { + Sum(&output, input[:], &key) + copy(key[0:], output[:]) + copy(key[16:], output[:]) + copy(input[:], output[:]) + copy(input[16:], output[:]) + } + + const expected = "5e3b866aea0b636d240c83c428f84bfa" + if got := hex.EncodeToString(output[:]); got != expected { + t.Errorf("expected %s, got %s", expected, got) + } +} + func TestSum(t *testing.T) { testSum(t, false) } func TestSumUnaligned(t *testing.T) { testSum(t, true) }