1cd255ccfSMarko Kovacevic /* SPDX-License-Identifier: BSD-3-Clause 2cd255ccfSMarko Kovacevic * Copyright(c) 2018 Intel Corporation 3cd255ccfSMarko Kovacevic */ 4cd255ccfSMarko Kovacevic 5cd255ccfSMarko Kovacevic #include <string.h> 6cd255ccfSMarko Kovacevic #include <time.h> 7cd255ccfSMarko Kovacevic #include <stdio.h> 8cd255ccfSMarko Kovacevic 9cd255ccfSMarko Kovacevic #include <rte_cryptodev.h> 10*8b8546aaSGowrishankar Muthukrishnan #include <rte_malloc.h> 11cd255ccfSMarko Kovacevic 12cd255ccfSMarko Kovacevic #include "fips_validation.h" 13cd255ccfSMarko Kovacevic 14cd255ccfSMarko Kovacevic #define MODE_STR "AESVS" 15cd255ccfSMarko Kovacevic #define ALGO_STR "test data for " 16cd255ccfSMarko Kovacevic #define OP_STR "State" 17cd255ccfSMarko Kovacevic #define KEY_SIZE_STR "Key Length : " 18cd255ccfSMarko Kovacevic 19cd255ccfSMarko Kovacevic 20cd255ccfSMarko Kovacevic #define COUNT_STR "COUNT = " 21cd255ccfSMarko Kovacevic #define KEY_STR "KEY = " 22cd255ccfSMarko Kovacevic #define IV_STR "IV = " 23cd255ccfSMarko Kovacevic #define PT_STR "PLAINTEXT = " 24cd255ccfSMarko Kovacevic #define CT_STR "CIPHERTEXT = " 25cd255ccfSMarko Kovacevic 26cd255ccfSMarko Kovacevic #define OP_ENC_STR "ENCRYPT" 27cd255ccfSMarko Kovacevic #define OP_DEC_STR "DECRYPT" 28cd255ccfSMarko Kovacevic 29*8b8546aaSGowrishankar Muthukrishnan #define ALGO_JSON_STR "algorithm" 30*8b8546aaSGowrishankar Muthukrishnan #define TESTTYPE_JSON_STR "testType" 31*8b8546aaSGowrishankar Muthukrishnan #define DIR_JSON_STR "direction" 32*8b8546aaSGowrishankar Muthukrishnan #define KEYLEN_JSON_STR "keyLen" 33*8b8546aaSGowrishankar Muthukrishnan 34*8b8546aaSGowrishankar Muthukrishnan #define KEY_JSON_STR "key" 35*8b8546aaSGowrishankar Muthukrishnan #define IV_JSON_STR "iv" 36*8b8546aaSGowrishankar Muthukrishnan #define PT_JSON_STR "pt" 37*8b8546aaSGowrishankar Muthukrishnan #define CT_JSON_STR "ct" 38*8b8546aaSGowrishankar Muthukrishnan 39*8b8546aaSGowrishankar Muthukrishnan #define OP_ENC_JSON_STR "encrypt" 40*8b8546aaSGowrishankar Muthukrishnan #define OP_DEC_JSON_STR "decrypt" 41*8b8546aaSGowrishankar Muthukrishnan 42cd255ccfSMarko Kovacevic struct { 43cd255ccfSMarko Kovacevic uint32_t type; 44cd255ccfSMarko Kovacevic const char *desc; 45cd255ccfSMarko Kovacevic } aes_test_types[] = { 46cd255ccfSMarko Kovacevic {AESAVS_TYPE_GFXBOX, "GFSbox"}, 47cd255ccfSMarko Kovacevic {AESAVS_TYPE_KEYSBOX, "KeySbox"}, 48cd255ccfSMarko Kovacevic {AESAVS_TYPE_VARKEY, "VarKey"}, 49cd255ccfSMarko Kovacevic {AESAVS_TYPE_VARTXT, "VarTxt"}, 50527cbf3dSMarko Kovacevic {TDES_VARIABLE_TEXT, "VARIABLE PLAINTEXT/CIPHERTEXT"}, 51527cbf3dSMarko Kovacevic {TDES_VARIABLE_TEXT, "KAT"}, 52cd255ccfSMarko Kovacevic {AESAVS_TYPE_MMT, "MMT"}, 53cd255ccfSMarko Kovacevic {AESAVS_TYPE_MCT, "MCT"}, 54*8b8546aaSGowrishankar Muthukrishnan {AESAVS_TYPE_AFT, "AFT"}, 55cd255ccfSMarko Kovacevic }; 56cd255ccfSMarko Kovacevic 57cd255ccfSMarko Kovacevic struct aes_test_algo { 58cd255ccfSMarko Kovacevic const char *name; 59cd255ccfSMarko Kovacevic enum rte_crypto_cipher_algorithm algo; 60cd255ccfSMarko Kovacevic } const algo_con[] = { 61cd255ccfSMarko Kovacevic {"CBC", RTE_CRYPTO_CIPHER_AES_CBC}, 62d3190431SMichael Shamis {"ECB", RTE_CRYPTO_CIPHER_AES_ECB}, 63cd255ccfSMarko Kovacevic }; 64cd255ccfSMarko Kovacevic 65cd255ccfSMarko Kovacevic static int 66cd255ccfSMarko Kovacevic parse_interim_enc_dec(const char *key, 67f2fc83b4SThomas Monjalon __rte_unused char *text, 68f2fc83b4SThomas Monjalon __rte_unused struct fips_val *val) 69cd255ccfSMarko Kovacevic { 70cd255ccfSMarko Kovacevic if (strcmp(key, OP_ENC_STR) == 0) 71cd255ccfSMarko Kovacevic info.op = FIPS_TEST_ENC_AUTH_GEN; 72cd255ccfSMarko Kovacevic else if (strcmp(key, OP_DEC_STR) == 0) 73cd255ccfSMarko Kovacevic info.op = FIPS_TEST_DEC_AUTH_VERIF; 74cd255ccfSMarko Kovacevic else 75cd255ccfSMarko Kovacevic return -1; 76cd255ccfSMarko Kovacevic 77cd255ccfSMarko Kovacevic return 0; 78cd255ccfSMarko Kovacevic } 79cd255ccfSMarko Kovacevic 80cd255ccfSMarko Kovacevic struct fips_test_callback aes_tests_interim[] = { 81cd255ccfSMarko Kovacevic {OP_ENC_STR, parse_interim_enc_dec, NULL}, 82cd255ccfSMarko Kovacevic {OP_DEC_STR, parse_interim_enc_dec, NULL}, 83cd255ccfSMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */ 84cd255ccfSMarko Kovacevic }; 85cd255ccfSMarko Kovacevic 86cd255ccfSMarko Kovacevic struct fips_test_callback aes_tests_vectors[] = { 87cd255ccfSMarko Kovacevic {KEY_STR, parse_uint8_hex_str, &vec.cipher_auth.key}, 88cd255ccfSMarko Kovacevic {IV_STR, parse_uint8_hex_str, &vec.iv}, 89cd255ccfSMarko Kovacevic {PT_STR, parse_uint8_hex_str, &vec.pt}, 90cd255ccfSMarko Kovacevic {CT_STR, parse_uint8_hex_str, &vec.ct}, 91cd255ccfSMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */ 92cd255ccfSMarko Kovacevic }; 93cd255ccfSMarko Kovacevic 94cd255ccfSMarko Kovacevic struct fips_test_callback aes_tests_interim_vectors[] = { 95cd255ccfSMarko Kovacevic {OP_ENC_STR, parse_interim_enc_dec, NULL}, 96cd255ccfSMarko Kovacevic {OP_DEC_STR, parse_interim_enc_dec, NULL}, 97cd255ccfSMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */ 98cd255ccfSMarko Kovacevic }; 99cd255ccfSMarko Kovacevic 100cd255ccfSMarko Kovacevic struct fips_test_callback aes_writeback_callbacks[] = { 101cd255ccfSMarko Kovacevic /** First element is used to pass COUNT string */ 102cd255ccfSMarko Kovacevic {COUNT_STR, NULL, NULL}, 103cd255ccfSMarko Kovacevic {IV_STR, writeback_hex_str, &vec.iv}, 104cd255ccfSMarko Kovacevic {KEY_STR, writeback_hex_str, &vec.cipher_auth.key}, 105cd255ccfSMarko Kovacevic {PT_STR, writeback_hex_str, &vec.pt}, 106cd255ccfSMarko Kovacevic {CT_STR, writeback_hex_str, &vec.ct}, 107cd255ccfSMarko Kovacevic {NULL, NULL, NULL} /**< end pointer */ 108cd255ccfSMarko Kovacevic }; 109cd255ccfSMarko Kovacevic 110*8b8546aaSGowrishankar Muthukrishnan #ifdef RTE_HAS_JANSSON 111*8b8546aaSGowrishankar Muthukrishnan struct fips_test_callback aes_dec_json_vectors[] = { 112*8b8546aaSGowrishankar Muthukrishnan {KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key}, 113*8b8546aaSGowrishankar Muthukrishnan {IV_JSON_STR, parse_uint8_hex_str, &vec.iv}, 114*8b8546aaSGowrishankar Muthukrishnan {CT_JSON_STR, parse_uint8_hex_str, &vec.ct}, 115*8b8546aaSGowrishankar Muthukrishnan {NULL, NULL, NULL} /**< end pointer */ 116*8b8546aaSGowrishankar Muthukrishnan }; 117*8b8546aaSGowrishankar Muthukrishnan 118*8b8546aaSGowrishankar Muthukrishnan struct fips_test_callback aes_interim_json_vectors[] = { 119*8b8546aaSGowrishankar Muthukrishnan {KEYLEN_JSON_STR, parser_read_uint32_bit_val, &vec.cipher_auth.key}, 120*8b8546aaSGowrishankar Muthukrishnan {NULL, NULL, NULL} /**< end pointer */ 121*8b8546aaSGowrishankar Muthukrishnan }; 122*8b8546aaSGowrishankar Muthukrishnan 123*8b8546aaSGowrishankar Muthukrishnan struct fips_test_callback aes_enc_json_vectors[] = { 124*8b8546aaSGowrishankar Muthukrishnan {KEY_JSON_STR, parse_uint8_known_len_hex_str, &vec.cipher_auth.key}, 125*8b8546aaSGowrishankar Muthukrishnan {IV_JSON_STR, parse_uint8_hex_str, &vec.iv}, 126*8b8546aaSGowrishankar Muthukrishnan {PT_JSON_STR, parse_uint8_hex_str, &vec.pt}, 127*8b8546aaSGowrishankar Muthukrishnan {NULL, NULL, NULL} /**< end pointer */ 128*8b8546aaSGowrishankar Muthukrishnan }; 129*8b8546aaSGowrishankar Muthukrishnan 130*8b8546aaSGowrishankar Muthukrishnan static int 131*8b8546aaSGowrishankar Muthukrishnan parse_test_aes_json_writeback(struct fips_val *val) 132*8b8546aaSGowrishankar Muthukrishnan { 133*8b8546aaSGowrishankar Muthukrishnan struct fips_val tmp_val; 134*8b8546aaSGowrishankar Muthukrishnan json_t *tcId; 135*8b8546aaSGowrishankar Muthukrishnan 136*8b8546aaSGowrishankar Muthukrishnan tcId = json_object_get(json_info.json_test_case, "tcId"); 137*8b8546aaSGowrishankar Muthukrishnan 138*8b8546aaSGowrishankar Muthukrishnan json_info.json_write_case = json_object(); 139*8b8546aaSGowrishankar Muthukrishnan json_object_set(json_info.json_write_case, "tcId", tcId); 140*8b8546aaSGowrishankar Muthukrishnan 141*8b8546aaSGowrishankar Muthukrishnan if (info.op == FIPS_TEST_ENC_AUTH_GEN) { 142*8b8546aaSGowrishankar Muthukrishnan json_t *ct; 143*8b8546aaSGowrishankar Muthukrishnan 144*8b8546aaSGowrishankar Muthukrishnan tmp_val.val = val->val; 145*8b8546aaSGowrishankar Muthukrishnan tmp_val.len = vec.pt.len; 146*8b8546aaSGowrishankar Muthukrishnan 147*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &tmp_val); 148*8b8546aaSGowrishankar Muthukrishnan ct = json_string(info.one_line_text); 149*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(json_info.json_write_case, CT_JSON_STR, ct); 150*8b8546aaSGowrishankar Muthukrishnan 151*8b8546aaSGowrishankar Muthukrishnan tmp_val.val = val->val + vec.pt.len; 152*8b8546aaSGowrishankar Muthukrishnan tmp_val.len = val->len - vec.pt.len; 153*8b8546aaSGowrishankar Muthukrishnan 154*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &tmp_val); 155*8b8546aaSGowrishankar Muthukrishnan } else { 156*8b8546aaSGowrishankar Muthukrishnan if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) { 157*8b8546aaSGowrishankar Muthukrishnan tmp_val.val = val->val; 158*8b8546aaSGowrishankar Muthukrishnan tmp_val.len = vec.ct.len; 159*8b8546aaSGowrishankar Muthukrishnan 160*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &tmp_val); 161*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(json_info.json_write_case, PT_JSON_STR, 162*8b8546aaSGowrishankar Muthukrishnan json_string(info.one_line_text)); 163*8b8546aaSGowrishankar Muthukrishnan } else { 164*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(json_info.json_write_case, "testPassed", json_false()); 165*8b8546aaSGowrishankar Muthukrishnan } 166*8b8546aaSGowrishankar Muthukrishnan } 167*8b8546aaSGowrishankar Muthukrishnan 168*8b8546aaSGowrishankar Muthukrishnan return 0; 169*8b8546aaSGowrishankar Muthukrishnan } 170*8b8546aaSGowrishankar Muthukrishnan 171*8b8546aaSGowrishankar Muthukrishnan static int 172*8b8546aaSGowrishankar Muthukrishnan parse_test_aes_mct_json_writeback(struct fips_val *val) 173*8b8546aaSGowrishankar Muthukrishnan { 174*8b8546aaSGowrishankar Muthukrishnan json_t *tcId, *resArr, *res, *ct, *pt, *key, *iv; 175*8b8546aaSGowrishankar Muthukrishnan struct fips_val tmp_val; 176*8b8546aaSGowrishankar Muthukrishnan 177*8b8546aaSGowrishankar Muthukrishnan tcId = json_object_get(json_info.json_test_case, "tcId"); 178*8b8546aaSGowrishankar Muthukrishnan if (json_info.json_write_case) { 179*8b8546aaSGowrishankar Muthukrishnan json_t *wcId; 180*8b8546aaSGowrishankar Muthukrishnan 181*8b8546aaSGowrishankar Muthukrishnan wcId = json_object_get(json_info.json_write_case, "tcId"); 182*8b8546aaSGowrishankar Muthukrishnan if (!json_equal(tcId, wcId)) { 183*8b8546aaSGowrishankar Muthukrishnan json_info.json_write_case = json_object(); 184*8b8546aaSGowrishankar Muthukrishnan json_object_set(json_info.json_write_case, "tcId", tcId); 185*8b8546aaSGowrishankar Muthukrishnan json_object_set(json_info.json_write_case, "resultsArray", json_array()); 186*8b8546aaSGowrishankar Muthukrishnan } 187*8b8546aaSGowrishankar Muthukrishnan } else { 188*8b8546aaSGowrishankar Muthukrishnan json_info.json_write_case = json_object(); 189*8b8546aaSGowrishankar Muthukrishnan json_object_set(json_info.json_write_case, "tcId", tcId); 190*8b8546aaSGowrishankar Muthukrishnan json_object_set(json_info.json_write_case, "resultsArray", json_array()); 191*8b8546aaSGowrishankar Muthukrishnan } 192*8b8546aaSGowrishankar Muthukrishnan 193*8b8546aaSGowrishankar Muthukrishnan resArr = json_object_get(json_info.json_write_case, "resultsArray"); 194*8b8546aaSGowrishankar Muthukrishnan if (!json_is_array(resArr)) 195*8b8546aaSGowrishankar Muthukrishnan return -EINVAL; 196*8b8546aaSGowrishankar Muthukrishnan 197*8b8546aaSGowrishankar Muthukrishnan res = json_object(); 198*8b8546aaSGowrishankar Muthukrishnan if (info .op == FIPS_TEST_ENC_AUTH_GEN) { 199*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &vec.cipher_auth.key); 200*8b8546aaSGowrishankar Muthukrishnan key = json_string(info.one_line_text); 201*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(res, KEY_JSON_STR, key); 202*8b8546aaSGowrishankar Muthukrishnan 203*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &val[2]); 204*8b8546aaSGowrishankar Muthukrishnan iv = json_string(info.one_line_text); 205*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(res, IV_JSON_STR, iv); 206*8b8546aaSGowrishankar Muthukrishnan 207*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &val[1]); 208*8b8546aaSGowrishankar Muthukrishnan pt = json_string(info.one_line_text); 209*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(res, PT_JSON_STR, pt); 210*8b8546aaSGowrishankar Muthukrishnan 211*8b8546aaSGowrishankar Muthukrishnan tmp_val.val = val->val; 212*8b8546aaSGowrishankar Muthukrishnan tmp_val.len = vec.pt.len; 213*8b8546aaSGowrishankar Muthukrishnan 214*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &tmp_val); 215*8b8546aaSGowrishankar Muthukrishnan ct = json_string(info.one_line_text); 216*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(res, CT_JSON_STR, ct); 217*8b8546aaSGowrishankar Muthukrishnan 218*8b8546aaSGowrishankar Muthukrishnan tmp_val.val = val->val + vec.pt.len; 219*8b8546aaSGowrishankar Muthukrishnan tmp_val.len = val->len - vec.pt.len; 220*8b8546aaSGowrishankar Muthukrishnan 221*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &tmp_val); 222*8b8546aaSGowrishankar Muthukrishnan } else { 223*8b8546aaSGowrishankar Muthukrishnan if (vec.status == RTE_CRYPTO_OP_STATUS_SUCCESS) { 224*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &vec.cipher_auth.key); 225*8b8546aaSGowrishankar Muthukrishnan key = json_string(info.one_line_text); 226*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(res, KEY_JSON_STR, key); 227*8b8546aaSGowrishankar Muthukrishnan 228*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &val[2]); 229*8b8546aaSGowrishankar Muthukrishnan iv = json_string(info.one_line_text); 230*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(res, IV_JSON_STR, iv); 231*8b8546aaSGowrishankar Muthukrishnan 232*8b8546aaSGowrishankar Muthukrishnan tmp_val.val = val->val; 233*8b8546aaSGowrishankar Muthukrishnan tmp_val.len = vec.ct.len; 234*8b8546aaSGowrishankar Muthukrishnan 235*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &tmp_val); 236*8b8546aaSGowrishankar Muthukrishnan pt = json_string(info.one_line_text); 237*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(res, PT_JSON_STR, pt); 238*8b8546aaSGowrishankar Muthukrishnan 239*8b8546aaSGowrishankar Muthukrishnan writeback_hex_str("", info.one_line_text, &val[1]); 240*8b8546aaSGowrishankar Muthukrishnan ct = json_string(info.one_line_text); 241*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(res, CT_JSON_STR, ct); 242*8b8546aaSGowrishankar Muthukrishnan } else { 243*8b8546aaSGowrishankar Muthukrishnan json_object_set_new(json_info.json_write_case, "testPassed", json_false()); 244*8b8546aaSGowrishankar Muthukrishnan } 245*8b8546aaSGowrishankar Muthukrishnan } 246*8b8546aaSGowrishankar Muthukrishnan 247*8b8546aaSGowrishankar Muthukrishnan json_array_append_new(resArr, res); 248*8b8546aaSGowrishankar Muthukrishnan return 0; 249*8b8546aaSGowrishankar Muthukrishnan } 250*8b8546aaSGowrishankar Muthukrishnan 251*8b8546aaSGowrishankar Muthukrishnan int 252*8b8546aaSGowrishankar Muthukrishnan parse_test_aes_json_init(void) 253*8b8546aaSGowrishankar Muthukrishnan { 254*8b8546aaSGowrishankar Muthukrishnan json_t *type_obj = json_object_get(json_info.json_test_group, TESTTYPE_JSON_STR); 255*8b8546aaSGowrishankar Muthukrishnan json_t *algo_obj = json_object_get(json_info.json_vector_set, ALGO_JSON_STR); 256*8b8546aaSGowrishankar Muthukrishnan const char *type_str = json_string_value(type_obj); 257*8b8546aaSGowrishankar Muthukrishnan const char *algo_str = json_string_value(algo_obj); 258*8b8546aaSGowrishankar Muthukrishnan uint32_t i; 259*8b8546aaSGowrishankar Muthukrishnan 260*8b8546aaSGowrishankar Muthukrishnan if (json_info.json_test_group) { 261*8b8546aaSGowrishankar Muthukrishnan json_t *direction_obj; 262*8b8546aaSGowrishankar Muthukrishnan const char *direction_str; 263*8b8546aaSGowrishankar Muthukrishnan 264*8b8546aaSGowrishankar Muthukrishnan direction_obj = json_object_get(json_info.json_test_group, DIR_JSON_STR); 265*8b8546aaSGowrishankar Muthukrishnan direction_str = json_string_value(direction_obj); 266*8b8546aaSGowrishankar Muthukrishnan 267*8b8546aaSGowrishankar Muthukrishnan if (strcmp(direction_str, OP_ENC_JSON_STR) == 0) { 268*8b8546aaSGowrishankar Muthukrishnan info.op = FIPS_TEST_ENC_AUTH_GEN; 269*8b8546aaSGowrishankar Muthukrishnan info.callbacks = aes_enc_json_vectors; 270*8b8546aaSGowrishankar Muthukrishnan 271*8b8546aaSGowrishankar Muthukrishnan } else if (strcmp(direction_str, OP_DEC_JSON_STR) == 0) { 272*8b8546aaSGowrishankar Muthukrishnan info.op = FIPS_TEST_DEC_AUTH_VERIF; 273*8b8546aaSGowrishankar Muthukrishnan info.callbacks = aes_dec_json_vectors; 274*8b8546aaSGowrishankar Muthukrishnan } else { 275*8b8546aaSGowrishankar Muthukrishnan return -EINVAL; 276*8b8546aaSGowrishankar Muthukrishnan } 277*8b8546aaSGowrishankar Muthukrishnan info.interim_callbacks = aes_interim_json_vectors; 278*8b8546aaSGowrishankar Muthukrishnan } 279*8b8546aaSGowrishankar Muthukrishnan 280*8b8546aaSGowrishankar Muthukrishnan for (i = 0; i < RTE_DIM(aes_test_types); i++) 281*8b8546aaSGowrishankar Muthukrishnan if (strstr(type_str, aes_test_types[i].desc)) { 282*8b8546aaSGowrishankar Muthukrishnan info.interim_info.aes_data.test_type = 283*8b8546aaSGowrishankar Muthukrishnan aes_test_types[i].type; 284*8b8546aaSGowrishankar Muthukrishnan break; 285*8b8546aaSGowrishankar Muthukrishnan } 286*8b8546aaSGowrishankar Muthukrishnan 287*8b8546aaSGowrishankar Muthukrishnan if (i >= RTE_DIM(aes_test_types)) 288*8b8546aaSGowrishankar Muthukrishnan return -EINVAL; 289*8b8546aaSGowrishankar Muthukrishnan 290*8b8546aaSGowrishankar Muthukrishnan switch (info.interim_info.aes_data.test_type) { 291*8b8546aaSGowrishankar Muthukrishnan case AESAVS_TYPE_MCT: 292*8b8546aaSGowrishankar Muthukrishnan info.parse_writeback = parse_test_aes_mct_json_writeback; 293*8b8546aaSGowrishankar Muthukrishnan break; 294*8b8546aaSGowrishankar Muthukrishnan case AESAVS_TYPE_AFT: 295*8b8546aaSGowrishankar Muthukrishnan info.parse_writeback = parse_test_aes_json_writeback; 296*8b8546aaSGowrishankar Muthukrishnan break; 297*8b8546aaSGowrishankar Muthukrishnan default: 298*8b8546aaSGowrishankar Muthukrishnan info.parse_writeback = NULL; 299*8b8546aaSGowrishankar Muthukrishnan } 300*8b8546aaSGowrishankar Muthukrishnan 301*8b8546aaSGowrishankar Muthukrishnan if (!info.parse_writeback) 302*8b8546aaSGowrishankar Muthukrishnan return -EINVAL; 303*8b8546aaSGowrishankar Muthukrishnan 304*8b8546aaSGowrishankar Muthukrishnan for (i = 0; i < RTE_DIM(algo_con); i++) 305*8b8546aaSGowrishankar Muthukrishnan if (strstr(algo_str, algo_con[i].name)) { 306*8b8546aaSGowrishankar Muthukrishnan info.interim_info.aes_data.cipher_algo = 307*8b8546aaSGowrishankar Muthukrishnan (uint32_t)algo_con[i].algo; 308*8b8546aaSGowrishankar Muthukrishnan break; 309*8b8546aaSGowrishankar Muthukrishnan } 310*8b8546aaSGowrishankar Muthukrishnan 311*8b8546aaSGowrishankar Muthukrishnan if (i >= RTE_DIM(algo_con)) 312*8b8546aaSGowrishankar Muthukrishnan return -EINVAL; 313*8b8546aaSGowrishankar Muthukrishnan 314*8b8546aaSGowrishankar Muthukrishnan return 0; 315*8b8546aaSGowrishankar Muthukrishnan } 316*8b8546aaSGowrishankar Muthukrishnan #endif /* RTE_HAS_JANSSON */ 317*8b8546aaSGowrishankar Muthukrishnan 318cd255ccfSMarko Kovacevic static int 319cd255ccfSMarko Kovacevic parse_test_aes_writeback(struct fips_val *val) 320cd255ccfSMarko Kovacevic { 321cd255ccfSMarko Kovacevic if (info.op == FIPS_TEST_ENC_AUTH_GEN) 322cd255ccfSMarko Kovacevic fprintf(info.fp_wr, "%s", CT_STR); 323cd255ccfSMarko Kovacevic else 324cd255ccfSMarko Kovacevic fprintf(info.fp_wr, "%s", PT_STR); 325cd255ccfSMarko Kovacevic 326cd255ccfSMarko Kovacevic parse_write_hex_str(val); 327cd255ccfSMarko Kovacevic 328cd255ccfSMarko Kovacevic return 0; 329cd255ccfSMarko Kovacevic } 330cd255ccfSMarko Kovacevic 331cd255ccfSMarko Kovacevic static int 332cd255ccfSMarko Kovacevic rsp_test_aes_check(struct fips_val *val) 333cd255ccfSMarko Kovacevic { 334cd255ccfSMarko Kovacevic struct fips_val *data; 335cd255ccfSMarko Kovacevic 336cd255ccfSMarko Kovacevic if (info.op == FIPS_TEST_ENC_AUTH_GEN) 337cd255ccfSMarko Kovacevic data = &vec.ct; 338cd255ccfSMarko Kovacevic else 339cd255ccfSMarko Kovacevic data = &vec.pt; 340cd255ccfSMarko Kovacevic 341cd255ccfSMarko Kovacevic if (memcmp(val->val, data->val, val->len) == 0) 342cd255ccfSMarko Kovacevic fprintf(info.fp_wr, "Success\n"); 343cd255ccfSMarko Kovacevic else 344cd255ccfSMarko Kovacevic fprintf(info.fp_wr, "Failed\n"); 345cd255ccfSMarko Kovacevic 346cd255ccfSMarko Kovacevic return 0; 347cd255ccfSMarko Kovacevic } 348cd255ccfSMarko Kovacevic 349cd255ccfSMarko Kovacevic int 350cd255ccfSMarko Kovacevic parse_test_aes_init(void) 351cd255ccfSMarko Kovacevic { 352cd255ccfSMarko Kovacevic char *tmp; 353cd255ccfSMarko Kovacevic uint32_t i, j; 354cd255ccfSMarko Kovacevic 355cd255ccfSMarko Kovacevic for (i = 0; i < info.nb_vec_lines; i++) { 356cd255ccfSMarko Kovacevic char *line = info.vec[i]; 357cd255ccfSMarko Kovacevic 358cd255ccfSMarko Kovacevic tmp = strstr(line, MODE_STR); 359cd255ccfSMarko Kovacevic if (tmp) { 360cd255ccfSMarko Kovacevic for (j = 0; j < RTE_DIM(aes_test_types); j++) 361cd255ccfSMarko Kovacevic if (strstr(line, aes_test_types[j].desc)) { 362cd255ccfSMarko Kovacevic info.interim_info.aes_data.test_type = 363cd255ccfSMarko Kovacevic aes_test_types[j].type; 364cd255ccfSMarko Kovacevic break; 365cd255ccfSMarko Kovacevic } 366cd255ccfSMarko Kovacevic 367cd255ccfSMarko Kovacevic if (j >= RTE_DIM(aes_test_types)) 368cd255ccfSMarko Kovacevic return -EINVAL; 369cd255ccfSMarko Kovacevic 370cd255ccfSMarko Kovacevic tmp = strstr(line, ALGO_STR); 371cd255ccfSMarko Kovacevic if (!tmp) 372cd255ccfSMarko Kovacevic return -EINVAL; 373cd255ccfSMarko Kovacevic 374cd255ccfSMarko Kovacevic tmp += strlen(ALGO_STR); 375cd255ccfSMarko Kovacevic for (j = 0; j < RTE_DIM(algo_con); j++) 376cd255ccfSMarko Kovacevic if (strcmp(algo_con[j].name, tmp) == 0) { 377cd255ccfSMarko Kovacevic info.interim_info.aes_data.cipher_algo = 378cd255ccfSMarko Kovacevic (uint32_t)algo_con[j].algo; 379cd255ccfSMarko Kovacevic break; 380cd255ccfSMarko Kovacevic } 381cd255ccfSMarko Kovacevic if (j >= RTE_DIM(algo_con)) 382cd255ccfSMarko Kovacevic return -EINVAL; 383cd255ccfSMarko Kovacevic 384cd255ccfSMarko Kovacevic continue; 385cd255ccfSMarko Kovacevic } 386cd255ccfSMarko Kovacevic 387cd255ccfSMarko Kovacevic tmp = strstr(line, OP_STR); 388cd255ccfSMarko Kovacevic if (tmp) 389cd255ccfSMarko Kovacevic continue; 390cd255ccfSMarko Kovacevic 391cd255ccfSMarko Kovacevic tmp = strstr(line, KEY_SIZE_STR); 392cd255ccfSMarko Kovacevic if (tmp) { 393cd255ccfSMarko Kovacevic tmp += strlen(KEY_SIZE_STR); 394cd255ccfSMarko Kovacevic if (parser_read_uint32 395cd255ccfSMarko Kovacevic (&info.interim_info.aes_data.key_len, 396cd255ccfSMarko Kovacevic tmp) < 0) 397cd255ccfSMarko Kovacevic return -EINVAL; 398cd255ccfSMarko Kovacevic 399cd255ccfSMarko Kovacevic info.interim_info.aes_data.key_len /= 8; 400cd255ccfSMarko Kovacevic 401cd255ccfSMarko Kovacevic continue; 402cd255ccfSMarko Kovacevic } 403cd255ccfSMarko Kovacevic } 404cd255ccfSMarko Kovacevic 405cd255ccfSMarko Kovacevic info.parse_writeback = parse_test_aes_writeback; 406cd255ccfSMarko Kovacevic info.callbacks = aes_tests_vectors; 407cd255ccfSMarko Kovacevic info.interim_callbacks = aes_tests_interim_vectors; 408cd255ccfSMarko Kovacevic info.writeback_callbacks = aes_writeback_callbacks; 409cd255ccfSMarko Kovacevic info.kat_check = rsp_test_aes_check; 410cd255ccfSMarko Kovacevic 411cd255ccfSMarko Kovacevic return 0; 412cd255ccfSMarko Kovacevic } 413