build: use static deps for pkg-config libs.private
[dpdk.git] / examples / fips_validation / main.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation
3  */
4
5 #include <sys/stat.h>
6 #include <getopt.h>
7 #include <dirent.h>
8
9 #include <rte_cryptodev.h>
10 #include <rte_cryptodev_pmd.h>
11 #include <rte_mempool.h>
12 #include <rte_mbuf.h>
13 #include <rte_string_fns.h>
14
15 #include "fips_validation.h"
16 #include "fips_dev_self_test.h"
17
18 #define REQ_FILE_PATH_KEYWORD   "req-file"
19 #define RSP_FILE_PATH_KEYWORD   "rsp-file"
20 #define FOLDER_KEYWORD          "path-is-folder"
21 #define CRYPTODEV_KEYWORD       "cryptodev"
22 #define CRYPTODEV_ID_KEYWORD    "cryptodev-id"
23 #define CRYPTODEV_ST_KEYWORD    "self-test"
24 #define CRYPTODEV_BK_ID_KEYWORD "broken-test-id"
25 #define CRYPTODEV_BK_DIR_KEY    "broken-test-dir"
26 #define CRYPTODEV_ENC_KEYWORD   "enc"
27 #define CRYPTODEV_DEC_KEYWORD   "dec"
28
29 struct fips_test_vector vec;
30 struct fips_test_interim_info info;
31
32 struct cryptodev_fips_validate_env {
33         const char *req_path;
34         const char *rsp_path;
35         uint32_t is_path_folder;
36         uint32_t dev_id;
37         struct rte_mempool *mpool;
38         struct rte_mempool *sess_mpool;
39         struct rte_mempool *sess_priv_mpool;
40         struct rte_mempool *op_pool;
41         struct rte_mbuf *mbuf;
42         struct rte_crypto_op *op;
43         struct rte_cryptodev_sym_session *sess;
44         uint32_t self_test;
45         struct fips_dev_broken_test_config *broken_test_config;
46 } env;
47
48 static int
49 cryptodev_fips_validate_app_int(void)
50 {
51         struct rte_cryptodev_config conf = {rte_socket_id(), 1};
52         struct rte_cryptodev_qp_conf qp_conf = {128, NULL, NULL};
53         uint32_t sess_sz = rte_cryptodev_sym_get_private_session_size(
54                         env.dev_id);
55         int ret;
56
57         if (env.self_test) {
58                 ret = fips_dev_self_test(env.dev_id, env.broken_test_config);
59                 if (ret < 0) {
60                         struct rte_cryptodev *cryptodev =
61                                         rte_cryptodev_pmd_get_dev(env.dev_id);
62
63                         rte_cryptodev_pmd_destroy(cryptodev);
64
65                         return ret;
66                 }
67         }
68
69         ret = rte_cryptodev_configure(env.dev_id, &conf);
70         if (ret < 0)
71                 return ret;
72
73         env.mpool = rte_pktmbuf_pool_create("FIPS_MEMPOOL", 128, 0, 0,
74                         UINT16_MAX, rte_socket_id());
75         if (!env.mpool)
76                 return ret;
77
78         ret = rte_cryptodev_queue_pair_setup(env.dev_id, 0, &qp_conf,
79                         rte_socket_id());
80         if (ret < 0)
81                 return ret;
82
83         ret = -ENOMEM;
84
85         env.sess_mpool = rte_cryptodev_sym_session_pool_create(
86                         "FIPS_SESS_MEMPOOL", 16, 0, 0, 0, rte_socket_id());
87         if (!env.sess_mpool)
88                 goto error_exit;
89
90         env.sess_priv_mpool = rte_mempool_create("FIPS_SESS_PRIV_MEMPOOL",
91                         16, sess_sz, 0, 0, NULL, NULL, NULL,
92                         NULL, rte_socket_id(), 0);
93         if (!env.sess_priv_mpool)
94                 goto error_exit;
95
96         env.op_pool = rte_crypto_op_pool_create(
97                         "FIPS_OP_POOL",
98                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
99                         1, 0,
100                         16,
101                         rte_socket_id());
102         if (!env.op_pool)
103                 goto error_exit;
104
105         env.mbuf = rte_pktmbuf_alloc(env.mpool);
106         if (!env.mbuf)
107                 goto error_exit;
108
109         env.op = rte_crypto_op_alloc(env.op_pool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
110         if (!env.op)
111                 goto error_exit;
112
113         qp_conf.mp_session = env.sess_mpool;
114         qp_conf.mp_session_private = env.sess_priv_mpool;
115
116         ret = rte_cryptodev_queue_pair_setup(env.dev_id, 0, &qp_conf,
117                         rte_socket_id());
118         if (ret < 0)
119                 goto error_exit;
120
121         return 0;
122
123 error_exit:
124
125         rte_mempool_free(env.mpool);
126         if (env.sess_mpool)
127                 rte_mempool_free(env.sess_mpool);
128         if (env.sess_priv_mpool)
129                 rte_mempool_free(env.sess_priv_mpool);
130         if (env.op_pool)
131                 rte_mempool_free(env.op_pool);
132
133         return ret;
134 }
135
136 static void
137 cryptodev_fips_validate_app_uninit(void)
138 {
139         rte_pktmbuf_free(env.mbuf);
140         rte_crypto_op_free(env.op);
141         rte_cryptodev_sym_session_clear(env.dev_id, env.sess);
142         rte_cryptodev_sym_session_free(env.sess);
143         rte_mempool_free(env.mpool);
144         rte_mempool_free(env.sess_mpool);
145         rte_mempool_free(env.sess_priv_mpool);
146         rte_mempool_free(env.op_pool);
147 }
148
149 static int
150 fips_test_one_file(void);
151
152 static int
153 parse_cryptodev_arg(char *arg)
154 {
155         int id = rte_cryptodev_get_dev_id(arg);
156
157         if (id < 0) {
158                 RTE_LOG(ERR, USER1, "Error %i: invalid cryptodev name %s\n",
159                                 id, arg);
160                 return id;
161         }
162
163         env.dev_id = (uint32_t)id;
164
165         return 0;
166 }
167
168 static int
169 parse_cryptodev_id_arg(char *arg)
170 {
171         uint32_t cryptodev_id;
172
173         if (parser_read_uint32(&cryptodev_id, arg) < 0) {
174                 RTE_LOG(ERR, USER1, "Error %i: invalid cryptodev id %s\n",
175                                 -EINVAL, arg);
176                 return -1;
177         }
178
179
180         if (!rte_cryptodev_pmd_is_valid_dev(cryptodev_id)) {
181                 RTE_LOG(ERR, USER1, "Error %i: invalid cryptodev id %s\n",
182                                 cryptodev_id, arg);
183                 return -1;
184         }
185
186         env.dev_id = (uint32_t)cryptodev_id;
187
188         return 0;
189 }
190
191 static void
192 cryptodev_fips_validate_usage(const char *prgname)
193 {
194         printf("%s [EAL options] --\n"
195                 "  --%s: REQUEST-FILE-PATH\n"
196                 "  --%s: RESPONSE-FILE-PATH\n"
197                 "  --%s: indicating both paths are folders\n"
198                 "  --%s: CRYPTODEV-NAME\n"
199                 "  --%s: CRYPTODEV-ID-NAME\n"
200                 "  --%s: self test indicator\n"
201                 "  --%s: self broken test ID\n"
202                 "  --%s: self broken test direction\n",
203                 prgname, REQ_FILE_PATH_KEYWORD, RSP_FILE_PATH_KEYWORD,
204                 FOLDER_KEYWORD, CRYPTODEV_KEYWORD, CRYPTODEV_ID_KEYWORD,
205                 CRYPTODEV_ST_KEYWORD, CRYPTODEV_BK_ID_KEYWORD,
206                 CRYPTODEV_BK_DIR_KEY);
207 }
208
209 static int
210 cryptodev_fips_validate_parse_args(int argc, char **argv)
211 {
212         int opt, ret;
213         char *prgname = argv[0];
214         char **argvopt;
215         int option_index;
216         struct option lgopts[] = {
217                         {REQ_FILE_PATH_KEYWORD, required_argument, 0, 0},
218                         {RSP_FILE_PATH_KEYWORD, required_argument, 0, 0},
219                         {FOLDER_KEYWORD, no_argument, 0, 0},
220                         {CRYPTODEV_KEYWORD, required_argument, 0, 0},
221                         {CRYPTODEV_ID_KEYWORD, required_argument, 0, 0},
222                         {CRYPTODEV_ST_KEYWORD, no_argument, 0, 0},
223                         {CRYPTODEV_BK_ID_KEYWORD, required_argument, 0, 0},
224                         {CRYPTODEV_BK_DIR_KEY, required_argument, 0, 0},
225                         {NULL, 0, 0, 0}
226         };
227
228         argvopt = argv;
229
230         while ((opt = getopt_long(argc, argvopt, "s:",
231                                   lgopts, &option_index)) != EOF) {
232
233                 switch (opt) {
234                 case 0:
235                         if (strcmp(lgopts[option_index].name,
236                                         REQ_FILE_PATH_KEYWORD) == 0)
237                                 env.req_path = optarg;
238                         else if (strcmp(lgopts[option_index].name,
239                                         RSP_FILE_PATH_KEYWORD) == 0)
240                                 env.rsp_path = optarg;
241                         else if (strcmp(lgopts[option_index].name,
242                                         FOLDER_KEYWORD) == 0)
243                                 env.is_path_folder = 1;
244                         else if (strcmp(lgopts[option_index].name,
245                                         CRYPTODEV_KEYWORD) == 0) {
246                                 ret = parse_cryptodev_arg(optarg);
247                                 if (ret < 0) {
248                                         cryptodev_fips_validate_usage(prgname);
249                                         return -EINVAL;
250                                 }
251                         } else if (strcmp(lgopts[option_index].name,
252                                         CRYPTODEV_ID_KEYWORD) == 0) {
253                                 ret = parse_cryptodev_id_arg(optarg);
254                                 if (ret < 0) {
255                                         cryptodev_fips_validate_usage(prgname);
256                                         return -EINVAL;
257                                 }
258                         } else if (strcmp(lgopts[option_index].name,
259                                         CRYPTODEV_ST_KEYWORD) == 0) {
260                                 env.self_test = 1;
261                         } else if (strcmp(lgopts[option_index].name,
262                                         CRYPTODEV_BK_ID_KEYWORD) == 0) {
263                                 if (!env.broken_test_config) {
264                                         env.broken_test_config = rte_malloc(
265                                                 NULL,
266                                                 sizeof(*env.broken_test_config),
267                                                 0);
268                                         if (!env.broken_test_config)
269                                                 return -ENOMEM;
270
271                                         env.broken_test_config->expect_fail_dir =
272                                                 self_test_dir_enc_auth_gen;
273                                 }
274
275                                 if (parser_read_uint32(
276                                         &env.broken_test_config->expect_fail_test_idx,
277                                                 optarg) < 0) {
278                                         rte_free(env.broken_test_config);
279                                         cryptodev_fips_validate_usage(prgname);
280                                         return -EINVAL;
281                                 }
282                         } else if (strcmp(lgopts[option_index].name,
283                                         CRYPTODEV_BK_DIR_KEY) == 0) {
284                                 if (!env.broken_test_config) {
285                                         env.broken_test_config = rte_malloc(
286                                                 NULL,
287                                                 sizeof(*env.broken_test_config),
288                                                 0);
289                                         if (!env.broken_test_config)
290                                                 return -ENOMEM;
291
292                                         env.broken_test_config->
293                                                 expect_fail_test_idx = 0;
294                                 }
295
296                                 if (strcmp(optarg, CRYPTODEV_ENC_KEYWORD) == 0)
297                                         env.broken_test_config->expect_fail_dir =
298                                                 self_test_dir_enc_auth_gen;
299                                 else if (strcmp(optarg, CRYPTODEV_DEC_KEYWORD)
300                                                 == 0)
301                                         env.broken_test_config->expect_fail_dir =
302                                                 self_test_dir_dec_auth_verify;
303                                 else {
304                                         rte_free(env.broken_test_config);
305                                         cryptodev_fips_validate_usage(prgname);
306                                         return -EINVAL;
307                                 }
308                         } else {
309                                 cryptodev_fips_validate_usage(prgname);
310                                 return -EINVAL;
311                         }
312                         break;
313                 default:
314                         return -1;
315                 }
316         }
317
318         if (env.req_path == NULL || env.rsp_path == NULL ||
319                         env.dev_id == UINT32_MAX) {
320                 cryptodev_fips_validate_usage(prgname);
321                 return -EINVAL;
322         }
323
324         return 0;
325 }
326
327 int
328 main(int argc, char *argv[])
329 {
330         int ret;
331
332         ret = rte_eal_init(argc, argv);
333         if (ret < 0) {
334                 RTE_LOG(ERR, USER1, "Error %i: Failed init\n", ret);
335                 return -1;
336         }
337
338         argc -= ret;
339         argv += ret;
340
341         ret = cryptodev_fips_validate_parse_args(argc, argv);
342         if (ret < 0)
343                 rte_exit(EXIT_FAILURE, "Failed to parse arguments!\n");
344
345         ret = cryptodev_fips_validate_app_int();
346         if (ret < 0) {
347                 RTE_LOG(ERR, USER1, "Error %i: Failed init\n", ret);
348                 return -1;
349         }
350
351         if (!env.is_path_folder) {
352                 printf("Processing file %s... ", env.req_path);
353
354                 ret = fips_test_init(env.req_path, env.rsp_path,
355                         rte_cryptodev_name_get(env.dev_id));
356                 if (ret < 0) {
357                         RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
358                                         ret, env.req_path);
359                         goto exit;
360                 }
361
362
363                 ret = fips_test_one_file();
364                 if (ret < 0) {
365                         RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
366                                         ret, env.req_path);
367                         goto exit;
368                 }
369
370                 printf("Done\n");
371
372         } else {
373                 struct dirent *dir;
374                 DIR *d_req, *d_rsp;
375                 char req_path[1024];
376                 char rsp_path[1024];
377
378                 d_req = opendir(env.req_path);
379                 if (!d_req) {
380                         RTE_LOG(ERR, USER1, "Error %i: Path %s not exist\n",
381                                         -EINVAL, env.req_path);
382                         goto exit;
383                 }
384
385                 d_rsp = opendir(env.rsp_path);
386                 if (!d_rsp) {
387                         ret = mkdir(env.rsp_path, 0700);
388                         if (ret == 0)
389                                 d_rsp = opendir(env.rsp_path);
390                         else {
391                                 RTE_LOG(ERR, USER1, "Error %i: Invalid %s\n",
392                                                 -EINVAL, env.rsp_path);
393                                 goto exit;
394                         }
395                 }
396                 closedir(d_rsp);
397
398                 while ((dir = readdir(d_req)) != NULL) {
399                         if (strstr(dir->d_name, "req") == NULL)
400                                 continue;
401
402                         snprintf(req_path, 1023, "%s/%s", env.req_path,
403                                         dir->d_name);
404                         snprintf(rsp_path, 1023, "%s/%s", env.rsp_path,
405                                         dir->d_name);
406                         strlcpy(strstr(rsp_path, "req"), "rsp", 4);
407
408                         printf("Processing file %s... ", req_path);
409
410                         ret = fips_test_init(req_path, rsp_path,
411                         rte_cryptodev_name_get(env.dev_id));
412                         if (ret < 0) {
413                                 RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
414                                                 ret, req_path);
415                                 break;
416                         }
417
418                         ret = fips_test_one_file();
419                         if (ret < 0) {
420                                 RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
421                                                 ret, req_path);
422                                 break;
423                         }
424
425                         printf("Done\n");
426                 }
427
428                 closedir(d_req);
429         }
430
431
432 exit:
433         fips_test_clear();
434         cryptodev_fips_validate_app_uninit();
435
436         return ret;
437
438 }
439
440 #define IV_OFF (sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op))
441 #define CRYPTODEV_FIPS_MAX_RETRIES      16
442
443 typedef int (*fips_test_one_case_t)(void);
444 typedef int (*fips_prepare_op_t)(void);
445 typedef int (*fips_prepare_xform_t)(struct rte_crypto_sym_xform *);
446
447 struct fips_test_ops {
448         fips_prepare_xform_t prepare_xform;
449         fips_prepare_op_t prepare_op;
450         fips_test_one_case_t test;
451 } test_ops;
452
453 static int
454 prepare_cipher_op(void)
455 {
456         struct rte_crypto_sym_op *sym = env.op->sym;
457         uint8_t *iv = rte_crypto_op_ctod_offset(env.op, uint8_t *, IV_OFF);
458
459         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
460         rte_pktmbuf_reset(env.mbuf);
461
462         sym->m_src = env.mbuf;
463         sym->cipher.data.offset = 0;
464
465         memcpy(iv, vec.iv.val, vec.iv.len);
466
467         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
468                 uint8_t *pt;
469
470                 if (vec.pt.len > RTE_MBUF_MAX_NB_SEGS) {
471                         RTE_LOG(ERR, USER1, "PT len %u\n", vec.pt.len);
472                         return -EPERM;
473                 }
474
475                 pt = (uint8_t *)rte_pktmbuf_append(env.mbuf, vec.pt.len);
476
477                 if (!pt) {
478                         RTE_LOG(ERR, USER1, "Error %i: MBUF too small\n",
479                                         -ENOMEM);
480                         return -ENOMEM;
481                 }
482
483                 memcpy(pt, vec.pt.val, vec.pt.len);
484                 sym->cipher.data.length = vec.pt.len;
485
486         } else {
487                 uint8_t *ct;
488
489                 if (vec.ct.len > RTE_MBUF_MAX_NB_SEGS) {
490                         RTE_LOG(ERR, USER1, "CT len %u\n", vec.ct.len);
491                         return -EPERM;
492                 }
493
494                 ct = (uint8_t *)rte_pktmbuf_append(env.mbuf, vec.ct.len);
495
496                 if (!ct) {
497                         RTE_LOG(ERR, USER1, "Error %i: MBUF too small\n",
498                                         -ENOMEM);
499                         return -ENOMEM;
500                 }
501
502                 memcpy(ct, vec.ct.val, vec.ct.len);
503                 sym->cipher.data.length = vec.ct.len;
504         }
505
506         rte_crypto_op_attach_sym_session(env.op, env.sess);
507
508         return 0;
509 }
510
511 static int
512 prepare_auth_op(void)
513 {
514         struct rte_crypto_sym_op *sym = env.op->sym;
515
516         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
517         rte_pktmbuf_reset(env.mbuf);
518
519         sym->m_src = env.mbuf;
520         sym->auth.data.offset = 0;
521
522         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
523                 uint8_t *pt;
524
525                 if (vec.pt.len > RTE_MBUF_MAX_NB_SEGS) {
526                         RTE_LOG(ERR, USER1, "PT len %u\n", vec.pt.len);
527                         return -EPERM;
528                 }
529
530                 pt = (uint8_t *)rte_pktmbuf_append(env.mbuf, vec.pt.len +
531                                 vec.cipher_auth.digest.len);
532
533                 if (!pt) {
534                         RTE_LOG(ERR, USER1, "Error %i: MBUF too small\n",
535                                         -ENOMEM);
536                         return -ENOMEM;
537                 }
538
539                 memcpy(pt, vec.pt.val, vec.pt.len);
540                 sym->auth.data.length = vec.pt.len;
541                 sym->auth.digest.data = pt + vec.pt.len;
542                 sym->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
543                                 env.mbuf, vec.pt.len);
544
545         } else {
546                 uint8_t *ct;
547
548                 if (vec.ct.len > RTE_MBUF_MAX_NB_SEGS) {
549                         RTE_LOG(ERR, USER1, "CT len %u\n", vec.ct.len);
550                         return -EPERM;
551                 }
552
553                 ct = (uint8_t *)rte_pktmbuf_append(env.mbuf,
554                                 vec.ct.len + vec.cipher_auth.digest.len);
555
556                 if (!ct) {
557                         RTE_LOG(ERR, USER1, "Error %i: MBUF too small\n",
558                                         -ENOMEM);
559                         return -ENOMEM;
560                 }
561
562                 memcpy(ct, vec.ct.val, vec.ct.len);
563                 sym->auth.data.length = vec.ct.len;
564                 sym->auth.digest.data = vec.cipher_auth.digest.val;
565                 sym->auth.digest.phys_addr = rte_malloc_virt2iova(
566                                 sym->auth.digest.data);
567         }
568
569         rte_crypto_op_attach_sym_session(env.op, env.sess);
570
571         return 0;
572 }
573
574 static int
575 prepare_aead_op(void)
576 {
577         struct rte_crypto_sym_op *sym = env.op->sym;
578         uint8_t *iv = rte_crypto_op_ctod_offset(env.op, uint8_t *, IV_OFF);
579
580         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
581         rte_pktmbuf_reset(env.mbuf);
582
583         if (info.algo == FIPS_TEST_ALGO_AES_CCM)
584                 memcpy(iv + 1, vec.iv.val, vec.iv.len);
585         else
586                 memcpy(iv, vec.iv.val, vec.iv.len);
587
588         sym->m_src = env.mbuf;
589         sym->aead.data.offset = 0;
590         sym->aead.aad.data = vec.aead.aad.val;
591         sym->aead.aad.phys_addr = rte_malloc_virt2iova(sym->aead.aad.data);
592
593         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
594                 uint8_t *pt;
595
596                 if (vec.pt.len > RTE_MBUF_MAX_NB_SEGS) {
597                         RTE_LOG(ERR, USER1, "PT len %u\n", vec.pt.len);
598                         return -EPERM;
599                 }
600
601                 pt = (uint8_t *)rte_pktmbuf_append(env.mbuf,
602                                 vec.pt.len + vec.aead.digest.len);
603
604                 if (!pt) {
605                         RTE_LOG(ERR, USER1, "Error %i: MBUF too small\n",
606                                         -ENOMEM);
607                         return -ENOMEM;
608                 }
609
610                 memcpy(pt, vec.pt.val, vec.pt.len);
611                 sym->aead.data.length = vec.pt.len;
612                 sym->aead.digest.data = pt + vec.pt.len;
613                 sym->aead.digest.phys_addr = rte_pktmbuf_mtophys_offset(
614                                 env.mbuf, vec.pt.len);
615         } else {
616                 uint8_t *ct;
617
618                 if (vec.ct.len > RTE_MBUF_MAX_NB_SEGS) {
619                         RTE_LOG(ERR, USER1, "CT len %u\n", vec.ct.len);
620                         return -EPERM;
621                 }
622
623                 ct = (uint8_t *)rte_pktmbuf_append(env.mbuf, vec.ct.len);
624
625                 if (!ct) {
626                         RTE_LOG(ERR, USER1, "Error %i: MBUF too small\n",
627                                         -ENOMEM);
628                         return -ENOMEM;
629                 }
630
631                 memcpy(ct, vec.ct.val, vec.ct.len);
632                 sym->aead.data.length = vec.ct.len;
633                 sym->aead.digest.data = vec.aead.digest.val;
634                 sym->aead.digest.phys_addr = rte_malloc_virt2iova(
635                                 sym->aead.digest.data);
636         }
637
638         rte_crypto_op_attach_sym_session(env.op, env.sess);
639
640         return 0;
641 }
642
643 static int
644 prepare_aes_xform(struct rte_crypto_sym_xform *xform)
645 {
646         const struct rte_cryptodev_symmetric_capability *cap;
647         struct rte_cryptodev_sym_capability_idx cap_idx;
648         struct rte_crypto_cipher_xform *cipher_xform = &xform->cipher;
649
650         xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
651
652         cipher_xform->algo = RTE_CRYPTO_CIPHER_AES_CBC;
653         cipher_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
654                         RTE_CRYPTO_CIPHER_OP_ENCRYPT :
655                         RTE_CRYPTO_CIPHER_OP_DECRYPT;
656         cipher_xform->key.data = vec.cipher_auth.key.val;
657         cipher_xform->key.length = vec.cipher_auth.key.len;
658         cipher_xform->iv.length = vec.iv.len;
659         cipher_xform->iv.offset = IV_OFF;
660
661         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
662         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
663
664         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
665         if (!cap) {
666                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
667                                 env.dev_id);
668                 return -EINVAL;
669         }
670
671         if (rte_cryptodev_sym_capability_check_cipher(cap,
672                         cipher_xform->key.length,
673                         cipher_xform->iv.length) != 0) {
674                 RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n",
675                                 info.device_name, cipher_xform->key.length,
676                                 cipher_xform->iv.length);
677                 return -EPERM;
678         }
679
680         return 0;
681 }
682
683 static int
684 prepare_tdes_xform(struct rte_crypto_sym_xform *xform)
685 {
686         const struct rte_cryptodev_symmetric_capability *cap;
687         struct rte_cryptodev_sym_capability_idx cap_idx;
688         struct rte_crypto_cipher_xform *cipher_xform = &xform->cipher;
689
690         xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
691
692         cipher_xform->algo = RTE_CRYPTO_CIPHER_3DES_CBC;
693         cipher_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
694                         RTE_CRYPTO_CIPHER_OP_ENCRYPT :
695                         RTE_CRYPTO_CIPHER_OP_DECRYPT;
696         cipher_xform->key.data = vec.cipher_auth.key.val;
697         cipher_xform->key.length = vec.cipher_auth.key.len;
698         cipher_xform->iv.length = vec.iv.len;
699         cipher_xform->iv.offset = IV_OFF;
700
701         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_3DES_CBC;
702         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
703
704         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
705         if (!cap) {
706                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
707                                 env.dev_id);
708                 return -EINVAL;
709         }
710
711         if (rte_cryptodev_sym_capability_check_cipher(cap,
712                         cipher_xform->key.length,
713                         cipher_xform->iv.length) != 0) {
714                 RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n",
715                                 info.device_name, cipher_xform->key.length,
716                                 cipher_xform->iv.length);
717                 return -EPERM;
718         }
719
720         return 0;
721 }
722
723 static int
724 prepare_hmac_xform(struct rte_crypto_sym_xform *xform)
725 {
726         const struct rte_cryptodev_symmetric_capability *cap;
727         struct rte_cryptodev_sym_capability_idx cap_idx;
728         struct rte_crypto_auth_xform *auth_xform = &xform->auth;
729
730         xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
731
732         auth_xform->algo = info.interim_info.hmac_data.algo;
733         auth_xform->op = RTE_CRYPTO_AUTH_OP_GENERATE;
734         auth_xform->digest_length = vec.cipher_auth.digest.len;
735         auth_xform->key.data = vec.cipher_auth.key.val;
736         auth_xform->key.length = vec.cipher_auth.key.len;
737
738         cap_idx.algo.auth = auth_xform->algo;
739         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
740
741         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
742         if (!cap) {
743                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
744                                 env.dev_id);
745                 return -EINVAL;
746         }
747
748         if (rte_cryptodev_sym_capability_check_auth(cap,
749                         auth_xform->key.length,
750                         auth_xform->digest_length, 0) != 0) {
751                 RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n",
752                                 info.device_name, auth_xform->key.length,
753                                 auth_xform->digest_length);
754                 return -EPERM;
755         }
756
757         return 0;
758 }
759
760 static int
761 prepare_gcm_xform(struct rte_crypto_sym_xform *xform)
762 {
763         const struct rte_cryptodev_symmetric_capability *cap;
764         struct rte_cryptodev_sym_capability_idx cap_idx;
765         struct rte_crypto_aead_xform *aead_xform = &xform->aead;
766
767         xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
768
769         aead_xform->algo = RTE_CRYPTO_AEAD_AES_GCM;
770         aead_xform->aad_length = vec.aead.aad.len;
771         aead_xform->digest_length = vec.aead.digest.len;
772         aead_xform->iv.offset = IV_OFF;
773         aead_xform->iv.length = vec.iv.len;
774         aead_xform->key.data = vec.aead.key.val;
775         aead_xform->key.length = vec.aead.key.len;
776         aead_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
777                         RTE_CRYPTO_AEAD_OP_ENCRYPT :
778                         RTE_CRYPTO_AEAD_OP_DECRYPT;
779
780         cap_idx.algo.aead = aead_xform->algo;
781         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
782
783         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
784         if (!cap) {
785                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
786                                 env.dev_id);
787                 return -EINVAL;
788         }
789
790         if (rte_cryptodev_sym_capability_check_aead(cap,
791                         aead_xform->key.length,
792                         aead_xform->digest_length, aead_xform->aad_length,
793                         aead_xform->iv.length) != 0) {
794                 RTE_LOG(ERR, USER1,
795                         "PMD %s key_len %u tag_len %u aad_len %u iv_len %u\n",
796                                 info.device_name, aead_xform->key.length,
797                                 aead_xform->digest_length,
798                                 aead_xform->aad_length,
799                                 aead_xform->iv.length);
800                 return -EPERM;
801         }
802
803         return 0;
804 }
805
806 static int
807 prepare_cmac_xform(struct rte_crypto_sym_xform *xform)
808 {
809         const struct rte_cryptodev_symmetric_capability *cap;
810         struct rte_cryptodev_sym_capability_idx cap_idx;
811         struct rte_crypto_auth_xform *auth_xform = &xform->auth;
812
813         xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
814
815         auth_xform->algo = RTE_CRYPTO_AUTH_AES_CMAC;
816         auth_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
817                         RTE_CRYPTO_AUTH_OP_GENERATE : RTE_CRYPTO_AUTH_OP_VERIFY;
818         auth_xform->digest_length = vec.cipher_auth.digest.len;
819         auth_xform->key.data = vec.cipher_auth.key.val;
820         auth_xform->key.length = vec.cipher_auth.key.len;
821
822         cap_idx.algo.auth = auth_xform->algo;
823         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
824
825         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
826         if (!cap) {
827                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
828                                 env.dev_id);
829                 return -EINVAL;
830         }
831
832         if (rte_cryptodev_sym_capability_check_auth(cap,
833                         auth_xform->key.length,
834                         auth_xform->digest_length, 0) != 0) {
835                 RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n",
836                                 info.device_name, auth_xform->key.length,
837                                 auth_xform->digest_length);
838                 return -EPERM;
839         }
840
841         return 0;
842 }
843
844 static int
845 prepare_ccm_xform(struct rte_crypto_sym_xform *xform)
846 {
847         const struct rte_cryptodev_symmetric_capability *cap;
848         struct rte_cryptodev_sym_capability_idx cap_idx;
849         struct rte_crypto_aead_xform *aead_xform = &xform->aead;
850
851         xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
852
853         aead_xform->algo = RTE_CRYPTO_AEAD_AES_CCM;
854         aead_xform->aad_length = vec.aead.aad.len;
855         aead_xform->digest_length = vec.aead.digest.len;
856         aead_xform->iv.offset = IV_OFF;
857         aead_xform->iv.length = vec.iv.len;
858         aead_xform->key.data = vec.aead.key.val;
859         aead_xform->key.length = vec.aead.key.len;
860         aead_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
861                         RTE_CRYPTO_AEAD_OP_ENCRYPT :
862                         RTE_CRYPTO_AEAD_OP_DECRYPT;
863
864         cap_idx.algo.aead = aead_xform->algo;
865         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
866
867         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
868         if (!cap) {
869                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
870                                 env.dev_id);
871                 return -EINVAL;
872         }
873
874         if (rte_cryptodev_sym_capability_check_aead(cap,
875                         aead_xform->key.length,
876                         aead_xform->digest_length, aead_xform->aad_length,
877                         aead_xform->iv.length) != 0) {
878                 RTE_LOG(ERR, USER1,
879                         "PMD %s key_len %u tag_len %u aad_len %u iv_len %u\n",
880                                 info.device_name, aead_xform->key.length,
881                                 aead_xform->digest_length,
882                                 aead_xform->aad_length,
883                                 aead_xform->iv.length);
884                 return -EPERM;
885         }
886
887         return 0;
888 }
889
890 static void
891 get_writeback_data(struct fips_val *val)
892 {
893         val->val = rte_pktmbuf_mtod(env.mbuf, uint8_t *);
894         val->len = rte_pktmbuf_pkt_len(env.mbuf);
895 }
896
897 static int
898 fips_run_test(void)
899 {
900         struct rte_crypto_sym_xform xform = {0};
901         uint16_t n_deqd;
902         int ret;
903
904         ret = test_ops.prepare_xform(&xform);
905         if (ret < 0)
906                 return ret;
907
908         env.sess = rte_cryptodev_sym_session_create(env.sess_mpool);
909         if (!env.sess)
910                 return -ENOMEM;
911
912         ret = rte_cryptodev_sym_session_init(env.dev_id,
913                         env.sess, &xform, env.sess_priv_mpool);
914         if (ret < 0) {
915                 RTE_LOG(ERR, USER1, "Error %i: Init session\n",
916                                 ret);
917                 return ret;
918         }
919
920         ret = test_ops.prepare_op();
921         if (ret < 0) {
922                 RTE_LOG(ERR, USER1, "Error %i: Prepare op\n",
923                                 ret);
924                 return ret;
925         }
926
927         if (rte_cryptodev_enqueue_burst(env.dev_id, 0, &env.op, 1) < 1) {
928                 RTE_LOG(ERR, USER1, "Error: Failed enqueue\n");
929                 return ret;
930         }
931
932         do {
933                 struct rte_crypto_op *deqd_op;
934
935                 n_deqd = rte_cryptodev_dequeue_burst(env.dev_id, 0, &deqd_op,
936                                 1);
937         } while (n_deqd == 0);
938
939         vec.status = env.op->status;
940
941         rte_cryptodev_sym_session_clear(env.dev_id, env.sess);
942         rte_cryptodev_sym_session_free(env.sess);
943         env.sess = NULL;
944
945         return ret;
946 }
947
948 static int
949 fips_generic_test(void)
950 {
951         struct fips_val val;
952         int ret;
953
954         fips_test_write_one_case();
955
956         ret = fips_run_test();
957         if (ret < 0) {
958                 if (ret == -EPERM) {
959                         fprintf(info.fp_wr, "Bypass\n\n");
960                         return 0;
961                 }
962
963                 return ret;
964         }
965
966         get_writeback_data(&val);
967
968         switch (info.file_type) {
969         case FIPS_TYPE_REQ:
970         case FIPS_TYPE_RSP:
971                 if (info.parse_writeback == NULL)
972                         return -EPERM;
973                 ret = info.parse_writeback(&val);
974                 if (ret < 0)
975                         return ret;
976                 break;
977         case FIPS_TYPE_FAX:
978                 if (info.kat_check == NULL)
979                         return -EPERM;
980                 ret = info.kat_check(&val);
981                 if (ret < 0)
982                         return ret;
983                 break;
984         }
985
986         fprintf(info.fp_wr, "\n");
987
988         return 0;
989 }
990
991 static int
992 fips_mct_tdes_test(void)
993 {
994 #define TDES_BLOCK_SIZE         8
995 #define TDES_EXTERN_ITER        400
996 #define TDES_INTERN_ITER        10000
997         struct fips_val val, val_key;
998         uint8_t prev_out[TDES_BLOCK_SIZE] = {0};
999         uint8_t prev_prev_out[TDES_BLOCK_SIZE] = {0};
1000         uint8_t prev_in[TDES_BLOCK_SIZE] = {0};
1001         uint32_t i, j, k;
1002         int ret;
1003
1004         for (i = 0; i < TDES_EXTERN_ITER; i++) {
1005                 if (i != 0)
1006                         update_info_vec(i);
1007
1008                 fips_test_write_one_case();
1009
1010                 for (j = 0; j < TDES_INTERN_ITER; j++) {
1011                         ret = fips_run_test();
1012                         if (ret < 0) {
1013                                 if (ret == -EPERM) {
1014                                         fprintf(info.fp_wr, "Bypass\n");
1015                                         return 0;
1016                                 }
1017
1018                                 return ret;
1019                         }
1020
1021                         get_writeback_data(&val);
1022
1023                         if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
1024                                 memcpy(prev_in, vec.ct.val, TDES_BLOCK_SIZE);
1025
1026                         if (j == 0) {
1027                                 memcpy(prev_out, val.val, TDES_BLOCK_SIZE);
1028
1029                                 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
1030                                         memcpy(vec.pt.val, vec.iv.val,
1031                                                         TDES_BLOCK_SIZE);
1032                                         memcpy(vec.iv.val, val.val,
1033                                                         TDES_BLOCK_SIZE);
1034                                 } else {
1035                                         memcpy(vec.iv.val, vec.ct.val,
1036                                                         TDES_BLOCK_SIZE);
1037                                         memcpy(vec.ct.val, val.val,
1038                                                         TDES_BLOCK_SIZE);
1039                                 }
1040                                 continue;
1041                         }
1042
1043                         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
1044                                 memcpy(vec.iv.val, val.val, TDES_BLOCK_SIZE);
1045                                 memcpy(vec.pt.val, prev_out, TDES_BLOCK_SIZE);
1046                         } else {
1047                                 memcpy(vec.iv.val, vec.ct.val, TDES_BLOCK_SIZE);
1048                                 memcpy(vec.ct.val, val.val, TDES_BLOCK_SIZE);
1049                         }
1050
1051                         if (j == TDES_INTERN_ITER - 1)
1052                                 continue;
1053
1054                         memcpy(prev_out, val.val, TDES_BLOCK_SIZE);
1055
1056                         if (j == TDES_INTERN_ITER - 3)
1057                                 memcpy(prev_prev_out, val.val, TDES_BLOCK_SIZE);
1058                 }
1059
1060                 info.parse_writeback(&val);
1061                 fprintf(info.fp_wr, "\n");
1062
1063                 if (i == TDES_EXTERN_ITER - 1)
1064                         continue;
1065
1066                 /** update key */
1067                 memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
1068
1069                 if (info.interim_info.tdes_data.nb_keys == 0) {
1070                         if (memcmp(val_key.val, val_key.val + 8, 8) == 0)
1071                                 info.interim_info.tdes_data.nb_keys = 1;
1072                         else if (memcmp(val_key.val, val_key.val + 16, 8) == 0)
1073                                 info.interim_info.tdes_data.nb_keys = 2;
1074                         else
1075                                 info.interim_info.tdes_data.nb_keys = 3;
1076
1077                 }
1078
1079                 for (k = 0; k < TDES_BLOCK_SIZE; k++) {
1080
1081                         switch (info.interim_info.tdes_data.nb_keys) {
1082                         case 3:
1083                                 val_key.val[k] ^= val.val[k];
1084                                 val_key.val[k + 8] ^= prev_out[k];
1085                                 val_key.val[k + 16] ^= prev_prev_out[k];
1086                                 break;
1087                         case 2:
1088                                 val_key.val[k] ^= val.val[k];
1089                                 val_key.val[k + 8] ^= prev_out[k];
1090                                 val_key.val[k + 16] ^= val.val[k];
1091                                 break;
1092                         default: /* case 1 */
1093                                 val_key.val[k] ^= val.val[k];
1094                                 val_key.val[k + 8] ^= val.val[k];
1095                                 val_key.val[k + 16] ^= val.val[k];
1096                                 break;
1097                         }
1098
1099                 }
1100
1101                 for (k = 0; k < 24; k++)
1102                         val_key.val[k] = (__builtin_popcount(val_key.val[k]) &
1103                                         0x1) ?
1104                                         val_key.val[k] : (val_key.val[k] ^ 0x1);
1105
1106                 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
1107                         memcpy(vec.iv.val, val.val, TDES_BLOCK_SIZE);
1108                         memcpy(vec.pt.val, prev_out, TDES_BLOCK_SIZE);
1109                 } else {
1110                         memcpy(vec.iv.val, prev_out, TDES_BLOCK_SIZE);
1111                         memcpy(vec.ct.val, val.val, TDES_BLOCK_SIZE);
1112                 }
1113         }
1114
1115         return 0;
1116 }
1117
1118 static int
1119 fips_mct_aes_test(void)
1120 {
1121 #define AES_BLOCK_SIZE  16
1122 #define AES_EXTERN_ITER 100
1123 #define AES_INTERN_ITER 1000
1124         struct fips_val val, val_key;
1125         uint8_t prev_out[AES_BLOCK_SIZE] = {0};
1126         uint8_t prev_in[AES_BLOCK_SIZE] = {0};
1127         uint32_t i, j, k;
1128         int ret;
1129
1130         for (i = 0; i < AES_EXTERN_ITER; i++) {
1131                 if (i != 0)
1132                         update_info_vec(i);
1133
1134                 fips_test_write_one_case();
1135
1136                 for (j = 0; j < AES_INTERN_ITER; j++) {
1137                         ret = fips_run_test();
1138                         if (ret < 0) {
1139                                 if (ret == -EPERM) {
1140                                         fprintf(info.fp_wr, "Bypass\n");
1141                                         return 0;
1142                                 }
1143
1144                                 return ret;
1145                         }
1146
1147                         get_writeback_data(&val);
1148
1149                         if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
1150                                 memcpy(prev_in, vec.ct.val, AES_BLOCK_SIZE);
1151
1152                         if (j == 0) {
1153                                 memcpy(prev_out, val.val, AES_BLOCK_SIZE);
1154
1155                                 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
1156                                         memcpy(vec.pt.val, vec.iv.val,
1157                                                         AES_BLOCK_SIZE);
1158                                         memcpy(vec.iv.val, val.val,
1159                                                         AES_BLOCK_SIZE);
1160                                 } else {
1161                                         memcpy(vec.ct.val, vec.iv.val,
1162                                                         AES_BLOCK_SIZE);
1163                                         memcpy(vec.iv.val, prev_in,
1164                                                         AES_BLOCK_SIZE);
1165                                 }
1166                                 continue;
1167                         }
1168
1169                         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
1170                                 memcpy(vec.iv.val, val.val, AES_BLOCK_SIZE);
1171                                 memcpy(vec.pt.val, prev_out, AES_BLOCK_SIZE);
1172                         } else {
1173                                 memcpy(vec.iv.val, prev_in, AES_BLOCK_SIZE);
1174                                 memcpy(vec.ct.val, prev_out, AES_BLOCK_SIZE);
1175                         }
1176
1177                         if (j == AES_INTERN_ITER - 1)
1178                                 continue;
1179
1180                         memcpy(prev_out, val.val, AES_BLOCK_SIZE);
1181                 }
1182
1183                 info.parse_writeback(&val);
1184                 fprintf(info.fp_wr, "\n");
1185
1186                 if (i == AES_EXTERN_ITER - 1)
1187                         continue;
1188
1189                 /** update key */
1190                 memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
1191                 for (k = 0; k < vec.cipher_auth.key.len; k++) {
1192                         switch (vec.cipher_auth.key.len) {
1193                         case 16:
1194                                 val_key.val[k] ^= val.val[k];
1195                                 break;
1196                         case 24:
1197                                 if (k < 8)
1198                                         val_key.val[k] ^= prev_out[k + 8];
1199                                 else
1200                                         val_key.val[k] ^= val.val[k - 8];
1201                                 break;
1202                         case 32:
1203                                 if (k < 16)
1204                                         val_key.val[k] ^= prev_out[k];
1205                                 else
1206                                         val_key.val[k] ^= val.val[k - 16];
1207                                 break;
1208                         default:
1209                                 return -1;
1210                         }
1211                 }
1212
1213                 if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
1214                         memcpy(vec.iv.val, val.val, AES_BLOCK_SIZE);
1215         }
1216
1217         return 0;
1218 }
1219
1220 static int
1221 init_test_ops(void)
1222 {
1223         switch (info.algo) {
1224         case FIPS_TEST_ALGO_AES:
1225                 test_ops.prepare_op = prepare_cipher_op;
1226                 test_ops.prepare_xform  = prepare_aes_xform;
1227                 if (info.interim_info.aes_data.test_type == AESAVS_TYPE_MCT)
1228                         test_ops.test = fips_mct_aes_test;
1229                 else
1230                         test_ops.test = fips_generic_test;
1231                 break;
1232         case FIPS_TEST_ALGO_HMAC:
1233                 test_ops.prepare_op = prepare_auth_op;
1234                 test_ops.prepare_xform = prepare_hmac_xform;
1235                 test_ops.test = fips_generic_test;
1236                 break;
1237         case FIPS_TEST_ALGO_TDES:
1238                 test_ops.prepare_op = prepare_cipher_op;
1239                 test_ops.prepare_xform  = prepare_tdes_xform;
1240                 if (info.interim_info.tdes_data.test_type == TDES_MCT)
1241                         test_ops.test = fips_mct_tdes_test;
1242                 else
1243                         test_ops.test = fips_generic_test;
1244                 break;
1245         case FIPS_TEST_ALGO_AES_GCM:
1246                 test_ops.prepare_op = prepare_aead_op;
1247                 test_ops.prepare_xform = prepare_gcm_xform;
1248                 test_ops.test = fips_generic_test;
1249                 break;
1250         case FIPS_TEST_ALGO_AES_CMAC:
1251                 test_ops.prepare_op = prepare_auth_op;
1252                 test_ops.prepare_xform = prepare_cmac_xform;
1253                 test_ops.test = fips_generic_test;
1254                 break;
1255         case FIPS_TEST_ALGO_AES_CCM:
1256                 test_ops.prepare_op = prepare_aead_op;
1257                 test_ops.prepare_xform = prepare_ccm_xform;
1258                 test_ops.test = fips_generic_test;
1259                 break;
1260         default:
1261                 return -1;
1262         }
1263
1264         return 0;
1265 }
1266
1267 static void
1268 print_test_block(void)
1269 {
1270         uint32_t i;
1271
1272         for (i = 0; i < info.nb_vec_lines; i++)
1273                 printf("%s\n", info.vec[i]);
1274
1275         printf("\n");
1276 }
1277
1278 static int
1279 fips_test_one_file(void)
1280 {
1281         int fetch_ret = 0, ret;
1282
1283
1284         ret = init_test_ops();
1285         if (ret < 0) {
1286                 RTE_LOG(ERR, USER1, "Error %i: Init test op\n", ret);
1287                 return ret;
1288         }
1289
1290         while (ret >= 0 && fetch_ret == 0) {
1291                 fetch_ret = fips_test_fetch_one_block();
1292                 if (fetch_ret < 0) {
1293                         RTE_LOG(ERR, USER1, "Error %i: Fetch block\n",
1294                                         fetch_ret);
1295                         ret = fetch_ret;
1296                         goto error_one_case;
1297                 }
1298
1299                 if (info.nb_vec_lines == 0) {
1300                         if (fetch_ret == -EOF)
1301                                 break;
1302
1303                         fprintf(info.fp_wr, "\n");
1304                         continue;
1305                 }
1306
1307                 ret = fips_test_parse_one_case();
1308                 switch (ret) {
1309                 case 0:
1310                         ret = test_ops.test();
1311                         if (ret == 0)
1312                                 break;
1313                         RTE_LOG(ERR, USER1, "Error %i: test block\n",
1314                                         ret);
1315                         goto error_one_case;
1316                 case 1:
1317                         break;
1318                 default:
1319                         RTE_LOG(ERR, USER1, "Error %i: Parse block\n",
1320                                         ret);
1321                         goto error_one_case;
1322                 }
1323
1324                 continue;
1325 error_one_case:
1326                 print_test_block();
1327         }
1328
1329         fips_test_clear();
1330
1331         return ret;
1332
1333 }