示例#1
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),
		))
}
示例#2
0
func (t *DecryptTest) GeneratedTestCases() {
	cases := aes_testing.EncryptCases()
	AssertGe(len(cases), 100)

	for i, c := range cases {
		plaintext, err := siv.Decrypt(c.Key, c.Output, c.Associated)
		AssertEq(nil, err, "Case %d: %v", i, c)
		ExpectThat(plaintext, DeepEquals(c.Plaintext), "Case %d: %v", i, c)
	}
}
示例#3
0
func (t *DecryptTest) CorruptedCiphertext() {
	// Grab a test case.
	cases := aes_testing.EncryptCases()
	AssertGt(len(cases), 10)
	c := cases[10]

	// Corrupt its ciphertext and call.
	AssertGt(len(c.Output), 19)
	c.Output[19]++

	_, err := siv.Decrypt(c.Key, c.Output, c.Associated)
	ExpectThat(err, Error(HasSubstr("authentic")))

	_, ok := err.(*siv.NotAuthenticError)
	ExpectTrue(ok, "Not an instance of *NotAuthenticError.")
}
示例#4
0
func (t *DecryptTest) WrongKey() {
	// Grab a test case.
	cases := aes_testing.EncryptCases()
	AssertGt(len(cases), 1)
	c := cases[1]

	// Corrupt its key and call.
	AssertGt(len(c.Key), 13)
	c.Key[13]++

	_, err := siv.Decrypt(c.Key, c.Output, c.Associated)
	ExpectThat(err, Error(HasSubstr("authentic")))

	_, ok := err.(*siv.NotAuthenticError)
	ExpectTrue(ok, "Not an instance of *NotAuthenticError.")
}
示例#5
0
func (t *EncryptTest) OutputIsDeterministic() {
	cases := aes_testing.EncryptCases()
	AssertGt(len(cases), 37)
	c := cases[37]

	output0, err := siv.Encrypt(nil, c.Key, c.Plaintext, c.Associated)
	AssertEq(nil, err)

	output1, err := siv.Encrypt(nil, c.Key, c.Plaintext, c.Associated)
	AssertEq(nil, err)

	output2, err := siv.Encrypt(nil, c.Key, c.Plaintext, c.Associated)
	AssertEq(nil, err)

	AssertGt(len(output0), 0)
	ExpectThat(output0, DeepEquals(output1))
	ExpectThat(output0, DeepEquals(output2))
}