LCOV - code coverage report
Current view: top level - app/fips_validation - main.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1587 0.0 %
Date: 2026-12-01 19:01:22 Functions: 0 53 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       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                 :            : #include <stdlib.h>
       9                 :            : 
      10                 :            : #include <rte_cryptodev.h>
      11                 :            : #include <rte_malloc.h>
      12                 :            : #include <rte_mempool.h>
      13                 :            : #include <rte_mbuf.h>
      14                 :            : #include <rte_string_fns.h>
      15                 :            : #include <rte_random.h>
      16                 :            : 
      17                 :            : #include "fips_validation.h"
      18                 :            : #include "fips_dev_self_test.h"
      19                 :            : 
      20                 :            : enum {
      21                 :            : #define OPT_REQ_FILE_PATH           "req-file"
      22                 :            :         OPT_REQ_FILE_PATH_NUM = 256,
      23                 :            : #define OPT_RSP_FILE_PATH           "rsp-file"
      24                 :            :         OPT_RSP_FILE_PATH_NUM,
      25                 :            : #define OPT_MBUF_DATAROOM           "mbuf-dataroom"
      26                 :            :         OPT_MBUF_DATAROOM_NUM,
      27                 :            : #define OPT_FOLDER                  "path-is-folder"
      28                 :            :         OPT_FOLDER_NUM,
      29                 :            : #define OPT_CRYPTODEV               "cryptodev"
      30                 :            :         OPT_CRYPTODEV_NUM,
      31                 :            : #define OPT_CRYPTODEV_ID            "cryptodev-id"
      32                 :            :         OPT_CRYPTODEV_ID_NUM,
      33                 :            : #define OPT_CRYPTODEV_ST            "self-test"
      34                 :            :         OPT_CRYPTODEV_ST_NUM,
      35                 :            : #define OPT_CRYPTODEV_BK_ID         "broken-test-id"
      36                 :            :         OPT_CRYPTODEV_BK_ID_NUM,
      37                 :            : #define OPT_CRYPTODEV_BK_DIR_KEY    "broken-test-dir"
      38                 :            :         OPT_CRYPTODEV_BK_DIR_KEY_NUM,
      39                 :            : #define OPT_USE_JSON                "use-json"
      40                 :            :         OPT_USE_JSON_NUM,
      41                 :            : #define OPT_CRYPTODEV_ASYM          "asymmetric"
      42                 :            :         OPT_CRYPTODEV_ASYM_NUM,
      43                 :            : };
      44                 :            : 
      45                 :            : struct fips_test_vector vec;
      46                 :            : struct fips_test_interim_info info;
      47                 :            : 
      48                 :            : #ifdef USE_JANSSON
      49                 :            : struct fips_test_json_info json_info;
      50                 :            : #endif /* USE_JANSSON */
      51                 :            : 
      52                 :            : struct cryptodev_fips_validate_env {
      53                 :            :         const char *req_path;
      54                 :            :         const char *rsp_path;
      55                 :            :         uint32_t is_path_folder;
      56                 :            :         uint8_t dev_id;
      57                 :            :         struct rte_mempool *mpool;
      58                 :            :         struct fips_sym_env {
      59                 :            :                 struct rte_mempool *sess_mpool;
      60                 :            :                 struct rte_mempool *op_pool;
      61                 :            :                 struct rte_cryptodev_sym_session *sess;
      62                 :            :                 struct rte_crypto_op *op;
      63                 :            :         } sym;
      64                 :            :         struct fips_asym_env {
      65                 :            :                 struct rte_mempool *sess_mpool;
      66                 :            :                 struct rte_mempool *op_pool;
      67                 :            :                 struct rte_cryptodev_asym_session *sess;
      68                 :            :                 struct rte_crypto_op *op;
      69                 :            :         } asym;
      70                 :            :         struct rte_crypto_op *op;
      71                 :            :         uint8_t dev_support_sgl;
      72                 :            :         uint16_t mbuf_data_room;
      73                 :            :         struct rte_mbuf *mbuf;
      74                 :            :         uint8_t *digest;
      75                 :            :         uint16_t digest_len;
      76                 :            :         bool is_asym_test;
      77                 :            :         uint16_t self_test;
      78                 :            :         struct fips_dev_broken_test_config *broken_test_config;
      79                 :            : } env;
      80                 :            : 
      81                 :            : static int
      82                 :          0 : cryptodev_fips_validate_app_sym_init(void)
      83                 :            : {
      84                 :          0 :         uint32_t sess_sz = rte_cryptodev_sym_get_private_session_size(
      85                 :          0 :                                                         env.dev_id);
      86                 :            :         struct rte_cryptodev_info dev_info;
      87                 :            :         struct fips_sym_env *sym = &env.sym;
      88                 :            :         int ret;
      89                 :            : 
      90                 :          0 :         rte_cryptodev_info_get(env.dev_id, &dev_info);
      91                 :          0 :         if (dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)
      92                 :          0 :                 env.dev_support_sgl = 1;
      93                 :            :         else
      94                 :          0 :                 env.dev_support_sgl = 0;
      95                 :            : 
      96                 :            :         ret = -ENOMEM;
      97                 :          0 :         sym->sess_mpool = rte_cryptodev_sym_session_pool_create(
      98                 :          0 :                         "FIPS_SYM_SESS_MEMPOOL", 16, sess_sz, 0, 0, rte_socket_id());
      99                 :          0 :         if (!sym->sess_mpool)
     100                 :          0 :                 goto error_exit;
     101                 :            : 
     102                 :          0 :         sym->op_pool = rte_crypto_op_pool_create(
     103                 :            :                         "FIPS_OP_SYM_POOL",
     104                 :            :                         RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     105                 :            :                         1, 0,
     106                 :            :                         16,
     107                 :          0 :                         rte_socket_id());
     108                 :          0 :         if (!sym->op_pool)
     109                 :          0 :                 goto error_exit;
     110                 :            : 
     111                 :          0 :         sym->op = rte_crypto_op_alloc(sym->op_pool, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
     112                 :          0 :         if (!sym->op)
     113                 :          0 :                 goto error_exit;
     114                 :            : 
     115                 :            :         return 0;
     116                 :            : 
     117                 :          0 : error_exit:
     118                 :          0 :         rte_mempool_free(sym->sess_mpool);
     119                 :          0 :         rte_mempool_free(sym->op_pool);
     120                 :          0 :         return ret;
     121                 :            : }
     122                 :            : 
     123                 :            : static void
     124                 :          0 : cryptodev_fips_validate_app_sym_uninit(void)
     125                 :            : {
     126                 :            :         struct fips_sym_env *sym = &env.sym;
     127                 :            : 
     128                 :          0 :         rte_pktmbuf_free(env.mbuf);
     129                 :          0 :         rte_crypto_op_free(sym->op);
     130                 :          0 :         rte_cryptodev_sym_session_free(env.dev_id, sym->sess);
     131                 :          0 :         rte_mempool_free(sym->sess_mpool);
     132                 :          0 :         rte_mempool_free(sym->op_pool);
     133                 :          0 : }
     134                 :            : 
     135                 :            : static int
     136                 :          0 : cryptodev_fips_validate_app_asym_init(void)
     137                 :            : {
     138                 :            :         struct fips_asym_env *asym = &env.asym;
     139                 :            :         int ret;
     140                 :            : 
     141                 :            :         ret = -ENOMEM;
     142                 :          0 :         asym->sess_mpool = rte_cryptodev_asym_session_pool_create(
     143                 :          0 :                         "FIPS_ASYM_SESS_MEMPOOL", 16, 0, 0, rte_socket_id());
     144                 :          0 :         if (!asym->sess_mpool)
     145                 :          0 :                 goto error_exit;
     146                 :            : 
     147                 :          0 :         asym->op_pool = rte_crypto_op_pool_create(
     148                 :            :                         "FIPS_OP_ASYM_POOL",
     149                 :            :                         RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
     150                 :            :                         1, 0,
     151                 :            :                         16,
     152                 :          0 :                         rte_socket_id());
     153                 :          0 :         if (!asym->op_pool)
     154                 :          0 :                 goto error_exit;
     155                 :            : 
     156                 :          0 :         asym->op = rte_crypto_op_alloc(asym->op_pool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     157                 :          0 :         if (!asym->op)
     158                 :          0 :                 goto error_exit;
     159                 :            : 
     160                 :            :         return 0;
     161                 :            : 
     162                 :          0 : error_exit:
     163                 :          0 :         rte_mempool_free(asym->sess_mpool);
     164                 :          0 :         rte_mempool_free(asym->op_pool);
     165                 :          0 :         return ret;
     166                 :            : }
     167                 :            : 
     168                 :            : static void
     169                 :          0 : cryptodev_fips_validate_app_asym_uninit(void)
     170                 :            : {
     171                 :            :         struct fips_asym_env *asym = &env.asym;
     172                 :            : 
     173                 :          0 :         rte_crypto_op_free(asym->op);
     174                 :          0 :         rte_cryptodev_asym_session_free(env.dev_id, asym->sess);
     175                 :          0 :         rte_mempool_free(asym->sess_mpool);
     176                 :          0 :         rte_mempool_free(asym->op_pool);
     177                 :          0 : }
     178                 :            : 
     179                 :            : static int
     180                 :          0 : cryptodev_fips_validate_app_init(void)
     181                 :            : {
     182                 :          0 :         struct rte_cryptodev_config conf = {rte_socket_id(), 1, 0};
     183                 :          0 :         struct rte_cryptodev_qp_conf qp_conf = {128, NULL};
     184                 :          0 :         uint32_t nb_mbufs = UINT16_MAX / env.mbuf_data_room + 1;
     185                 :            :         int ret;
     186                 :            : 
     187                 :          0 :         if (env.self_test) {
     188                 :          0 :                 ret = fips_dev_self_test(env.dev_id, env.broken_test_config);
     189                 :          0 :                 if (ret < 0) {
     190                 :          0 :                         rte_cryptodev_stop(env.dev_id);
     191                 :          0 :                         rte_cryptodev_close(env.dev_id);
     192                 :            : 
     193                 :          0 :                         return ret;
     194                 :            :                 }
     195                 :            :         }
     196                 :            : 
     197                 :          0 :         ret = rte_cryptodev_configure(env.dev_id, &conf);
     198                 :          0 :         if (ret < 0)
     199                 :            :                 return ret;
     200                 :            : 
     201                 :            :         ret = -ENOMEM;
     202                 :          0 :         env.mpool = rte_pktmbuf_pool_create("FIPS_MEMPOOL", nb_mbufs,
     203                 :          0 :                         0, 0, sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM +
     204                 :          0 :                         env.mbuf_data_room, rte_socket_id());
     205                 :          0 :         if (!env.mpool)
     206                 :            :                 return ret;
     207                 :            : 
     208                 :          0 :         ret = cryptodev_fips_validate_app_sym_init();
     209                 :          0 :         if (ret < 0)
     210                 :          0 :                 goto error_exit;
     211                 :            : 
     212                 :          0 :         if (env.is_asym_test) {
     213                 :          0 :                 ret = cryptodev_fips_validate_app_asym_init();
     214                 :          0 :                 if (ret < 0)
     215                 :          0 :                         goto error_exit;
     216                 :            :         }
     217                 :            : 
     218                 :          0 :         qp_conf.mp_session = env.sym.sess_mpool;
     219                 :            : 
     220                 :          0 :         ret = rte_cryptodev_queue_pair_setup(env.dev_id, 0, &qp_conf,
     221                 :          0 :                         rte_socket_id());
     222                 :          0 :         if (ret < 0)
     223                 :          0 :                 goto error_exit;
     224                 :            : 
     225                 :          0 :         ret = rte_cryptodev_start(env.dev_id);
     226                 :          0 :         if (ret < 0)
     227                 :          0 :                 goto error_exit;
     228                 :            : 
     229                 :            :         return 0;
     230                 :            : 
     231                 :          0 : error_exit:
     232                 :          0 :         rte_mempool_free(env.mpool);
     233                 :          0 :         return ret;
     234                 :            : }
     235                 :            : 
     236                 :            : static void
     237                 :          0 : cryptodev_fips_validate_app_uninit(void)
     238                 :            : {
     239                 :          0 :         cryptodev_fips_validate_app_sym_uninit();
     240                 :            : 
     241                 :          0 :         if (env.is_asym_test)
     242                 :          0 :                 cryptodev_fips_validate_app_asym_uninit();
     243                 :            : 
     244                 :          0 :         rte_mempool_free(env.mpool);
     245                 :          0 :         rte_cryptodev_stop(env.dev_id);
     246                 :          0 :         rte_cryptodev_close(env.dev_id);
     247                 :          0 : }
     248                 :            : 
     249                 :            : static int
     250                 :            : fips_test_one_file(void);
     251                 :            : 
     252                 :            : #ifdef USE_JANSSON
     253                 :            : static int
     254                 :            : fips_test_one_json_file(void);
     255                 :            : #endif /* USE_JANSSON */
     256                 :            : 
     257                 :            : static int
     258                 :          0 : parse_cryptodev_arg(char *arg)
     259                 :            : {
     260                 :          0 :         int id = rte_cryptodev_get_dev_id(arg);
     261                 :            : 
     262                 :          0 :         if (id < 0) {
     263                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: invalid cryptodev name %s\n",
     264                 :            :                                 id, arg);
     265                 :          0 :                 return id;
     266                 :            :         }
     267                 :            : 
     268                 :          0 :         env.dev_id = (uint8_t)id;
     269                 :            : 
     270                 :          0 :         return 0;
     271                 :            : }
     272                 :            : 
     273                 :            : static int
     274                 :          0 : parse_cryptodev_id_arg(char *arg)
     275                 :            : {
     276                 :            :         uint32_t cryptodev_id;
     277                 :            : 
     278                 :          0 :         if (parser_read_uint32(&cryptodev_id, arg) < 0) {
     279                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: invalid cryptodev id %s\n",
     280                 :            :                                 -EINVAL, arg);
     281                 :          0 :                 return -1;
     282                 :            :         }
     283                 :            : 
     284                 :            : 
     285                 :          0 :         if (!rte_cryptodev_is_valid_dev(cryptodev_id)) {
     286                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: invalid cryptodev id %s\n",
     287                 :            :                                 cryptodev_id, arg);
     288                 :          0 :                 return -1;
     289                 :            :         }
     290                 :            : 
     291                 :          0 :         env.dev_id = (uint8_t)cryptodev_id;
     292                 :            : 
     293                 :          0 :         return 0;
     294                 :            : }
     295                 :            : 
     296                 :            : static void
     297                 :          0 : cryptodev_fips_validate_usage(const char *prgname)
     298                 :            : {
     299                 :            :         uint32_t def_mbuf_seg_size = DEF_MBUF_SEG_SIZE;
     300                 :            :         printf("%s [EAL options] --\n"
     301                 :            :                 "  --%s: REQUEST-FILE-PATH\n"
     302                 :            :                 "  --%s: RESPONSE-FILE-PATH\n"
     303                 :            :                 "  --%s: indicating both paths are folders\n"
     304                 :            :                 "  --%s: mbuf dataroom size (default %u bytes)\n"
     305                 :            :                 "  --%s: CRYPTODEV-NAME\n"
     306                 :            :                 "  --%s: CRYPTODEV-ID-NAME\n"
     307                 :            :                 "  --%s: self test indicator\n"
     308                 :            :                 "  --%s: self broken test ID\n"
     309                 :            :                 "  --%s: self broken test direction\n",
     310                 :            :                 prgname, OPT_REQ_FILE_PATH, OPT_RSP_FILE_PATH,
     311                 :            :                 OPT_FOLDER, OPT_MBUF_DATAROOM, def_mbuf_seg_size,
     312                 :            :                 OPT_CRYPTODEV, OPT_CRYPTODEV_ID, OPT_CRYPTODEV_ST,
     313                 :            :                 OPT_CRYPTODEV_BK_ID, OPT_CRYPTODEV_BK_DIR_KEY);
     314                 :          0 : }
     315                 :            : 
     316                 :            : static int
     317                 :          0 : cryptodev_fips_validate_parse_args(int argc, char **argv)
     318                 :            : {
     319                 :            :         int opt, ret;
     320                 :          0 :         char *prgname = argv[0];
     321                 :            :         char **argvopt;
     322                 :            :         int option_index;
     323                 :          0 :         struct option lgopts[] = {
     324                 :            :                 {OPT_REQ_FILE_PATH, required_argument,
     325                 :            :                                 NULL, OPT_REQ_FILE_PATH_NUM},
     326                 :            :                 {OPT_RSP_FILE_PATH, required_argument,
     327                 :            :                                 NULL, OPT_RSP_FILE_PATH_NUM},
     328                 :            :                 {OPT_FOLDER, no_argument,
     329                 :            :                                 NULL, OPT_FOLDER_NUM},
     330                 :            :                 {OPT_MBUF_DATAROOM, required_argument,
     331                 :            :                                 NULL, OPT_MBUF_DATAROOM_NUM},
     332                 :            :                 {OPT_CRYPTODEV, required_argument,
     333                 :            :                                 NULL, OPT_CRYPTODEV_NUM},
     334                 :            :                 {OPT_CRYPTODEV_ID, required_argument,
     335                 :            :                                 NULL, OPT_CRYPTODEV_ID_NUM},
     336                 :            :                 {OPT_CRYPTODEV_ST, no_argument,
     337                 :            :                                 NULL, OPT_CRYPTODEV_ST_NUM},
     338                 :            :                 {OPT_CRYPTODEV_BK_ID, required_argument,
     339                 :            :                                 NULL, OPT_CRYPTODEV_BK_ID_NUM},
     340                 :            :                 {OPT_CRYPTODEV_BK_DIR_KEY, required_argument,
     341                 :            :                                 NULL, OPT_CRYPTODEV_BK_DIR_KEY_NUM},
     342                 :            :                 {OPT_CRYPTODEV_ASYM, no_argument,
     343                 :            :                                 NULL, OPT_CRYPTODEV_ASYM_NUM},
     344                 :            :                 {NULL, 0, 0, 0}
     345                 :            :         };
     346                 :            : 
     347                 :            :         argvopt = argv;
     348                 :            : 
     349                 :          0 :         env.mbuf_data_room = DEF_MBUF_SEG_SIZE;
     350                 :          0 :         if (rte_cryptodev_count())
     351                 :          0 :                 env.dev_id = 0;
     352                 :            :         else {
     353                 :          0 :                 cryptodev_fips_validate_usage(prgname);
     354                 :          0 :                 return -EINVAL;
     355                 :            :         }
     356                 :            : 
     357                 :          0 :         while ((opt = getopt_long(argc, argvopt, "s:",
     358                 :          0 :                                   lgopts, &option_index)) != EOF) {
     359                 :            : 
     360                 :          0 :                 switch (opt) {
     361                 :          0 :                 case OPT_REQ_FILE_PATH_NUM:
     362                 :          0 :                         env.req_path = optarg;
     363                 :          0 :                         break;
     364                 :            : 
     365                 :          0 :                 case OPT_RSP_FILE_PATH_NUM:
     366                 :          0 :                         env.rsp_path = optarg;
     367                 :          0 :                         break;
     368                 :            : 
     369                 :          0 :                 case OPT_FOLDER_NUM:
     370                 :          0 :                         env.is_path_folder = 1;
     371                 :          0 :                         break;
     372                 :            : 
     373                 :          0 :                 case OPT_CRYPTODEV_NUM:
     374                 :          0 :                         ret = parse_cryptodev_arg(optarg);
     375                 :          0 :                         if (ret < 0) {
     376                 :          0 :                                 cryptodev_fips_validate_usage(prgname);
     377                 :          0 :                                 return -EINVAL;
     378                 :            :                         }
     379                 :            :                         break;
     380                 :            : 
     381                 :          0 :                 case OPT_CRYPTODEV_ID_NUM:
     382                 :          0 :                         ret = parse_cryptodev_id_arg(optarg);
     383                 :          0 :                         if (ret < 0) {
     384                 :          0 :                                 cryptodev_fips_validate_usage(prgname);
     385                 :          0 :                                 return -EINVAL;
     386                 :            :                         }
     387                 :            :                         break;
     388                 :            : 
     389                 :          0 :                 case OPT_CRYPTODEV_ST_NUM:
     390                 :          0 :                         env.self_test = 1;
     391                 :          0 :                         break;
     392                 :            : 
     393                 :          0 :                 case OPT_CRYPTODEV_BK_ID_NUM:
     394                 :          0 :                         if (!env.broken_test_config) {
     395                 :          0 :                                 env.broken_test_config = rte_malloc(
     396                 :            :                                         NULL,
     397                 :            :                                         sizeof(*env.broken_test_config),
     398                 :            :                                         0);
     399                 :          0 :                                 if (!env.broken_test_config)
     400                 :            :                                         return -ENOMEM;
     401                 :            : 
     402                 :          0 :                                 env.broken_test_config->expect_fail_dir =
     403                 :            :                                         self_test_dir_enc_auth_gen;
     404                 :            :                         }
     405                 :            : 
     406                 :          0 :                         if (parser_read_uint32(
     407                 :          0 :                                 &env.broken_test_config->expect_fail_test_idx,
     408                 :            :                                         optarg) < 0) {
     409                 :          0 :                                 rte_free(env.broken_test_config);
     410                 :          0 :                                 cryptodev_fips_validate_usage(prgname);
     411                 :          0 :                                 return -EINVAL;
     412                 :            :                         }
     413                 :            :                         break;
     414                 :            : 
     415                 :          0 :                 case OPT_CRYPTODEV_BK_DIR_KEY_NUM:
     416                 :          0 :                         if (!env.broken_test_config) {
     417                 :          0 :                                 env.broken_test_config = rte_malloc(
     418                 :            :                                         NULL,
     419                 :            :                                         sizeof(*env.broken_test_config),
     420                 :            :                                         0);
     421                 :          0 :                                 if (!env.broken_test_config)
     422                 :            :                                         return -ENOMEM;
     423                 :            : 
     424                 :          0 :                                 env.broken_test_config->expect_fail_test_idx =
     425                 :            :                                         0;
     426                 :            :                         }
     427                 :            : 
     428                 :          0 :                         if (strcmp(optarg, "enc") == 0)
     429                 :          0 :                                 env.broken_test_config->expect_fail_dir =
     430                 :            :                                         self_test_dir_enc_auth_gen;
     431                 :          0 :                         else if (strcmp(optarg, "dec")
     432                 :            :                                         == 0)
     433                 :          0 :                                 env.broken_test_config->expect_fail_dir =
     434                 :            :                                         self_test_dir_dec_auth_verify;
     435                 :            :                         else {
     436                 :          0 :                                 rte_free(env.broken_test_config);
     437                 :          0 :                                 cryptodev_fips_validate_usage(prgname);
     438                 :          0 :                                 return -EINVAL;
     439                 :            :                         }
     440                 :            :                         break;
     441                 :            : 
     442                 :            : 
     443                 :          0 :                 case OPT_MBUF_DATAROOM_NUM:
     444                 :          0 :                         if (parser_read_uint16(&env.mbuf_data_room,
     445                 :            :                                         optarg) < 0) {
     446                 :          0 :                                 cryptodev_fips_validate_usage(prgname);
     447                 :          0 :                                 return -EINVAL;
     448                 :            :                         }
     449                 :            : 
     450                 :          0 :                         if (env.mbuf_data_room == 0) {
     451                 :          0 :                                 cryptodev_fips_validate_usage(prgname);
     452                 :          0 :                                 return -EINVAL;
     453                 :            :                         }
     454                 :            :                         break;
     455                 :            : 
     456                 :          0 :                 case OPT_CRYPTODEV_ASYM_NUM:
     457                 :          0 :                         env.is_asym_test = true;
     458                 :          0 :                         break;
     459                 :            : 
     460                 :          0 :                 default:
     461                 :          0 :                         cryptodev_fips_validate_usage(prgname);
     462                 :          0 :                         return -EINVAL;
     463                 :            :                 }
     464                 :            :         }
     465                 :            : 
     466                 :          0 :         if ((env.req_path == NULL && env.rsp_path != NULL) ||
     467                 :          0 :                         (env.req_path != NULL && env.rsp_path == NULL)) {
     468                 :          0 :                 RTE_LOG(ERR, USER1, "Missing req path or rsp path\n");
     469                 :          0 :                 cryptodev_fips_validate_usage(prgname);
     470                 :          0 :                 return -EINVAL;
     471                 :            :         }
     472                 :            : 
     473                 :          0 :         if (env.req_path == NULL && env.self_test == 0) {
     474                 :          0 :                 RTE_LOG(ERR, USER1, "--self-test must be set if req path is missing\n");
     475                 :          0 :                 cryptodev_fips_validate_usage(prgname);
     476                 :          0 :                 return -EINVAL;
     477                 :            :         }
     478                 :            : 
     479                 :            :         return 0;
     480                 :            : }
     481                 :            : 
     482                 :            : int
     483                 :          0 : main(int argc, char *argv[])
     484                 :            : {
     485                 :            :         int ret;
     486                 :            : 
     487                 :          0 :         ret = rte_eal_init(argc, argv);
     488                 :          0 :         if (ret < 0) {
     489                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Failed init\n", ret);
     490                 :          0 :                 return -1;
     491                 :            :         }
     492                 :            : 
     493                 :          0 :         argc -= ret;
     494                 :          0 :         argv += ret;
     495                 :            : 
     496                 :          0 :         ret = cryptodev_fips_validate_parse_args(argc, argv);
     497                 :          0 :         if (ret < 0)
     498                 :          0 :                 rte_exit(EXIT_FAILURE, "Failed to parse arguments!\n");
     499                 :            : 
     500                 :          0 :         ret = cryptodev_fips_validate_app_init();
     501                 :          0 :         if (ret < 0) {
     502                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Failed init\n", ret);
     503                 :          0 :                 return -1;
     504                 :            :         }
     505                 :            : 
     506                 :          0 :         if (env.req_path == NULL || env.rsp_path == NULL) {
     507                 :            :                 printf("No request, exit.\n");
     508                 :          0 :                 goto exit;
     509                 :            :         }
     510                 :            : 
     511                 :          0 :         if (!env.is_path_folder) {
     512                 :            :                 printf("Processing file %s... ", env.req_path);
     513                 :            : 
     514                 :          0 :                 ret = fips_test_init(env.req_path, env.rsp_path,
     515                 :          0 :                         rte_cryptodev_name_get(env.dev_id));
     516                 :          0 :                 if (ret < 0) {
     517                 :          0 :                         RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
     518                 :            :                                         ret, env.req_path);
     519                 :          0 :                         goto exit;
     520                 :            :                 }
     521                 :            : 
     522                 :            : #ifdef USE_JANSSON
     523                 :          0 :                 if (info.file_type == FIPS_TYPE_JSON) {
     524                 :          0 :                         ret = fips_test_one_json_file();
     525                 :          0 :                         json_decref(json_info.json_root);
     526                 :            :                 }  else {
     527                 :          0 :                         ret = fips_test_one_file();
     528                 :            :                 }
     529                 :            : #else /* USE_JANSSON */
     530                 :            :                 ret = fips_test_one_file();
     531                 :            : #endif /* USE_JANSSON */
     532                 :            : 
     533                 :          0 :                 if (ret < 0) {
     534                 :          0 :                         RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
     535                 :            :                                         ret, env.req_path);
     536                 :          0 :                         goto exit;
     537                 :            :                 }
     538                 :            : 
     539                 :            :                 printf("Done\n");
     540                 :            : 
     541                 :            :         } else {
     542                 :            :                 struct dirent *dir;
     543                 :            :                 DIR *d_req, *d_rsp;
     544                 :            :                 char req_path[1024];
     545                 :            :                 char rsp_path[1024];
     546                 :            : 
     547                 :          0 :                 d_req = opendir(env.req_path);
     548                 :          0 :                 if (!d_req) {
     549                 :          0 :                         RTE_LOG(ERR, USER1, "Error %i: Path %s not exist\n",
     550                 :            :                                         -EINVAL, env.req_path);
     551                 :          0 :                         goto exit;
     552                 :            :                 }
     553                 :            : 
     554                 :          0 :                 d_rsp = opendir(env.rsp_path);
     555                 :          0 :                 if (!d_rsp) {
     556                 :          0 :                         ret = mkdir(env.rsp_path, 0700);
     557                 :          0 :                         if (ret == 0)
     558                 :          0 :                                 d_rsp = opendir(env.rsp_path);
     559                 :            :                         else {
     560                 :          0 :                                 RTE_LOG(ERR, USER1, "Error %i: Invalid %s\n",
     561                 :            :                                                 -EINVAL, env.rsp_path);
     562                 :          0 :                                 goto exit;
     563                 :            :                         }
     564                 :            :                 }
     565                 :          0 :                 closedir(d_rsp);
     566                 :            : 
     567                 :          0 :                 while ((dir = readdir(d_req)) != NULL) {
     568                 :          0 :                         if (strstr(dir->d_name, "req") == NULL)
     569                 :          0 :                                 continue;
     570                 :            : 
     571                 :          0 :                         snprintf(req_path, 1023, "%s/%s", env.req_path,
     572                 :            :                                         dir->d_name);
     573                 :          0 :                         snprintf(rsp_path, 1023, "%s/%s", env.rsp_path,
     574                 :            :                                         dir->d_name);
     575                 :          0 :                         strlcpy(strstr(rsp_path, "req"), "rsp", 4);
     576                 :            : 
     577                 :            :                         printf("Processing file %s... ", req_path);
     578                 :            : 
     579                 :          0 :                         ret = fips_test_init(req_path, rsp_path,
     580                 :          0 :                         rte_cryptodev_name_get(env.dev_id));
     581                 :          0 :                         if (ret < 0) {
     582                 :          0 :                                 RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
     583                 :            :                                                 ret, req_path);
     584                 :          0 :                                 break;
     585                 :            :                         }
     586                 :            : 
     587                 :            : #ifdef USE_JANSSON
     588                 :          0 :                         if (info.file_type == FIPS_TYPE_JSON) {
     589                 :          0 :                                 ret = fips_test_one_json_file();
     590                 :          0 :                                 json_decref(json_info.json_root);
     591                 :            :                         } else {
     592                 :          0 :                                 ret = fips_test_one_file();
     593                 :            :                         }
     594                 :            : #else /* USE_JANSSON */
     595                 :            :                         ret = fips_test_one_file();
     596                 :            : #endif /* USE_JANSSON */
     597                 :            : 
     598                 :          0 :                         if (ret < 0) {
     599                 :          0 :                                 RTE_LOG(ERR, USER1, "Error %i: Failed test %s\n",
     600                 :            :                                                 ret, req_path);
     601                 :          0 :                                 break;
     602                 :            :                         }
     603                 :            : 
     604                 :            :                         printf("Done\n");
     605                 :            :                 }
     606                 :            : 
     607                 :          0 :                 closedir(d_req);
     608                 :            :         }
     609                 :            : 
     610                 :            : 
     611                 :          0 : exit:
     612                 :          0 :         fips_test_clear();
     613                 :          0 :         cryptodev_fips_validate_app_uninit();
     614                 :            : 
     615                 :            :         /* clean up the EAL */
     616                 :          0 :         rte_eal_cleanup();
     617                 :            : 
     618                 :          0 :         return ret;
     619                 :            : 
     620                 :            : }
     621                 :            : 
     622                 :            : #define IV_OFF (sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op))
     623                 :            : #define CRYPTODEV_FIPS_MAX_RETRIES      16
     624                 :            : 
     625                 :            : struct fips_test_ops test_ops;
     626                 :            : 
     627                 :            : static int
     628                 :          0 : prepare_data_mbufs(struct fips_val *val)
     629                 :            : {
     630                 :            :         struct rte_mbuf *m, *head = 0;
     631                 :          0 :         uint8_t *src = val->val;
     632                 :          0 :         uint32_t total_len = val->len;
     633                 :            :         uint16_t nb_seg;
     634                 :            :         int ret = 0;
     635                 :            : 
     636                 :          0 :         rte_pktmbuf_free(env.mbuf);
     637                 :            : 
     638                 :          0 :         if (total_len > RTE_MBUF_MAX_NB_SEGS) {
     639                 :          0 :                 RTE_LOG(ERR, USER1, "Data len %u too big\n", total_len);
     640                 :          0 :                 return -EPERM;
     641                 :            :         }
     642                 :            : 
     643                 :          0 :         nb_seg = total_len / env.mbuf_data_room;
     644                 :          0 :         if (total_len % env.mbuf_data_room)
     645                 :          0 :                 nb_seg++;
     646                 :            : 
     647                 :          0 :         m = rte_pktmbuf_alloc(env.mpool);
     648                 :          0 :         if (!m) {
     649                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Not enough mbuf\n",
     650                 :            :                                 -ENOMEM);
     651                 :          0 :                 return -ENOMEM;
     652                 :            :         }
     653                 :            :         head = m;
     654                 :            : 
     655                 :          0 :         while (nb_seg) {
     656                 :          0 :                 uint16_t len = RTE_MIN(total_len, env.mbuf_data_room);
     657                 :            :                 uint8_t *dst = (uint8_t *)rte_pktmbuf_append(m, len);
     658                 :            : 
     659                 :          0 :                 if (!dst) {
     660                 :          0 :                         RTE_LOG(ERR, USER1, "Error %i: MBUF too small\n",
     661                 :            :                                         -ENOMEM);
     662                 :            :                         ret = -ENOMEM;
     663                 :          0 :                         goto error_exit;
     664                 :            :                 }
     665                 :            : 
     666                 :          0 :                 memcpy(dst, src, len);
     667                 :            : 
     668                 :          0 :                 if (head != m) {
     669                 :            :                         ret = rte_pktmbuf_chain(head, m);
     670                 :            :                         if (ret) {
     671                 :          0 :                                 rte_pktmbuf_free(m);
     672                 :          0 :                                 RTE_LOG(ERR, USER1, "Error %i: SGL build\n",
     673                 :            :                                                 ret);
     674                 :          0 :                                 goto error_exit;
     675                 :            :                         }
     676                 :            :                 }
     677                 :          0 :                 total_len -= len;
     678                 :            : 
     679                 :          0 :                 if (total_len) {
     680                 :          0 :                         if (!env.dev_support_sgl) {
     681                 :          0 :                                 RTE_LOG(ERR, USER1, "SGL not supported\n");
     682                 :            :                                 ret = -EPERM;
     683                 :          0 :                                 goto error_exit;
     684                 :            :                         }
     685                 :            : 
     686                 :          0 :                         m = rte_pktmbuf_alloc(env.mpool);
     687                 :          0 :                         if (!m) {
     688                 :          0 :                                 RTE_LOG(ERR, USER1, "Error %i: No memory\n",
     689                 :            :                                                 -ENOMEM);
     690                 :          0 :                                 goto error_exit;
     691                 :            :                         }
     692                 :            :                 } else
     693                 :            :                         break;
     694                 :            : 
     695                 :          0 :                 src += len;
     696                 :          0 :                 nb_seg--;
     697                 :            :         }
     698                 :            : 
     699                 :          0 :         if (total_len) {
     700                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Failed to store all data\n",
     701                 :            :                                 -ENOMEM);
     702                 :          0 :                 goto error_exit;
     703                 :            :         }
     704                 :            : 
     705                 :          0 :         env.mbuf = head;
     706                 :            : 
     707                 :          0 :         return 0;
     708                 :            : 
     709                 :          0 : error_exit:
     710                 :          0 :         rte_pktmbuf_free(head);
     711                 :          0 :         return ret;
     712                 :            : }
     713                 :            : 
     714                 :            : static int
     715                 :          0 : prepare_cipher_op(void)
     716                 :            : {
     717                 :          0 :         struct rte_crypto_sym_op *sym = env.op->sym;
     718                 :          0 :         uint8_t *iv = rte_crypto_op_ctod_offset(env.op, uint8_t *, IV_OFF);
     719                 :            :         int ret;
     720                 :            : 
     721                 :            :         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
     722                 :            : 
     723                 :          0 :         memcpy(iv, vec.iv.val, vec.iv.len);
     724                 :            : 
     725                 :          0 :         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
     726                 :          0 :                 ret = prepare_data_mbufs(&vec.pt);
     727                 :          0 :                 if (ret < 0)
     728                 :            :                         return ret;
     729                 :            : 
     730                 :          0 :                 sym->cipher.data.length = vec.pt.len;
     731                 :            :         } else {
     732                 :          0 :                 ret = prepare_data_mbufs(&vec.ct);
     733                 :          0 :                 if (ret < 0)
     734                 :            :                         return ret;
     735                 :            : 
     736                 :          0 :                 sym->cipher.data.length = vec.ct.len;
     737                 :            :         }
     738                 :            : 
     739                 :          0 :         rte_crypto_op_attach_sym_session(env.op, env.sym.sess);
     740                 :            : 
     741                 :          0 :         sym->m_src = env.mbuf;
     742                 :          0 :         sym->cipher.data.offset = 0;
     743                 :            : 
     744                 :          0 :         return 0;
     745                 :            : }
     746                 :            : 
     747                 :            : int
     748                 :          0 : prepare_auth_op(void)
     749                 :            : {
     750                 :          0 :         struct rte_crypto_sym_op *sym = env.op->sym;
     751                 :            :         int ret;
     752                 :            : 
     753                 :            :         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
     754                 :            : 
     755                 :          0 :         if (info.interim_info.gcm_data.gen_iv == 1) {
     756                 :            :                 uint32_t i;
     757                 :            : 
     758                 :          0 :                 if (!vec.iv.val) {
     759                 :          0 :                         vec.iv.val = rte_malloc(0, vec.iv.len, 0);
     760                 :          0 :                         if (!vec.iv.val)
     761                 :            :                                 return -ENOMEM;
     762                 :            :                 }
     763                 :            : 
     764                 :          0 :                 for (i = 0; i < vec.iv.len; i++) {
     765                 :          0 :                         int random = rte_rand();
     766                 :          0 :                         vec.iv.val[i] = (uint8_t)random;
     767                 :            :                 }
     768                 :            :         }
     769                 :            : 
     770                 :          0 :         if (vec.iv.len) {
     771                 :          0 :                 uint8_t *iv = rte_crypto_op_ctod_offset(env.op, uint8_t *,
     772                 :            :                                 IV_OFF);
     773                 :          0 :                 memset(iv, 0, vec.iv.len);
     774                 :          0 :                 if (vec.iv.val)
     775                 :          0 :                         memcpy(iv, vec.iv.val, vec.iv.len);
     776                 :            :         }
     777                 :            : 
     778                 :          0 :         ret = prepare_data_mbufs(&vec.pt);
     779                 :          0 :         if (ret < 0)
     780                 :            :                 return ret;
     781                 :            : 
     782                 :          0 :         rte_free(env.digest);
     783                 :            : 
     784                 :          0 :         env.digest = rte_zmalloc(NULL, vec.cipher_auth.digest.len,
     785                 :            :                         RTE_CACHE_LINE_SIZE);
     786                 :          0 :         if (!env.digest) {
     787                 :          0 :                 RTE_LOG(ERR, USER1, "Not enough memory\n");
     788                 :          0 :                 return -ENOMEM;
     789                 :            :         }
     790                 :          0 :         env.digest_len = vec.cipher_auth.digest.len;
     791                 :            : 
     792                 :          0 :         sym->m_src = env.mbuf;
     793                 :          0 :         sym->auth.data.offset = 0;
     794                 :          0 :         sym->auth.data.length = vec.pt.len;
     795                 :          0 :         sym->auth.digest.data = env.digest;
     796                 :          0 :         sym->auth.digest.phys_addr = rte_malloc_virt2iova(env.digest);
     797                 :            : 
     798                 :          0 :         if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
     799                 :          0 :                 memcpy(env.digest, vec.cipher_auth.digest.val,
     800                 :          0 :                                 vec.cipher_auth.digest.len);
     801                 :            : 
     802                 :          0 :         rte_crypto_op_attach_sym_session(env.op, env.sym.sess);
     803                 :            : 
     804                 :            :         return 0;
     805                 :            : }
     806                 :            : 
     807                 :            : int
     808                 :          0 : prepare_aead_op(void)
     809                 :            : {
     810                 :          0 :         struct rte_crypto_sym_op *sym = env.op->sym;
     811                 :          0 :         uint8_t *iv = rte_crypto_op_ctod_offset(env.op, uint8_t *, IV_OFF);
     812                 :            :         int ret;
     813                 :            : 
     814                 :            :         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_SYMMETRIC);
     815                 :            : 
     816                 :          0 :         if (info.algo == FIPS_TEST_ALGO_AES_CCM)
     817                 :          0 :                 iv++;
     818                 :            : 
     819                 :          0 :         if (vec.iv.val)
     820                 :          0 :                 memcpy(iv, vec.iv.val, vec.iv.len);
     821                 :            :         else
     822                 :            :                 /* if REQ file has iv length but not data, default as all 0 */
     823                 :          0 :                 memset(iv, 0, vec.iv.len);
     824                 :            : 
     825                 :          0 :         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
     826                 :          0 :                 ret = prepare_data_mbufs(&vec.pt);
     827                 :          0 :                 if (ret < 0)
     828                 :            :                         return ret;
     829                 :            : 
     830                 :          0 :                 rte_free(env.digest);
     831                 :          0 :                 env.digest = rte_zmalloc(NULL, vec.aead.digest.len,
     832                 :            :                                 RTE_CACHE_LINE_SIZE);
     833                 :          0 :                 if (!env.digest) {
     834                 :          0 :                         RTE_LOG(ERR, USER1, "Not enough memory\n");
     835                 :          0 :                         return -ENOMEM;
     836                 :            :                 }
     837                 :          0 :                 env.digest_len = vec.aead.digest.len;
     838                 :            : 
     839                 :          0 :                 sym->aead.data.length = vec.pt.len;
     840                 :          0 :                 sym->aead.digest.data = env.digest;
     841                 :          0 :                 sym->aead.digest.phys_addr = rte_malloc_virt2iova(env.digest);
     842                 :            :         } else {
     843                 :          0 :                 ret = prepare_data_mbufs(&vec.ct);
     844                 :          0 :                 if (ret < 0)
     845                 :            :                         return ret;
     846                 :          0 :                 env.digest_len = vec.aead.digest.len;
     847                 :          0 :                 sym->aead.data.length = vec.ct.len;
     848                 :          0 :                 sym->aead.digest.data = vec.aead.digest.val;
     849                 :          0 :                 sym->aead.digest.phys_addr = rte_malloc_virt2iova(
     850                 :            :                                 sym->aead.digest.data);
     851                 :            :         }
     852                 :            : 
     853                 :          0 :         sym->m_src = env.mbuf;
     854                 :          0 :         sym->aead.data.offset = 0;
     855                 :          0 :         sym->aead.aad.data = vec.aead.aad.val;
     856                 :          0 :         sym->aead.aad.phys_addr = rte_malloc_virt2iova(sym->aead.aad.data);
     857                 :            : 
     858                 :          0 :         rte_crypto_op_attach_sym_session(env.op, env.sym.sess);
     859                 :            : 
     860                 :            :         return 0;
     861                 :            : }
     862                 :            : 
     863                 :            : static int
     864                 :          0 : get_hash_oid(enum rte_crypto_auth_algorithm hash, uint8_t *buf)
     865                 :            : {
     866                 :          0 :         uint8_t id_sha512[] = {0x30, 0x51, 0x30, 0x0d, 0x06, 0x09,
     867                 :            :                                   0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
     868                 :            :                                   0x04, 0x02, 0x03, 0x05, 0x00, 0x04,
     869                 :            :                                   0x40};
     870                 :          0 :         uint8_t id_sha384[] = {0x30, 0x41, 0x30, 0x0d, 0x06, 0x09,
     871                 :            :                                   0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
     872                 :            :                                   0x04, 0x02, 0x02, 0x05, 0x00, 0x04,
     873                 :            :                                   0x30};
     874                 :          0 :         uint8_t id_sha256[] = {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09,
     875                 :            :                                   0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
     876                 :            :                                   0x04, 0x02, 0x01, 0x05, 0x00, 0x04,
     877                 :            :                                   0x20};
     878                 :          0 :         uint8_t id_sha224[] = {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09,
     879                 :            :                                   0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
     880                 :            :                                   0x04, 0x02, 0x04, 0x05, 0x00, 0x04,
     881                 :            :                                   0x1c};
     882                 :          0 :         uint8_t id_sha1[] = {0x30, 0x21, 0x30, 0x09, 0x06, 0x05,
     883                 :            :                                 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
     884                 :            :                                 0x00, 0x04, 0x14};
     885                 :            :         const uint8_t *id;
     886                 :            :         size_t id_len;
     887                 :            : 
     888                 :          0 :         switch (hash) {
     889                 :            :         case RTE_CRYPTO_AUTH_SHA1:
     890                 :            :                 id = id_sha1;
     891                 :            :                 id_len = sizeof(id_sha1);
     892                 :            :                 break;
     893                 :          0 :         case RTE_CRYPTO_AUTH_SHA224:
     894                 :            :                 id = id_sha224;
     895                 :            :                 id_len = sizeof(id_sha224);
     896                 :          0 :                 break;
     897                 :          0 :         case RTE_CRYPTO_AUTH_SHA256:
     898                 :            :                 id = id_sha256;
     899                 :            :                 id_len = sizeof(id_sha256);
     900                 :          0 :                 break;
     901                 :          0 :         case RTE_CRYPTO_AUTH_SHA384:
     902                 :            :                 id = id_sha384;
     903                 :            :                 id_len = sizeof(id_sha384);
     904                 :          0 :                 break;
     905                 :          0 :         case RTE_CRYPTO_AUTH_SHA512:
     906                 :            :                 id = id_sha512;
     907                 :            :                 id_len = sizeof(id_sha512);
     908                 :          0 :                 break;
     909                 :            :         default:
     910                 :            :                 return -1;
     911                 :            :         }
     912                 :            : 
     913                 :            :         memcpy(buf, id, id_len);
     914                 :            : 
     915                 :          0 :         return id_len;
     916                 :            : }
     917                 :            : 
     918                 :            : static int
     919                 :          0 : prepare_rsa_op(void)
     920                 :            : {
     921                 :            :         struct rte_crypto_asym_op *asym;
     922                 :            :         struct fips_val msg;
     923                 :            : 
     924                 :          0 :         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     925                 :            : 
     926                 :          0 :         asym = env.op->asym;
     927                 :          0 :         if (env.digest) {
     928                 :            :                 msg.val = env.digest;
     929                 :          0 :                 msg.len = env.digest_len;
     930                 :            :         } else {
     931                 :          0 :                 msg.val = vec.pt.val;
     932                 :          0 :                 msg.len = vec.pt.len;
     933                 :            :         }
     934                 :            : 
     935                 :          0 :         if (info.op == FIPS_TEST_ASYM_SIGGEN) {
     936                 :          0 :                 asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
     937                 :          0 :                 asym->rsa.message.data = msg.val;
     938                 :          0 :                 asym->rsa.message.length = msg.len;
     939                 :            : 
     940                 :          0 :                 rte_free(vec.rsa.signature.val);
     941                 :            : 
     942                 :          0 :                 vec.rsa.signature.val = rte_zmalloc(NULL, vec.rsa.n.len, 0);
     943                 :          0 :                 vec.rsa.signature.len = vec.rsa.n.len;
     944                 :          0 :                 asym->rsa.sign.data = vec.rsa.signature.val;
     945                 :          0 :                 asym->rsa.sign.length = 0;
     946                 :          0 :         } else if (info.op == FIPS_TEST_ASYM_SIGVER) {
     947                 :          0 :                 asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
     948                 :          0 :                 asym->rsa.message.data = msg.val;
     949                 :          0 :                 asym->rsa.message.length = msg.len;
     950                 :          0 :                 asym->rsa.sign.data = vec.rsa.signature.val;
     951                 :          0 :                 asym->rsa.sign.length = vec.rsa.signature.len;
     952                 :            :         } else {
     953                 :          0 :                 RTE_LOG(ERR, USER1, "Invalid op %d\n", info.op);
     954                 :          0 :                 return -EINVAL;
     955                 :            :         }
     956                 :            : 
     957                 :          0 :         rte_crypto_op_attach_asym_session(env.op, env.asym.sess);
     958                 :            : 
     959                 :            :         return 0;
     960                 :            : }
     961                 :            : 
     962                 :            : static int
     963                 :          0 : prepare_ecdsa_op(void)
     964                 :            : {
     965                 :            :         struct rte_crypto_asym_op *asym;
     966                 :            :         struct fips_val msg;
     967                 :            : 
     968                 :          0 :         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     969                 :            : 
     970                 :          0 :         asym = env.op->asym;
     971                 :          0 :         if (env.digest) {
     972                 :            :                 msg.val = env.digest;
     973                 :          0 :                 msg.len = env.digest_len;
     974                 :            :         } else {
     975                 :          0 :                 msg.val = vec.pt.val;
     976                 :          0 :                 msg.len = vec.pt.len;
     977                 :            :         }
     978                 :            : 
     979                 :          0 :         if (info.op == FIPS_TEST_ASYM_SIGGEN) {
     980                 :          0 :                 asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
     981                 :          0 :                 asym->ecdsa.message.data = msg.val;
     982                 :          0 :                 asym->ecdsa.message.length = msg.len;
     983                 :          0 :                 asym->ecdsa.k.data = vec.ecdsa.k.val;
     984                 :          0 :                 asym->ecdsa.k.length = vec.ecdsa.k.len;
     985                 :            : 
     986                 :          0 :                 rte_free(vec.ecdsa.r.val);
     987                 :            : 
     988                 :          0 :                 rte_free(vec.ecdsa.s.val);
     989                 :            : 
     990                 :          0 :                 vec.ecdsa.r.len = info.interim_info.ecdsa_data.curve_len;
     991                 :          0 :                 vec.ecdsa.r.val = rte_zmalloc(NULL, vec.ecdsa.r.len, 0);
     992                 :            : 
     993                 :          0 :                 vec.ecdsa.s.len = vec.ecdsa.r.len;
     994                 :          0 :                 vec.ecdsa.s.val = rte_zmalloc(NULL, vec.ecdsa.s.len, 0);
     995                 :            : 
     996                 :          0 :                 asym->ecdsa.r.data = vec.ecdsa.r.val;
     997                 :          0 :                 asym->ecdsa.r.length = 0;
     998                 :          0 :                 asym->ecdsa.s.data = vec.ecdsa.s.val;
     999                 :          0 :                 asym->ecdsa.s.length = 0;
    1000                 :          0 :         } else if (info.op == FIPS_TEST_ASYM_SIGVER) {
    1001                 :          0 :                 asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
    1002                 :          0 :                 asym->ecdsa.message.data = msg.val;
    1003                 :          0 :                 asym->ecdsa.message.length = msg.len;
    1004                 :          0 :                 asym->ecdsa.r.data = vec.ecdsa.r.val;
    1005                 :          0 :                 asym->ecdsa.r.length = vec.ecdsa.r.len;
    1006                 :          0 :                 asym->ecdsa.s.data = vec.ecdsa.s.val;
    1007                 :          0 :                 asym->ecdsa.s.length = vec.ecdsa.s.len;
    1008                 :            :         } else {
    1009                 :          0 :                 RTE_LOG(ERR, USER1, "Invalid op %d\n", info.op);
    1010                 :          0 :                 return -EINVAL;
    1011                 :            :         }
    1012                 :            : 
    1013                 :          0 :         rte_crypto_op_attach_asym_session(env.op, env.asym.sess);
    1014                 :            : 
    1015                 :            :         return 0;
    1016                 :            : }
    1017                 :            : 
    1018                 :            : static int
    1019                 :          0 : prepare_eddsa_op(void)
    1020                 :            : {
    1021                 :            :         struct rte_crypto_asym_op *asym;
    1022                 :            :         struct fips_val msg;
    1023                 :            : 
    1024                 :          0 :         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1025                 :            : 
    1026                 :          0 :         asym = env.op->asym;
    1027                 :          0 :         if (env.digest) {
    1028                 :            :                 msg.val = env.digest;
    1029                 :          0 :                 msg.len = env.digest_len;
    1030                 :            :         } else {
    1031                 :          0 :                 msg.val = vec.pt.val;
    1032                 :          0 :                 msg.len = vec.pt.len;
    1033                 :            :         }
    1034                 :            : 
    1035                 :          0 :         if (info.op == FIPS_TEST_ASYM_SIGGEN) {
    1036                 :          0 :                 asym->eddsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
    1037                 :          0 :                 asym->eddsa.message.data = msg.val;
    1038                 :          0 :                 asym->eddsa.message.length = msg.len;
    1039                 :          0 :                 asym->eddsa.context.data = vec.eddsa.ctx.val;
    1040                 :          0 :                 asym->eddsa.context.length = vec.eddsa.ctx.len;
    1041                 :            : 
    1042                 :          0 :                 rte_free(vec.eddsa.sign.val);
    1043                 :            : 
    1044                 :          0 :                 vec.eddsa.sign.len = info.interim_info.eddsa_data.curve_len;
    1045                 :          0 :                 vec.eddsa.sign.val = rte_zmalloc(NULL, vec.eddsa.sign.len, 0);
    1046                 :            : 
    1047                 :          0 :                 asym->eddsa.sign.data = vec.eddsa.sign.val;
    1048                 :          0 :                 asym->eddsa.sign.length = 0;
    1049                 :          0 :         } else if (info.op == FIPS_TEST_ASYM_SIGVER) {
    1050                 :          0 :                 asym->eddsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
    1051                 :          0 :                 asym->eddsa.message.data = msg.val;
    1052                 :          0 :                 asym->eddsa.message.length = msg.len;
    1053                 :          0 :                 asym->eddsa.sign.data = vec.eddsa.sign.val;
    1054                 :          0 :                 asym->eddsa.sign.length = vec.eddsa.sign.len;
    1055                 :            :         } else {
    1056                 :          0 :                 RTE_LOG(ERR, USER1, "Invalid op %d\n", info.op);
    1057                 :          0 :                 return -EINVAL;
    1058                 :            :         }
    1059                 :            : 
    1060                 :          0 :         if (info.interim_info.eddsa_data.curve_id == RTE_CRYPTO_EC_GROUP_ED25519) {
    1061                 :          0 :                 asym->eddsa.instance = RTE_CRYPTO_EDCURVE_25519;
    1062                 :          0 :                 if (info.interim_info.eddsa_data.prehash)
    1063                 :          0 :                         asym->eddsa.instance = RTE_CRYPTO_EDCURVE_25519PH;
    1064                 :          0 :                 if (vec.eddsa.ctx.len > 0)
    1065                 :          0 :                         asym->eddsa.instance = RTE_CRYPTO_EDCURVE_25519CTX;
    1066                 :            :         } else {
    1067                 :          0 :                 asym->eddsa.instance = RTE_CRYPTO_EDCURVE_448;
    1068                 :          0 :                 if (info.interim_info.eddsa_data.prehash)
    1069                 :          0 :                         asym->eddsa.instance = RTE_CRYPTO_EDCURVE_448PH;
    1070                 :            :         }
    1071                 :          0 :         rte_crypto_op_attach_asym_session(env.op, env.asym.sess);
    1072                 :            : 
    1073                 :            :         return 0;
    1074                 :            : }
    1075                 :            : 
    1076                 :            : static int
    1077                 :          0 : prepare_ecfpm_op(void)
    1078                 :            : {
    1079                 :            :         struct rte_crypto_asym_op *asym;
    1080                 :            : 
    1081                 :          0 :         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1082                 :            : 
    1083                 :          0 :         asym = env.op->asym;
    1084                 :          0 :         asym->ecpm.scalar.data = vec.ecdsa.pkey.val;
    1085                 :          0 :         asym->ecpm.scalar.length = vec.ecdsa.pkey.len;
    1086                 :            : 
    1087                 :          0 :         rte_free(vec.ecdsa.qx.val);
    1088                 :            : 
    1089                 :          0 :         rte_free(vec.ecdsa.qy.val);
    1090                 :            : 
    1091                 :          0 :         vec.ecdsa.qx.len = info.interim_info.ecdsa_data.curve_len;
    1092                 :          0 :         vec.ecdsa.qx.val = rte_zmalloc(NULL, vec.ecdsa.qx.len, 0);
    1093                 :            : 
    1094                 :          0 :         vec.ecdsa.qy.len = vec.ecdsa.qx.len;
    1095                 :          0 :         vec.ecdsa.qy.val = rte_zmalloc(NULL, vec.ecdsa.qy.len, 0);
    1096                 :            : 
    1097                 :          0 :         asym->ecpm.r.x.data = vec.ecdsa.qx.val;
    1098                 :          0 :         asym->ecpm.r.x.length = 0;
    1099                 :          0 :         asym->ecpm.r.y.data = vec.ecdsa.qy.val;
    1100                 :          0 :         asym->ecpm.r.y.length = 0;
    1101                 :            : 
    1102                 :          0 :         rte_crypto_op_attach_asym_session(env.op, env.asym.sess);
    1103                 :            : 
    1104                 :          0 :         return 0;
    1105                 :            : }
    1106                 :            : 
    1107                 :            : static int
    1108                 :          0 : prepare_edfpm_op(void)
    1109                 :            : {
    1110                 :            :         struct rte_crypto_asym_op *asym;
    1111                 :            : 
    1112                 :          0 :         __rte_crypto_op_reset(env.op, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1113                 :            : 
    1114                 :          0 :         asym = env.op->asym;
    1115                 :          0 :         asym->ecpm.scalar.data = vec.eddsa.pkey.val;
    1116                 :          0 :         asym->ecpm.scalar.length = vec.eddsa.pkey.len;
    1117                 :            : 
    1118                 :          0 :         rte_free(vec.eddsa.q.val);
    1119                 :            : 
    1120                 :          0 :         vec.eddsa.q.len = info.interim_info.eddsa_data.curve_len;
    1121                 :          0 :         vec.eddsa.q.val = rte_zmalloc(NULL, vec.eddsa.q.len, 0);
    1122                 :            : 
    1123                 :          0 :         asym->ecpm.r.x.data = vec.eddsa.q.val;
    1124                 :          0 :         asym->ecpm.r.x.length = 0;
    1125                 :          0 :         asym->flags |= RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED;
    1126                 :            : 
    1127                 :          0 :         rte_crypto_op_attach_asym_session(env.op, env.asym.sess);
    1128                 :            : 
    1129                 :          0 :         return 0;
    1130                 :            : }
    1131                 :            : 
    1132                 :            : static int
    1133                 :          0 : prepare_aes_xform(struct rte_crypto_sym_xform *xform)
    1134                 :            : {
    1135                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1136                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1137                 :            :         struct rte_crypto_cipher_xform *cipher_xform = &xform->cipher;
    1138                 :            : 
    1139                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1140                 :          0 :         if (info.interim_info.aes_data.cipher_algo == RTE_CRYPTO_CIPHER_AES_CBC)
    1141                 :          0 :                 cipher_xform->algo = RTE_CRYPTO_CIPHER_AES_CBC;
    1142                 :          0 :         else if (info.interim_info.aes_data.cipher_algo ==
    1143                 :            :                         RTE_CRYPTO_CIPHER_AES_CTR)
    1144                 :          0 :                 cipher_xform->algo = RTE_CRYPTO_CIPHER_AES_CTR;
    1145                 :            :         else
    1146                 :          0 :                 cipher_xform->algo = RTE_CRYPTO_CIPHER_AES_ECB;
    1147                 :            : 
    1148                 :          0 :         cipher_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
    1149                 :          0 :                         RTE_CRYPTO_CIPHER_OP_ENCRYPT :
    1150                 :            :                         RTE_CRYPTO_CIPHER_OP_DECRYPT;
    1151                 :          0 :         cipher_xform->key.data = vec.cipher_auth.key.val;
    1152                 :          0 :         cipher_xform->key.length = vec.cipher_auth.key.len;
    1153                 :          0 :         if (cipher_xform->algo == RTE_CRYPTO_CIPHER_AES_CBC ||
    1154                 :            :                         cipher_xform->algo == RTE_CRYPTO_CIPHER_AES_CTR) {
    1155                 :          0 :                 cipher_xform->iv.length = vec.iv.len;
    1156                 :          0 :                 cipher_xform->iv.offset = IV_OFF;
    1157                 :            :         } else {
    1158                 :          0 :                 cipher_xform->iv.length = 0;
    1159                 :          0 :                 cipher_xform->iv.offset = 0;
    1160                 :            :         }
    1161                 :          0 :         cap_idx.algo.cipher = cipher_xform->algo;
    1162                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1163                 :            : 
    1164                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1165                 :          0 :         if (!cap) {
    1166                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1167                 :            :                                 env.dev_id);
    1168                 :          0 :                 return -EINVAL;
    1169                 :            :         }
    1170                 :            : 
    1171                 :          0 :         if (rte_cryptodev_sym_capability_check_cipher(cap,
    1172                 :          0 :                         cipher_xform->key.length,
    1173                 :          0 :                         cipher_xform->iv.length) != 0) {
    1174                 :          0 :                 RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n",
    1175                 :            :                                 info.device_name, cipher_xform->key.length,
    1176                 :            :                                 cipher_xform->iv.length);
    1177                 :          0 :                 return -EPERM;
    1178                 :            :         }
    1179                 :            : 
    1180                 :            :         return 0;
    1181                 :            : }
    1182                 :            : 
    1183                 :            : static int
    1184                 :          0 : prepare_tdes_xform(struct rte_crypto_sym_xform *xform)
    1185                 :            : {
    1186                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1187                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1188                 :            :         struct rte_crypto_cipher_xform *cipher_xform = &xform->cipher;
    1189                 :            : 
    1190                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1191                 :            : 
    1192                 :          0 :         if (info.interim_info.tdes_data.test_mode == TDES_MODE_CBC)
    1193                 :          0 :                 cipher_xform->algo = RTE_CRYPTO_CIPHER_3DES_CBC;
    1194                 :            :         else
    1195                 :          0 :                 cipher_xform->algo = RTE_CRYPTO_CIPHER_3DES_ECB;
    1196                 :          0 :         cipher_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
    1197                 :          0 :                         RTE_CRYPTO_CIPHER_OP_ENCRYPT :
    1198                 :            :                         RTE_CRYPTO_CIPHER_OP_DECRYPT;
    1199                 :          0 :         cipher_xform->key.data = vec.cipher_auth.key.val;
    1200                 :          0 :         cipher_xform->key.length = vec.cipher_auth.key.len;
    1201                 :            : 
    1202                 :          0 :         if (cipher_xform->algo == RTE_CRYPTO_CIPHER_3DES_CBC) {
    1203                 :          0 :                 cipher_xform->iv.length = vec.iv.len;
    1204                 :          0 :                 cipher_xform->iv.offset = IV_OFF;
    1205                 :            :         } else {
    1206                 :          0 :                 cipher_xform->iv.length = 0;
    1207                 :          0 :                 cipher_xform->iv.offset = 0;
    1208                 :            :         }
    1209                 :          0 :         cap_idx.algo.cipher = cipher_xform->algo;
    1210                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1211                 :            : 
    1212                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1213                 :          0 :         if (!cap) {
    1214                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1215                 :            :                                 env.dev_id);
    1216                 :          0 :                 return -EINVAL;
    1217                 :            :         }
    1218                 :            : 
    1219                 :          0 :         if (rte_cryptodev_sym_capability_check_cipher(cap,
    1220                 :          0 :                         cipher_xform->key.length,
    1221                 :          0 :                         cipher_xform->iv.length) != 0) {
    1222                 :          0 :                 RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n",
    1223                 :            :                                 info.device_name, cipher_xform->key.length,
    1224                 :            :                                 cipher_xform->iv.length);
    1225                 :          0 :                 return -EPERM;
    1226                 :            :         }
    1227                 :            : 
    1228                 :            :         return 0;
    1229                 :            : }
    1230                 :            : 
    1231                 :            : static int
    1232                 :          0 : prepare_hmac_xform(struct rte_crypto_sym_xform *xform)
    1233                 :            : {
    1234                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1235                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1236                 :            :         struct rte_crypto_auth_xform *auth_xform = &xform->auth;
    1237                 :            : 
    1238                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1239                 :            : 
    1240                 :          0 :         auth_xform->algo = info.interim_info.hmac_data.algo;
    1241                 :          0 :         auth_xform->op = RTE_CRYPTO_AUTH_OP_GENERATE;
    1242                 :          0 :         auth_xform->digest_length = vec.cipher_auth.digest.len;
    1243                 :          0 :         auth_xform->key.data = vec.cipher_auth.key.val;
    1244                 :          0 :         auth_xform->key.length = vec.cipher_auth.key.len;
    1245                 :            : 
    1246                 :          0 :         cap_idx.algo.auth = auth_xform->algo;
    1247                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1248                 :            : 
    1249                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1250                 :          0 :         if (!cap) {
    1251                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1252                 :            :                                 env.dev_id);
    1253                 :          0 :                 return -EINVAL;
    1254                 :            :         }
    1255                 :            : 
    1256                 :          0 :         if (rte_cryptodev_sym_capability_check_auth(cap,
    1257                 :          0 :                         auth_xform->key.length,
    1258                 :          0 :                         auth_xform->digest_length, 0) != 0) {
    1259                 :          0 :                 RTE_LOG(ERR, USER1, "PMD %s key length %u Digest length %u\n",
    1260                 :            :                                 info.device_name, auth_xform->key.length,
    1261                 :            :                                 auth_xform->digest_length);
    1262                 :          0 :                 return -EPERM;
    1263                 :            :         }
    1264                 :            : 
    1265                 :            :         return 0;
    1266                 :            : }
    1267                 :            : 
    1268                 :            : int
    1269                 :          0 : prepare_gcm_xform(struct rte_crypto_sym_xform *xform)
    1270                 :            : {
    1271                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1272                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1273                 :            :         struct rte_crypto_aead_xform *aead_xform = &xform->aead;
    1274                 :            : 
    1275                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
    1276                 :            : 
    1277                 :          0 :         aead_xform->algo = RTE_CRYPTO_AEAD_AES_GCM;
    1278                 :          0 :         aead_xform->aad_length = vec.aead.aad.len;
    1279                 :          0 :         aead_xform->digest_length = vec.aead.digest.len;
    1280                 :          0 :         aead_xform->iv.offset = IV_OFF;
    1281                 :          0 :         aead_xform->iv.length = vec.iv.len;
    1282                 :          0 :         aead_xform->key.data = vec.aead.key.val;
    1283                 :          0 :         aead_xform->key.length = vec.aead.key.len;
    1284                 :          0 :         aead_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
    1285                 :          0 :                         RTE_CRYPTO_AEAD_OP_ENCRYPT :
    1286                 :            :                         RTE_CRYPTO_AEAD_OP_DECRYPT;
    1287                 :            : 
    1288                 :          0 :         cap_idx.algo.aead = aead_xform->algo;
    1289                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
    1290                 :            : 
    1291                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1292                 :          0 :         if (!cap) {
    1293                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1294                 :            :                                 env.dev_id);
    1295                 :          0 :                 return -EINVAL;
    1296                 :            :         }
    1297                 :            : 
    1298                 :          0 :         if (rte_cryptodev_sym_capability_check_aead(cap,
    1299                 :          0 :                         aead_xform->key.length,
    1300                 :          0 :                         aead_xform->digest_length, aead_xform->aad_length,
    1301                 :          0 :                         aead_xform->iv.length) != 0) {
    1302                 :          0 :                 RTE_LOG(ERR, USER1,
    1303                 :            :                         "PMD %s key_len %u tag_len %u aad_len %u iv_len %u\n",
    1304                 :            :                                 info.device_name, aead_xform->key.length,
    1305                 :            :                                 aead_xform->digest_length,
    1306                 :            :                                 aead_xform->aad_length,
    1307                 :            :                                 aead_xform->iv.length);
    1308                 :          0 :                 return -EPERM;
    1309                 :            :         }
    1310                 :            : 
    1311                 :            :         return 0;
    1312                 :            : }
    1313                 :            : 
    1314                 :            : int
    1315                 :          0 : prepare_gmac_xform(struct rte_crypto_sym_xform *xform)
    1316                 :            : {
    1317                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1318                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1319                 :            :         struct rte_crypto_auth_xform *auth_xform = &xform->auth;
    1320                 :            : 
    1321                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1322                 :            : 
    1323                 :          0 :         auth_xform->algo = RTE_CRYPTO_AUTH_AES_GMAC;
    1324                 :          0 :         auth_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
    1325                 :          0 :                         RTE_CRYPTO_AUTH_OP_GENERATE :
    1326                 :            :                         RTE_CRYPTO_AUTH_OP_VERIFY;
    1327                 :          0 :         auth_xform->iv.offset = IV_OFF;
    1328                 :          0 :         auth_xform->iv.length = vec.iv.len;
    1329                 :          0 :         auth_xform->digest_length = vec.aead.digest.len;
    1330                 :          0 :         auth_xform->key.data = vec.aead.key.val;
    1331                 :          0 :         auth_xform->key.length = vec.aead.key.len;
    1332                 :            : 
    1333                 :          0 :         cap_idx.algo.auth = auth_xform->algo;
    1334                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1335                 :            : 
    1336                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1337                 :          0 :         if (!cap) {
    1338                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1339                 :            :                                 env.dev_id);
    1340                 :          0 :                 return -EINVAL;
    1341                 :            :         }
    1342                 :            : 
    1343                 :          0 :         if (rte_cryptodev_sym_capability_check_auth(cap,
    1344                 :          0 :                         auth_xform->key.length,
    1345                 :          0 :                         auth_xform->digest_length,
    1346                 :          0 :                         auth_xform->iv.length) != 0) {
    1347                 :            : 
    1348                 :          0 :                 RTE_LOG(ERR, USER1,
    1349                 :            :                         "PMD %s key length %u Digest length %u IV length %u\n",
    1350                 :            :                                 info.device_name, auth_xform->key.length,
    1351                 :            :                                 auth_xform->digest_length,
    1352                 :            :                                 auth_xform->iv.length);
    1353                 :          0 :                 return -EPERM;
    1354                 :            :         }
    1355                 :            : 
    1356                 :            :         return 0;
    1357                 :            : }
    1358                 :            : 
    1359                 :            : static int
    1360                 :          0 : prepare_cmac_xform(struct rte_crypto_sym_xform *xform)
    1361                 :            : {
    1362                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1363                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1364                 :            :         struct rte_crypto_auth_xform *auth_xform = &xform->auth;
    1365                 :            : 
    1366                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1367                 :            : 
    1368                 :          0 :         auth_xform->algo = RTE_CRYPTO_AUTH_AES_CMAC;
    1369                 :          0 :         auth_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
    1370                 :          0 :                         RTE_CRYPTO_AUTH_OP_GENERATE : RTE_CRYPTO_AUTH_OP_VERIFY;
    1371                 :          0 :         auth_xform->digest_length = vec.cipher_auth.digest.len;
    1372                 :          0 :         auth_xform->key.data = vec.cipher_auth.key.val;
    1373                 :          0 :         auth_xform->key.length = vec.cipher_auth.key.len;
    1374                 :            : 
    1375                 :          0 :         cap_idx.algo.auth = auth_xform->algo;
    1376                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1377                 :            : 
    1378                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1379                 :          0 :         if (!cap) {
    1380                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1381                 :            :                                 env.dev_id);
    1382                 :          0 :                 return -EINVAL;
    1383                 :            :         }
    1384                 :            : 
    1385                 :          0 :         if (rte_cryptodev_sym_capability_check_auth(cap,
    1386                 :          0 :                         auth_xform->key.length,
    1387                 :          0 :                         auth_xform->digest_length, 0) != 0) {
    1388                 :          0 :                 RTE_LOG(ERR, USER1, "PMD %s key length %u Digest length %u\n",
    1389                 :            :                                 info.device_name, auth_xform->key.length,
    1390                 :            :                                 auth_xform->digest_length);
    1391                 :          0 :                 return -EPERM;
    1392                 :            :         }
    1393                 :            : 
    1394                 :            :         return 0;
    1395                 :            : }
    1396                 :            : 
    1397                 :            : static int
    1398                 :          0 : prepare_ccm_xform(struct rte_crypto_sym_xform *xform)
    1399                 :            : {
    1400                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1401                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1402                 :            :         struct rte_crypto_aead_xform *aead_xform = &xform->aead;
    1403                 :            : 
    1404                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
    1405                 :            : 
    1406                 :          0 :         aead_xform->algo = RTE_CRYPTO_AEAD_AES_CCM;
    1407                 :          0 :         aead_xform->aad_length = vec.aead.aad.len;
    1408                 :          0 :         aead_xform->digest_length = vec.aead.digest.len;
    1409                 :          0 :         aead_xform->iv.offset = IV_OFF;
    1410                 :          0 :         aead_xform->iv.length = vec.iv.len;
    1411                 :          0 :         aead_xform->key.data = vec.aead.key.val;
    1412                 :          0 :         aead_xform->key.length = vec.aead.key.len;
    1413                 :          0 :         aead_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
    1414                 :          0 :                         RTE_CRYPTO_AEAD_OP_ENCRYPT :
    1415                 :            :                         RTE_CRYPTO_AEAD_OP_DECRYPT;
    1416                 :            : 
    1417                 :          0 :         cap_idx.algo.aead = aead_xform->algo;
    1418                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
    1419                 :            : 
    1420                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1421                 :          0 :         if (!cap) {
    1422                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1423                 :            :                                 env.dev_id);
    1424                 :          0 :                 return -EINVAL;
    1425                 :            :         }
    1426                 :            : 
    1427                 :          0 :         if (rte_cryptodev_sym_capability_check_aead(cap,
    1428                 :          0 :                         aead_xform->key.length,
    1429                 :          0 :                         aead_xform->digest_length, aead_xform->aad_length,
    1430                 :          0 :                         aead_xform->iv.length) != 0) {
    1431                 :          0 :                 RTE_LOG(ERR, USER1,
    1432                 :            :                         "PMD %s key_len %u tag_len %u aad_len %u iv_len %u\n",
    1433                 :            :                                 info.device_name, aead_xform->key.length,
    1434                 :            :                                 aead_xform->digest_length,
    1435                 :            :                                 aead_xform->aad_length,
    1436                 :            :                                 aead_xform->iv.length);
    1437                 :          0 :                 return -EPERM;
    1438                 :            :         }
    1439                 :            : 
    1440                 :            :         return 0;
    1441                 :            : }
    1442                 :            : 
    1443                 :            : static int
    1444                 :          0 : prepare_sha_xform(struct rte_crypto_sym_xform *xform)
    1445                 :            : {
    1446                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1447                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1448                 :            :         struct rte_crypto_auth_xform *auth_xform = &xform->auth;
    1449                 :            : 
    1450                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1451                 :            : 
    1452                 :          0 :         auth_xform->algo = info.interim_info.sha_data.algo;
    1453                 :          0 :         auth_xform->op = RTE_CRYPTO_AUTH_OP_GENERATE;
    1454                 :          0 :         auth_xform->digest_length = vec.cipher_auth.digest.len;
    1455                 :            : 
    1456                 :          0 :         cap_idx.algo.auth = auth_xform->algo;
    1457                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1458                 :            : 
    1459                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1460                 :          0 :         if (!cap) {
    1461                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1462                 :            :                                 env.dev_id);
    1463                 :          0 :                 return -EINVAL;
    1464                 :            :         }
    1465                 :            : 
    1466                 :          0 :         if (rte_cryptodev_sym_capability_check_auth(cap,
    1467                 :          0 :                         auth_xform->key.length,
    1468                 :          0 :                         auth_xform->digest_length, 0) != 0) {
    1469                 :          0 :                 RTE_LOG(ERR, USER1, "PMD %s key length %u digest length %u\n",
    1470                 :            :                                 info.device_name, auth_xform->key.length,
    1471                 :            :                                 auth_xform->digest_length);
    1472                 :          0 :                 return -EPERM;
    1473                 :            :         }
    1474                 :            : 
    1475                 :            :         return 0;
    1476                 :            : }
    1477                 :            : 
    1478                 :            : static int
    1479                 :          0 : prepare_xts_xform(struct rte_crypto_sym_xform *xform)
    1480                 :            : {
    1481                 :            :         const struct rte_cryptodev_symmetric_capability *cap;
    1482                 :            :         struct rte_cryptodev_sym_capability_idx cap_idx;
    1483                 :            :         struct rte_crypto_cipher_xform *cipher_xform = &xform->cipher;
    1484                 :            : 
    1485                 :          0 :         xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1486                 :            : 
    1487                 :          0 :         cipher_xform->algo = RTE_CRYPTO_CIPHER_AES_XTS;
    1488                 :          0 :         cipher_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
    1489                 :          0 :                         RTE_CRYPTO_CIPHER_OP_ENCRYPT :
    1490                 :            :                         RTE_CRYPTO_CIPHER_OP_DECRYPT;
    1491                 :          0 :         cipher_xform->key.data = vec.cipher_auth.key.val;
    1492                 :          0 :         cipher_xform->key.length = vec.cipher_auth.key.len;
    1493                 :          0 :         cipher_xform->iv.length = vec.iv.len;
    1494                 :          0 :         cipher_xform->iv.offset = IV_OFF;
    1495                 :            : 
    1496                 :          0 :         cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_XTS;
    1497                 :          0 :         cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1498                 :            : 
    1499                 :          0 :         cap = rte_cryptodev_sym_capability_get(env.dev_id, &cap_idx);
    1500                 :          0 :         if (!cap) {
    1501                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1502                 :            :                                 env.dev_id);
    1503                 :          0 :                 return -EINVAL;
    1504                 :            :         }
    1505                 :            : 
    1506                 :          0 :         if (rte_cryptodev_sym_capability_check_cipher(cap,
    1507                 :          0 :                         cipher_xform->key.length,
    1508                 :          0 :                         cipher_xform->iv.length) != 0) {
    1509                 :          0 :                 RTE_LOG(ERR, USER1, "PMD %s key length %u IV length %u\n",
    1510                 :            :                                 info.device_name, cipher_xform->key.length,
    1511                 :            :                                 cipher_xform->iv.length);
    1512                 :          0 :                 return -EPERM;
    1513                 :            :         }
    1514                 :            : 
    1515                 :            :         return 0;
    1516                 :            : }
    1517                 :            : 
    1518                 :            : static int
    1519                 :          0 : prepare_rsa_xform(struct rte_crypto_asym_xform *xform)
    1520                 :            : {
    1521                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *cap;
    1522                 :            :         struct rte_cryptodev_asym_capability_idx cap_idx;
    1523                 :            :         struct rte_cryptodev_info dev_info;
    1524                 :            : 
    1525                 :          0 :         xform->xform_type = RTE_CRYPTO_ASYM_XFORM_RSA;
    1526                 :          0 :         xform->next = NULL;
    1527                 :            : 
    1528                 :          0 :         cap_idx.type = xform->xform_type;
    1529                 :          0 :         cap = rte_cryptodev_asym_capability_get(env.dev_id, &cap_idx);
    1530                 :          0 :         if (!cap) {
    1531                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1532                 :            :                                 env.dev_id);
    1533                 :          0 :                 return -EINVAL;
    1534                 :            :         }
    1535                 :            : 
    1536                 :          0 :         switch (info.op) {
    1537                 :          0 :         case FIPS_TEST_ASYM_SIGGEN:
    1538                 :          0 :                 if (!rte_cryptodev_asym_xform_capability_check_optype(cap,
    1539                 :            :                         RTE_CRYPTO_ASYM_OP_SIGN)) {
    1540                 :          0 :                         RTE_LOG(ERR, USER1, "PMD %s xform_op %u\n",
    1541                 :            :                                 info.device_name, RTE_CRYPTO_ASYM_OP_SIGN);
    1542                 :          0 :                         return -EPERM;
    1543                 :            :                 }
    1544                 :            :                 break;
    1545                 :          0 :         case FIPS_TEST_ASYM_SIGVER:
    1546                 :          0 :                 if (!rte_cryptodev_asym_xform_capability_check_optype(cap,
    1547                 :            :                         RTE_CRYPTO_ASYM_OP_VERIFY)) {
    1548                 :          0 :                         RTE_LOG(ERR, USER1, "PMD %s xform_op %u\n",
    1549                 :            :                                 info.device_name, RTE_CRYPTO_ASYM_OP_VERIFY);
    1550                 :          0 :                         return -EPERM;
    1551                 :            :                 }
    1552                 :            :                 break;
    1553                 :            :         case FIPS_TEST_ASYM_KEYGEN:
    1554                 :            :                 break;
    1555                 :            :         default:
    1556                 :            :                 break;
    1557                 :            :         }
    1558                 :            : 
    1559                 :          0 :         rte_cryptodev_info_get(env.dev_id, &dev_info);
    1560                 :          0 :         xform->rsa.key_type = info.interim_info.rsa_data.privkey;
    1561                 :          0 :         switch (xform->rsa.key_type) {
    1562                 :          0 :         case RTE_RSA_KEY_TYPE_QT:
    1563                 :          0 :                 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
    1564                 :          0 :                         RTE_LOG(ERR, USER1, "PMD %s does not support QT key type\n",
    1565                 :            :                                 info.device_name);
    1566                 :          0 :                         return -EPERM;
    1567                 :            :                 }
    1568                 :          0 :                 xform->rsa.qt.p.data = vec.rsa.p.val;
    1569                 :          0 :                 xform->rsa.qt.p.length = vec.rsa.p.len;
    1570                 :          0 :                 xform->rsa.qt.q.data = vec.rsa.q.val;
    1571                 :          0 :                 xform->rsa.qt.q.length = vec.rsa.q.len;
    1572                 :          0 :                 xform->rsa.qt.dP.data = vec.rsa.dp.val;
    1573                 :          0 :                 xform->rsa.qt.dP.length = vec.rsa.dp.len;
    1574                 :          0 :                 xform->rsa.qt.dQ.data = vec.rsa.dq.val;
    1575                 :          0 :                 xform->rsa.qt.dQ.length = vec.rsa.dq.len;
    1576                 :          0 :                 xform->rsa.qt.qInv.data = vec.rsa.qinv.val;
    1577                 :          0 :                 xform->rsa.qt.qInv.length = vec.rsa.qinv.len;
    1578                 :          0 :                 break;
    1579                 :          0 :         case RTE_RSA_KEY_TYPE_EXP:
    1580                 :          0 :                 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
    1581                 :          0 :                         RTE_LOG(ERR, USER1, "PMD %s does not support EXP key type\n",
    1582                 :            :                                 info.device_name);
    1583                 :          0 :                         return -EPERM;
    1584                 :            :                 }
    1585                 :          0 :                 xform->rsa.d.data = vec.rsa.d.val;
    1586                 :          0 :                 xform->rsa.d.length = vec.rsa.d.len;
    1587                 :          0 :                 break;
    1588                 :            :         default:
    1589                 :            :                 break;
    1590                 :            :         }
    1591                 :            : 
    1592                 :          0 :         xform->rsa.e.data = vec.rsa.e.val;
    1593                 :          0 :         xform->rsa.e.length = vec.rsa.e.len;
    1594                 :          0 :         xform->rsa.n.data = vec.rsa.n.val;
    1595                 :          0 :         xform->rsa.n.length = vec.rsa.n.len;
    1596                 :            : 
    1597                 :          0 :         xform->rsa.padding.type = info.interim_info.rsa_data.padding;
    1598                 :          0 :         xform->rsa.padding.hash = info.interim_info.rsa_data.auth;
    1599                 :          0 :         if (env.digest) {
    1600                 :          0 :                 if (xform->rsa.padding.type == RTE_CRYPTO_RSA_PADDING_PKCS1_5) {
    1601                 :            :                         struct fips_val msg;
    1602                 :            :                         int b_len = 0;
    1603                 :            :                         uint8_t b[32];
    1604                 :            : 
    1605                 :          0 :                         b_len = get_hash_oid(xform->rsa.padding.hash, b);
    1606                 :          0 :                         if (b_len < 0) {
    1607                 :          0 :                                 RTE_LOG(ERR, USER1, "Failed to get digest info for hash %d\n",
    1608                 :            :                                         xform->rsa.padding.hash);
    1609                 :          0 :                                 return -EINVAL;
    1610                 :            :                         }
    1611                 :            : 
    1612                 :          0 :                         if (b_len) {
    1613                 :          0 :                                 msg.len = env.digest_len + b_len;
    1614                 :          0 :                                 msg.val = rte_zmalloc(NULL, msg.len, 0);
    1615                 :          0 :                                 memcpy(msg.val, b, b_len);
    1616                 :          0 :                                 memcpy(msg.val + b_len, env.digest, env.digest_len);
    1617                 :          0 :                                 rte_free(env.digest);
    1618                 :          0 :                                 env.digest = msg.val;
    1619                 :          0 :                                 env.digest_len = msg.len;
    1620                 :            :                         }
    1621                 :            :                 }
    1622                 :            :         }
    1623                 :            : 
    1624                 :            :         return 0;
    1625                 :            : }
    1626                 :            : 
    1627                 :            : static int
    1628                 :          0 : prepare_ecdsa_xform(struct rte_crypto_asym_xform *xform)
    1629                 :            : {
    1630                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *cap;
    1631                 :            :         struct rte_cryptodev_asym_capability_idx cap_idx;
    1632                 :            : 
    1633                 :          0 :         xform->xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
    1634                 :          0 :         xform->next = NULL;
    1635                 :            : 
    1636                 :          0 :         cap_idx.type = xform->xform_type;
    1637                 :          0 :         cap = rte_cryptodev_asym_capability_get(env.dev_id, &cap_idx);
    1638                 :          0 :         if (!cap) {
    1639                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1640                 :            :                                 env.dev_id);
    1641                 :          0 :                 return -EINVAL;
    1642                 :            :         }
    1643                 :            : 
    1644                 :          0 :         switch (info.op) {
    1645                 :          0 :         case FIPS_TEST_ASYM_SIGGEN:
    1646                 :          0 :                 if (!rte_cryptodev_asym_xform_capability_check_optype(cap,
    1647                 :            :                         RTE_CRYPTO_ASYM_OP_SIGN)) {
    1648                 :          0 :                         RTE_LOG(ERR, USER1, "PMD %s xform_op %u\n",
    1649                 :            :                                 info.device_name, RTE_CRYPTO_ASYM_OP_SIGN);
    1650                 :          0 :                         return -EPERM;
    1651                 :            :                 }
    1652                 :            : 
    1653                 :          0 :                 xform->ec.pkey.data = vec.ecdsa.pkey.val;
    1654                 :          0 :                 xform->ec.pkey.length = vec.ecdsa.pkey.len;
    1655                 :          0 :                 break;
    1656                 :          0 :         case FIPS_TEST_ASYM_SIGVER:
    1657                 :          0 :                 if (!rte_cryptodev_asym_xform_capability_check_optype(cap,
    1658                 :            :                         RTE_CRYPTO_ASYM_OP_VERIFY)) {
    1659                 :          0 :                         RTE_LOG(ERR, USER1, "PMD %s xform_op %u\n",
    1660                 :            :                                 info.device_name, RTE_CRYPTO_ASYM_OP_VERIFY);
    1661                 :          0 :                         return -EPERM;
    1662                 :            :                 }
    1663                 :            : 
    1664                 :          0 :                 xform->ec.q.x.data = vec.ecdsa.qx.val;
    1665                 :          0 :                 xform->ec.q.x.length = vec.ecdsa.qx.len;
    1666                 :          0 :                 xform->ec.q.y.data = vec.ecdsa.qy.val;
    1667                 :          0 :                 xform->ec.q.y.length = vec.ecdsa.qy.len;
    1668                 :          0 :                 break;
    1669                 :            :         default:
    1670                 :            :                 break;
    1671                 :            :         }
    1672                 :            : 
    1673                 :          0 :         xform->ec.curve_id = info.interim_info.ecdsa_data.curve_id;
    1674                 :          0 :         return 0;
    1675                 :            : }
    1676                 :            : 
    1677                 :            : static int
    1678                 :          0 : prepare_eddsa_xform(struct rte_crypto_asym_xform *xform)
    1679                 :            : {
    1680                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *cap;
    1681                 :            :         struct rte_cryptodev_asym_capability_idx cap_idx;
    1682                 :            : 
    1683                 :          0 :         xform->xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
    1684                 :          0 :         xform->next = NULL;
    1685                 :            : 
    1686                 :          0 :         cap_idx.type = xform->xform_type;
    1687                 :          0 :         cap = rte_cryptodev_asym_capability_get(env.dev_id, &cap_idx);
    1688                 :          0 :         if (!cap) {
    1689                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1690                 :            :                                 env.dev_id);
    1691                 :          0 :                 return -EINVAL;
    1692                 :            :         }
    1693                 :            : 
    1694                 :          0 :         switch (info.op) {
    1695                 :          0 :         case FIPS_TEST_ASYM_SIGGEN:
    1696                 :          0 :                 if (!rte_cryptodev_asym_xform_capability_check_optype(cap,
    1697                 :            :                         RTE_CRYPTO_ASYM_OP_SIGN)) {
    1698                 :          0 :                         RTE_LOG(ERR, USER1, "PMD %s xform_op %u\n",
    1699                 :            :                                 info.device_name, RTE_CRYPTO_ASYM_OP_SIGN);
    1700                 :          0 :                         return -EPERM;
    1701                 :            :                 }
    1702                 :            : 
    1703                 :          0 :                 xform->ec.pkey.data = vec.eddsa.pkey.val;
    1704                 :          0 :                 xform->ec.pkey.length = vec.eddsa.pkey.len;
    1705                 :          0 :                 xform->ec.q.x.data = vec.eddsa.q.val;
    1706                 :          0 :                 xform->ec.q.x.length = vec.eddsa.q.len;
    1707                 :          0 :                 break;
    1708                 :          0 :         case FIPS_TEST_ASYM_SIGVER:
    1709                 :          0 :                 if (!rte_cryptodev_asym_xform_capability_check_optype(cap,
    1710                 :            :                         RTE_CRYPTO_ASYM_OP_VERIFY)) {
    1711                 :          0 :                         RTE_LOG(ERR, USER1, "PMD %s xform_op %u\n",
    1712                 :            :                                 info.device_name, RTE_CRYPTO_ASYM_OP_VERIFY);
    1713                 :          0 :                         return -EPERM;
    1714                 :            :                 }
    1715                 :            : 
    1716                 :          0 :                 xform->ec.q.x.data = vec.eddsa.q.val;
    1717                 :          0 :                 xform->ec.q.x.length = vec.eddsa.q.len;
    1718                 :          0 :                 break;
    1719                 :            :         default:
    1720                 :            :                 break;
    1721                 :            :         }
    1722                 :            : 
    1723                 :          0 :         xform->ec.curve_id = info.interim_info.eddsa_data.curve_id;
    1724                 :          0 :         return 0;
    1725                 :            : }
    1726                 :            : 
    1727                 :            : static int
    1728                 :          0 : prepare_ecfpm_xform(struct rte_crypto_asym_xform *xform)
    1729                 :            : {
    1730                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *cap;
    1731                 :            :         struct rte_cryptodev_asym_capability_idx cap_idx;
    1732                 :            : 
    1733                 :          0 :         xform->xform_type = RTE_CRYPTO_ASYM_XFORM_ECFPM;
    1734                 :          0 :         xform->next = NULL;
    1735                 :            : 
    1736                 :          0 :         cap_idx.type = xform->xform_type;
    1737                 :          0 :         cap = rte_cryptodev_asym_capability_get(env.dev_id, &cap_idx);
    1738                 :          0 :         if (!cap) {
    1739                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1740                 :            :                                 env.dev_id);
    1741                 :          0 :                 return -EINVAL;
    1742                 :            :         }
    1743                 :            : 
    1744                 :          0 :         xform->ec.curve_id = info.interim_info.ecdsa_data.curve_id;
    1745                 :          0 :         return 0;
    1746                 :            : }
    1747                 :            : 
    1748                 :            : static int
    1749                 :          0 : prepare_edfpm_xform(struct rte_crypto_asym_xform *xform)
    1750                 :            : {
    1751                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *cap;
    1752                 :            :         struct rte_cryptodev_asym_capability_idx cap_idx;
    1753                 :            : 
    1754                 :          0 :         xform->xform_type = RTE_CRYPTO_ASYM_XFORM_ECFPM;
    1755                 :          0 :         xform->next = NULL;
    1756                 :            : 
    1757                 :          0 :         cap_idx.type = xform->xform_type;
    1758                 :          0 :         cap = rte_cryptodev_asym_capability_get(env.dev_id, &cap_idx);
    1759                 :          0 :         if (!cap) {
    1760                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1761                 :            :                                 env.dev_id);
    1762                 :          0 :                 return -EINVAL;
    1763                 :            :         }
    1764                 :            : 
    1765                 :          0 :         xform->ec.curve_id = info.interim_info.eddsa_data.curve_id;
    1766                 :          0 :         return 0;
    1767                 :            : }
    1768                 :            : 
    1769                 :            : static int
    1770                 :          0 : get_writeback_data(struct fips_val *val)
    1771                 :            : {
    1772                 :          0 :         struct rte_mbuf *m = env.mbuf;
    1773                 :          0 :         uint16_t data_len = rte_pktmbuf_pkt_len(m);
    1774                 :          0 :         uint16_t total_len = data_len + env.digest_len;
    1775                 :            :         uint8_t *src, *dst, *wb_data;
    1776                 :            : 
    1777                 :            :         /* in case val is reused for MCT test, try to free the buffer first */
    1778                 :          0 :         if (val->val) {
    1779                 :          0 :                 rte_free(val->val);
    1780                 :          0 :                 val->val = NULL;
    1781                 :            :         }
    1782                 :            : 
    1783                 :          0 :         wb_data = dst = rte_malloc(NULL, total_len, 0);
    1784                 :          0 :         if (!dst) {
    1785                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Not enough memory\n", -ENOMEM);
    1786                 :          0 :                 return -ENOMEM;
    1787                 :            :         }
    1788                 :            : 
    1789                 :          0 :         while (m && data_len) {
    1790                 :          0 :                 uint16_t seg_len = RTE_MIN(rte_pktmbuf_data_len(m), data_len);
    1791                 :            : 
    1792                 :          0 :                 src = rte_pktmbuf_mtod(m, uint8_t *);
    1793                 :          0 :                 memcpy(dst, src, seg_len);
    1794                 :          0 :                 m = m->next;
    1795                 :          0 :                 data_len -= seg_len;
    1796                 :          0 :                 dst += seg_len;
    1797                 :            :         }
    1798                 :            : 
    1799                 :          0 :         if (data_len) {
    1800                 :          0 :                 RTE_LOG(ERR, USER1, "Error -1: write back data\n");
    1801                 :          0 :                 rte_free(wb_data);
    1802                 :          0 :                 return -1;
    1803                 :            :         }
    1804                 :            : 
    1805                 :          0 :         if (env.digest)
    1806                 :          0 :                 memcpy(dst, env.digest, env.digest_len);
    1807                 :            : 
    1808                 :          0 :         val->val = wb_data;
    1809                 :          0 :         val->len = total_len;
    1810                 :            : 
    1811                 :          0 :         return 0;
    1812                 :            : }
    1813                 :            : 
    1814                 :            : static int
    1815                 :          0 : fips_run_sym_test(void)
    1816                 :            : {
    1817                 :          0 :         struct rte_crypto_sym_xform xform = {0};
    1818                 :            :         uint16_t n_deqd;
    1819                 :            :         int ret;
    1820                 :            : 
    1821                 :          0 :         if (!test_ops.prepare_sym_xform || !test_ops.prepare_sym_op)
    1822                 :            :                 return -EINVAL;
    1823                 :            : 
    1824                 :          0 :         ret = test_ops.prepare_sym_xform(&xform);
    1825                 :          0 :         if (ret < 0)
    1826                 :            :                 return ret;
    1827                 :            : 
    1828                 :          0 :         env.sym.sess = rte_cryptodev_sym_session_create(env.dev_id, &xform,
    1829                 :            :                                                 env.sym.sess_mpool);
    1830                 :          0 :         if (!env.sym.sess)
    1831                 :            :                 return -ENOMEM;
    1832                 :            : 
    1833                 :          0 :         ret = test_ops.prepare_sym_op();
    1834                 :          0 :         if (ret < 0) {
    1835                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Prepare op\n",
    1836                 :            :                                 ret);
    1837                 :          0 :                 goto exit;
    1838                 :            :         }
    1839                 :            : 
    1840                 :          0 :         if (rte_cryptodev_enqueue_burst(env.dev_id, 0, &env.op, 1) < 1) {
    1841                 :          0 :                 RTE_LOG(ERR, USER1, "Error: Failed enqueue\n");
    1842                 :            :                 ret = -1;
    1843                 :          0 :                 goto exit;
    1844                 :            :         }
    1845                 :            : 
    1846                 :            :         do {
    1847                 :            :                 struct rte_crypto_op *deqd_op;
    1848                 :            : 
    1849                 :          0 :                 n_deqd = rte_cryptodev_dequeue_burst(env.dev_id, 0, &deqd_op, 1);
    1850                 :          0 :         } while (n_deqd == 0);
    1851                 :            : 
    1852                 :          0 :         vec.status = env.op->status;
    1853                 :            : 
    1854                 :          0 : exit:
    1855                 :          0 :         rte_cryptodev_sym_session_free(env.dev_id, env.sym.sess);
    1856                 :          0 :         env.sym.sess = NULL;
    1857                 :          0 :         return ret;
    1858                 :            : }
    1859                 :            : 
    1860                 :            : static int
    1861                 :          0 : fips_run_asym_test(void)
    1862                 :            : {
    1863                 :          0 :         struct rte_crypto_asym_xform xform = {0};
    1864                 :            :         struct rte_crypto_asym_op *asym;
    1865                 :            :         struct rte_crypto_op *deqd_op;
    1866                 :            :         int ret;
    1867                 :            : 
    1868                 :          0 :         if (info.op == FIPS_TEST_ASYM_KEYGEN &&
    1869                 :          0 :                 (info.algo != FIPS_TEST_ALGO_ECDSA &&
    1870                 :            :                  info.algo != FIPS_TEST_ALGO_EDDSA)) {
    1871                 :            :                 RTE_SET_USED(asym);
    1872                 :            :                 ret = 0;
    1873                 :          0 :                 goto exit;
    1874                 :            :         }
    1875                 :            : 
    1876                 :          0 :         if (!test_ops.prepare_asym_xform || !test_ops.prepare_asym_op)
    1877                 :            :                 return -EINVAL;
    1878                 :            : 
    1879                 :            :         asym = env.op->asym;
    1880                 :          0 :         ret = test_ops.prepare_asym_xform(&xform);
    1881                 :          0 :         if (ret < 0)
    1882                 :            :                 return ret;
    1883                 :            : 
    1884                 :          0 :         ret = rte_cryptodev_asym_session_create(env.dev_id, &xform, env.asym.sess_mpool,
    1885                 :            :                         (void *)&env.asym.sess);
    1886                 :          0 :         if (ret < 0)
    1887                 :            :                 return ret;
    1888                 :            : 
    1889                 :          0 :         ret = test_ops.prepare_asym_op();
    1890                 :          0 :         if (ret < 0) {
    1891                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Prepare op\n", ret);
    1892                 :          0 :                 goto exit;
    1893                 :            :         }
    1894                 :            : 
    1895                 :          0 :         if (rte_cryptodev_enqueue_burst(env.dev_id, 0, &env.op, 1) < 1) {
    1896                 :          0 :                 RTE_LOG(ERR, USER1, "Error: Failed enqueue\n");
    1897                 :            :                 ret = -1;
    1898                 :          0 :                 goto exit;
    1899                 :            :         }
    1900                 :            : 
    1901                 :          0 :         while (rte_cryptodev_dequeue_burst(env.dev_id, 0, &deqd_op, 1) == 0)
    1902                 :            :                 rte_pause();
    1903                 :            : 
    1904                 :          0 :         vec.status = env.op->status;
    1905                 :            : 
    1906                 :          0 :  exit:
    1907                 :          0 :         if (env.asym.sess)
    1908                 :          0 :                 rte_cryptodev_asym_session_free(env.dev_id, env.asym.sess);
    1909                 :            : 
    1910                 :          0 :         env.asym.sess = NULL;
    1911                 :          0 :         return ret;
    1912                 :            : }
    1913                 :            : 
    1914                 :            : static int
    1915                 :          0 : fips_run_test(void)
    1916                 :            : {
    1917                 :            :         int ret;
    1918                 :            : 
    1919                 :          0 :         env.op = NULL;
    1920                 :          0 :         if (!env.is_asym_test) {
    1921                 :          0 :                 env.op = env.sym.op;
    1922                 :          0 :                 return fips_run_sym_test();
    1923                 :            :         }
    1924                 :            : 
    1925                 :          0 :         if (info.op == FIPS_TEST_ASYM_KEYGEN) {
    1926                 :          0 :                 if (info.algo == FIPS_TEST_ALGO_ECDSA) {
    1927                 :          0 :                         test_ops.prepare_asym_xform = prepare_ecfpm_xform;
    1928                 :          0 :                         test_ops.prepare_asym_op = prepare_ecfpm_op;
    1929                 :          0 :                         info.interim_info.ecdsa_data.pubkey_gen = 0;
    1930                 :            : 
    1931                 :          0 :                 } else if (info.algo == FIPS_TEST_ALGO_EDDSA) {
    1932                 :          0 :                         test_ops.prepare_asym_xform = prepare_edfpm_xform;
    1933                 :          0 :                         test_ops.prepare_asym_op = prepare_edfpm_op;
    1934                 :          0 :                         info.interim_info.eddsa_data.pubkey_gen = 0;
    1935                 :            :                 }
    1936                 :            : 
    1937                 :          0 :                 env.op = env.asym.op;
    1938                 :          0 :                 return fips_run_asym_test();
    1939                 :            :         }
    1940                 :            : 
    1941                 :          0 :         if (info.algo == FIPS_TEST_ALGO_ECDSA ||
    1942                 :            :             info.algo == FIPS_TEST_ALGO_RSA) {
    1943                 :          0 :                 vec.cipher_auth.digest.len =
    1944                 :          0 :                         parse_test_sha_hash_size(info.interim_info.ecdsa_data.auth);
    1945                 :          0 :                 test_ops.prepare_sym_xform = prepare_sha_xform;
    1946                 :          0 :                 test_ops.prepare_sym_op = prepare_auth_op;
    1947                 :            : 
    1948                 :          0 :                 env.op = env.sym.op;
    1949                 :          0 :                 ret = fips_run_sym_test();
    1950                 :          0 :                 if (ret < 0)
    1951                 :            :                         return ret;
    1952                 :            :         }
    1953                 :            : 
    1954                 :          0 :         env.op = env.asym.op;
    1955                 :          0 :         if (info.op == FIPS_TEST_ASYM_SIGGEN) {
    1956                 :            :                 fips_prepare_asym_xform_t old_xform;
    1957                 :            :                 fips_prepare_op_t old_op;
    1958                 :            : 
    1959                 :          0 :                 old_xform = test_ops.prepare_asym_xform;
    1960                 :          0 :                 old_op = test_ops.prepare_asym_op;
    1961                 :            : 
    1962                 :          0 :                 if (info.algo == FIPS_TEST_ALGO_ECDSA &&
    1963                 :          0 :                     info.interim_info.ecdsa_data.pubkey_gen == 1) {
    1964                 :          0 :                         info.op = FIPS_TEST_ASYM_KEYGEN;
    1965                 :          0 :                         test_ops.prepare_asym_xform = prepare_ecfpm_xform;
    1966                 :          0 :                         test_ops.prepare_asym_op = prepare_ecfpm_op;
    1967                 :            : 
    1968                 :          0 :                         ret = fips_run_asym_test();
    1969                 :          0 :                         if (ret < 0)
    1970                 :            :                                 return ret;
    1971                 :            : 
    1972                 :          0 :                         info.post_interim_writeback(NULL);
    1973                 :          0 :                         info.interim_info.ecdsa_data.pubkey_gen = 0;
    1974                 :            : 
    1975                 :          0 :                 } else if (info.algo == FIPS_TEST_ALGO_EDDSA &&
    1976                 :          0 :                                    info.interim_info.eddsa_data.pubkey_gen == 1) {
    1977                 :          0 :                         info.op = FIPS_TEST_ASYM_KEYGEN;
    1978                 :          0 :                         test_ops.prepare_asym_xform = prepare_edfpm_xform;
    1979                 :          0 :                         test_ops.prepare_asym_op = prepare_edfpm_op;
    1980                 :            : 
    1981                 :            :                         const struct rte_cryptodev_asymmetric_xform_capability *cap;
    1982                 :            :                         struct rte_cryptodev_asym_capability_idx cap_idx;
    1983                 :            : 
    1984                 :          0 :                         cap_idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
    1985                 :          0 :                         cap = rte_cryptodev_asym_capability_get(env.dev_id, &cap_idx);
    1986                 :          0 :                         if (!cap) {
    1987                 :          0 :                                 RTE_LOG(ERR, USER1, "Failed to get capability for cdev %u\n",
    1988                 :            :                                                 env.dev_id);
    1989                 :          0 :                                 return -EINVAL;
    1990                 :            :                         }
    1991                 :            : 
    1992                 :          0 :                         if (cap->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE)) {
    1993                 :          0 :                                 ret = fips_run_asym_test();
    1994                 :          0 :                                 if (ret < 0)
    1995                 :            :                                         return ret;
    1996                 :            :                         } else {
    1997                 :            :                                 /* Below is only a workaround by using known keys. */
    1998                 :          0 :                                 struct rte_crypto_asym_xform xform = {0};
    1999                 :            : 
    2000                 :          0 :                                 prepare_edfpm_xform(&xform);
    2001                 :          0 :                                 prepare_edfpm_op();
    2002                 :          0 :                                 uint8_t pkey25519[] = {
    2003                 :            :                                         0x83, 0x3f, 0xe6, 0x24, 0x09, 0x23, 0x7b, 0x9d,
    2004                 :            :                                         0x62, 0xec, 0x77, 0x58, 0x75, 0x20, 0x91, 0x1e,
    2005                 :            :                                         0x9a, 0x75, 0x9c, 0xec, 0x1d, 0x19, 0x75, 0x5b,
    2006                 :            :                                         0x7d, 0xa9, 0x01, 0xb9, 0x6d, 0xca, 0x3d, 0x42
    2007                 :            :                                 };
    2008                 :          0 :                                 uint8_t q25519[] = {
    2009                 :            :                                         0xec, 0x17, 0x2b, 0x93, 0xad, 0x5e, 0x56, 0x3b,
    2010                 :            :                                         0xf4, 0x93, 0x2c, 0x70, 0xe1, 0x24, 0x50, 0x34,
    2011                 :            :                                         0xc3, 0x54, 0x67, 0xef, 0x2e, 0xfd, 0x4d, 0x64,
    2012                 :            :                                         0xeb, 0xf8, 0x19, 0x68, 0x34, 0x67, 0xe2, 0xbf
    2013                 :            :                                 };
    2014                 :          0 :                                 uint8_t pkey448[] = {
    2015                 :            :                                         0xd6, 0x5d, 0xf3, 0x41, 0xad, 0x13, 0xe0, 0x08,
    2016                 :            :                                         0x56, 0x76, 0x88, 0xba, 0xed, 0xda, 0x8e, 0x9d,
    2017                 :            :                                         0xcd, 0xc1, 0x7d, 0xc0, 0x24, 0x97, 0x4e, 0xa5,
    2018                 :            :                                         0xb4, 0x22, 0x7b, 0x65, 0x30, 0xe3, 0x39, 0xbf,
    2019                 :            :                                         0xf2, 0x1f, 0x99, 0xe6, 0x8c, 0xa6, 0x96, 0x8f,
    2020                 :            :                                         0x3c, 0xca, 0x6d, 0xfe, 0x0f, 0xb9, 0xf4, 0xfa,
    2021                 :            :                                         0xb4, 0xfa, 0x13, 0x5d, 0x55, 0x42, 0xea, 0x3f,
    2022                 :            :                                         0x01
    2023                 :            :                                 };
    2024                 :          0 :                                 uint8_t q448[] = {
    2025                 :            :                                         0xdf, 0x97, 0x05, 0xf5, 0x8e, 0xdb, 0xab, 0x80,
    2026                 :            :                                         0x2c, 0x7f, 0x83, 0x63, 0xcf, 0xe5, 0x56, 0x0a,
    2027                 :            :                                         0xb1, 0xc6, 0x13, 0x2c, 0x20, 0xa9, 0xf1, 0xdd,
    2028                 :            :                                         0x16, 0x34, 0x83, 0xa2, 0x6f, 0x8a, 0xc5, 0x3a,
    2029                 :            :                                         0x39, 0xd6, 0x80, 0x8b, 0xf4, 0xa1, 0xdf, 0xbd,
    2030                 :            :                                         0x26, 0x1b, 0x09, 0x9b, 0xb0, 0x3b, 0x3f, 0xb5,
    2031                 :            :                                         0x09, 0x06, 0xcb, 0x28, 0xbd, 0x8a, 0x08, 0x1f,
    2032                 :            :                                         0x00
    2033                 :            :                                 };
    2034                 :          0 :                                 if (info.interim_info.eddsa_data.curve_id ==
    2035                 :            :                                         RTE_CRYPTO_EC_GROUP_ED25519) {
    2036                 :          0 :                                         memcpy(vec.eddsa.pkey.val, pkey25519, RTE_DIM(pkey25519));
    2037                 :          0 :                                         vec.eddsa.pkey.len = 32;
    2038                 :          0 :                                         memcpy(vec.eddsa.q.val, q25519, RTE_DIM(q25519));
    2039                 :          0 :                                         vec.eddsa.q.len = 32;
    2040                 :            :                                 } else {
    2041                 :          0 :                                         memcpy(vec.eddsa.pkey.val, pkey448, RTE_DIM(pkey448));
    2042                 :          0 :                                         vec.eddsa.pkey.len = 32;
    2043                 :          0 :                                         memcpy(vec.eddsa.q.val, q448, RTE_DIM(q448));
    2044                 :          0 :                                         vec.eddsa.q.len = 32;
    2045                 :            :                                 }
    2046                 :            :                         }
    2047                 :          0 :                         info.post_interim_writeback(NULL);
    2048                 :          0 :                         info.interim_info.eddsa_data.pubkey_gen = 0;
    2049                 :            : 
    2050                 :            :                 }
    2051                 :            : 
    2052                 :          0 :                 test_ops.prepare_asym_xform = old_xform;
    2053                 :          0 :                 test_ops.prepare_asym_op = old_op;
    2054                 :          0 :                 info.op = FIPS_TEST_ASYM_SIGGEN;
    2055                 :          0 :                 ret = fips_run_asym_test();
    2056                 :            :         } else {
    2057                 :          0 :                 ret = fips_run_asym_test();
    2058                 :            :         }
    2059                 :            : 
    2060                 :            :         return ret;
    2061                 :            : }
    2062                 :            : 
    2063                 :            : static int
    2064                 :          0 : fips_generic_test(void)
    2065                 :            : {
    2066                 :          0 :         struct fips_val val = {NULL, 0};
    2067                 :            :         int ret;
    2068                 :            : 
    2069                 :          0 :         if (info.file_type != FIPS_TYPE_JSON)
    2070                 :          0 :                 fips_test_write_one_case();
    2071                 :            : 
    2072                 :          0 :         ret = fips_run_test();
    2073                 :          0 :         if (ret < 0) {
    2074                 :          0 :                 if (ret == -EPERM || ret == -ENOTSUP) {
    2075                 :          0 :                         if (info.file_type == FIPS_TYPE_JSON)
    2076                 :            :                                 return ret;
    2077                 :            : 
    2078                 :          0 :                         fprintf(info.fp_wr, "Bypass\n\n");
    2079                 :          0 :                         return 0;
    2080                 :            :                 }
    2081                 :            : 
    2082                 :            :                 return ret;
    2083                 :            :         }
    2084                 :            : 
    2085                 :          0 :         if (!env.is_asym_test) {
    2086                 :          0 :                 ret = get_writeback_data(&val);
    2087                 :          0 :                 if (ret < 0)
    2088                 :            :                         return ret;
    2089                 :            :         }
    2090                 :            : 
    2091                 :          0 :         switch (info.file_type) {
    2092                 :          0 :         case FIPS_TYPE_REQ:
    2093                 :            :         case FIPS_TYPE_RSP:
    2094                 :            :         case FIPS_TYPE_JSON:
    2095                 :          0 :                 if (info.parse_writeback == NULL)
    2096                 :            :                         return -EPERM;
    2097                 :          0 :                 ret = info.parse_writeback(&val);
    2098                 :          0 :                 if (ret < 0)
    2099                 :            :                         return ret;
    2100                 :            :                 break;
    2101                 :          0 :         case FIPS_TYPE_FAX:
    2102                 :          0 :                 if (info.kat_check == NULL)
    2103                 :            :                         return -EPERM;
    2104                 :          0 :                 ret = info.kat_check(&val);
    2105                 :          0 :                 if (ret < 0)
    2106                 :            :                         return ret;
    2107                 :            :                 break;
    2108                 :            :         default:
    2109                 :            :                 break;
    2110                 :            :         }
    2111                 :            : 
    2112                 :          0 :         if (info.file_type != FIPS_TYPE_JSON)
    2113                 :          0 :                 fprintf(info.fp_wr, "\n");
    2114                 :          0 :         rte_free(val.val);
    2115                 :            : 
    2116                 :          0 :         return 0;
    2117                 :            : }
    2118                 :            : 
    2119                 :            : static int
    2120                 :          0 : fips_mct_tdes_test(void)
    2121                 :            : {
    2122                 :            : #define TDES_BLOCK_SIZE         8
    2123                 :            : #define TDES_EXTERN_ITER        400
    2124                 :            : #define TDES_INTERN_ITER        10000
    2125                 :          0 :         struct fips_val val[3] = {{NULL, 0},}, val_key, pt, ct, iv;
    2126                 :          0 :         uint8_t prev_out[TDES_BLOCK_SIZE] = {0};
    2127                 :          0 :         uint8_t prev_prev_out[TDES_BLOCK_SIZE] = {0};
    2128                 :          0 :         uint8_t prev_in[TDES_BLOCK_SIZE] = {0};
    2129                 :            :         uint32_t i, j, k;
    2130                 :            :         int ret;
    2131                 :          0 :         int test_mode = info.interim_info.tdes_data.test_mode;
    2132                 :            : 
    2133                 :          0 :         pt.len = vec.pt.len;
    2134                 :          0 :         pt.val = rte_malloc(NULL, pt.len, 0);
    2135                 :          0 :         ct.len = vec.ct.len;
    2136                 :          0 :         ct.val = rte_malloc(NULL, ct.len, 0);
    2137                 :          0 :         iv.len = vec.iv.len;
    2138                 :          0 :         iv.val = rte_malloc(NULL, iv.len, 0);
    2139                 :            : 
    2140                 :          0 :         for (i = 0; i < TDES_EXTERN_ITER; i++) {
    2141                 :          0 :                 if (info.file_type != FIPS_TYPE_JSON) {
    2142                 :          0 :                         if ((i == 0) && (info.version == 21.4f)) {
    2143                 :          0 :                                 if (!(strstr(info.vec[0], "COUNT")))
    2144                 :          0 :                                         fprintf(info.fp_wr, "%s%u\n", "COUNT = ", 0);
    2145                 :            :                         }
    2146                 :            : 
    2147                 :          0 :                         if (i != 0)
    2148                 :          0 :                                 update_info_vec(i);
    2149                 :            : 
    2150                 :          0 :                         fips_test_write_one_case();
    2151                 :            :                 }
    2152                 :            : 
    2153                 :          0 :                 for (j = 0; j < TDES_INTERN_ITER; j++) {
    2154                 :          0 :                         ret = fips_run_test();
    2155                 :          0 :                         if (ret < 0) {
    2156                 :          0 :                                 if (ret == -EPERM) {
    2157                 :          0 :                                         if (info.file_type == FIPS_TYPE_JSON)
    2158                 :            :                                                 return ret;
    2159                 :            : 
    2160                 :          0 :                                         fprintf(info.fp_wr, "Bypass\n");
    2161                 :          0 :                                         return 0;
    2162                 :            :                                 }
    2163                 :            :                                 return ret;
    2164                 :            :                         }
    2165                 :            : 
    2166                 :          0 :                         ret = get_writeback_data(&val[0]);
    2167                 :          0 :                         if (ret < 0)
    2168                 :          0 :                                 return ret;
    2169                 :            : 
    2170                 :          0 :                         if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
    2171                 :          0 :                                 memcpy(prev_in, vec.ct.val, TDES_BLOCK_SIZE);
    2172                 :            : 
    2173                 :          0 :                         if (j == 0) {
    2174                 :          0 :                                 memcpy(prev_out, val[0].val, TDES_BLOCK_SIZE);
    2175                 :          0 :                                 memcpy(pt.val, vec.pt.val, pt.len);
    2176                 :          0 :                                 memcpy(ct.val, vec.ct.val, ct.len);
    2177                 :          0 :                                 memcpy(iv.val, vec.iv.val, iv.len);
    2178                 :            : 
    2179                 :          0 :                                 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
    2180                 :          0 :                                         if (test_mode == TDES_MODE_ECB) {
    2181                 :          0 :                                                 memcpy(vec.pt.val, val[0].val,
    2182                 :            :                                                            TDES_BLOCK_SIZE);
    2183                 :            :                                         } else {
    2184                 :          0 :                                                 memcpy(vec.pt.val, vec.iv.val,
    2185                 :            :                                                            TDES_BLOCK_SIZE);
    2186                 :          0 :                                                 memcpy(vec.iv.val, val[0].val,
    2187                 :            :                                                            TDES_BLOCK_SIZE);
    2188                 :            :                                         }
    2189                 :          0 :                                         val[1].val = pt.val;
    2190                 :          0 :                                         val[1].len = pt.len;
    2191                 :          0 :                                         val[2].val = iv.val;
    2192                 :          0 :                                         val[2].len = iv.len;
    2193                 :            :                                 } else {
    2194                 :          0 :                                         if (test_mode == TDES_MODE_ECB) {
    2195                 :          0 :                                                 memcpy(vec.ct.val, val[0].val,
    2196                 :            :                                                            TDES_BLOCK_SIZE);
    2197                 :            :                                         } else {
    2198                 :          0 :                                                 memcpy(vec.iv.val, vec.ct.val,
    2199                 :            :                                                            TDES_BLOCK_SIZE);
    2200                 :          0 :                                                 memcpy(vec.ct.val, val[0].val,
    2201                 :            :                                                            TDES_BLOCK_SIZE);
    2202                 :            :                                         }
    2203                 :          0 :                                         val[1].val = ct.val;
    2204                 :          0 :                                         val[1].len = ct.len;
    2205                 :          0 :                                         val[2].val = iv.val;
    2206                 :          0 :                                         val[2].len = iv.len;
    2207                 :            :                                 }
    2208                 :          0 :                                 continue;
    2209                 :            :                         }
    2210                 :            : 
    2211                 :          0 :                         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
    2212                 :          0 :                                 if (test_mode == TDES_MODE_ECB) {
    2213                 :          0 :                                         memcpy(vec.pt.val, val[0].val,
    2214                 :            :                                                    TDES_BLOCK_SIZE);
    2215                 :            :                                 } else {
    2216                 :          0 :                                         memcpy(vec.iv.val, val[0].val,
    2217                 :            :                                                    TDES_BLOCK_SIZE);
    2218                 :          0 :                                         memcpy(vec.pt.val, prev_out,
    2219                 :            :                                                    TDES_BLOCK_SIZE);
    2220                 :            :                                 }
    2221                 :            :                         } else {
    2222                 :          0 :                                 if (test_mode == TDES_MODE_ECB) {
    2223                 :          0 :                                         memcpy(vec.ct.val, val[0].val,
    2224                 :            :                                                    TDES_BLOCK_SIZE);
    2225                 :            :                                 } else {
    2226                 :          0 :                                         memcpy(vec.iv.val, vec.ct.val,
    2227                 :            :                                                    TDES_BLOCK_SIZE);
    2228                 :          0 :                                         memcpy(vec.ct.val, val[0].val,
    2229                 :            :                                                    TDES_BLOCK_SIZE);
    2230                 :            :                                 }
    2231                 :            :                         }
    2232                 :            : 
    2233                 :          0 :                         if (j == TDES_INTERN_ITER - 1)
    2234                 :          0 :                                 continue;
    2235                 :            : 
    2236                 :          0 :                         memcpy(prev_out, val[0].val, TDES_BLOCK_SIZE);
    2237                 :            : 
    2238                 :          0 :                         if (j == TDES_INTERN_ITER - 3)
    2239                 :            :                                 memcpy(prev_prev_out, val[0].val, TDES_BLOCK_SIZE);
    2240                 :            :                 }
    2241                 :            : 
    2242                 :          0 :                 info.parse_writeback(val);
    2243                 :          0 :                 if (info.file_type != FIPS_TYPE_JSON)
    2244                 :          0 :                         fprintf(info.fp_wr, "\n");
    2245                 :            : 
    2246                 :          0 :                 if (i == TDES_EXTERN_ITER - 1)
    2247                 :          0 :                         continue;
    2248                 :            : 
    2249                 :            :                 /** update key */
    2250                 :            :                 memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
    2251                 :            : 
    2252                 :          0 :                 if (info.interim_info.tdes_data.nb_keys == 0) {
    2253                 :          0 :                         if (memcmp(val_key.val, val_key.val + 8, 8) == 0)
    2254                 :          0 :                                 info.interim_info.tdes_data.nb_keys = 1;
    2255                 :          0 :                         else if (memcmp(val_key.val, val_key.val + 16, 8) == 0)
    2256                 :          0 :                                 info.interim_info.tdes_data.nb_keys = 2;
    2257                 :            :                         else
    2258                 :          0 :                                 info.interim_info.tdes_data.nb_keys = 3;
    2259                 :            : 
    2260                 :            :                 }
    2261                 :            : 
    2262                 :          0 :                 for (k = 0; k < TDES_BLOCK_SIZE; k++) {
    2263                 :            : 
    2264                 :          0 :                         switch (info.interim_info.tdes_data.nb_keys) {
    2265                 :          0 :                         case 3:
    2266                 :          0 :                                 val_key.val[k] ^= val[0].val[k];
    2267                 :          0 :                                 val_key.val[k + 8] ^= prev_out[k];
    2268                 :          0 :                                 val_key.val[k + 16] ^= prev_prev_out[k];
    2269                 :          0 :                                 break;
    2270                 :          0 :                         case 2:
    2271                 :          0 :                                 val_key.val[k] ^= val[0].val[k];
    2272                 :          0 :                                 val_key.val[k + 8] ^= prev_out[k];
    2273                 :          0 :                                 val_key.val[k + 16] ^= val[0].val[k];
    2274                 :          0 :                                 break;
    2275                 :          0 :                         default: /* case 1 */
    2276                 :          0 :                                 val_key.val[k] ^= val[0].val[k];
    2277                 :          0 :                                 val_key.val[k + 8] ^= val[0].val[k];
    2278                 :          0 :                                 val_key.val[k + 16] ^= val[0].val[k];
    2279                 :          0 :                                 break;
    2280                 :            :                         }
    2281                 :            : 
    2282                 :            :                 }
    2283                 :            : 
    2284                 :          0 :                 for (k = 0; k < 24; k++)
    2285                 :          0 :                         val_key.val[k] = (rte_popcount32(val_key.val[k]) &
    2286                 :            :                                         0x1) ?
    2287                 :            :                                         val_key.val[k] : (val_key.val[k] ^ 0x1);
    2288                 :            : 
    2289                 :          0 :                 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
    2290                 :          0 :                         if (test_mode == TDES_MODE_ECB) {
    2291                 :          0 :                                 memcpy(vec.pt.val, val[0].val, TDES_BLOCK_SIZE);
    2292                 :            :                         } else {
    2293                 :          0 :                                 memcpy(vec.iv.val, val[0].val, TDES_BLOCK_SIZE);
    2294                 :          0 :                                 memcpy(vec.pt.val, prev_out, TDES_BLOCK_SIZE);
    2295                 :            :                         }
    2296                 :            :                 } else {
    2297                 :          0 :                         if (test_mode == TDES_MODE_ECB) {
    2298                 :          0 :                                 memcpy(vec.ct.val, val[0].val, TDES_BLOCK_SIZE);
    2299                 :            :                         } else {
    2300                 :          0 :                                 memcpy(vec.iv.val, prev_out, TDES_BLOCK_SIZE);
    2301                 :          0 :                                 memcpy(vec.ct.val, val[0].val, TDES_BLOCK_SIZE);
    2302                 :            :                         }
    2303                 :            :                 }
    2304                 :            :         }
    2305                 :            : 
    2306                 :          0 :         rte_free(val[0].val);
    2307                 :          0 :         rte_free(pt.val);
    2308                 :          0 :         rte_free(ct.val);
    2309                 :          0 :         rte_free(iv.val);
    2310                 :            : 
    2311                 :          0 :         return 0;
    2312                 :            : }
    2313                 :            : 
    2314                 :            : static int
    2315                 :          0 : fips_mct_aes_ecb_test(void)
    2316                 :            : {
    2317                 :            : #define AES_BLOCK_SIZE  16
    2318                 :            : #define AES_EXTERN_ITER 100
    2319                 :            : #define AES_INTERN_ITER 1000
    2320                 :          0 :         struct fips_val val = {NULL, 0}, val_key;
    2321                 :          0 :         uint8_t prev_out[AES_BLOCK_SIZE] = {0};
    2322                 :            :         uint32_t i, j, k;
    2323                 :            :         int ret;
    2324                 :            : 
    2325                 :          0 :         for (i = 0; i < AES_EXTERN_ITER; i++) {
    2326                 :          0 :                 if (i != 0)
    2327                 :          0 :                         update_info_vec(i);
    2328                 :            : 
    2329                 :          0 :                 fips_test_write_one_case();
    2330                 :            : 
    2331                 :          0 :                 for (j = 0; j < AES_INTERN_ITER; j++) {
    2332                 :          0 :                         ret = fips_run_test();
    2333                 :          0 :                         if (ret < 0) {
    2334                 :          0 :                                 if (ret == -EPERM) {
    2335                 :          0 :                                         if (info.file_type == FIPS_TYPE_JSON)
    2336                 :            :                                                 return ret;
    2337                 :            : 
    2338                 :          0 :                                         fprintf(info.fp_wr, "Bypass\n");
    2339                 :          0 :                                         return 0;
    2340                 :            :                                 }
    2341                 :            : 
    2342                 :            :                                 return ret;
    2343                 :            :                         }
    2344                 :            : 
    2345                 :          0 :                         ret = get_writeback_data(&val);
    2346                 :          0 :                         if (ret < 0)
    2347                 :          0 :                                 return ret;
    2348                 :            : 
    2349                 :          0 :                         if (info.op == FIPS_TEST_ENC_AUTH_GEN)
    2350                 :          0 :                                 memcpy(vec.pt.val, val.val, AES_BLOCK_SIZE);
    2351                 :            :                         else
    2352                 :          0 :                                 memcpy(vec.ct.val, val.val, AES_BLOCK_SIZE);
    2353                 :            : 
    2354                 :          0 :                         if (j == AES_INTERN_ITER - 1)
    2355                 :          0 :                                 continue;
    2356                 :            : 
    2357                 :          0 :                         memcpy(prev_out, val.val, AES_BLOCK_SIZE);
    2358                 :            :                 }
    2359                 :            : 
    2360                 :          0 :                 info.parse_writeback(&val);
    2361                 :          0 :                 fprintf(info.fp_wr, "\n");
    2362                 :            : 
    2363                 :          0 :                 if (i == AES_EXTERN_ITER - 1)
    2364                 :          0 :                         continue;
    2365                 :            : 
    2366                 :            :                 /** update key */
    2367                 :            :                 memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
    2368                 :          0 :                 for (k = 0; k < vec.cipher_auth.key.len; k++) {
    2369                 :          0 :                         switch (vec.cipher_auth.key.len) {
    2370                 :          0 :                         case 16:
    2371                 :          0 :                                 val_key.val[k] ^= val.val[k];
    2372                 :          0 :                                 break;
    2373                 :          0 :                         case 24:
    2374                 :          0 :                                 if (k < 8)
    2375                 :          0 :                                         val_key.val[k] ^= prev_out[k + 8];
    2376                 :            :                                 else
    2377                 :          0 :                                         val_key.val[k] ^= val.val[k - 8];
    2378                 :            :                                 break;
    2379                 :          0 :                         case 32:
    2380                 :          0 :                                 if (k < 16)
    2381                 :          0 :                                         val_key.val[k] ^= prev_out[k];
    2382                 :            :                                 else
    2383                 :          0 :                                         val_key.val[k] ^= val.val[k - 16];
    2384                 :            :                                 break;
    2385                 :            :                         default:
    2386                 :            :                                 return -1;
    2387                 :            :                         }
    2388                 :            :                 }
    2389                 :            :         }
    2390                 :            : 
    2391                 :          0 :         rte_free(val.val);
    2392                 :            : 
    2393                 :          0 :         return 0;
    2394                 :            : }
    2395                 :            : static int
    2396                 :          0 : fips_mct_aes_test(void)
    2397                 :            : {
    2398                 :            : #define AES_BLOCK_SIZE  16
    2399                 :            : #define AES_EXTERN_ITER 100
    2400                 :            : #define AES_INTERN_ITER 1000
    2401                 :          0 :         struct fips_val val[3] = {{NULL, 0},}, val_key,  pt, ct, iv;
    2402                 :          0 :         uint8_t prev_out[AES_BLOCK_SIZE] = {0};
    2403                 :          0 :         uint8_t prev_in[AES_BLOCK_SIZE] = {0};
    2404                 :            :         uint32_t i, j, k;
    2405                 :            :         int ret;
    2406                 :            : 
    2407                 :          0 :         if (info.interim_info.aes_data.cipher_algo == RTE_CRYPTO_CIPHER_AES_ECB)
    2408                 :          0 :                 return fips_mct_aes_ecb_test();
    2409                 :            : 
    2410                 :          0 :         pt.len = vec.pt.len;
    2411                 :          0 :         pt.val = rte_malloc(NULL, pt.len, 0);
    2412                 :          0 :         ct.len = vec.ct.len;
    2413                 :          0 :         ct.val = rte_malloc(NULL, ct.len, 0);
    2414                 :          0 :         iv.len = vec.iv.len;
    2415                 :          0 :         iv.val = rte_malloc(NULL, iv.len, 0);
    2416                 :          0 :         for (i = 0; i < AES_EXTERN_ITER; i++) {
    2417                 :          0 :                 if (info.file_type != FIPS_TYPE_JSON) {
    2418                 :          0 :                         if (i != 0)
    2419                 :          0 :                                 update_info_vec(i);
    2420                 :            : 
    2421                 :          0 :                         fips_test_write_one_case();
    2422                 :            :                 }
    2423                 :            : 
    2424                 :          0 :                 for (j = 0; j < AES_INTERN_ITER; j++) {
    2425                 :          0 :                         ret = fips_run_test();
    2426                 :          0 :                         if (ret < 0) {
    2427                 :          0 :                                 if (ret == -EPERM) {
    2428                 :          0 :                                         if (info.file_type == FIPS_TYPE_JSON)
    2429                 :            :                                                 return ret;
    2430                 :            : 
    2431                 :          0 :                                         fprintf(info.fp_wr, "Bypass\n");
    2432                 :          0 :                                         return 0;
    2433                 :            :                                 }
    2434                 :            : 
    2435                 :            :                                 return ret;
    2436                 :            :                         }
    2437                 :            : 
    2438                 :          0 :                         ret = get_writeback_data(&val[0]);
    2439                 :          0 :                         if (ret < 0)
    2440                 :          0 :                                 return ret;
    2441                 :            : 
    2442                 :          0 :                         if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
    2443                 :          0 :                                 memcpy(prev_in, vec.ct.val, AES_BLOCK_SIZE);
    2444                 :            : 
    2445                 :          0 :                         if (j == 0) {
    2446                 :          0 :                                 memcpy(prev_out, val[0].val, AES_BLOCK_SIZE);
    2447                 :          0 :                                 memcpy(pt.val, vec.pt.val, pt.len);
    2448                 :          0 :                                 memcpy(ct.val, vec.ct.val, ct.len);
    2449                 :          0 :                                 memcpy(iv.val, vec.iv.val, iv.len);
    2450                 :            : 
    2451                 :          0 :                                 if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
    2452                 :          0 :                                         memcpy(vec.pt.val, vec.iv.val, AES_BLOCK_SIZE);
    2453                 :          0 :                                         memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE);
    2454                 :          0 :                                         val[1].val = pt.val;
    2455                 :          0 :                                         val[1].len = pt.len;
    2456                 :          0 :                                         val[2].val = iv.val;
    2457                 :          0 :                                         val[2].len = iv.len;
    2458                 :            :                                 } else {
    2459                 :          0 :                                         memcpy(vec.ct.val, vec.iv.val, AES_BLOCK_SIZE);
    2460                 :          0 :                                         memcpy(vec.iv.val, prev_in, AES_BLOCK_SIZE);
    2461                 :          0 :                                         val[1].val = ct.val;
    2462                 :          0 :                                         val[1].len = ct.len;
    2463                 :          0 :                                         val[2].val = iv.val;
    2464                 :          0 :                                         val[2].len = iv.len;
    2465                 :            :                                 }
    2466                 :          0 :                                 continue;
    2467                 :            :                         }
    2468                 :            : 
    2469                 :          0 :                         if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
    2470                 :          0 :                                 memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE);
    2471                 :          0 :                                 memcpy(vec.pt.val, prev_out, AES_BLOCK_SIZE);
    2472                 :            :                         } else {
    2473                 :          0 :                                 memcpy(vec.iv.val, prev_in, AES_BLOCK_SIZE);
    2474                 :          0 :                                 memcpy(vec.ct.val, prev_out, AES_BLOCK_SIZE);
    2475                 :            :                         }
    2476                 :            : 
    2477                 :          0 :                         if (j == AES_INTERN_ITER - 1)
    2478                 :          0 :                                 continue;
    2479                 :            : 
    2480                 :          0 :                         memcpy(prev_out, val[0].val, AES_BLOCK_SIZE);
    2481                 :            :                 }
    2482                 :            : 
    2483                 :          0 :                 info.parse_writeback(val);
    2484                 :          0 :                 if (info.file_type != FIPS_TYPE_JSON)
    2485                 :          0 :                         fprintf(info.fp_wr, "\n");
    2486                 :            : 
    2487                 :          0 :                 if (i == AES_EXTERN_ITER - 1)
    2488                 :          0 :                         continue;
    2489                 :            : 
    2490                 :            :                 /** update key */
    2491                 :            :                 memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
    2492                 :          0 :                 for (k = 0; k < vec.cipher_auth.key.len; k++) {
    2493                 :          0 :                         switch (vec.cipher_auth.key.len) {
    2494                 :          0 :                         case 16:
    2495                 :          0 :                                 val_key.val[k] ^= val[0].val[k];
    2496                 :          0 :                                 break;
    2497                 :          0 :                         case 24:
    2498                 :          0 :                                 if (k < 8)
    2499                 :          0 :                                         val_key.val[k] ^= prev_out[k + 8];
    2500                 :            :                                 else
    2501                 :          0 :                                         val_key.val[k] ^= val[0].val[k - 8];
    2502                 :            :                                 break;
    2503                 :          0 :                         case 32:
    2504                 :          0 :                                 if (k < 16)
    2505                 :          0 :                                         val_key.val[k] ^= prev_out[k];
    2506                 :            :                                 else
    2507                 :          0 :                                         val_key.val[k] ^= val[0].val[k - 16];
    2508                 :            :                                 break;
    2509                 :            :                         default:
    2510                 :            :                                 return -1;
    2511                 :            :                         }
    2512                 :            :                 }
    2513                 :            : 
    2514                 :          0 :                 if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
    2515                 :          0 :                         memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE);
    2516                 :            :         }
    2517                 :            : 
    2518                 :          0 :         rte_free(val[0].val);
    2519                 :          0 :         rte_free(pt.val);
    2520                 :          0 :         rte_free(ct.val);
    2521                 :          0 :         rte_free(iv.val);
    2522                 :            : 
    2523                 :          0 :         return 0;
    2524                 :            : }
    2525                 :            : 
    2526                 :            : static int
    2527                 :          0 : fips_mct_sha_test(void)
    2528                 :          0 : {
    2529                 :            : #define SHA_EXTERN_ITER 100
    2530                 :            : #define SHA_INTERN_ITER 1000
    2531                 :          0 :         uint8_t md_blocks = info.interim_info.sha_data.md_blocks;
    2532                 :          0 :         struct fips_val val = {NULL, 0};
    2533                 :          0 :         struct fips_val  md[md_blocks];
    2534                 :            :         int ret;
    2535                 :            :         uint32_t i, j, k, offset, max_outlen;
    2536                 :            : 
    2537                 :          0 :         max_outlen = md_blocks * vec.cipher_auth.digest.len;
    2538                 :            : 
    2539                 :          0 :         rte_free(vec.cipher_auth.digest.val);
    2540                 :          0 :         vec.cipher_auth.digest.val = rte_malloc(NULL, max_outlen, 0);
    2541                 :            : 
    2542                 :          0 :         if (vec.pt.val)
    2543                 :          0 :                 memcpy(vec.cipher_auth.digest.val, vec.pt.val, vec.cipher_auth.digest.len);
    2544                 :            : 
    2545                 :          0 :         rte_free(vec.pt.val);
    2546                 :          0 :         vec.pt.val = rte_malloc(NULL, (MAX_DIGEST_SIZE*md_blocks), 0);
    2547                 :            : 
    2548                 :          0 :         for (i = 0; i < md_blocks; i++)
    2549                 :          0 :                 md[i].val = rte_malloc(NULL, (MAX_DIGEST_SIZE*2), 0);
    2550                 :            : 
    2551                 :          0 :         if (info.file_type != FIPS_TYPE_JSON) {
    2552                 :          0 :                 fips_test_write_one_case();
    2553                 :          0 :                 fprintf(info.fp_wr, "\n");
    2554                 :            :         }
    2555                 :            : 
    2556                 :          0 :         for (j = 0; j < SHA_EXTERN_ITER; j++) {
    2557                 :          0 :                 for (i = 0; i < md_blocks; i++) {
    2558                 :          0 :                         memcpy(md[i].val, vec.cipher_auth.digest.val,
    2559                 :          0 :                                 vec.cipher_auth.digest.len);
    2560                 :          0 :                         md[i].len = vec.cipher_auth.digest.len;
    2561                 :            :                 }
    2562                 :            : 
    2563                 :          0 :                 for (i = 0; i < (SHA_INTERN_ITER); i++) {
    2564                 :            :                         offset = 0;
    2565                 :          0 :                         for (k = 0; k < md_blocks; k++) {
    2566                 :          0 :                                 memcpy(vec.pt.val + offset, md[k].val, (size_t)md[k].len);
    2567                 :          0 :                                 offset += md[k].len;
    2568                 :            :                         }
    2569                 :          0 :                         vec.pt.len = offset;
    2570                 :            : 
    2571                 :          0 :                         ret = fips_run_test();
    2572                 :          0 :                         if (ret < 0) {
    2573                 :          0 :                                 if (ret == -EPERM || ret == -ENOTSUP) {
    2574                 :          0 :                                         if (info.file_type == FIPS_TYPE_JSON)
    2575                 :            :                                                 return ret;
    2576                 :            : 
    2577                 :          0 :                                         fprintf(info.fp_wr, "Bypass\n\n");
    2578                 :          0 :                                         return 0;
    2579                 :            :                                 }
    2580                 :            :                                 return ret;
    2581                 :            :                         }
    2582                 :            : 
    2583                 :          0 :                         ret = get_writeback_data(&val);
    2584                 :          0 :                         if (ret < 0)
    2585                 :          0 :                                 return ret;
    2586                 :            : 
    2587                 :          0 :                         for (k = 1; k < md_blocks; k++) {
    2588                 :          0 :                                 memcpy(md[k-1].val, md[k].val, md[k].len);
    2589                 :          0 :                                 md[k-1].len = md[k].len;
    2590                 :            :                         }
    2591                 :            : 
    2592                 :          0 :                         memcpy(md[md_blocks-1].val, (val.val + vec.pt.len),
    2593                 :          0 :                                 vec.cipher_auth.digest.len);
    2594                 :          0 :                         md[md_blocks-1].len = vec.cipher_auth.digest.len;
    2595                 :            :                 }
    2596                 :            : 
    2597                 :          0 :                 memcpy(vec.cipher_auth.digest.val, md[md_blocks-1].val, md[md_blocks-1].len);
    2598                 :          0 :                 vec.cipher_auth.digest.len = md[md_blocks-1].len;
    2599                 :            : 
    2600                 :          0 :                 if (info.file_type != FIPS_TYPE_JSON)
    2601                 :          0 :                         fprintf(info.fp_wr, "COUNT = %u\n", j);
    2602                 :            : 
    2603                 :          0 :                 info.parse_writeback(&val);
    2604                 :            : 
    2605                 :          0 :                 if (info.file_type != FIPS_TYPE_JSON)
    2606                 :          0 :                         fprintf(info.fp_wr, "\n");
    2607                 :            :         }
    2608                 :            : 
    2609                 :          0 :         for (i = 0; i < (md_blocks); i++)
    2610                 :          0 :                 rte_free(md[i].val);
    2611                 :            : 
    2612                 :          0 :         rte_free(vec.pt.val);
    2613                 :          0 :         vec.pt.val = NULL;
    2614                 :          0 :         rte_free(val.val);
    2615                 :          0 :         return 0;
    2616                 :            : }
    2617                 :            : 
    2618                 :            : static int
    2619                 :          0 : fips_mct_shake_test(void)
    2620                 :            : {
    2621                 :            : #define SHAKE_EXTERN_ITER       100
    2622                 :            : #define SHAKE_INTERN_ITER       1000
    2623                 :            :         uint32_t i, j, range, outlen, max_outlen;
    2624                 :          0 :         struct fips_val val = {NULL, 0}, md;
    2625                 :            :         uint8_t rightmost[2];
    2626                 :            :         uint16_t *rightptr;
    2627                 :            :         int ret;
    2628                 :            : 
    2629                 :          0 :         max_outlen = vec.cipher_auth.digest.len;
    2630                 :            : 
    2631                 :          0 :         rte_free(vec.cipher_auth.digest.val);
    2632                 :          0 :         vec.cipher_auth.digest.val = rte_malloc(NULL, max_outlen, 0);
    2633                 :            : 
    2634                 :          0 :         if (vec.pt.val)
    2635                 :          0 :                 memcpy(vec.cipher_auth.digest.val, vec.pt.val, vec.pt.len);
    2636                 :            : 
    2637                 :          0 :         rte_free(vec.pt.val);
    2638                 :          0 :         vec.pt.val = rte_malloc(NULL, 16, 0);
    2639                 :          0 :         vec.pt.len = 16;
    2640                 :            : 
    2641                 :          0 :         md.val = rte_malloc(NULL, max_outlen, 0);
    2642                 :            :         md.len = max_outlen;
    2643                 :            : 
    2644                 :          0 :         if (info.file_type != FIPS_TYPE_JSON) {
    2645                 :          0 :                 fips_test_write_one_case();
    2646                 :          0 :                 fprintf(info.fp_wr, "\n");
    2647                 :            :         }
    2648                 :            : 
    2649                 :          0 :         range = max_outlen - info.interim_info.sha_data.min_outlen + 1;
    2650                 :            :         outlen = max_outlen;
    2651                 :          0 :         for (j = 0; j < SHAKE_EXTERN_ITER; j++) {
    2652                 :            :                 memset(md.val, 0, max_outlen);
    2653                 :          0 :                 memcpy(md.val, vec.cipher_auth.digest.val,
    2654                 :          0 :                         vec.cipher_auth.digest.len);
    2655                 :            : 
    2656                 :          0 :                 for (i = 0; i < (SHAKE_INTERN_ITER); i++) {
    2657                 :          0 :                         memset(vec.pt.val, 0, vec.pt.len);
    2658                 :          0 :                         memcpy(vec.pt.val, md.val, vec.pt.len);
    2659                 :          0 :                         vec.cipher_auth.digest.len = outlen;
    2660                 :          0 :                         ret = fips_run_test();
    2661                 :          0 :                         if (ret < 0) {
    2662                 :          0 :                                 if (ret == -EPERM || ret == -ENOTSUP) {
    2663                 :          0 :                                         if (info.file_type == FIPS_TYPE_JSON)
    2664                 :            :                                                 return ret;
    2665                 :            : 
    2666                 :          0 :                                         fprintf(info.fp_wr, "Bypass\n\n");
    2667                 :          0 :                                         return 0;
    2668                 :            :                                 }
    2669                 :            :                                 return ret;
    2670                 :            :                         }
    2671                 :            : 
    2672                 :          0 :                         ret = get_writeback_data(&val);
    2673                 :          0 :                         if (ret < 0)
    2674                 :          0 :                                 return ret;
    2675                 :            : 
    2676                 :            :                         memset(md.val, 0, max_outlen);
    2677                 :          0 :                         memcpy(md.val, (val.val + vec.pt.len),
    2678                 :          0 :                                 vec.cipher_auth.digest.len);
    2679                 :            :                         md.len = outlen;
    2680                 :          0 :                         rightmost[0] = md.val[md.len-1];
    2681                 :          0 :                         rightmost[1] = md.val[md.len-2];
    2682                 :            :                         rightptr = (uint16_t *)rightmost;
    2683                 :          0 :                         outlen = info.interim_info.sha_data.min_outlen +
    2684                 :          0 :                                 (*rightptr % range);
    2685                 :            :                 }
    2686                 :            : 
    2687                 :          0 :                 memcpy(vec.cipher_auth.digest.val, md.val, md.len);
    2688                 :          0 :                 vec.cipher_auth.digest.len = md.len;
    2689                 :            : 
    2690                 :          0 :                 if (info.file_type != FIPS_TYPE_JSON)
    2691                 :          0 :                         fprintf(info.fp_wr, "COUNT = %u\n", j);
    2692                 :            : 
    2693                 :          0 :                 info.parse_writeback(&val);
    2694                 :            : 
    2695                 :          0 :                 if (info.file_type != FIPS_TYPE_JSON)
    2696                 :          0 :                         fprintf(info.fp_wr, "\n");
    2697                 :            :         }
    2698                 :            : 
    2699                 :          0 :         rte_free(md.val);
    2700                 :          0 :         rte_free(vec.pt.val);
    2701                 :          0 :         vec.pt.val = NULL;
    2702                 :          0 :         rte_free(val.val);
    2703                 :          0 :         return 0;
    2704                 :            : }
    2705                 :            : 
    2706                 :            : static int
    2707                 :          0 : init_test_ops(void)
    2708                 :            : {
    2709                 :          0 :         switch (info.algo) {
    2710                 :          0 :         case FIPS_TEST_ALGO_AES_CBC:
    2711                 :            :         case FIPS_TEST_ALGO_AES_CTR:
    2712                 :            :         case FIPS_TEST_ALGO_AES:
    2713                 :          0 :                 test_ops.prepare_sym_op = prepare_cipher_op;
    2714                 :          0 :                 test_ops.prepare_sym_xform  = prepare_aes_xform;
    2715                 :          0 :                 if (info.interim_info.aes_data.test_type == AESAVS_TYPE_MCT)
    2716                 :          0 :                         test_ops.test = fips_mct_aes_test;
    2717                 :            :                 else
    2718                 :          0 :                         test_ops.test = fips_generic_test;
    2719                 :            :                 break;
    2720                 :          0 :         case FIPS_TEST_ALGO_HMAC:
    2721                 :          0 :                 test_ops.prepare_sym_op = prepare_auth_op;
    2722                 :          0 :                 test_ops.prepare_sym_xform = prepare_hmac_xform;
    2723                 :          0 :                 test_ops.test = fips_generic_test;
    2724                 :          0 :                 break;
    2725                 :          0 :         case FIPS_TEST_ALGO_TDES:
    2726                 :          0 :                 test_ops.prepare_sym_op = prepare_cipher_op;
    2727                 :          0 :                 test_ops.prepare_sym_xform = prepare_tdes_xform;
    2728                 :          0 :                 if (info.interim_info.tdes_data.test_type == TDES_MCT)
    2729                 :          0 :                         test_ops.test = fips_mct_tdes_test;
    2730                 :            :                 else
    2731                 :          0 :                         test_ops.test = fips_generic_test;
    2732                 :            :                 break;
    2733                 :          0 :         case FIPS_TEST_ALGO_AES_GMAC:
    2734                 :          0 :                 test_ops.prepare_sym_op = prepare_auth_op;
    2735                 :          0 :                 test_ops.prepare_sym_xform = prepare_gmac_xform;
    2736                 :          0 :                 test_ops.test = fips_generic_test;
    2737                 :          0 :                 break;
    2738                 :          0 :         case FIPS_TEST_ALGO_AES_GCM:
    2739                 :          0 :                 test_ops.prepare_sym_op = prepare_aead_op;
    2740                 :          0 :                 test_ops.prepare_sym_xform = prepare_gcm_xform;
    2741                 :          0 :                 test_ops.test = fips_generic_test;
    2742                 :          0 :                 break;
    2743                 :          0 :         case FIPS_TEST_ALGO_AES_CMAC:
    2744                 :          0 :                 test_ops.prepare_sym_op = prepare_auth_op;
    2745                 :          0 :                 test_ops.prepare_sym_xform = prepare_cmac_xform;
    2746                 :          0 :                 test_ops.test = fips_generic_test;
    2747                 :          0 :                 break;
    2748                 :          0 :         case FIPS_TEST_ALGO_AES_CCM:
    2749                 :          0 :                 test_ops.prepare_sym_op = prepare_aead_op;
    2750                 :          0 :                 test_ops.prepare_sym_xform = prepare_ccm_xform;
    2751                 :          0 :                 test_ops.test = fips_generic_test;
    2752                 :          0 :                 break;
    2753                 :          0 :         case FIPS_TEST_ALGO_SHA:
    2754                 :          0 :                 test_ops.prepare_sym_op = prepare_auth_op;
    2755                 :          0 :                 test_ops.prepare_sym_xform = prepare_sha_xform;
    2756                 :          0 :                 if (info.interim_info.sha_data.test_type == SHA_MCT)
    2757                 :          0 :                         if (info.interim_info.sha_data.algo == RTE_CRYPTO_AUTH_SHAKE_128 ||
    2758                 :            :                                 info.interim_info.sha_data.algo == RTE_CRYPTO_AUTH_SHAKE_256)
    2759                 :          0 :                                 test_ops.test = fips_mct_shake_test;
    2760                 :            :                         else
    2761                 :          0 :                                 test_ops.test = fips_mct_sha_test;
    2762                 :            :                 else
    2763                 :          0 :                         test_ops.test = fips_generic_test;
    2764                 :            :                 break;
    2765                 :          0 :         case FIPS_TEST_ALGO_AES_XTS:
    2766                 :          0 :                 test_ops.prepare_sym_op = prepare_cipher_op;
    2767                 :          0 :                 test_ops.prepare_sym_xform = prepare_xts_xform;
    2768                 :          0 :                 test_ops.test = fips_generic_test;
    2769                 :          0 :                 break;
    2770                 :          0 :         case FIPS_TEST_ALGO_RSA:
    2771                 :          0 :                 test_ops.prepare_asym_op = prepare_rsa_op;
    2772                 :          0 :                 test_ops.prepare_asym_xform = prepare_rsa_xform;
    2773                 :          0 :                 test_ops.test = fips_generic_test;
    2774                 :          0 :                 break;
    2775                 :          0 :         case FIPS_TEST_ALGO_ECDSA:
    2776                 :          0 :                 if (info.op == FIPS_TEST_ASYM_KEYGEN) {
    2777                 :          0 :                         test_ops.prepare_asym_op = prepare_ecfpm_op;
    2778                 :          0 :                         test_ops.prepare_asym_xform = prepare_ecfpm_xform;
    2779                 :          0 :                         test_ops.test = fips_generic_test;
    2780                 :            :                 } else {
    2781                 :          0 :                         test_ops.prepare_asym_op = prepare_ecdsa_op;
    2782                 :          0 :                         test_ops.prepare_asym_xform = prepare_ecdsa_xform;
    2783                 :          0 :                         test_ops.test = fips_generic_test;
    2784                 :            :                 }
    2785                 :            :                 break;
    2786                 :          0 :         case FIPS_TEST_ALGO_EDDSA:
    2787                 :          0 :                 if (info.op == FIPS_TEST_ASYM_KEYGEN) {
    2788                 :          0 :                         test_ops.prepare_asym_op = prepare_edfpm_op;
    2789                 :          0 :                         test_ops.prepare_asym_xform = prepare_edfpm_xform;
    2790                 :          0 :                         test_ops.test = fips_generic_test;
    2791                 :            :                 } else {
    2792                 :          0 :                         test_ops.prepare_asym_op = prepare_eddsa_op;
    2793                 :          0 :                         test_ops.prepare_asym_xform = prepare_eddsa_xform;
    2794                 :          0 :                         test_ops.test = fips_generic_test;
    2795                 :            :                 }
    2796                 :            :                 break;
    2797                 :          0 :         default:
    2798                 :          0 :                 if (strstr(info.file_name, "TECB") ||
    2799                 :          0 :                                 strstr(info.file_name, "TCBC")) {
    2800                 :          0 :                         info.algo = FIPS_TEST_ALGO_TDES;
    2801                 :          0 :                         test_ops.prepare_sym_op = prepare_cipher_op;
    2802                 :          0 :                         test_ops.prepare_sym_xform = prepare_tdes_xform;
    2803                 :          0 :                         if (info.interim_info.tdes_data.test_type == TDES_MCT)
    2804                 :          0 :                                 test_ops.test = fips_mct_tdes_test;
    2805                 :            :                         else
    2806                 :          0 :                                 test_ops.test = fips_generic_test;
    2807                 :            :                         break;
    2808                 :            :                 }
    2809                 :            :                 return -1;
    2810                 :            :         }
    2811                 :            : 
    2812                 :            :         return 0;
    2813                 :            : }
    2814                 :            : 
    2815                 :            : static void
    2816                 :          0 : print_test_block(void)
    2817                 :            : {
    2818                 :            :         uint32_t i;
    2819                 :            : 
    2820                 :          0 :         for (i = 0; i < info.nb_vec_lines; i++)
    2821                 :          0 :                 printf("%s\n", info.vec[i]);
    2822                 :            : 
    2823                 :            :         printf("\n");
    2824                 :          0 : }
    2825                 :            : 
    2826                 :            : static int
    2827                 :          0 : fips_test_one_file(void)
    2828                 :          0 : {
    2829                 :            :         int fetch_ret = 0, ret;
    2830                 :            : 
    2831                 :          0 :         ret = init_test_ops();
    2832                 :          0 :         if (ret < 0) {
    2833                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Init test op\n", ret);
    2834                 :          0 :                 return ret;
    2835                 :            :         }
    2836                 :            : 
    2837                 :          0 :         while (ret >= 0 && fetch_ret == 0) {
    2838                 :          0 :                 fetch_ret = fips_test_fetch_one_block();
    2839                 :          0 :                 if (fetch_ret < 0) {
    2840                 :          0 :                         RTE_LOG(ERR, USER1, "Error %i: Fetch block\n",
    2841                 :            :                                         fetch_ret);
    2842                 :            :                         ret = fetch_ret;
    2843                 :          0 :                         goto error_one_case;
    2844                 :            :                 }
    2845                 :            : 
    2846                 :          0 :                 if (info.nb_vec_lines == 0) {
    2847                 :          0 :                         if (fetch_ret == -EOF)
    2848                 :            :                                 break;
    2849                 :            : 
    2850                 :          0 :                         fprintf(info.fp_wr, "\n");
    2851                 :          0 :                         continue;
    2852                 :            :                 }
    2853                 :            : 
    2854                 :          0 :                 ret = fips_test_parse_one_case();
    2855                 :          0 :                 switch (ret) {
    2856                 :          0 :                 case 0:
    2857                 :          0 :                         ret = test_ops.test();
    2858                 :          0 :                         if (ret == 0)
    2859                 :            :                                 break;
    2860                 :          0 :                         RTE_LOG(ERR, USER1, "Error %i: test block\n",
    2861                 :            :                                         ret);
    2862                 :          0 :                         goto error_one_case;
    2863                 :            :                 case 1:
    2864                 :            :                         break;
    2865                 :          0 :                 default:
    2866                 :          0 :                         RTE_LOG(ERR, USER1, "Error %i: Parse block\n",
    2867                 :            :                                         ret);
    2868                 :          0 :                         goto error_one_case;
    2869                 :            :                 }
    2870                 :            : 
    2871                 :          0 :                 continue;
    2872                 :          0 : error_one_case:
    2873                 :          0 :                 print_test_block();
    2874                 :            :         }
    2875                 :            : 
    2876                 :          0 :         fips_test_clear();
    2877                 :            : 
    2878                 :          0 :         if (env.digest) {
    2879                 :          0 :                 rte_free(env.digest);
    2880                 :          0 :                 env.digest = NULL;
    2881                 :          0 :                 env.digest_len = 0;
    2882                 :            :         }
    2883                 :          0 :         rte_pktmbuf_free(env.mbuf);
    2884                 :            : 
    2885                 :          0 :         return ret;
    2886                 :            : }
    2887                 :            : 
    2888                 :            : #ifdef USE_JANSSON
    2889                 :            : static int
    2890                 :          0 : fips_test_json_init_writeback(void)
    2891                 :            : {
    2892                 :            :         json_t *session_info, *session_write;
    2893                 :          0 :         session_info = json_array_get(json_info.json_root, 0);
    2894                 :          0 :         session_write = json_object();
    2895                 :          0 :         json_info.json_write_root = json_array();
    2896                 :            : 
    2897                 :          0 :         json_object_set(session_write, "jwt",
    2898                 :            :                 json_object_get(session_info, "jwt"));
    2899                 :          0 :         json_object_set(session_write, "url",
    2900                 :            :                 json_object_get(session_info, "url"));
    2901                 :          0 :         json_object_set(session_write, "isSample",
    2902                 :            :                 json_object_get(session_info, "isSample"));
    2903                 :            : 
    2904                 :          0 :         json_info.is_sample = json_boolean_value(
    2905                 :            :                 json_object_get(session_info, "isSample"));
    2906                 :            : 
    2907                 :          0 :         json_array_append_new(json_info.json_write_root, session_write);
    2908                 :          0 :         return 0;
    2909                 :            : }
    2910                 :            : 
    2911                 :            : static int
    2912                 :          0 : fips_test_one_test_case(void)
    2913                 :            : {
    2914                 :            :         int ret;
    2915                 :            : 
    2916                 :          0 :         ret = fips_test_parse_one_json_case();
    2917                 :            : 
    2918                 :          0 :         switch (ret) {
    2919                 :          0 :         case 0:
    2920                 :          0 :                 ret = test_ops.test();
    2921                 :          0 :                 if ((ret == 0) || (ret == -EPERM || ret == -ENOTSUP))
    2922                 :            :                         break;
    2923                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: test block\n",
    2924                 :            :                                 ret);
    2925                 :          0 :                 break;
    2926                 :          0 :         default:
    2927                 :          0 :                 RTE_LOG(ERR, USER1, "Error %i: Parse block\n",
    2928                 :            :                                 ret);
    2929                 :            :         }
    2930                 :          0 :         return ret;
    2931                 :            : }
    2932                 :            : 
    2933                 :            : static int
    2934                 :          0 : fips_test_one_test_group(void)
    2935                 :            : {
    2936                 :            :         int ret;
    2937                 :            :         json_t *tests, *write_tests;
    2938                 :            :         size_t test_idx, tests_size;
    2939                 :            : 
    2940                 :          0 :         write_tests = json_array();
    2941                 :          0 :         json_info.json_write_group = json_object();
    2942                 :          0 :         json_object_set(json_info.json_write_group, "tgId",
    2943                 :          0 :                 json_object_get(json_info.json_test_group, "tgId"));
    2944                 :          0 :         json_object_set_new(json_info.json_write_group, "tests", write_tests);
    2945                 :            : 
    2946                 :          0 :         switch (info.algo) {
    2947                 :          0 :         case FIPS_TEST_ALGO_AES_GMAC:
    2948                 :            :         case FIPS_TEST_ALGO_AES_GCM:
    2949                 :          0 :                 ret = parse_test_gcm_json_init();
    2950                 :          0 :                 break;
    2951                 :          0 :         case FIPS_TEST_ALGO_AES_CCM:
    2952                 :          0 :                 ret = parse_test_ccm_json_init();
    2953                 :          0 :                 break;
    2954                 :          0 :         case FIPS_TEST_ALGO_HMAC:
    2955                 :          0 :                 ret = parse_test_hmac_json_init();
    2956                 :          0 :                 break;
    2957                 :          0 :         case FIPS_TEST_ALGO_AES_CMAC:
    2958                 :          0 :                 ret = parse_test_cmac_json_init();
    2959                 :          0 :                 break;
    2960                 :          0 :         case FIPS_TEST_ALGO_AES_XTS:
    2961                 :          0 :                 ret = parse_test_xts_json_init();
    2962                 :          0 :                 break;
    2963                 :          0 :         case FIPS_TEST_ALGO_AES_CBC:
    2964                 :            :         case FIPS_TEST_ALGO_AES_CTR:
    2965                 :            :         case FIPS_TEST_ALGO_AES:
    2966                 :          0 :                 ret = parse_test_aes_json_init();
    2967                 :          0 :                 break;
    2968                 :          0 :         case FIPS_TEST_ALGO_SHA:
    2969                 :          0 :                 ret = parse_test_sha_json_init();
    2970                 :          0 :                 break;
    2971                 :          0 :         case FIPS_TEST_ALGO_TDES:
    2972                 :          0 :                 ret = parse_test_tdes_json_init();
    2973                 :          0 :                 break;
    2974                 :          0 :         case FIPS_TEST_ALGO_RSA:
    2975                 :          0 :                 ret = parse_test_rsa_json_init();
    2976                 :          0 :                 break;
    2977                 :          0 :         case FIPS_TEST_ALGO_ECDSA:
    2978                 :          0 :                 ret = parse_test_ecdsa_json_init();
    2979                 :          0 :                 break;
    2980                 :          0 :         case FIPS_TEST_ALGO_EDDSA:
    2981                 :          0 :                 ret = parse_test_eddsa_json_init();
    2982                 :          0 :                 break;
    2983                 :            :         default:
    2984                 :            :                 return -EINVAL;
    2985                 :            :         }
    2986                 :            : 
    2987                 :          0 :         if (ret < 0)
    2988                 :            :                 return ret;
    2989                 :            : 
    2990                 :          0 :         ret = fips_test_parse_one_json_group();
    2991                 :          0 :         if (ret < 0)
    2992                 :            :                 return ret;
    2993                 :            : 
    2994                 :          0 :         ret = init_test_ops();
    2995                 :          0 :         if (ret < 0)
    2996                 :            :                 return ret;
    2997                 :            : 
    2998                 :          0 :         tests = json_object_get(json_info.json_test_group, "tests");
    2999                 :          0 :         tests_size = json_array_size(tests);
    3000                 :          0 :         for (test_idx = 0; test_idx < tests_size; test_idx++) {
    3001                 :          0 :                 json_info.json_test_case = json_array_get(tests, test_idx);
    3002                 :          0 :                 if (fips_test_one_test_case() == 0)
    3003                 :          0 :                         json_array_append_new(write_tests, json_info.json_write_case);
    3004                 :            :         }
    3005                 :            : 
    3006                 :            :         return 0;
    3007                 :            : }
    3008                 :            : 
    3009                 :            : static int
    3010                 :          0 : fips_test_one_vector_set(void)
    3011                 :            : {
    3012                 :            :         int ret;
    3013                 :            :         json_t *test_groups, *write_groups, *write_version, *write_set, *mode;
    3014                 :            :         size_t group_idx, num_groups;
    3015                 :            : 
    3016                 :          0 :         test_groups = json_object_get(json_info.json_vector_set, "testGroups");
    3017                 :          0 :         num_groups = json_array_size(test_groups);
    3018                 :            : 
    3019                 :          0 :         json_info.json_write_set = json_array();
    3020                 :          0 :         write_version = json_object();
    3021                 :          0 :         json_object_set_new(write_version, "acvVersion", json_string(ACVVERSION));
    3022                 :          0 :         json_array_append_new(json_info.json_write_set, write_version);
    3023                 :            : 
    3024                 :          0 :         write_set = json_object();
    3025                 :          0 :         json_array_append(json_info.json_write_set, write_set);
    3026                 :          0 :         write_groups = json_array();
    3027                 :            : 
    3028                 :          0 :         json_object_set(write_set, "vsId",
    3029                 :          0 :                 json_object_get(json_info.json_vector_set, "vsId"));
    3030                 :          0 :         json_object_set(write_set, "algorithm",
    3031                 :          0 :                 json_object_get(json_info.json_vector_set, "algorithm"));
    3032                 :          0 :         mode = json_object_get(json_info.json_vector_set, "mode");
    3033                 :          0 :         if (mode != NULL)
    3034                 :          0 :                 json_object_set_new(write_set, "mode", mode);
    3035                 :            : 
    3036                 :          0 :         json_object_set(write_set, "revision",
    3037                 :          0 :                 json_object_get(json_info.json_vector_set, "revision"));
    3038                 :          0 :         json_object_set_new(write_set, "isSample",
    3039                 :          0 :                 json_boolean(json_info.is_sample));
    3040                 :          0 :         json_object_set_new(write_set, "testGroups", write_groups);
    3041                 :            : 
    3042                 :          0 :         ret = fips_test_parse_one_json_vector_set();
    3043                 :          0 :         if (ret < 0) {
    3044                 :          0 :                 RTE_LOG(ERR, USER1, "Error: Unsupported or invalid vector set algorithm: %s\n",
    3045                 :            :                         json_string_value(json_object_get(json_info.json_vector_set, "algorithm")));
    3046                 :          0 :                 return ret;
    3047                 :            :         }
    3048                 :            : 
    3049                 :          0 :         for (group_idx = 0; group_idx < num_groups; group_idx++) {
    3050                 :          0 :                 json_info.json_test_group = json_array_get(test_groups, group_idx);
    3051                 :          0 :                 ret = fips_test_one_test_group();
    3052                 :          0 :                 json_array_append_new(write_groups, json_info.json_write_group);
    3053                 :            :         }
    3054                 :            : 
    3055                 :            :         return 0;
    3056                 :            : }
    3057                 :            : 
    3058                 :            : static int
    3059                 :          0 : fips_test_one_json_file(void)
    3060                 :            : {
    3061                 :            :         size_t vector_set_idx, root_size;
    3062                 :            : 
    3063                 :          0 :         root_size = json_array_size(json_info.json_root);
    3064                 :          0 :         fips_test_json_init_writeback();
    3065                 :            : 
    3066                 :          0 :         for (vector_set_idx = 1; vector_set_idx < root_size; vector_set_idx++) {
    3067                 :            :                 /* Vector set index starts at 1, the 0th index contains test session
    3068                 :            :                  * information.
    3069                 :            :                  */
    3070                 :          0 :                 json_info.json_vector_set = json_array_get(json_info.json_root, vector_set_idx);
    3071                 :          0 :                 fips_test_one_vector_set();
    3072                 :          0 :                 json_array_append_new(json_info.json_write_root, json_info.json_write_set);
    3073                 :          0 :                 json_incref(json_info.json_write_set);
    3074                 :            :         }
    3075                 :            : 
    3076                 :          0 :         json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4));
    3077                 :          0 :         json_decref(json_info.json_write_root);
    3078                 :            : 
    3079                 :          0 :         return 0;
    3080                 :            : }
    3081                 :            : #endif /* USE_JANSSON */

Generated by: LCOV version 1.14