Go to the documentation of this file.
24 #include "../crypto/test/file_test.h"
25 #include "../crypto/test/test_util.h"
45 bool encrypt, std::vector<uint8_t>
key,
46 std::vector<uint8_t> iv, std::vector<uint8_t>
in) {
47 const std::string in_label = encrypt ?
"PLAINTEXT" :
"CIPHERTEXT",
48 result_label = encrypt ?
"CIPHERTEXT" :
"PLAINTEXT";
49 std::vector<uint8_t> prev_result,
result, prev_in;
50 for (
int i = 0;
i < 100;
i++) {
58 for (
int j = 0; j < 1000; j++) {
66 for (
int j = 0; j < 1000; j++) {
92 const size_t key_len =
key.size() * 8;
94 for (
size_t k = 0;
k <
key.size();
k++) {
97 }
else if (key_len == 192) {
98 for (
size_t k = 0;
k <
key.size();
k++) {
101 key[
k] ^= prev_result[prev_result.size() - 8 +
k];
107 for (
size_t k = 0;
k <
key.size();
k++) {
110 key[
k] ^= prev_result[
k];
129 TestCtx *
ctx =
reinterpret_cast<TestCtx *
>(
arg);
131 if (t->HasInstruction(
"ENCRYPT") == t->HasInstruction(
"DECRYPT")) {
132 t->PrintLine(
"Want either ENCRYPT or DECRYPT");
138 } operation = t->HasInstruction(
"ENCRYPT") ? kEncrypt : kDecrypt;
142 if (!t->GetAttribute(&
count,
"COUNT") ||
143 !t->GetBytes(&
key,
"KEY") ||
144 (
ctx->has_iv && !t->GetBytes(&iv,
"IV"))) {
149 if (operation == kEncrypt) {
150 if (!t->GetBytes(&
in,
"PLAINTEXT")) {
154 if (!t->GetBytes(&
in,
"CIPHERTEXT")) {
159 if (
ctx->mode == TestCtx::kKAT) {
164 operation == kEncrypt ?
"CIPHERTEXT" :
"PLAINTEXT";
165 printf(
"%s%s = %s\r\n\r\n", t->CurrentTestToString().c_str(),
label.c_str(),
169 operation == kEncrypt ?
"[ENCRYPT]" :
"[DECRYPT]";
170 printf(
"%s\r\n\r\n", op_label.c_str());
175 if (operation == kEncrypt) {
185 fprintf(
stderr,
"usage: %s (kat|mct) <cipher> <test file>\n",
arg);
191 return usage(argv[0]);
198 }
else if (
tm ==
"mct") {
201 fprintf(
stderr,
"invalid test_mode: %s\n",
tm.c_str());
202 return usage(argv[0]);
207 if (cipher ==
nullptr) {
208 fprintf(
stderr,
"invalid cipher: %s\n", argv[2]);
212 (cipher_name !=
"aes-128-ecb" &&
213 cipher_name !=
"aes-192-ecb" &&
214 cipher_name !=
"aes-256-ecb");
int FileTestMain(FileTestFunc run_test, void *arg, const char *path)
int cavp_aes_test_main(int argc, char **argv)
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
static struct test_ctx ctx
static bool TestCipher(FileTest *t, void *arg)
def c_str(s, encoding='ascii')
std::string EncodeHex(bssl::Span< const uint8_t > in)
void EchoComment(const std::string &comment)
bool CipherOperation(const EVP_CIPHER *cipher, std::vector< uint8_t > *out, bool encrypt, const std::vector< uint8_t > &key, const std::vector< uint8_t > &iv, const std::vector< uint8_t > &in)
static int usage(char *arg)
static bool MonteCarlo(const TestCtx *ctx, FileTest *t, const EVP_CIPHER *cipher, std::vector< uint8_t > *out, bool encrypt, std::vector< uint8_t > key, std::vector< uint8_t > iv, std::vector< uint8_t > in)
static const EVP_CIPHER * GetCipher(const std::string &name)
static test_mode_t test_mode
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:52