1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
9 #include <rte_cryptodev.h>
11 #include "fips_validation.h"
13 #define MODE_STR "AESVS"
14 #define ALGO_STR "test data for "
15 #define OP_STR "State"
16 #define KEY_SIZE_STR "Key Length : "
19 #define COUNT_STR "COUNT = "
20 #define KEY_STR "KEY = "
21 #define IV_STR "IV = "
22 #define PT_STR "PLAINTEXT = "
23 #define CT_STR "CIPHERTEXT = "
25 #define OP_ENC_STR "ENCRYPT"
26 #define OP_DEC_STR "DECRYPT"
31 } aes_test_types[] = {
32 {AESAVS_TYPE_GFXBOX, "GFSbox"},
33 {AESAVS_TYPE_KEYSBOX, "KeySbox"},
34 {AESAVS_TYPE_VARKEY, "VarKey"},
35 {AESAVS_TYPE_VARTXT, "VarTxt"},
36 {TDES_VARIABLE_TEXT, "VARIABLE PLAINTEXT/CIPHERTEXT"},
37 {TDES_VARIABLE_TEXT, "KAT"},
38 {AESAVS_TYPE_MMT, "MMT"},
39 {AESAVS_TYPE_MCT, "MCT"},
42 struct aes_test_algo {
44 enum rte_crypto_cipher_algorithm algo;
45 } const algo_con[] = {
46 {"CBC", RTE_CRYPTO_CIPHER_AES_CBC},
50 parse_interim_enc_dec(const char *key,
51 __attribute__((__unused__)) char *text,
52 __attribute__((__unused__)) struct fips_val *val)
54 if (strcmp(key, OP_ENC_STR) == 0)
55 info.op = FIPS_TEST_ENC_AUTH_GEN;
56 else if (strcmp(key, OP_DEC_STR) == 0)
57 info.op = FIPS_TEST_DEC_AUTH_VERIF;
64 struct fips_test_callback aes_tests_interim[] = {
65 {OP_ENC_STR, parse_interim_enc_dec, NULL},
66 {OP_DEC_STR, parse_interim_enc_dec, NULL},
67 {NULL, NULL, NULL} /**< end pointer */
70 struct fips_test_callback aes_tests_vectors[] = {
71 {KEY_STR, parse_uint8_hex_str, &vec.cipher_auth.key},
72 {IV_STR, parse_uint8_hex_str, &vec.iv},
73 {PT_STR, parse_uint8_hex_str, &vec.pt},
74 {CT_STR, parse_uint8_hex_str, &vec.ct},
75 {NULL, NULL, NULL} /**< end pointer */
78 struct fips_test_callback aes_tests_interim_vectors[] = {
79 {OP_ENC_STR, parse_interim_enc_dec, NULL},
80 {OP_DEC_STR, parse_interim_enc_dec, NULL},
81 {NULL, NULL, NULL} /**< end pointer */
84 struct fips_test_callback aes_writeback_callbacks[] = {
85 /** First element is used to pass COUNT string */
86 {COUNT_STR, NULL, NULL},
87 {IV_STR, writeback_hex_str, &vec.iv},
88 {KEY_STR, writeback_hex_str, &vec.cipher_auth.key},
89 {PT_STR, writeback_hex_str, &vec.pt},
90 {CT_STR, writeback_hex_str, &vec.ct},
91 {NULL, NULL, NULL} /**< end pointer */
95 parse_test_aes_writeback(struct fips_val *val)
97 if (info.op == FIPS_TEST_ENC_AUTH_GEN)
98 fprintf(info.fp_wr, "%s", CT_STR);
100 fprintf(info.fp_wr, "%s", PT_STR);
102 parse_write_hex_str(val);
108 rsp_test_aes_check(struct fips_val *val)
110 struct fips_val *data;
112 if (info.op == FIPS_TEST_ENC_AUTH_GEN)
117 if (memcmp(val->val, data->val, val->len) == 0)
118 fprintf(info.fp_wr, "Success\n");
120 fprintf(info.fp_wr, "Failed\n");
126 parse_test_aes_init(void)
131 for (i = 0; i < info.nb_vec_lines; i++) {
132 char *line = info.vec[i];
134 tmp = strstr(line, MODE_STR);
136 for (j = 0; j < RTE_DIM(aes_test_types); j++)
137 if (strstr(line, aes_test_types[j].desc)) {
138 info.interim_info.aes_data.test_type =
139 aes_test_types[j].type;
143 if (j >= RTE_DIM(aes_test_types))
146 tmp = strstr(line, ALGO_STR);
150 tmp += strlen(ALGO_STR);
151 for (j = 0; j < RTE_DIM(algo_con); j++)
152 if (strcmp(algo_con[j].name, tmp) == 0) {
153 info.interim_info.aes_data.cipher_algo =
154 (uint32_t)algo_con[j].algo;
157 if (j >= RTE_DIM(algo_con))
163 tmp = strstr(line, OP_STR);
167 tmp = strstr(line, KEY_SIZE_STR);
169 tmp += strlen(KEY_SIZE_STR);
170 if (parser_read_uint32
171 (&info.interim_info.aes_data.key_len,
175 info.interim_info.aes_data.key_len /= 8;
181 info.parse_writeback = parse_test_aes_writeback;
182 info.callbacks = aes_tests_vectors;
183 info.interim_callbacks = aes_tests_interim_vectors;
184 info.writeback_callbacks = aes_writeback_callbacks;
185 info.kat_check = rsp_test_aes_check;