Browse Source

Add tests against the vector(s) from Appendix A.

Yawning Angel 1 year ago
parent
commit
85e24218ab
3 changed files with 83 additions and 7 deletions
  1. 23 0
      norx_kat_6441_test.go
  2. 23 0
      norx_kat_6461_test.go
  3. 37 7
      norx_test.go

+ 23 - 0
norx_kat_6441_test.go

@@ -7,6 +7,29 @@
 
 package norx
 
+var vec6441 = []byte{
+	0xC0, 0x81, 0x6E, 0x50, 0x8A, 0xE4, 0xA0, 0x50,
+	0x0B, 0x93, 0x38, 0x7B, 0xBB, 0xAB, 0xC2, 0x41,
+	0xAC, 0x42, 0x38, 0x7E, 0xF5, 0xE8, 0xBF, 0x0E,
+	0xC3, 0x82, 0x6C, 0xED, 0xE1, 0x66, 0xA1, 0xD5,
+	0xCA, 0xA3, 0xE8, 0xD6, 0x2C, 0xD6, 0x41, 0xB3,
+	0xFA, 0xF2, 0xAA, 0x2A, 0xDD, 0xE3, 0xE5, 0xED,
+	0x0A, 0x13, 0xBD, 0x8B, 0x96, 0xD5, 0xF0, 0xFB,
+	0x7F, 0xE3, 0x9C, 0xA7, 0x80, 0x95, 0x31, 0x75,
+	0xE2, 0x45, 0xBC, 0x3E, 0x53, 0x4B, 0x80, 0x0E,
+	0x96, 0x46, 0x77, 0x1F, 0x13, 0xEA, 0x40, 0x85,
+	0xCB, 0x3E, 0x26, 0x7F, 0x10, 0x6F, 0x5F, 0x17,
+	0xA0, 0x64, 0xFF, 0x23, 0x4A, 0x02, 0x7C, 0x64,
+	0x4B, 0xE7, 0x86, 0x65, 0xDB, 0x1C, 0x46, 0xA4,
+	0xB0, 0x1A, 0x4F, 0xBF, 0x52, 0x76, 0xDF, 0xBD,
+	0x30, 0xEB, 0xBF, 0xB8, 0x84, 0x66, 0xF8, 0xDC,
+	0x89, 0x7A, 0x78, 0x16, 0xD0, 0xD0, 0x70, 0xD8,
+	0xD1, 0xF2, 0xFA, 0x33, 0x05, 0xA3, 0x23, 0x76,
+	0xE2, 0x3A, 0x61, 0xD1, 0xC9, 0x89, 0x30, 0x3F,
+	0xBF, 0xBD, 0x93, 0x5A, 0xA5, 0x5B, 0x17, 0xE4,
+	0xE7, 0x25, 0x47, 0x33, 0xC4, 0x73, 0x40, 0x8E,
+}
+
 var kat6441 = []byte{
 	0x9C, 0x89, 0x02, 0x43, 0x8E, 0x99, 0x52, 0x8E,
 	0xD8, 0x61, 0x28, 0x94, 0x8B, 0xB6, 0x97, 0x2F,

+ 23 - 0
norx_kat_6461_test.go

@@ -7,6 +7,29 @@
 
 package norx
 
+var vec6461 = []byte{
+	0x50, 0xCE, 0x69, 0x2C, 0x19, 0xCB, 0x91, 0x02,
+	0xC6, 0x12, 0x96, 0x6F, 0x0F, 0x62, 0x6B, 0x62,
+	0x96, 0xDE, 0x89, 0x27, 0x1C, 0x98, 0x29, 0x10,
+	0xAA, 0xC1, 0xC3, 0x55, 0x52, 0x2E, 0x8F, 0xA7,
+	0x13, 0x03, 0xF8, 0xD5, 0xC9, 0xDE, 0x39, 0x04,
+	0x84, 0xBA, 0x91, 0xA9, 0x94, 0xCF, 0xF9, 0x1B,
+	0xF7, 0x15, 0xD6, 0xCB, 0x22, 0xCC, 0x00, 0xF3,
+	0x64, 0x02, 0x10, 0x03, 0x17, 0x19, 0x61, 0x68,
+	0x72, 0x39, 0xDD, 0x94, 0x53, 0x02, 0x9B, 0x87,
+	0x85, 0x9C, 0x10, 0x93, 0x21, 0x13, 0x59, 0x40,
+	0xBC, 0x1B, 0xC8, 0x1A, 0x55, 0xA9, 0x51, 0xC7,
+	0x1B, 0x29, 0x42, 0xFF, 0xDE, 0xBF, 0x8D, 0x13,
+	0xC4, 0xF3, 0x87, 0x2B, 0x78, 0xD4, 0x50, 0x6F,
+	0x40, 0xDB, 0x65, 0x3C, 0xE3, 0xB8, 0xD2, 0xBE,
+	0xA7, 0xA2, 0xF9, 0xE9, 0x7F, 0xF4, 0x56, 0xB7,
+	0xF0, 0xDB, 0x8C, 0x92, 0x27, 0xE2, 0x2F, 0x23,
+	0xA0, 0xD1, 0x0D, 0x28, 0x52, 0x91, 0xBE, 0xDB,
+	0x7B, 0x7C, 0xBD, 0xC4, 0x7E, 0x0F, 0xE2, 0x38,
+	0x5B, 0xF5, 0x5B, 0xC5, 0xF0, 0x57, 0xBC, 0xAB,
+	0x2C, 0x57, 0xCC, 0xD0, 0x83, 0xD2, 0x9B, 0x2C,
+}
+
 var kat6461 = []byte{
 	0x31, 0x13, 0x20, 0x19, 0x0F, 0x63, 0xF8, 0x5D,
 	0x85, 0xAF, 0x1A, 0x03, 0xF1, 0x04, 0x82, 0x7A,

+ 37 - 7
norx_test.go

@@ -21,6 +21,10 @@ var (
 		"NORX-64-4-1": kat6441,
 		"NORX-64-6-1": kat6461,
 	}
+	testVectorCipherTexts = map[string][]byte{
+		"NORX-64-4-1": vec6441,
+		"NORX-64-6-1": vec6461,
+	}
 	canAccelerate bool
 )
 
@@ -74,10 +78,39 @@ func doTestKAT(t *testing.T) {
 
 	for _, l := range testRounds {
 		n := fmt.Sprintf("NORX-64-%d-1", l)
-		t.Run(n+impl, func(t *testing.T) { doTestKATFull(t, n, l) })
+		t.Run(n+"_Vector"+impl, func(t *testing.T) { doTestVector(t, n, l) })
+		t.Run(n+"_KAT"+impl, func(t *testing.T) { doTestKATFull(t, n, l) })
 	}
 }
 
+func doTestVector(t *testing.T, vn string, l int) {
+	require := require.New(t)
+	var k, n [32]byte
+	var a, m, z [128]byte
+
+	for i := range k {
+		k[i] = byte(i)
+		n[i] = byte(i + 32)
+	}
+	for i := range a {
+		a[i] = byte(i)
+		m[i] = byte(i)
+		z[i] = byte(i)
+	}
+
+	ctVec := testVectorCipherTexts[vn]
+	if ctVec == nil {
+		panic("missing test vector cipher text")
+	}
+
+	ct := aeadEncrypt(l, nil, a[:], m[:], z[:], n[:], k[:])
+	require.Equal(ctVec, ct, "aeadEncrypt()")
+
+	pt, ok := aeadDecrypt(l, nil, a[:], ct, z[:], n[:], k[:])
+	require.True(ok, "aeadDecrypt(): ok")
+	require.Equal(m[:], pt, "aeadDecrupt()")
+}
+
 func doTestKATFull(t *testing.T, vn string, l int) {
 	require := require.New(t)
 	var w, h [256]byte
@@ -113,7 +146,7 @@ func doTestKATFull(t *testing.T, vn string, l int) {
 		require.True(ok, "aeadDecrypt(): ok %d", i)
 		require.Len(m, i, "aeadDecrypt(): len(m) %d", i)
 		if len(m) != 0 {
-			require.EqualValues(m, w[:i], "aeadDecrupt(): m %d", i)
+			require.Equal(m, w[:i], "aeadDecrupt(): m %d", i)
 		}
 
 		katOff += len(c)
@@ -153,11 +186,8 @@ func doBenchmarkAEAD(b *testing.B, l, sz int, isEncrypt bool) {
 	b.StopTimer()
 	b.SetBytes(int64(sz))
 
-	m := make([]byte, sz)
-	nonce := make([]byte, NonceSize)
-	key := make([]byte, KeySize)
-	c := make([]byte, 0, sz+TagSize)
-	d := make([]byte, 0, sz)
+	nonce, key := make([]byte, NonceSize), make([]byte, KeySize)
+	m, c, d := make([]byte, sz), make([]byte, 0, sz+TagSize), make([]byte, 0, sz)
 	rand.Read(nonce)
 	rand.Read(key)
 	rand.Read(m)