1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Intel Corporation
9 #include <rte_cryptodev.h>
11 #include "fips_validation.h"
13 #define ALGO_PREFIX "[L = "
14 #define MSGLEN_STR "Len = "
15 #define MSG_STR "Msg = "
16 #define MD_STR "MD = "
17 #define SEED_STR "Seed = "
18 #define MCT_STR "Monte"
20 struct plain_hash_size_conversion {
22 enum rte_crypto_auth_algorithm algo;
24 {"20", RTE_CRYPTO_AUTH_SHA1},
25 {"28", RTE_CRYPTO_AUTH_SHA224},
26 {"32", RTE_CRYPTO_AUTH_SHA256},
27 {"48", RTE_CRYPTO_AUTH_SHA384},
28 {"64", RTE_CRYPTO_AUTH_SHA512},
32 parse_interim_algo(__attribute__((__unused__)) const char *key,
34 __attribute__((__unused__)) struct fips_val *val)
38 for (i = 0; i < RTE_DIM(phsc); i++) {
39 if (strstr(text, phsc[i].str)) {
40 info.interim_info.sha_data.algo = phsc[i].algo;
41 parser_read_uint32_val(ALGO_PREFIX,
42 text, &vec.cipher_auth.digest);
47 if (i == RTE_DIM(phsc))
53 struct fips_test_callback sha_tests_vectors[] = {
54 {MSGLEN_STR, parser_read_uint32_bit_val, &vec.pt},
55 {MSG_STR, parse_uint8_known_len_hex_str, &vec.pt},
56 {SEED_STR, parse_uint8_hex_str, &vec.cipher_auth.digest},
57 {NULL, NULL, NULL} /**< end pointer */
60 struct fips_test_callback sha_tests_interim_vectors[] = {
61 {ALGO_PREFIX, parse_interim_algo, NULL},
62 {NULL, NULL, NULL} /**< end pointer */
66 parse_test_sha_writeback(struct fips_val *val) // !
68 struct fips_val val_local;
70 fprintf(info.fp_wr, "%s", MD_STR);
72 val_local.val = val->val + vec.pt.len;
73 val_local.len = vec.cipher_auth.digest.len;
75 parse_write_hex_str(&val_local);
80 rsp_test_sha_check(struct fips_val *val)
82 if (memcmp(val->val + vec.pt.len, vec.cipher_auth.digest.val,
83 vec.cipher_auth.digest.len) == 0)
84 fprintf(info.fp_wr, "Success\n");
86 fprintf(info.fp_wr, "Failed\n");
92 parse_test_sha_init(void)
96 info.interim_info.sha_data.test_type = SHA_KAT;
97 for (i = 0; i < info.nb_vec_lines; i++) {
98 char *line = info.vec[i];
99 if (strstr(line, MCT_STR))
100 info.interim_info.sha_data.test_type = SHA_MCT;
103 info.op = FIPS_TEST_ENC_AUTH_GEN;
104 info.parse_writeback = parse_test_sha_writeback;
105 info.callbacks = sha_tests_vectors;
106 info.interim_callbacks = sha_tests_interim_vectors;
107 info.writeback_callbacks = NULL;
108 info.kat_check = rsp_test_sha_check;