examples/fips_validation: fix version compatibility
authorArchana Muniganti <marchana@marvell.com>
Wed, 9 Sep 2020 16:26:35 +0000 (21:56 +0530)
committerAkhil Goyal <akhil.goyal@nxp.com>
Wed, 14 Oct 2020 20:22:06 +0000 (22:22 +0200)
Separate out CAVS request file version 21.4 code to support
lower versions.

Fixes: 32440cdf2af9 ("examples/fips_validation: fix parsing of TDES vectors")
Fixes: 2b84d2bd47df ("examples/fips_validation: fix count overwrite for TDES")
Cc: stable@dpdk.org
Signed-off-by: Archana Muniganti <marchana@marvell.com>
Acked-by: Fan Zhang <roy.fan.zhang@intel.com>
Tested-by: Yu Jiang <yux.jiang@intel.com>
examples/fips_validation/fips_validation.c
examples/fips_validation/fips_validation.h
examples/fips_validation/main.c

index 13f763c..7454a03 100644 (file)
@@ -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,7 +115,10 @@ fips_test_parse_header(void)
        if (ret < 0)
                return ret;
 
-       for (i = 0; i < info.nb_vec_lines; i++) {
+       if (info.nb_vec_lines)
+               fips_test_parse_version();
+
+       for (i = 1; i < info.nb_vec_lines; i++) {
                if (!algo_parsed) {
                        if (strstr(info.vec[i], "AESVS")) {
                                algo_parsed = 1;
@@ -352,6 +364,8 @@ fips_test_parse_one_case(void)
        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;
@@ -373,17 +387,24 @@ fips_test_parse_one_case(void)
                }
        }
 
-       info.vec_start_off = interim_cnt;
-
        if (interim_cnt) {
-               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)
+               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;
+               }
        }
 
+       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)) {
@@ -648,7 +669,7 @@ update_info_vec(uint32_t count)
 
        cb = &info.writeback_callbacks[0];
 
-       if (!(strstr(info.vec[0], cb->key))) {
+       if ((info.version == 21.4f) && (!(strstr(info.vec[0], cb->key)))) {
                fprintf(info.fp_wr, "%s%u\n", cb->key, count);
                i = 0;
        } else {
@@ -656,9 +677,8 @@ update_info_vec(uint32_t count)
                                count);
                i = 1;
        }
-       snprintf(info.vec[0], strlen(info.vec[0]) + 4, "%s%u", cb->key, count);
 
-       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)) {
index deba83e..ca8964a 100644 (file)
@@ -166,6 +166,7 @@ struct fips_test_interim_info {
        uint32_t nb_vec_lines;
        char device_name[MAX_STRING_SIZE];
        char file_name[MAX_FILE_NAME_SIZE];
+       float version;
 
        union {
                struct aesavs_interim_data aes_data;
index 9e46307..2a7a3fb 100644 (file)
@@ -1088,10 +1088,12 @@ fips_mct_tdes_test(void)
        int test_mode = info.interim_info.tdes_data.test_mode;
 
        for (i = 0; i < TDES_EXTERN_ITER; i++) {
-               if (i == 0) {
+               if ((i == 0) && (info.version == 21.4f)) {
                        if (!(strstr(info.vec[0], "COUNT")))
                                fprintf(info.fp_wr, "%s%u\n", "COUNT = ", 0);
-               } else
+               }
+
+               if (i != 0)
                        update_info_vec(i);
 
                fips_test_write_one_case();