1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Intel Corporation 3 */ 4 5 #include <string.h> 6 #include <time.h> 7 #include <stdio.h> 8 9 #include <rte_cryptodev.h> 10 11 #include "fips_validation.h" 12 13 #define ALGO_PREFIX "[L=" 14 #define KEYLEN_STR "Klen = " 15 #define TAGLEN_STR "Tlen = " 16 17 #define COUNT_STR "Count = " 18 #define KEY_STR "Key = " 19 #define PT_STR "Msg = " 20 #define TAG_STR "Mac = " 21 22 struct hash_size_conversion { 23 const char *str; 24 enum rte_crypto_auth_algorithm algo; 25 } hsc[] = { 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}, 31 }; 32 33 static int 34 parse_interim_algo(__rte_unused const char *key, 35 char *text, 36 __rte_unused struct fips_val *val) 37 { 38 39 uint32_t i; 40 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; 44 break; 45 } 46 } 47 48 if (i == RTE_DIM(hsc)) 49 return -1; 50 51 return 0; 52 } 53 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 */ 61 }; 62 63 struct fips_test_callback hmac_tests_interim_vectors[] = { 64 {ALGO_PREFIX, parse_interim_algo, NULL}, 65 {NULL, NULL, NULL} /**< end pointer */ 66 }; 67 68 static int 69 parse_test_hmac_writeback(struct fips_val *val) 70 { 71 struct fips_val val_local; 72 73 fprintf(info.fp_wr, "%s", TAG_STR); 74 75 val_local.val = val->val + vec.pt.len; 76 val_local.len = vec.cipher_auth.digest.len; 77 78 parse_write_hex_str(&val_local); 79 return 0; 80 } 81 82 static int 83 rsp_test_hmac_check(struct fips_val *val) 84 { 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"); 88 else 89 fprintf(info.fp_wr, "Failed\n"); 90 91 return 0; 92 } 93 94 int 95 parse_test_hmac_init(void) 96 { 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; 103 104 return 0; 105 } 106