20 #include <gtest/gtest.h>
26 #include "../test/file_test.h"
27 #include "../test/test_util.h"
28 #include "../test/wycheproof_util.h"
44 for (
unsigned chunk_size = 1; chunk_size <= msg_len; chunk_size++) {
50 while (
done < msg_len) {
63 size_t chunk = msg_len / 2;
74 TEST(CMACTest, RFC4493TestVectors) {
76 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
77 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
79 static const uint8_t kOut1[16] = {
80 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
81 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46,
83 static const uint8_t kMsg2[] = {
84 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
85 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
87 static const uint8_t kOut2[16] = {
88 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
89 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c,
91 static const uint8_t kMsg3[] = {
92 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
93 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
94 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
95 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
96 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
98 static const uint8_t kOut3[16] = {
99 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
100 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27,
102 static const uint8_t kMsg4[] = {
103 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
104 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
105 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
106 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
107 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
108 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
109 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
110 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10,
112 static const uint8_t kOut4[16] = {
113 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
114 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe,
117 test(
"RFC 4493 #1",
kKey,
sizeof(
kKey), NULL, 0, kOut1);
118 test(
"RFC 4493 #2",
kKey,
sizeof(
kKey), kMsg2,
sizeof(kMsg2), kOut2);
119 test(
"RFC 4493 #3",
kKey,
sizeof(
kKey), kMsg3,
sizeof(kMsg3), kOut3);
120 test(
"RFC 4493 #4",
kKey,
sizeof(
kKey), kMsg4,
sizeof(kMsg4), kOut4);
124 FileTestGTest(
"third_party/wycheproof_testvectors/aes_cmac_test.txt",
127 ASSERT_TRUE(t->GetInstruction(&key_size,
"keySize"));
128 ASSERT_TRUE(t->GetInstruction(&tag_size,
"tagSize"));
137 switch (atoi(key_size.c_str())) {
155 size_t tag_len =
static_cast<size_t>(atoi(tag_size.c_str())) / 8;
165 out_len =
std::min(out_len, tag_len);
176 out_len =
std::min(out_len, tag_len);
190 t->IgnoreAttribute(
"Count");
191 t->IgnoreAttribute(
"Klen");
196 std::vector<uint8_t>
key,
msg, mac;
198 std::vector<uint8_t>
key2, key3;
203 key.insert(
key.end(), key3.begin(), key3.end());
211 if (atoi(m_len.c_str()) == 0) {
214 EXPECT_EQ(
static_cast<size_t>(atoi(m_len.c_str())),
msg.size());
217 size_t tag_len =
static_cast<size_t>(atoi(t_len.c_str()));
227 out_len =
std::min(out_len, tag_len);
239 out_len =
std::min(out_len, tag_len);