Переглянути джерело

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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Adam Langley 8 роки тому
батько
коміт
453249f01c
1 змінених файлів з 37 додано та 0 видалено
  1. 37 0
      poly1305/poly1305_test.go

+ 37 - 0
poly1305/poly1305_test.go

@@ -6,10 +6,14 @@ package poly1305
 
 
 import (
 import (
 	"bytes"
 	"bytes"
+	"encoding/hex"
+	"flag"
 	"testing"
 	"testing"
 	"unsafe"
 	"unsafe"
 )
 )
 
 
+var stressFlag = flag.Bool("stress", false, "run slow stress tests")
+
 var testData = []struct {
 var testData = []struct {
 	in, k, correct []byte
 	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 TestSum(t *testing.T)          { testSum(t, false) }
 func TestSumUnaligned(t *testing.T) { testSum(t, true) }
 func TestSumUnaligned(t *testing.T) { testSum(t, true) }