1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
8 #include <rte_string_fns.h>
10 #include <rte_cryptodev.h>
12 #include "fips_validation.h"
14 #define NEW_LINE_STR "#"
17 #define ALGO_STR "Alg = "
18 #define MODE_STR "Mode = "
20 #define COUNT_STR "Count = "
21 #define KLEN_STR "Klen = "
22 #define PTLEN_STR "Mlen = "
23 #define TAGLEN_STR "Tlen = "
24 #define KEY_STR "Key = "
25 #define PT_STR "Msg = "
26 #define TAG_STR "Mac = "
28 #define GEN_STR "Generate"
29 #define VERIF_STR "Verify"
31 #define POS_NEG_STR "Result = "
35 struct hash_algo_conversion {
37 enum fips_test_algorithms algo;
39 {"AES", FIPS_TEST_ALGO_AES_CMAC},
43 parse_test_cmac_writeback(struct fips_val *val)
45 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
46 struct fips_val tmp_val = {val->val + vec.pt.len,
47 vec.cipher_auth.digest.len};
49 fprintf(info.fp_wr, "%s", TAG_STR);
50 parse_write_hex_str(&tmp_val);
52 fprintf(info.fp_wr, "%s", POS_NEG_STR);
54 if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS)
55 fprintf(info.fp_wr, "%s\n", PASS_STR);
56 else if (vec.status == RTE_CRYPTO_OP_STATUS_AUTH_FAILED)
57 fprintf(info.fp_wr, "%s\n", FAIL_STR);
59 fprintf(info.fp_wr, "Error\n");
65 struct fips_test_callback cmac_tests_vectors[] = {
66 {KLEN_STR, parser_read_uint32_val, &vec.cipher_auth.key},
67 {PTLEN_STR, parser_read_uint32_val, &vec.pt},
68 {TAGLEN_STR, parser_read_uint32_val, &vec.cipher_auth.digest},
69 {KEY_STR, parse_uint8_hex_str, &vec.cipher_auth.key},
70 {PT_STR, parse_uint8_known_len_hex_str, &vec.pt},
71 {TAG_STR, parse_uint8_known_len_hex_str,
72 &vec.cipher_auth.digest},
73 {NULL, NULL, NULL} /**< end pointer */
77 parse_test_cmac_init(void)
82 for (i = 0; i < info.nb_vec_lines; i++) {
83 char *line = info.vec[i];
85 tmp = strstr(line, ALGO_STR);
89 for (j = 0; j < RTE_DIM(cmac_algo); j++) {
90 if (!strstr(line, cmac_algo[j].str))
93 info.algo = cmac_algo[j].algo;
97 if (j == RTE_DIM(cmac_algo))
100 tmp = strstr(line, MODE_STR);
104 if (strstr(tmp, GEN_STR))
105 info.op = FIPS_TEST_ENC_AUTH_GEN;
106 else if (strstr(tmp, VERIF_STR))
107 info.op = FIPS_TEST_DEC_AUTH_VERIF;
112 info.parse_writeback = parse_test_cmac_writeback;
113 info.callbacks = cmac_tests_vectors;