Example #1
0
func (t *HashTest) NilMessage() {
	key := aes_testing.FromRfcHex("2b7e1516 28aed2a6 abf71588 09cf4f3c")

	var msg []byte = nil

	expectedMac := aes_testing.FromRfcHex("bb1d6929 e9593728 7fa37d12 9b756746")

	mac := runCmac(key, msg)
	ExpectThat(mac, DeepEquals(expectedMac))
}
Example #2
0
func (t *SubkeyTest) NistTestCaseD1() {
	key := aes_testing.FromRfcHex("2b7e1516 28aed2a6 abf71588 09cf4f3c")
	expectedK1 := aes_testing.FromRfcHex("fbeed618 35713366 7c85e08f 7236a8de")
	expectedK2 := aes_testing.FromRfcHex("f7ddac30 6ae266cc f90bc11e e46d513b")

	ciph, err := aes.NewCipher(key)
	AssertEq(nil, err)

	k1, k2 := generateSubkeys(ciph)
	ExpectThat(k1, DeepEquals(expectedK1))
	ExpectThat(k2, DeepEquals(expectedK2))
}
Example #3
0
func (t *S2vTest) Rfc5297GoldenTestCaseA1() {
	key := aes_testing.FromRfcHex("fffefdfc fbfaf9f8 f7f6f5f4 f3f2f1f0")

	strings := [][]byte{
		aes_testing.FromRfcHex(
			"10111213 14151617 18191a1b 1c1d1e1f" +
				"20212223 24252627"),
		aes_testing.FromRfcHex(
			"11223344 55667788 99aabbcc ddee"),
	}

	expected := aes_testing.FromRfcHex("85632d07 c6e8f37f 950acd32 0a2ecc93")

	ExpectThat(s2v(key, strings, nil), DeepEquals(expected))
}
Example #4
0
func (t *SubkeyTest) NistTestCaseD3() {
	key := aes_testing.FromRfcHex(
		"603deb10 15ca71be 2b73aef0 857d7781" +
			"1f352c07 3b6108d7 2d9810a3 0914dff4")

	expectedK1 := aes_testing.FromRfcHex("cad1ed03 299eedac 2e9a9980 8621502f")
	expectedK2 := aes_testing.FromRfcHex("95a3da06 533ddb58 5d353301 0c42a0d9")

	ciph, err := aes.NewCipher(key)
	AssertEq(nil, err)

	k1, k2 := generateSubkeys(ciph)
	ExpectThat(k1, DeepEquals(expectedK1))
	ExpectThat(k2, DeepEquals(expectedK2))
}
Example #5
0
func (t *SubkeyTest) NistTestCaseD2() {
	key := aes_testing.FromRfcHex(
		"8e73b0f7 da0e6452 c810f32b 809079e5" +
			"62f8ead2 522c6b7b")

	expectedK1 := aes_testing.FromRfcHex("448a5b1c 93514b27 3ee6439d d4daa296")
	expectedK2 := aes_testing.FromRfcHex("8914b639 26a2964e 7dcc873b a9b5452c")

	ciph, err := aes.NewCipher(key)
	AssertEq(nil, err)

	k1, k2 := generateSubkeys(ciph)
	ExpectThat(k1, DeepEquals(expectedK1))
	ExpectThat(k2, DeepEquals(expectedK2))
}
Example #6
0
func (t *S2vTest) EmptyStringsVector() {
	key := aes_testing.FromRfcHex("fffefdfc fbfaf9f8 f7f6f5f4 f3f2f1f0")
	strings := [][]byte{}

	f := func() { s2v(key, strings, nil) }
	ExpectThat(f, Panics(HasSubstr("non-empty")))
}
Example #7
0
func (t *DecryptTest) DoesntClobberAssociatedSlice() {
	// Grab a test case with some associated data.
	cases := aes_testing.EncryptCases()
	AssertGt(len(cases), 1)
	c := cases[1]
	AssertEq(len(c.Associated), 1)

	// Make a copy of the associated data.
	associated0 := dup(c.Associated[0])

	// Create a longer slice with some other data too.
	associated1 := aes_testing.FromRfcHex("deadbeef")
	longSlice := [][]byte{
		associated0,
		associated1,
	}

	// Call with a slice missing the last element, equivalent to the original
	// associated data. The last element shouldn't be clobbered.
	_, err := siv.Decrypt(c.Key, c.Output, longSlice[:1])
	AssertEq(nil, err)

	ExpectThat(
		longSlice,
		ElementsAre(
			DeepEquals(associated0),
			DeepEquals(associated1),
		))
}
Example #8
0
func (t *DecryptTest) Rfc5297TestCaseA2() {
	key := aes_testing.FromRfcHex(
		"7f7e7d7c 7b7a7978 77767574 73727170" +
			"40414243 44454647 48494a4b 4c4d4e4f")

	ciphertext := aes_testing.FromRfcHex(
		"7bdb6e3b 432667eb 06f4d14b ff2fbd0f" +
			"cb900f2f ddbe4043 26601965 c889bf17" +
			"dba77ceb 094fa663 b7a3f748 ba8af829" +
			"ea64ad54 4a272e9c 485b62a3 fd5c0d")

	associated := [][]byte{
		aes_testing.FromRfcHex(
			"00112233 44556677 8899aabb ccddeeff" +
				"deaddada deaddada ffeeddcc bbaa9988" +
				"77665544 33221100"),
		aes_testing.FromRfcHex(
			"10203040 50607080 90a0"),
		aes_testing.FromRfcHex(
			"09f91102 9d74e35b d84156c5 635688c0"),
	}

	expected := aes_testing.FromRfcHex(
		"74686973 20697320 736f6d65 20706c61" +
			"696e7465 78742074 6f20656e 63727970" +
			"74207573 696e6720 5349562d 414553")

	output, err := siv.Decrypt(key, ciphertext, associated)
	AssertEq(nil, err)
	ExpectThat(output, DeepEquals(expected))
}
Example #9
0
func (t *HashTest) NistTestCaseD3() {
	key := aes_testing.FromRfcHex(
		"603deb10 15ca71be 2b73aef0 857d7781" +
			"1f352c07 3b6108d7 2d9810a3 0914dff4")

	msg := aes_testing.FromRfcHex(
		"6bc1bee2 2e409f96 e93d7e11 7393172a" +
			"ae2d8a57 1e03ac9c 9eb76fac 45af8e51" +
			"30c81c46 a35ce411 e5fbc119 1a0a52ef" +
			"f69f2445 df4f9b17 ad2b417b e66c3710")

	var expectedMac []byte

	// Example 1
	expectedMac = aes_testing.FromRfcHex("028962f6 1b7bf89e fc6b551f 4667d983")
	ExpectThat(runCmac(key, msg[0:0]), DeepEquals(expectedMac))

	// Example 2
	expectedMac = aes_testing.FromRfcHex("28a7023f 452e8f82 bd4bf28d 8c37c35c")
	ExpectThat(runCmac(key, msg[0:16]), DeepEquals(expectedMac))

	// Example 3
	expectedMac = aes_testing.FromRfcHex("aaf3d8f1 de5640c2 32f5b169 b9c911e6")
	ExpectThat(runCmac(key, msg[0:40]), DeepEquals(expectedMac))

	// Example 4
	expectedMac = aes_testing.FromRfcHex("e1992190 549f6ed5 696a2c05 6c315410")
	ExpectThat(runCmac(key, msg[0:64]), DeepEquals(expectedMac))
}
Example #10
0
func (t *HashTest) NistTestCaseD2() {
	key := aes_testing.FromRfcHex(
		"8e73b0f7 da0e6452 c810f32b 809079e5" +
			"62f8ead2 522c6b7b")

	msg := aes_testing.FromRfcHex(
		"6bc1bee2 2e409f96 e93d7e11 7393172a" +
			"ae2d8a57 1e03ac9c 9eb76fac 45af8e51" +
			"30c81c46 a35ce411 e5fbc119 1a0a52ef" +
			"f69f2445 df4f9b17 ad2b417b e66c3710")

	var expectedMac []byte

	// Example 1
	expectedMac = aes_testing.FromRfcHex("d17ddf46 adaacde5 31cac483 de7a9367")
	ExpectThat(runCmac(key, msg[0:0]), DeepEquals(expectedMac))

	// Example 2
	expectedMac = aes_testing.FromRfcHex("9e99a7bf 31e71090 0662f65e 617c5184")
	ExpectThat(runCmac(key, msg[0:16]), DeepEquals(expectedMac))

	// Example 3
	expectedMac = aes_testing.FromRfcHex("8a1de5be 2eb31aad 089a82e6 ee908b0e")
	ExpectThat(runCmac(key, msg[0:40]), DeepEquals(expectedMac))

	// Example 4
	expectedMac = aes_testing.FromRfcHex("a1d5df0e ed790f79 4d775896 59f39a11")
	ExpectThat(runCmac(key, msg[0:64]), DeepEquals(expectedMac))
}
Example #11
0
func (t *HashTest) NistTestCaseD1() {
	key := aes_testing.FromRfcHex("2b7e1516 28aed2a6 abf71588 09cf4f3c")
	msg := aes_testing.FromRfcHex(
		"6bc1bee2 2e409f96 e93d7e11 7393172a" +
			"ae2d8a57 1e03ac9c 9eb76fac 45af8e51" +
			"30c81c46 a35ce411 e5fbc119 1a0a52ef" +
			"f69f2445 df4f9b17 ad2b417b e66c3710")

	var expectedMac []byte

	// Example 1
	expectedMac = aes_testing.FromRfcHex("bb1d6929 e9593728 7fa37d12 9b756746")
	ExpectThat(runCmac(key, msg[0:0]), DeepEquals(expectedMac))

	// Example 2
	expectedMac = aes_testing.FromRfcHex("070a16b4 6b4d4144 f79bdd9d d04a287c")
	ExpectThat(runCmac(key, msg[0:16]), DeepEquals(expectedMac))

	// Example 3
	expectedMac = aes_testing.FromRfcHex("dfa66747 de9ae630 30ca3261 1497c827")
	ExpectThat(runCmac(key, msg[0:40]), DeepEquals(expectedMac))

	// Example 4
	expectedMac = aes_testing.FromRfcHex("51f0bebf 7e3b9d92 fc497417 79363cfe")
	ExpectThat(runCmac(key, msg[0:64]), DeepEquals(expectedMac))
}
Example #12
0
func (t *DecryptTest) Rfc5297TestCaseA1() {
	key := aes_testing.FromRfcHex(
		"fffefdfc fbfaf9f8 f7f6f5f4 f3f2f1f0" +
			"f0f1f2f3 f4f5f6f7 f8f9fafb fcfdfeff")

	ciphertext := aes_testing.FromRfcHex(
		"85632d07 c6e8f37f 950acd32 0a2ecc93" +
			"40c02b96 90c4dc04 daef7f6a fe5c")

	associated := [][]byte{
		aes_testing.FromRfcHex(
			"10111213 14151617 18191a1b 1c1d1e1f" +
				"20212223 24252627"),
	}

	expected := aes_testing.FromRfcHex(
		"11223344 55667788 99aabbcc ddee")

	output, err := siv.Decrypt(key, ciphertext, associated)
	AssertEq(nil, err)
	ExpectThat(output, DeepEquals(expected))
}
Example #13
0
func (t *EncryptTest) DoesntClobberAssociatedSlice() {
	key := make([]byte, 32)
	plaintext := []byte{}

	associated0 := aes_testing.FromRfcHex("deadbeef")
	associated1 := aes_testing.FromRfcHex("feedface")
	associated2 := aes_testing.FromRfcHex("ba5eba11")
	associated := [][]byte{associated0, associated1, associated2}

	// Call with a slice of associated missing the last element. The last element
	// shouldn't be clobbered.
	_, err := siv.Encrypt(nil, key, plaintext, associated[:2])
	AssertEq(nil, err)

	ExpectThat(
		associated,
		ElementsAre(
			DeepEquals(associated0),
			DeepEquals(associated1),
			DeepEquals(associated2),
		))
}
Example #14
0
func (t *DblTest) RfcTestCases() {
	type testCase struct {
		iHex string
		oHex string
	}

	cases := []testCase{
		testCase{
			"0e04dfaf c1efbf04 01405828 59bf073a",
			"1c09bf5f 83df7e08 0280b050 b37e0e74",
		},
		testCase{
			"edf09de8 76c642ee 4d78bce4 ceedfc4f",
			"dbe13bd0 ed8c85dc 9af179c9 9ddbf819",
		},
		testCase{
			"0e04dfaf c1efbf04 01405828 59bf073a",
			"1c09bf5f 83df7e08 0280b050 b37e0e74",
		},
		testCase{
			"c8b43b59 74960e7c e6a5dd85 231e591a",
			"916876b2 e92c1cf9 cd4bbb0a 463cb2b3",
		},
		testCase{
			"adf31e28 5d3d1e1d 4ddefc1e 5bec63e9",
			"5be63c50 ba7a3c3a 9bbdf83c b7d8c755",
		},
		testCase{
			"826aa75b 5e568eed 3125bfb2 66c61d4e",
			"04d54eb6 bcad1dda 624b7f64 cd8c3a1b",
		},
	}

	for i, c := range cases {
		input := aes_testing.FromRfcHex(c.iHex)
		expected := aes_testing.FromRfcHex(c.oHex)
		ExpectThat(dbl(input), DeepEquals(expected), "Case %d: %v", i, c)
	}
}
Example #15
0
func (t *S2vTest) Rfc5297GoldenTestCaseA2() {
	key := aes_testing.FromRfcHex("7f7e7d7c 7b7a7978 77767574 73727170")

	strings := [][]byte{
		aes_testing.FromRfcHex(
			"00112233 44556677 8899aabb ccddeeff" +
				"deaddada deaddada ffeeddcc bbaa9988" +
				"77665544 33221100"),
		aes_testing.FromRfcHex("10203040 50607080 90a0"),
		aes_testing.FromRfcHex("09f91102 9d74e35b d84156c5 635688c0"),
		aes_testing.FromRfcHex(
			"74686973 20697320 736f6d65 20706c61" +
				"696e7465 78742074 6f20656e 63727970" +
				"74207573 696e6720 5349562d 414553"),
	}

	expected := aes_testing.FromRfcHex("7bdb6e3b 432667eb 06f4d14b ff2fbd0f")

	ExpectThat(s2v(key, strings, nil), DeepEquals(expected))
}