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},
47 {"ECB", RTE_CRYPTO_CIPHER_AES_ECB},
51 parse_interim_enc_dec(const char *key,
52 __rte_unused char *text,
53 __rte_unused struct fips_val *val)
55 if (strcmp(key, OP_ENC_STR) == 0)
56 info.op = FIPS_TEST_ENC_AUTH_GEN;
57 else if (strcmp(key, OP_DEC_STR) == 0)
58 info.op = FIPS_TEST_DEC_AUTH_VERIF;
65 struct fips_test_callback aes_tests_interim[] = {
66 {OP_ENC_STR, parse_interim_enc_dec, NULL},
67 {OP_DEC_STR, parse_interim_enc_dec, NULL},
68 {NULL, NULL, NULL} /**< end pointer */
71 struct fips_test_callback aes_tests_vectors[] = {
72 {KEY_STR, parse_uint8_hex_str, &vec.cipher_auth.key},
73 {IV_STR, parse_uint8_hex_str, &vec.iv},
74 {PT_STR, parse_uint8_hex_str, &vec.pt},
75 {CT_STR, parse_uint8_hex_str, &vec.ct},
76 {NULL, NULL, NULL} /**< end pointer */
79 struct fips_test_callback aes_tests_interim_vectors[] = {
80 {OP_ENC_STR, parse_interim_enc_dec, NULL},
81 {OP_DEC_STR, parse_interim_enc_dec, NULL},
82 {NULL, NULL, NULL} /**< end pointer */
85 struct fips_test_callback aes_writeback_callbacks[] = {
86 /** First element is used to pass COUNT string */
87 {COUNT_STR, NULL, NULL},
88 {IV_STR, writeback_hex_str, &vec.iv},
89 {KEY_STR, writeback_hex_str, &vec.cipher_auth.key},
90 {PT_STR, writeback_hex_str, &vec.pt},
91 {CT_STR, writeback_hex_str, &vec.ct},
92 {NULL, NULL, NULL} /**< end pointer */
96 parse_test_aes_writeback(struct fips_val *val)
98 if (info.op == FIPS_TEST_ENC_AUTH_GEN)
99 fprintf(info.fp_wr, "%s", CT_STR);
101 fprintf(info.fp_wr, "%s", PT_STR);
103 parse_write_hex_str(val);
109 rsp_test_aes_check(struct fips_val *val)
111 struct fips_val *data;
113 if (info.op == FIPS_TEST_ENC_AUTH_GEN)
118 if (memcmp(val->val, data->val, val->len) == 0)
119 fprintf(info.fp_wr, "Success\n");
121 fprintf(info.fp_wr, "Failed\n");
127 parse_test_aes_init(void)
132 for (i = 0; i < info.nb_vec_lines; i++) {
133 char *line = info.vec[i];
135 tmp = strstr(line, MODE_STR);
137 for (j = 0; j < RTE_DIM(aes_test_types); j++)
138 if (strstr(line, aes_test_types[j].desc)) {
139 info.interim_info.aes_data.test_type =
140 aes_test_types[j].type;
144 if (j >= RTE_DIM(aes_test_types))
147 tmp = strstr(line, ALGO_STR);
151 tmp += strlen(ALGO_STR);
152 for (j = 0; j < RTE_DIM(algo_con); j++)
153 if (strcmp(algo_con[j].name, tmp) == 0) {
154 info.interim_info.aes_data.cipher_algo =
155 (uint32_t)algo_con[j].algo;
158 if (j >= RTE_DIM(algo_con))
164 tmp = strstr(line, OP_STR);
168 tmp = strstr(line, KEY_SIZE_STR);
170 tmp += strlen(KEY_SIZE_STR);
171 if (parser_read_uint32
172 (&info.interim_info.aes_data.key_len,
176 info.interim_info.aes_data.key_len /= 8;
182 info.parse_writeback = parse_test_aes_writeback;
183 info.callbacks = aes_tests_vectors;
184 info.interim_callbacks = aes_tests_interim_vectors;
185 info.writeback_callbacks = aes_writeback_callbacks;
186 info.kat_check = rsp_test_aes_check;