25 #include "../crypto/test/file_test.h"
26 #include "../crypto/test/test_util.h"
39 if (
name ==
"aes-128-gcm") {
41 }
else if (
name ==
"aes-192-gcm") {
43 }
else if (
name ==
"aes-256-gcm") {
50 TestCtx *
ctx =
reinterpret_cast<TestCtx *
>(
arg);
52 std::string key_len_str, iv_len_str, pt_len_str, aad_len_str, tag_len_str;
53 if (!t->GetInstruction(&key_len_str,
"Keylen") ||
54 !t->GetInstruction(&iv_len_str,
"IVlen") ||
55 !t->GetInstruction(&pt_len_str,
"PTlen") ||
56 !t->GetInstruction(&aad_len_str,
"AADlen") ||
57 !t->GetInstruction(&tag_len_str,
"Taglen")) {
62 std::vector<uint8_t>
key, iv, pt, aad,
tag, ct;
63 if (!t->GetAttribute(&
count,
"Count") ||
64 !t->GetBytes(&
key,
"Key") ||
65 !t->GetBytes(&iv,
"IV") ||
66 !t->GetBytes(&pt,
"PT") ||
67 !t->GetBytes(&aad,
"AAD") ||
68 key.size() * 8 != strtoul(key_len_str.c_str(),
nullptr, 0) ||
69 iv.size() * 8 != strtoul(iv_len_str.c_str(),
nullptr, 0) ||
70 pt.size() * 8 != strtoul(pt_len_str.c_str(),
nullptr, 0) ||
71 aad.size() * 8 != strtoul(aad_len_str.c_str(),
nullptr, 0) ||
76 const size_t tag_len = strtoul(tag_len_str.c_str(),
nullptr, 0) / 8;
80 printf(
"%s", t->CurrentTestToString().c_str());
88 TestCtx *
ctx =
reinterpret_cast<TestCtx *
>(
arg);
90 std::string key_len, iv_len, pt_len_str, aad_len_str, tag_len;
91 if (!t->GetInstruction(&key_len,
"Keylen") ||
92 !t->GetInstruction(&iv_len,
"IVlen") ||
93 !t->GetInstruction(&pt_len_str,
"PTlen") ||
94 !t->GetInstruction(&aad_len_str,
"AADlen") ||
95 !t->GetInstruction(&tag_len,
"Taglen")) {
96 t->PrintLine(
"Invalid instruction block.");
99 size_t aad_len = strtoul(aad_len_str.c_str(),
nullptr, 0) / 8;
100 size_t pt_len = strtoul(pt_len_str.c_str(),
nullptr, 0) / 8;
103 std::vector<uint8_t>
key, iv, ct, aad,
tag, pt;
104 if (!t->GetAttribute(&
count,
"Count") ||
105 !t->GetBytes(&
key,
"Key") ||
106 !t->GetBytes(&aad,
"AAD") ||
107 !t->GetBytes(&
tag,
"Tag") ||
108 !t->GetBytes(&iv,
"IV") ||
109 !t->GetBytes(&ct,
"CT") ||
110 key.size() * 8 != strtoul(key_len.c_str(),
nullptr, 0) ||
111 iv.size() * 8 != strtoul(iv_len.c_str(),
nullptr, 0) ||
112 ct.size() != pt_len ||
113 aad.size() != aad_len ||
114 tag.size() * 8 != strtoul(tag_len.c_str(),
nullptr, 0)) {
115 t->PrintLine(
"Invalid test case");
119 printf(
"%s", t->CurrentTestToString().c_str());
132 fprintf(
stderr,
"usage: %s (enc|dec) <cipher> <test file>\n",
arg);
138 return usage(argv[0]);
145 }
else if (
mode ==
"dec") {
148 return usage(argv[0]);
152 if (aead ==
nullptr) {
153 fprintf(
stderr,
"invalid aead: %s\n", argv[2]);
157 TestCtx
ctx = {aead};
161 opts.callback = test_fn;