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 ALGO_PREFIX "[L="
14 #define KEYLEN_STR "Klen = "
15 #define TAGLEN_STR "Tlen = "
17 #define COUNT_STR "Count = "
18 #define KEY_STR "Key = "
19 #define PT_STR "Msg = "
20 #define TAG_STR "Mac = "
22 struct hash_size_conversion {
24 enum rte_crypto_auth_algorithm algo;
26 {"20", RTE_CRYPTO_AUTH_SHA1_HMAC},
27 {"28", RTE_CRYPTO_AUTH_SHA224_HMAC},
28 {"32", RTE_CRYPTO_AUTH_SHA256_HMAC},
29 {"48", RTE_CRYPTO_AUTH_SHA384_HMAC},
30 {"64", RTE_CRYPTO_AUTH_SHA512_HMAC},
34 parse_interim_algo(__attribute__((__unused__)) const char *key,
36 __attribute__((__unused__)) struct fips_val *val)
41 for (i = 0; i < RTE_DIM(hsc); i++) {
42 if (strstr(text, hsc[i].str)) {
43 info.interim_info.hmac_data.algo = hsc[i].algo;
48 if (i == RTE_DIM(hsc))
54 struct fips_test_callback hmac_tests_vectors[] = {
55 {KEYLEN_STR, parser_read_uint32_val, &vec.cipher_auth.key},
56 {TAGLEN_STR, parser_read_uint32_val, &vec.cipher_auth.digest},
57 {KEY_STR, parse_uint8_hex_str, &vec.cipher_auth.key},
58 {PT_STR, parse_uint8_hex_str, &vec.pt},
59 {TAG_STR, parse_uint8_hex_str, &vec.cipher_auth.digest},
60 {NULL, NULL, NULL} /**< end pointer */
63 struct fips_test_callback hmac_tests_interim_vectors[] = {
64 {ALGO_PREFIX, parse_interim_algo, NULL},
65 {NULL, NULL, NULL} /**< end pointer */
69 parse_test_hmac_writeback(struct fips_val *val)
71 struct fips_val val_local;
73 fprintf(info.fp_wr, "%s", TAG_STR);
75 val_local.val = val->val + vec.pt.len;
76 val_local.len = vec.cipher_auth.digest.len;
78 parse_write_hex_str(&val_local);
83 rsp_test_hmac_check(struct fips_val *val)
85 if (memcmp(val->val + vec.pt.len, vec.cipher_auth.digest.val,
86 vec.cipher_auth.digest.len) == 0)
87 fprintf(info.fp_wr, "Success\n");
89 fprintf(info.fp_wr, "Failed\n");
95 parse_test_hmac_init(void)
97 info.op = FIPS_TEST_ENC_AUTH_GEN;
98 info.parse_writeback = parse_test_hmac_writeback;
99 info.callbacks = hmac_tests_vectors;
100 info.interim_callbacks = hmac_tests_interim_vectors;
101 info.writeback_callbacks = NULL;
102 info.kat_check = rsp_test_hmac_check;