X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=examples%2Ffips_validation%2Ffips_validation.c;h=52a7bf952d46a73368cb11525d28cb27b5a97865;hb=704512214d031e4e27f19b53c44464d9821ed1a1;hp=ef24b72037ad756bb2cc6320918ff7ae918d9697;hpb=d5a9ea551f57bdd6fa0b28810bca538473866066;p=dpdk.git diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c index ef24b72037..52a7bf952d 100644 --- a/examples/fips_validation/fips_validation.c +++ b/examples/fips_validation/fips_validation.c @@ -92,6 +92,15 @@ error_exit: return -ENOMEM; } +static void +fips_test_parse_version(void) +{ + int len = strlen(info.vec[0]); + char *ptr = info.vec[0]; + + info.version = strtof(ptr + len - 4, NULL); +} + static int fips_test_parse_header(void) { @@ -106,6 +115,9 @@ fips_test_parse_header(void) if (ret < 0) return ret; + if (info.nb_vec_lines) + fips_test_parse_version(); + for (i = 0; i < info.nb_vec_lines; i++) { if (!algo_parsed) { if (strstr(info.vec[i], "AESVS")) { @@ -144,6 +156,24 @@ fips_test_parse_header(void) ret = parse_test_tdes_init(); if (ret < 0) return 0; + } else if (strstr(info.vec[i], "PERMUTATION")) { + algo_parsed = 1; + info.algo = FIPS_TEST_ALGO_TDES; + ret = parse_test_tdes_init(); + if (ret < 0) + return 0; + } else if (strstr(info.vec[i], "VARIABLE")) { + algo_parsed = 1; + info.algo = FIPS_TEST_ALGO_TDES; + ret = parse_test_tdes_init(); + if (ret < 0) + return 0; + } else if (strstr(info.vec[i], "SUBSTITUTION")) { + algo_parsed = 1; + info.algo = FIPS_TEST_ALGO_TDES; + ret = parse_test_tdes_init(); + if (ret < 0) + return 0; } else if (strstr(info.vec[i], "SHA-")) { algo_parsed = 1; info.algo = FIPS_TEST_ALGO_SHA; @@ -263,7 +293,11 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, fips_test_clear(); - strcpy(info.file_name, req_file_path); + if (rte_strscpy(info.file_name, req_file_path, + sizeof(info.file_name)) < 0) { + RTE_LOG(ERR, USER1, "Path %s too long\n", req_file_path); + return -EINVAL; + } info.algo = FIPS_TEST_ALGO_MAX; if (parse_file_type(req_file_path) < 0) { RTE_LOG(ERR, USER1, "File %s type not supported\n", @@ -289,7 +323,11 @@ fips_test_init(const char *req_file_path, const char *rsp_file_path, return -ENOMEM; } - strlcpy(info.device_name, device_name, sizeof(info.device_name)); + if (rte_strscpy(info.device_name, device_name, + sizeof(info.device_name)) < 0) { + RTE_LOG(ERR, USER1, "Device name %s too long\n", device_name); + return -EINVAL; + } if (fips_test_parse_header() < 0) { RTE_LOG(ERR, USER1, "Failed parsing header\n"); @@ -322,11 +360,15 @@ int fips_test_parse_one_case(void) { uint32_t i, j = 0; - uint32_t is_interim = 0; + uint32_t is_interim; + uint32_t interim_cnt = 0; int ret; + info.vec_start_off = 0; + if (info.interim_callbacks) { for (i = 0; i < info.nb_vec_lines; i++) { + is_interim = 0; for (j = 0; info.interim_callbacks[j].key != NULL; j++) if (strstr(info.vec[i], info.interim_callbacks[j].key)) { @@ -339,17 +381,31 @@ fips_test_parse_one_case(void) if (ret < 0) return ret; } + + if (is_interim) + interim_cnt += 1; } } - if (is_interim) { - for (i = 0; i < info.nb_vec_lines; i++) - fprintf(info.fp_wr, "%s\n", info.vec[i]); - fprintf(info.fp_wr, "\n"); - return 1; + if (interim_cnt) { + if (info.version == 21.4f) { + for (i = 0; i < interim_cnt; i++) + fprintf(info.fp_wr, "%s\n", info.vec[i]); + fprintf(info.fp_wr, "\n"); + + if (info.nb_vec_lines == interim_cnt) + return 1; + } else { + for (i = 0; i < info.nb_vec_lines; i++) + fprintf(info.fp_wr, "%s\n", info.vec[i]); + fprintf(info.fp_wr, "\n"); + return 1; + } } - for (i = 0; i < info.nb_vec_lines; i++) { + info.vec_start_off = interim_cnt; + + for (i = info.vec_start_off; i < info.nb_vec_lines; i++) { for (j = 0; info.callbacks[j].key != NULL; j++) if (strstr(info.vec[i], info.callbacks[j].key)) { ret = info.callbacks[j].cb( @@ -369,7 +425,7 @@ fips_test_write_one_case(void) { uint32_t i; - for (i = 0; i < info.nb_vec_lines; i++) + for (i = info.vec_start_off; i < info.nb_vec_lines; i++) fprintf(info.fp_wr, "%s\n", info.vec[i]); } @@ -594,6 +650,22 @@ parser_read_uint32(uint32_t *value, char *p) return 0; } +int +parser_read_uint16(uint16_t *value, const char *p) +{ + uint64_t val = 0; + int ret = parser_read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT16_MAX) + return -ERANGE; + + *value = val; + return 0; +} + void parse_write_hex_str(struct fips_val *src) { @@ -613,9 +685,16 @@ update_info_vec(uint32_t count) cb = &info.writeback_callbacks[0]; - snprintf(info.vec[0], strlen(info.vec[0]) + 4, "%s%u", cb->key, count); + if ((info.version == 21.4f) && (!(strstr(info.vec[0], cb->key)))) { + fprintf(info.fp_wr, "%s%u\n", cb->key, count); + i = 0; + } else { + snprintf(info.vec[0], strlen(info.vec[0]) + 4, "%s%u", cb->key, + count); + i = 1; + } - for (i = 1; i < info.nb_vec_lines; i++) { + for (; i < info.nb_vec_lines; i++) { for (j = 1; info.writeback_callbacks[j].key != NULL; j++) { cb = &info.writeback_callbacks[j]; if (strstr(info.vec[i], cb->key)) {