#include <sys/stat.h>
#include <getopt.h>
#include <dirent.h>
#include <stdlib.h>
#include "fips_validation.h"
#include "fips_dev_self_test.h"
enum {
#define OPT_REQ_FILE_PATH "req-file"
OPT_REQ_FILE_PATH_NUM = 256,
#define OPT_RSP_FILE_PATH "rsp-file"
OPT_RSP_FILE_PATH_NUM,
#define OPT_MBUF_DATAROOM "mbuf-dataroom"
OPT_MBUF_DATAROOM_NUM,
#define OPT_FOLDER "path-is-folder"
OPT_FOLDER_NUM,
#define OPT_CRYPTODEV "cryptodev"
OPT_CRYPTODEV_NUM,
#define OPT_CRYPTODEV_ID "cryptodev-id"
OPT_CRYPTODEV_ID_NUM,
#define OPT_CRYPTODEV_ST "self-test"
OPT_CRYPTODEV_ST_NUM,
#define OPT_CRYPTODEV_BK_ID "broken-test-id"
OPT_CRYPTODEV_BK_ID_NUM,
#define OPT_CRYPTODEV_BK_DIR_KEY "broken-test-dir"
OPT_CRYPTODEV_BK_DIR_KEY_NUM,
#define OPT_USE_JSON "use-json"
OPT_USE_JSON_NUM,
#define OPT_CRYPTODEV_ASYM "asymmetric"
OPT_CRYPTODEV_ASYM_NUM,
};
struct fips_test_vector vec;
struct fips_test_interim_info info;
#ifdef USE_JANSSON
struct fips_test_json_info json_info;
#endif
struct cryptodev_fips_validate_env {
const char *req_path;
const char *rsp_path;
uint32_t is_path_folder;
uint8_t dev_id;
struct fips_sym_env {
struct rte_cryptodev_sym_session *sess;
struct fips_asym_env {
struct rte_cryptodev_asym_session *sess;
uint8_t dev_support_sgl;
uint16_t mbuf_data_room;
uint8_t *digest;
uint16_t digest_len;
bool is_asym_test;
uint16_t self_test;
struct fips_dev_broken_test_config *broken_test_config;
} env;
static int
cryptodev_fips_validate_app_sym_init(void)
{
env.dev_id);
struct fips_sym_env *sym = &env.
sym;
int ret;
env.dev_support_sgl = 1;
else
env.dev_support_sgl = 0;
ret = -ENOMEM;
if (!sym->sess_mpool)
goto error_exit;
"FIPS_OP_SYM_POOL",
1, 0,
16,
if (!sym->op_pool)
goto error_exit;
if (!sym->op)
goto error_exit;
return 0;
error_exit:
return ret;
}
static void
cryptodev_fips_validate_app_sym_uninit(void)
{
struct fips_sym_env *sym = &env.sym;
}
static int
cryptodev_fips_validate_app_asym_init(void)
{
struct fips_asym_env *asym = &env.asym;
int ret;
ret = -ENOMEM;
if (!asym->sess_mpool)
goto error_exit;
"FIPS_OP_ASYM_POOL",
1, 0,
16,
if (!asym->op_pool)
goto error_exit;
if (!asym->op)
goto error_exit;
return 0;
error_exit:
return ret;
}
static void
cryptodev_fips_validate_app_asym_uninit(void)
{
struct fips_asym_env *asym = &env.asym;
}
static int
cryptodev_fips_validate_app_init(void)
{
uint32_t nb_mbufs = UINT16_MAX / env.mbuf_data_room + 1;
int ret;
if (env.self_test) {
ret = fips_dev_self_test(env.dev_id, env.broken_test_config);
if (ret < 0) {
return ret;
}
}
if (ret < 0)
return ret;
ret = -ENOMEM;
0, 0,
sizeof(
struct rte_mbuf) + RTE_PKTMBUF_HEADROOM +
if (!env.mpool)
return ret;
ret = cryptodev_fips_validate_app_sym_init();
if (ret < 0)
goto error_exit;
if (env.is_asym_test) {
ret = cryptodev_fips_validate_app_asym_init();
if (ret < 0)
goto error_exit;
}
if (ret < 0)
goto error_exit;
if (ret < 0)
goto error_exit;
return 0;
error_exit:
return ret;
}
static void
cryptodev_fips_validate_app_uninit(void)
{
cryptodev_fips_validate_app_sym_uninit();
if (env.is_asym_test)
cryptodev_fips_validate_app_asym_uninit();
}
static int
fips_test_one_file(void);
#ifdef USE_JANSSON
static int
fips_test_one_json_file(void);
#endif
static int
parse_cryptodev_arg(char *arg)
{
if (id < 0) {
RTE_LOG(ERR, USER1,
"Error %i: invalid cryptodev name %s\n",
id, arg);
return id;
}
env.dev_id = (uint8_t)id;
return 0;
}
static int
parse_cryptodev_id_arg(char *arg)
{
uint32_t cryptodev_id;
if (parser_read_uint32(&cryptodev_id, arg) < 0) {
RTE_LOG(ERR, USER1,
"Error %i: invalid cryptodev id %s\n",
-EINVAL, arg);
return -1;
}
RTE_LOG(ERR, USER1,
"Error %i: invalid cryptodev id %s\n",
cryptodev_id, arg);
return -1;
}
env.dev_id = (uint8_t)cryptodev_id;
return 0;
}
static void
cryptodev_fips_validate_usage(const char *prgname)
{
uint32_t def_mbuf_seg_size = DEF_MBUF_SEG_SIZE;
printf("%s [EAL options] --\n"
" --%s: REQUEST-FILE-PATH\n"
" --%s: RESPONSE-FILE-PATH\n"
" --%s: indicating both paths are folders\n"
" --%s: mbuf dataroom size (default %u bytes)\n"
" --%s: CRYPTODEV-NAME\n"
" --%s: CRYPTODEV-ID-NAME\n"
" --%s: self test indicator\n"
" --%s: self broken test ID\n"
" --%s: self broken test direction\n",
prgname, OPT_REQ_FILE_PATH, OPT_RSP_FILE_PATH,
OPT_FOLDER, OPT_MBUF_DATAROOM, def_mbuf_seg_size,
OPT_CRYPTODEV, OPT_CRYPTODEV_ID, OPT_CRYPTODEV_ST,
OPT_CRYPTODEV_BK_ID, OPT_CRYPTODEV_BK_DIR_KEY);
}
static int
cryptodev_fips_validate_parse_args(int argc, char **argv)
{
int opt, ret;
char *prgname = argv[0];
char **argvopt;
int option_index;
struct option lgopts[] = {
{OPT_REQ_FILE_PATH, required_argument,
NULL, OPT_REQ_FILE_PATH_NUM},
{OPT_RSP_FILE_PATH, required_argument,
NULL, OPT_RSP_FILE_PATH_NUM},
{OPT_FOLDER, no_argument,
NULL, OPT_FOLDER_NUM},
{OPT_MBUF_DATAROOM, required_argument,
NULL, OPT_MBUF_DATAROOM_NUM},
{OPT_CRYPTODEV, required_argument,
NULL, OPT_CRYPTODEV_NUM},
{OPT_CRYPTODEV_ID, required_argument,
NULL, OPT_CRYPTODEV_ID_NUM},
{OPT_CRYPTODEV_ST, no_argument,
NULL, OPT_CRYPTODEV_ST_NUM},
{OPT_CRYPTODEV_BK_ID, required_argument,
NULL, OPT_CRYPTODEV_BK_ID_NUM},
{OPT_CRYPTODEV_BK_DIR_KEY, required_argument,
NULL, OPT_CRYPTODEV_BK_DIR_KEY_NUM},
{OPT_CRYPTODEV_ASYM, no_argument,
NULL, OPT_CRYPTODEV_ASYM_NUM},
{NULL, 0, 0, 0}
};
argvopt = argv;
env.mbuf_data_room = DEF_MBUF_SEG_SIZE;
env.dev_id = 0;
else {
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
while ((opt = getopt_long(argc, argvopt, "s:",
lgopts, &option_index)) != EOF) {
switch (opt) {
case OPT_REQ_FILE_PATH_NUM:
env.req_path = optarg;
break;
case OPT_RSP_FILE_PATH_NUM:
env.rsp_path = optarg;
break;
case OPT_FOLDER_NUM:
env.is_path_folder = 1;
break;
case OPT_CRYPTODEV_NUM:
ret = parse_cryptodev_arg(optarg);
if (ret < 0) {
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
break;
case OPT_CRYPTODEV_ID_NUM:
ret = parse_cryptodev_id_arg(optarg);
if (ret < 0) {
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
break;
case OPT_CRYPTODEV_ST_NUM:
env.self_test = 1;
break;
case OPT_CRYPTODEV_BK_ID_NUM:
if (!env.broken_test_config) {
NULL,
sizeof(*env.broken_test_config),
0);
if (!env.broken_test_config)
return -ENOMEM;
env.broken_test_config->expect_fail_dir =
self_test_dir_enc_auth_gen;
}
if (parser_read_uint32(
&env.broken_test_config->expect_fail_test_idx,
optarg) < 0) {
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
break;
case OPT_CRYPTODEV_BK_DIR_KEY_NUM:
if (!env.broken_test_config) {
NULL,
sizeof(*env.broken_test_config),
0);
if (!env.broken_test_config)
return -ENOMEM;
env.broken_test_config->expect_fail_test_idx =
0;
}
if (strcmp(optarg, "enc") == 0)
env.broken_test_config->expect_fail_dir =
self_test_dir_enc_auth_gen;
else if (strcmp(optarg, "dec")
== 0)
env.broken_test_config->expect_fail_dir =
self_test_dir_dec_auth_verify;
else {
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
break;
case OPT_MBUF_DATAROOM_NUM:
if (parser_read_uint16(&env.mbuf_data_room,
optarg) < 0) {
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
if (env.mbuf_data_room == 0) {
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
break;
case OPT_CRYPTODEV_ASYM_NUM:
env.is_asym_test = true;
break;
default:
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
}
if ((env.req_path == NULL && env.rsp_path != NULL) ||
(env.req_path != NULL && env.rsp_path == NULL)) {
RTE_LOG(ERR, USER1,
"Missing req path or rsp path\n");
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
if (env.req_path == NULL && env.self_test == 0) {
RTE_LOG(ERR, USER1,
"--self-test must be set if req path is missing\n");
cryptodev_fips_validate_usage(prgname);
return -EINVAL;
}
return 0;
}
int
main(int argc, char *argv[])
{
int ret;
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Failed init\n", ret);
return -1;
}
argc -= ret;
argv += ret;
ret = cryptodev_fips_validate_parse_args(argc, argv);
if (ret < 0)
rte_exit(EXIT_FAILURE,
"Failed to parse arguments!\n");
ret = cryptodev_fips_validate_app_init();
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Failed init\n", ret);
return -1;
}
if (env.req_path == NULL || env.rsp_path == NULL) {
printf("No request, exit.\n");
goto exit;
}
if (!env.is_path_folder) {
printf("Processing file %s... ", env.req_path);
ret = fips_test_init(env.req_path, env.rsp_path,
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Failed test %s\n",
ret, env.req_path);
goto exit;
}
#ifdef USE_JANSSON
if (info.file_type == FIPS_TYPE_JSON) {
ret = fips_test_one_json_file();
json_decref(json_info.json_root);
} else {
ret = fips_test_one_file();
}
#else
ret = fips_test_one_file();
#endif
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Failed test %s\n",
ret, env.req_path);
goto exit;
}
printf("Done\n");
} else {
struct dirent *dir;
DIR *d_req, *d_rsp;
char req_path[1024];
char rsp_path[1024];
d_req = opendir(env.req_path);
if (!d_req) {
RTE_LOG(ERR, USER1,
"Error %i: Path %s not exist\n",
-EINVAL, env.req_path);
goto exit;
}
d_rsp = opendir(env.rsp_path);
if (!d_rsp) {
ret = mkdir(env.rsp_path, 0700);
if (ret == 0)
d_rsp = opendir(env.rsp_path);
else {
RTE_LOG(ERR, USER1,
"Error %i: Invalid %s\n",
-EINVAL, env.rsp_path);
goto exit;
}
}
closedir(d_rsp);
while ((dir = readdir(d_req)) != NULL) {
if (strstr(dir->d_name, "req") == NULL)
continue;
snprintf(req_path, 1023, "%s/%s", env.req_path,
dir->d_name);
snprintf(rsp_path, 1023, "%s/%s", env.rsp_path,
dir->d_name);
strlcpy(strstr(rsp_path, "req"), "rsp", 4);
printf("Processing file %s... ", req_path);
ret = fips_test_init(req_path, rsp_path,
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Failed test %s\n",
ret, req_path);
break;
}
#ifdef USE_JANSSON
if (info.file_type == FIPS_TYPE_JSON) {
ret = fips_test_one_json_file();
json_decref(json_info.json_root);
} else {
ret = fips_test_one_file();
}
#else
ret = fips_test_one_file();
#endif
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Failed test %s\n",
ret, req_path);
break;
}
printf("Done\n");
}
closedir(d_req);
}
exit:
fips_test_clear();
cryptodev_fips_validate_app_uninit();
return ret;
}
#define IV_OFF (sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op))
#define CRYPTODEV_FIPS_MAX_RETRIES 16
struct fips_test_ops test_ops;
static int
prepare_data_mbufs(struct fips_val *val)
{
uint8_t *src = val->val;
uint32_t total_len = val->len;
uint16_t nb_seg;
int ret = 0;
RTE_LOG(ERR, USER1,
"Data len %u too big\n", total_len);
return -EPERM;
}
nb_seg = total_len / env.mbuf_data_room;
if (total_len % env.mbuf_data_room)
nb_seg++;
if (!m) {
RTE_LOG(ERR, USER1,
"Error %i: Not enough mbuf\n",
-ENOMEM);
return -ENOMEM;
}
head = m;
while (nb_seg) {
uint16_t len =
RTE_MIN(total_len, env.mbuf_data_room);
if (!dst) {
RTE_LOG(ERR, USER1,
"Error %i: MBUF too small\n",
-ENOMEM);
ret = -ENOMEM;
goto error_exit;
}
memcpy(dst, src, len);
if (head != m) {
if (ret) {
RTE_LOG(ERR, USER1,
"Error %i: SGL build\n",
ret);
goto error_exit;
}
}
total_len -= len;
if (total_len) {
if (!env.dev_support_sgl) {
RTE_LOG(ERR, USER1,
"SGL not supported\n");
ret = -EPERM;
goto error_exit;
}
if (!m) {
RTE_LOG(ERR, USER1,
"Error %i: No memory\n",
-ENOMEM);
goto error_exit;
}
} else
break;
src += len;
nb_seg--;
}
if (total_len) {
RTE_LOG(ERR, USER1,
"Error %i: Failed to store all data\n",
-ENOMEM);
goto error_exit;
}
env.mbuf = head;
return 0;
error_exit:
return ret;
}
static int
prepare_cipher_op(void)
{
int ret;
memcpy(iv, vec.iv.val, vec.iv.len);
if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
ret = prepare_data_mbufs(&vec.pt);
if (ret < 0)
return ret;
} else {
ret = prepare_data_mbufs(&vec.ct);
if (ret < 0)
return ret;
}
return 0;
}
int
prepare_auth_op(void)
{
int ret;
if (info.interim_info.gcm_data.gen_iv == 1) {
uint32_t i;
if (!vec.iv.val) {
if (!vec.iv.val)
return -ENOMEM;
}
for (i = 0; i < vec.iv.len; i++) {
vec.iv.val[i] = (uint8_t)random;
}
}
if (vec.iv.len) {
IV_OFF);
memset(iv, 0, vec.iv.len);
if (vec.iv.val)
memcpy(iv, vec.iv.val, vec.iv.len);
}
ret = prepare_data_mbufs(&vec.pt);
if (ret < 0)
return ret;
env.digest =
rte_zmalloc(NULL, vec.cipher_auth.digest.len,
RTE_CACHE_LINE_SIZE);
if (!env.digest) {
RTE_LOG(ERR, USER1,
"Not enough memory\n");
return -ENOMEM;
}
env.digest_len = vec.cipher_auth.digest.len;
if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
memcpy(env.digest, vec.cipher_auth.digest.val,
vec.cipher_auth.digest.len);
return 0;
}
int
prepare_aead_op(void)
{
int ret;
if (info.algo == FIPS_TEST_ALGO_AES_CCM)
iv++;
if (vec.iv.val)
memcpy(iv, vec.iv.val, vec.iv.len);
else
memset(iv, 0, vec.iv.len);
if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
ret = prepare_data_mbufs(&vec.pt);
if (ret < 0)
return ret;
RTE_CACHE_LINE_SIZE);
if (!env.digest) {
RTE_LOG(ERR, USER1,
"Not enough memory\n");
return -ENOMEM;
}
env.digest_len = vec.aead.digest.len;
} else {
ret = prepare_data_mbufs(&vec.ct);
if (ret < 0)
return ret;
env.digest_len = vec.aead.digest.len;
}
return 0;
}
static int
{
uint8_t id_sha512[] = {0x30, 0x51, 0x30, 0x0d, 0x06, 0x09,
0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
0x04, 0x02, 0x03, 0x05, 0x00, 0x04,
0x40};
uint8_t id_sha384[] = {0x30, 0x41, 0x30, 0x0d, 0x06, 0x09,
0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
0x04, 0x02, 0x02, 0x05, 0x00, 0x04,
0x30};
uint8_t id_sha256[] = {0x30, 0x31, 0x30, 0x0d, 0x06, 0x09,
0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
0x04, 0x02, 0x01, 0x05, 0x00, 0x04,
0x20};
uint8_t id_sha224[] = {0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09,
0x60, 0x86, 0x48, 0x01, 0x65, 0x03,
0x04, 0x02, 0x04, 0x05, 0x00, 0x04,
0x1c};
uint8_t id_sha1[] = {0x30, 0x21, 0x30, 0x09, 0x06, 0x05,
0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
0x00, 0x04, 0x14};
uint8_t *id = NULL;
int id_len = 0;
switch (hash) {
id = id_sha1;
id_len = sizeof(id_sha1);
break;
id = id_sha224;
id_len = sizeof(id_sha224);
break;
id = id_sha256;
id_len = sizeof(id_sha256);
break;
id = id_sha384;
id_len = sizeof(id_sha384);
break;
id = id_sha512;
id_len = sizeof(id_sha512);
break;
default:
id_len = -1;
break;
}
if (id != NULL)
return id_len;
}
static int
prepare_rsa_op(void)
{
struct fips_val msg;
asym = env.op->asym;
asym->
rsa.
padding.
type = info.interim_info.rsa_data.padding;
asym->rsa.
padding.
hash = info.interim_info.rsa_data.auth;
if (env.digest) {
int b_len = 0;
uint8_t b[32];
if (b_len < 0) {
RTE_LOG(ERR, USER1,
"Failed to get digest info for hash %d\n",
return -EINVAL;
}
if (b_len) {
msg.len = env.digest_len + b_len;
rte_memcpy(msg.val + b_len, env.digest, env.digest_len);
env.digest = msg.val;
env.digest_len = msg.len;
}
}
msg.val = env.digest;
msg.len = env.digest_len;
} else {
msg.val = vec.pt.val;
msg.len = vec.pt.len;
}
if (info.op == FIPS_TEST_ASYM_SIGGEN) {
vec.rsa.signature.val =
rte_zmalloc(NULL, vec.rsa.n.len, 0);
vec.rsa.signature.len = vec.rsa.n.len;
asym->rsa.
sign.
data = vec.rsa.signature.val;
} else if (info.op == FIPS_TEST_ASYM_SIGVER) {
asym->rsa.
sign.
data = vec.rsa.signature.val;
} else {
RTE_LOG(ERR, USER1,
"Invalid op %d\n", info.op);
return -EINVAL;
}
return 0;
}
static int
prepare_ecdsa_op(void)
{
struct fips_val msg;
asym = env.op->asym;
if (env.digest) {
msg.val = env.digest;
msg.len = env.digest_len;
} else {
msg.val = vec.pt.val;
msg.len = vec.pt.len;
}
if (info.op == FIPS_TEST_ASYM_SIGGEN) {
asym->ecdsa.
pkey.
data = vec.ecdsa.pkey.val;
asym->ecdsa.
k.
data = vec.ecdsa.k.val;
asym->ecdsa.
k.
length = vec.ecdsa.k.len;
vec.ecdsa.r.len = info.interim_info.ecdsa_data.curve_len;
vec.ecdsa.r.val =
rte_zmalloc(NULL, vec.ecdsa.r.len, 0);
vec.ecdsa.s.len = vec.ecdsa.r.len;
vec.ecdsa.s.val =
rte_zmalloc(NULL, vec.ecdsa.s.len, 0);
asym->ecdsa.
r.
data = vec.ecdsa.r.val;
asym->ecdsa.
s.
data = vec.ecdsa.s.val;
} else if (info.op == FIPS_TEST_ASYM_SIGVER) {
asym->ecdsa.
q.
x.
data = vec.ecdsa.qx.val;
asym->ecdsa.
q.
x.
length = vec.ecdsa.qx.len;
asym->ecdsa.
q.
y.
data = vec.ecdsa.qy.val;
asym->ecdsa.
q.
y.
length = vec.ecdsa.qy.len;
asym->ecdsa.
r.
data = vec.ecdsa.r.val;
asym->ecdsa.
r.
length = vec.ecdsa.r.len;
asym->ecdsa.
s.
data = vec.ecdsa.s.val;
asym->ecdsa.
s.
length = vec.ecdsa.s.len;
} else {
RTE_LOG(ERR, USER1,
"Invalid op %d\n", info.op);
return -EINVAL;
}
return 0;
}
static int
prepare_ecfpm_op(void)
{
asym = env.op->asym;
vec.ecdsa.qx.len = info.interim_info.ecdsa_data.curve_len;
vec.ecdsa.qx.val =
rte_zmalloc(NULL, vec.ecdsa.qx.len, 0);
vec.ecdsa.qy.len = vec.ecdsa.qx.len;
vec.ecdsa.qy.val =
rte_zmalloc(NULL, vec.ecdsa.qy.len, 0);
asym->ecpm.
r.
x.
data = vec.ecdsa.qx.val;
asym->ecpm.
r.
y.
data = vec.ecdsa.qy.val;
return 0;
}
static int
{
else if (info.interim_info.aes_data.cipher_algo ==
else
cipher_xform->
op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
cipher_xform->
key.
data = vec.cipher_auth.key.val;
cipher_xform->
key.
length = vec.cipher_auth.key.len;
} else {
}
cap_idx.algo.cipher = cipher_xform->
algo;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
RTE_LOG(ERR, USER1,
"PMD %s key length %u IV length %u\n",
return -EPERM;
}
return 0;
}
static int
{
if (info.interim_info.tdes_data.test_mode == TDES_MODE_CBC)
else
cipher_xform->
op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
cipher_xform->
key.
data = vec.cipher_auth.key.val;
cipher_xform->
key.
length = vec.cipher_auth.key.len;
} else {
}
cap_idx.algo.cipher = cipher_xform->
algo;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
RTE_LOG(ERR, USER1,
"PMD %s key length %u IV length %u\n",
return -EPERM;
}
return 0;
}
static int
{
auth_xform->
algo = info.interim_info.hmac_data.algo;
auth_xform->
key.
data = vec.cipher_auth.key.val;
auth_xform->
key.
length = vec.cipher_auth.key.len;
cap_idx.algo.auth = auth_xform->
algo;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
RTE_LOG(ERR, USER1,
"PMD %s key length %u Digest length %u\n",
return -EPERM;
}
return 0;
}
int
{
struct rte_crypto_aead_xform *aead_xform = &xform->
aead;
aead_xform->aad_length = vec.aead.aad.len;
aead_xform->digest_length = vec.aead.digest.len;
aead_xform->iv.offset = IV_OFF;
aead_xform->iv.length = vec.iv.len;
aead_xform->key.data = vec.aead.key.val;
aead_xform->key.length = vec.aead.key.len;
aead_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
cap_idx.algo.aead = aead_xform->algo;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
aead_xform->key.length,
aead_xform->digest_length, aead_xform->aad_length,
aead_xform->iv.length) != 0) {
"PMD %s key_len %u tag_len %u aad_len %u iv_len %u\n",
info.device_name, aead_xform->key.length,
aead_xform->digest_length,
aead_xform->aad_length,
aead_xform->iv.length);
return -EPERM;
}
return 0;
}
int
{
auth_xform->
op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
auth_xform->
key.
data = vec.aead.key.val;
cap_idx.algo.auth = auth_xform->
algo;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
"PMD %s key length %u Digest length %u IV length %u\n",
return -EPERM;
}
return 0;
}
static int
{
auth_xform->
op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
auth_xform->
key.
data = vec.cipher_auth.key.val;
auth_xform->
key.
length = vec.cipher_auth.key.len;
cap_idx.algo.auth = auth_xform->
algo;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
RTE_LOG(ERR, USER1,
"PMD %s key length %u Digest length %u\n",
return -EPERM;
}
return 0;
}
static int
{
struct rte_crypto_aead_xform *aead_xform = &xform->
aead;
aead_xform->aad_length = vec.aead.aad.len;
aead_xform->digest_length = vec.aead.digest.len;
aead_xform->iv.offset = IV_OFF;
aead_xform->iv.length = vec.iv.len;
aead_xform->key.data = vec.aead.key.val;
aead_xform->key.length = vec.aead.key.len;
aead_xform->op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
cap_idx.algo.aead = aead_xform->algo;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
aead_xform->key.length,
aead_xform->digest_length, aead_xform->aad_length,
aead_xform->iv.length) != 0) {
"PMD %s key_len %u tag_len %u aad_len %u iv_len %u\n",
info.device_name, aead_xform->key.length,
aead_xform->digest_length,
aead_xform->aad_length,
aead_xform->iv.length);
return -EPERM;
}
return 0;
}
static int
{
auth_xform->
algo = info.interim_info.sha_data.algo;
cap_idx.algo.auth = auth_xform->
algo;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
RTE_LOG(ERR, USER1,
"PMD %s key length %u digest length %u\n",
return -EPERM;
}
return 0;
}
static int
{
cipher_xform->
op = (info.op == FIPS_TEST_ENC_AUTH_GEN) ?
cipher_xform->
key.
data = vec.cipher_auth.key.val;
cipher_xform->
key.
length = vec.cipher_auth.key.len;
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
RTE_LOG(ERR, USER1,
"PMD %s key length %u IV length %u\n",
return -EPERM;
}
return 0;
}
static int
{
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
switch (info.op) {
case FIPS_TEST_ASYM_SIGGEN:
RTE_LOG(ERR, USER1,
"PMD %s xform_op %u\n",
return -EPERM;
}
break;
case FIPS_TEST_ASYM_SIGVER:
RTE_LOG(ERR, USER1,
"PMD %s xform_op %u\n",
return -EPERM;
}
break;
case FIPS_TEST_ASYM_KEYGEN:
break;
default:
break;
}
xform->
rsa.
key_type = info.interim_info.rsa_data.privkey;
switch (xform->
rsa.key_type) {
RTE_LOG(ERR, USER1,
"PMD %s does not support QT key type\n",
info.device_name);
return -EPERM;
}
break;
RTE_LOG(ERR, USER1,
"PMD %s does not support EXP key type\n",
info.device_name);
return -EPERM;
}
break;
default:
break;
}
return 0;
}
static int
{
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
switch (info.op) {
case FIPS_TEST_ASYM_SIGGEN:
RTE_LOG(ERR, USER1,
"PMD %s xform_op %u\n",
return -EPERM;
}
break;
case FIPS_TEST_ASYM_SIGVER:
RTE_LOG(ERR, USER1,
"PMD %s xform_op %u\n",
return -EPERM;
}
break;
default:
break;
}
xform->
ec.
curve_id = info.interim_info.ecdsa_data.curve_id;
return 0;
}
static int
{
if (!cap) {
RTE_LOG(ERR, USER1,
"Failed to get capability for cdev %u\n",
env.dev_id);
return -EINVAL;
}
xform->
ec.
curve_id = info.interim_info.ecdsa_data.curve_id;
return 0;
}
static int
get_writeback_data(struct fips_val *val)
{
uint16_t total_len =
data_len + env.digest_len;
uint8_t *src, *dst, *wb_data;
if (val->val) {
free(val->val);
val->val = NULL;
}
wb_data = dst = calloc(1, total_len);
if (!dst) {
RTE_LOG(ERR, USER1,
"Error %i: Not enough memory\n", -ENOMEM);
return -ENOMEM;
}
memcpy(dst, src, seg_len);
dst += seg_len;
}
RTE_LOG(ERR, USER1,
"Error -1: write back data\n");
free(wb_data);
return -1;
}
if (env.digest)
memcpy(dst, env.digest, env.digest_len);
val->val = wb_data;
val->len = total_len;
return 0;
}
static int
fips_run_sym_test(void)
{
uint16_t n_deqd;
int ret;
if (!test_ops.prepare_sym_xform || !test_ops.prepare_sym_op)
return -EINVAL;
ret = test_ops.prepare_sym_xform(&xform);
if (ret < 0)
return ret;
env.sym.sess_mpool);
if (!env.sym.sess)
return -ENOMEM;
ret = test_ops.prepare_sym_op();
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Prepare op\n",
ret);
goto exit;
}
RTE_LOG(ERR, USER1,
"Error: Failed enqueue\n");
ret = -1;
goto exit;
}
do {
} while (n_deqd == 0);
vec.status = env.op->status;
exit:
env.sym.sess = NULL;
return ret;
}
static int
fips_run_asym_test(void)
{
int ret;
if (info.op == FIPS_TEST_ASYM_KEYGEN && info.algo != FIPS_TEST_ALGO_ECDSA) {
ret = 0;
goto exit;
}
if (!test_ops.prepare_asym_xform || !test_ops.prepare_asym_op)
return -EINVAL;
ret = test_ops.prepare_asym_xform(&xform);
if (ret < 0)
return ret;
(void *)&env.asym.sess);
if (ret < 0)
return ret;
ret = test_ops.prepare_asym_op();
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Prepare op\n", ret);
goto exit;
}
RTE_LOG(ERR, USER1,
"Error: Failed enqueue\n");
ret = -1;
goto exit;
}
vec.status = env.op->status;
exit:
if (env.asym.sess)
env.asym.sess = NULL;
return ret;
}
static int
fips_run_test(void)
{
int ret;
env.op = env.sym.op;
if (env.is_asym_test) {
vec.cipher_auth.digest.len = parse_test_sha_hash_size(
info.interim_info.rsa_data.auth);
test_ops.prepare_sym_xform = prepare_sha_xform;
test_ops.prepare_sym_op = prepare_auth_op;
ret = fips_run_sym_test();
if (ret < 0)
return ret;
} else {
return fips_run_sym_test();
}
env.op = env.asym.op;
if (info.op == FIPS_TEST_ASYM_SIGGEN &&
info.algo == FIPS_TEST_ALGO_ECDSA &&
info.interim_info.ecdsa_data.pubkey_gen == 1) {
fips_prepare_asym_xform_t ecdsa_xform;
fips_prepare_op_t ecdsa_op;
ecdsa_xform = test_ops.prepare_asym_xform;
ecdsa_op = test_ops.prepare_asym_op;
info.op = FIPS_TEST_ASYM_KEYGEN;
test_ops.prepare_asym_xform = prepare_ecfpm_xform;
test_ops.prepare_asym_op = prepare_ecfpm_op;
ret = fips_run_asym_test();
if (ret < 0)
return ret;
info.post_interim_writeback(NULL);
info.interim_info.ecdsa_data.pubkey_gen = 0;
test_ops.prepare_asym_xform = ecdsa_xform;
test_ops.prepare_asym_op = ecdsa_op;
info.op = FIPS_TEST_ASYM_SIGGEN;
ret = fips_run_asym_test();
} else {
ret = fips_run_asym_test();
}
return ret;
}
static int
fips_generic_test(void)
{
struct fips_val val = {NULL, 0};
int ret;
if (info.file_type != FIPS_TYPE_JSON)
fips_test_write_one_case();
ret = fips_run_test();
if (ret < 0) {
if (ret == -EPERM || ret == -ENOTSUP) {
if (info.file_type == FIPS_TYPE_JSON)
return ret;
fprintf(info.fp_wr, "Bypass\n\n");
return 0;
}
return ret;
}
if (!env.is_asym_test) {
ret = get_writeback_data(&val);
if (ret < 0)
return ret;
}
switch (info.file_type) {
case FIPS_TYPE_REQ:
case FIPS_TYPE_RSP:
case FIPS_TYPE_JSON:
if (info.parse_writeback == NULL)
return -EPERM;
ret = info.parse_writeback(&val);
if (ret < 0)
return ret;
break;
case FIPS_TYPE_FAX:
if (info.kat_check == NULL)
return -EPERM;
ret = info.kat_check(&val);
if (ret < 0)
return ret;
break;
default:
break;
}
if (info.file_type != FIPS_TYPE_JSON)
fprintf(info.fp_wr, "\n");
free(val.val);
return 0;
}
static int
fips_mct_tdes_test(void)
{
#define TDES_BLOCK_SIZE 8
#define TDES_EXTERN_ITER 400
#define TDES_INTERN_ITER 10000
struct fips_val val[3] = {{NULL, 0},}, val_key, pt, ct, iv;
uint8_t prev_out[TDES_BLOCK_SIZE] = {0};
uint8_t prev_prev_out[TDES_BLOCK_SIZE] = {0};
uint8_t prev_in[TDES_BLOCK_SIZE] = {0};
uint32_t i, j, k;
int ret;
int test_mode = info.interim_info.tdes_data.test_mode;
pt.len = vec.pt.len;
pt.val = calloc(1, pt.len);
ct.len = vec.ct.len;
ct.val = calloc(1, ct.len);
iv.len = vec.iv.len;
iv.val = calloc(1, iv.len);
for (i = 0; i < TDES_EXTERN_ITER; i++) {
if (info.file_type != FIPS_TYPE_JSON) {
if ((i == 0) && (info.version == 21.4f)) {
if (!(strstr(info.vec[0], "COUNT")))
fprintf(info.fp_wr, "%s%u\n", "COUNT = ", 0);
}
if (i != 0)
update_info_vec(i);
fips_test_write_one_case();
}
for (j = 0; j < TDES_INTERN_ITER; j++) {
ret = fips_run_test();
if (ret < 0) {
if (ret == -EPERM) {
if (info.file_type == FIPS_TYPE_JSON)
return ret;
fprintf(info.fp_wr, "Bypass\n");
return 0;
}
return ret;
}
ret = get_writeback_data(&val[0]);
if (ret < 0)
return ret;
if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
memcpy(prev_in, vec.ct.val, TDES_BLOCK_SIZE);
if (j == 0) {
memcpy(prev_out, val[0].val, TDES_BLOCK_SIZE);
memcpy(pt.val, vec.pt.val, pt.len);
memcpy(ct.val, vec.ct.val, ct.len);
memcpy(iv.val, vec.iv.val, iv.len);
if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
if (test_mode == TDES_MODE_ECB) {
memcpy(vec.pt.val, val[0].val,
TDES_BLOCK_SIZE);
} else {
memcpy(vec.pt.val, vec.iv.val,
TDES_BLOCK_SIZE);
memcpy(vec.iv.val, val[0].val,
TDES_BLOCK_SIZE);
}
val[1].val = pt.val;
val[1].len = pt.len;
val[2].val = iv.val;
val[2].len = iv.len;
} else {
if (test_mode == TDES_MODE_ECB) {
memcpy(vec.ct.val, val[0].val,
TDES_BLOCK_SIZE);
} else {
memcpy(vec.iv.val, vec.ct.val,
TDES_BLOCK_SIZE);
memcpy(vec.ct.val, val[0].val,
TDES_BLOCK_SIZE);
}
val[1].val = ct.val;
val[1].len = ct.len;
val[2].val = iv.val;
val[2].len = iv.len;
}
continue;
}
if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
if (test_mode == TDES_MODE_ECB) {
memcpy(vec.pt.val, val[0].val,
TDES_BLOCK_SIZE);
} else {
memcpy(vec.iv.val, val[0].val,
TDES_BLOCK_SIZE);
memcpy(vec.pt.val, prev_out,
TDES_BLOCK_SIZE);
}
} else {
if (test_mode == TDES_MODE_ECB) {
memcpy(vec.ct.val, val[0].val,
TDES_BLOCK_SIZE);
} else {
memcpy(vec.iv.val, vec.ct.val,
TDES_BLOCK_SIZE);
memcpy(vec.ct.val, val[0].val,
TDES_BLOCK_SIZE);
}
}
if (j == TDES_INTERN_ITER - 1)
continue;
memcpy(prev_out, val[0].val, TDES_BLOCK_SIZE);
if (j == TDES_INTERN_ITER - 3)
memcpy(prev_prev_out, val[0].val, TDES_BLOCK_SIZE);
}
info.parse_writeback(val);
if (info.file_type != FIPS_TYPE_JSON)
fprintf(info.fp_wr, "\n");
if (i == TDES_EXTERN_ITER - 1)
continue;
memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
if (info.interim_info.tdes_data.nb_keys == 0) {
if (memcmp(val_key.val, val_key.val + 8, 8) == 0)
info.interim_info.tdes_data.nb_keys = 1;
else if (memcmp(val_key.val, val_key.val + 16, 8) == 0)
info.interim_info.tdes_data.nb_keys = 2;
else
info.interim_info.tdes_data.nb_keys = 3;
}
for (k = 0; k < TDES_BLOCK_SIZE; k++) {
switch (info.interim_info.tdes_data.nb_keys) {
case 3:
val_key.val[k] ^= val[0].val[k];
val_key.val[k + 8] ^= prev_out[k];
val_key.val[k + 16] ^= prev_prev_out[k];
break;
case 2:
val_key.val[k] ^= val[0].val[k];
val_key.val[k + 8] ^= prev_out[k];
val_key.val[k + 16] ^= val[0].val[k];
break;
default:
val_key.val[k] ^= val[0].val[k];
val_key.val[k + 8] ^= val[0].val[k];
val_key.val[k + 16] ^= val[0].val[k];
break;
}
}
for (k = 0; k < 24; k++)
val_key.val[k] = (__builtin_popcount(val_key.val[k]) &
0x1) ?
val_key.val[k] : (val_key.val[k] ^ 0x1);
if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
if (test_mode == TDES_MODE_ECB) {
memcpy(vec.pt.val, val[0].val, TDES_BLOCK_SIZE);
} else {
memcpy(vec.iv.val, val[0].val, TDES_BLOCK_SIZE);
memcpy(vec.pt.val, prev_out, TDES_BLOCK_SIZE);
}
} else {
if (test_mode == TDES_MODE_ECB) {
memcpy(vec.ct.val, val[0].val, TDES_BLOCK_SIZE);
} else {
memcpy(vec.iv.val, prev_out, TDES_BLOCK_SIZE);
memcpy(vec.ct.val, val[0].val, TDES_BLOCK_SIZE);
}
}
}
free(val[0].val);
free(pt.val);
free(ct.val);
free(iv.val);
return 0;
}
static int
fips_mct_aes_ecb_test(void)
{
#define AES_BLOCK_SIZE 16
#define AES_EXTERN_ITER 100
#define AES_INTERN_ITER 1000
struct fips_val val = {NULL, 0}, val_key;
uint8_t prev_out[AES_BLOCK_SIZE] = {0};
uint32_t i, j, k;
int ret;
for (i = 0; i < AES_EXTERN_ITER; i++) {
if (i != 0)
update_info_vec(i);
fips_test_write_one_case();
for (j = 0; j < AES_INTERN_ITER; j++) {
ret = fips_run_test();
if (ret < 0) {
if (ret == -EPERM) {
if (info.file_type == FIPS_TYPE_JSON)
return ret;
fprintf(info.fp_wr, "Bypass\n");
return 0;
}
return ret;
}
ret = get_writeback_data(&val);
if (ret < 0)
return ret;
if (info.op == FIPS_TEST_ENC_AUTH_GEN)
memcpy(vec.pt.val, val.val, AES_BLOCK_SIZE);
else
memcpy(vec.ct.val, val.val, AES_BLOCK_SIZE);
if (j == AES_INTERN_ITER - 1)
continue;
memcpy(prev_out, val.val, AES_BLOCK_SIZE);
}
info.parse_writeback(&val);
fprintf(info.fp_wr, "\n");
if (i == AES_EXTERN_ITER - 1)
continue;
memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
for (k = 0; k < vec.cipher_auth.key.len; k++) {
switch (vec.cipher_auth.key.len) {
case 16:
val_key.val[k] ^= val.val[k];
break;
case 24:
if (k < 8)
val_key.val[k] ^= prev_out[k + 8];
else
val_key.val[k] ^= val.val[k - 8];
break;
case 32:
if (k < 16)
val_key.val[k] ^= prev_out[k];
else
val_key.val[k] ^= val.val[k - 16];
break;
default:
return -1;
}
}
}
free(val.val);
return 0;
}
static int
fips_mct_aes_test(void)
{
#define AES_BLOCK_SIZE 16
#define AES_EXTERN_ITER 100
#define AES_INTERN_ITER 1000
struct fips_val val[3] = {{NULL, 0},}, val_key, pt, ct, iv;
uint8_t prev_out[AES_BLOCK_SIZE] = {0};
uint8_t prev_in[AES_BLOCK_SIZE] = {0};
uint32_t i, j, k;
int ret;
return fips_mct_aes_ecb_test();
pt.len = vec.pt.len;
pt.val = calloc(1, pt.len);
ct.len = vec.ct.len;
ct.val = calloc(1, ct.len);
iv.len = vec.iv.len;
iv.val = calloc(1, iv.len);
for (i = 0; i < AES_EXTERN_ITER; i++) {
if (info.file_type != FIPS_TYPE_JSON) {
if (i != 0)
update_info_vec(i);
fips_test_write_one_case();
}
for (j = 0; j < AES_INTERN_ITER; j++) {
ret = fips_run_test();
if (ret < 0) {
if (ret == -EPERM) {
if (info.file_type == FIPS_TYPE_JSON)
return ret;
fprintf(info.fp_wr, "Bypass\n");
return 0;
}
return ret;
}
ret = get_writeback_data(&val[0]);
if (ret < 0)
return ret;
if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
memcpy(prev_in, vec.ct.val, AES_BLOCK_SIZE);
if (j == 0) {
memcpy(prev_out, val[0].val, AES_BLOCK_SIZE);
memcpy(pt.val, vec.pt.val, pt.len);
memcpy(ct.val, vec.ct.val, ct.len);
memcpy(iv.val, vec.iv.val, iv.len);
if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
memcpy(vec.pt.val, vec.iv.val, AES_BLOCK_SIZE);
memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE);
val[1].val = pt.val;
val[1].len = pt.len;
val[2].val = iv.val;
val[2].len = iv.len;
} else {
memcpy(vec.ct.val, vec.iv.val, AES_BLOCK_SIZE);
memcpy(vec.iv.val, prev_in, AES_BLOCK_SIZE);
val[1].val = ct.val;
val[1].len = ct.len;
val[2].val = iv.val;
val[2].len = iv.len;
}
continue;
}
if (info.op == FIPS_TEST_ENC_AUTH_GEN) {
memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE);
memcpy(vec.pt.val, prev_out, AES_BLOCK_SIZE);
} else {
memcpy(vec.iv.val, prev_in, AES_BLOCK_SIZE);
memcpy(vec.ct.val, prev_out, AES_BLOCK_SIZE);
}
if (j == AES_INTERN_ITER - 1)
continue;
memcpy(prev_out, val[0].val, AES_BLOCK_SIZE);
}
info.parse_writeback(val);
if (info.file_type != FIPS_TYPE_JSON)
fprintf(info.fp_wr, "\n");
if (i == AES_EXTERN_ITER - 1)
continue;
memcpy(&val_key, &vec.cipher_auth.key, sizeof(val_key));
for (k = 0; k < vec.cipher_auth.key.len; k++) {
switch (vec.cipher_auth.key.len) {
case 16:
val_key.val[k] ^= val[0].val[k];
break;
case 24:
if (k < 8)
val_key.val[k] ^= prev_out[k + 8];
else
val_key.val[k] ^= val[0].val[k - 8];
break;
case 32:
if (k < 16)
val_key.val[k] ^= prev_out[k];
else
val_key.val[k] ^= val[0].val[k - 16];
break;
default:
return -1;
}
}
if (info.op == FIPS_TEST_DEC_AUTH_VERIF)
memcpy(vec.iv.val, val[0].val, AES_BLOCK_SIZE);
}
free(val[0].val);
free(pt.val);
free(ct.val);
free(iv.val);
return 0;
}
static int
fips_mct_sha_test(void)
{
#define SHA_EXTERN_ITER 100
#define SHA_INTERN_ITER 1000
#define SHA_MD_BLOCK 3
struct fips_val val = {NULL, 0};
struct fips_val md[SHA_MD_BLOCK], msg;
int ret;
uint32_t i, j;
msg.len = SHA_MD_BLOCK * vec.cipher_auth.digest.len;
msg.val = calloc(1, msg.len);
if (vec.pt.val)
memcpy(vec.cipher_auth.digest.val, vec.pt.val, vec.cipher_auth.digest.len);
for (i = 0; i < SHA_MD_BLOCK; i++)
md[i].val =
rte_malloc(NULL, (MAX_DIGEST_SIZE*2), 0);
vec.pt.val =
rte_malloc(NULL, (MAX_DIGEST_SIZE*SHA_MD_BLOCK), 0);
if (info.file_type != FIPS_TYPE_JSON) {
fips_test_write_one_case();
fprintf(info.fp_wr, "\n");
}
for (j = 0; j < SHA_EXTERN_ITER; j++) {
memcpy(md[0].val, vec.cipher_auth.digest.val,
vec.cipher_auth.digest.len);
md[0].len = vec.cipher_auth.digest.len;
memcpy(md[1].val, vec.cipher_auth.digest.val,
vec.cipher_auth.digest.len);
md[1].len = vec.cipher_auth.digest.len;
memcpy(md[2].val, vec.cipher_auth.digest.val,
vec.cipher_auth.digest.len);
md[2].len = vec.cipher_auth.digest.len;
for (i = 0; i < SHA_MD_BLOCK; i++)
memcpy(&msg.val[i * md[i].len], md[i].val, md[i].len);
for (i = 0; i < (SHA_INTERN_ITER); i++) {
memcpy(vec.pt.val, md[0].val,
(size_t)md[0].len);
memcpy((vec.pt.val + md[0].len), md[1].val,
(size_t)md[1].len);
memcpy((vec.pt.val + md[0].len + md[1].len),
md[2].val,
(size_t)md[2].len);
vec.pt.len = md[0].len + md[1].len + md[2].len;
ret = fips_run_test();
if (ret < 0) {
if (ret == -EPERM || ret == -ENOTSUP) {
if (info.file_type == FIPS_TYPE_JSON)
return ret;
fprintf(info.fp_wr, "Bypass\n\n");
return 0;
}
return ret;
}
ret = get_writeback_data(&val);
if (ret < 0)
return ret;
memcpy(md[0].val, md[1].val, md[1].len);
md[0].len = md[1].len;
memcpy(md[1].val, md[2].val, md[2].len);
md[1].len = md[2].len;
memcpy(md[2].val, (val.val + vec.pt.len),
vec.cipher_auth.digest.len);
md[2].len = vec.cipher_auth.digest.len;
}
memcpy(vec.cipher_auth.digest.val, md[2].val, md[2].len);
vec.cipher_auth.digest.len = md[2].len;
if (info.file_type != FIPS_TYPE_JSON)
fprintf(info.fp_wr, "COUNT = %u\n", j);
info.parse_writeback(&val);
if (info.file_type != FIPS_TYPE_JSON)
fprintf(info.fp_wr, "\n");
}
for (i = 0; i < (SHA_MD_BLOCK); i++)
free(val.val);
free(msg.val);
return 0;
}
static int
init_test_ops(void)
{
switch (info.algo) {
case FIPS_TEST_ALGO_AES_CBC:
case FIPS_TEST_ALGO_AES_CTR:
case FIPS_TEST_ALGO_AES:
test_ops.prepare_sym_op = prepare_cipher_op;
test_ops.prepare_sym_xform = prepare_aes_xform;
if (info.interim_info.aes_data.test_type == AESAVS_TYPE_MCT)
test_ops.test = fips_mct_aes_test;
else
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_HMAC:
test_ops.prepare_sym_op = prepare_auth_op;
test_ops.prepare_sym_xform = prepare_hmac_xform;
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_TDES:
test_ops.prepare_sym_op = prepare_cipher_op;
test_ops.prepare_sym_xform = prepare_tdes_xform;
if (info.interim_info.tdes_data.test_type == TDES_MCT)
test_ops.test = fips_mct_tdes_test;
else
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_AES_GMAC:
test_ops.prepare_sym_op = prepare_auth_op;
test_ops.prepare_sym_xform = prepare_gmac_xform;
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_AES_GCM:
test_ops.prepare_sym_op = prepare_aead_op;
test_ops.prepare_sym_xform = prepare_gcm_xform;
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_AES_CMAC:
test_ops.prepare_sym_op = prepare_auth_op;
test_ops.prepare_sym_xform = prepare_cmac_xform;
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_AES_CCM:
test_ops.prepare_sym_op = prepare_aead_op;
test_ops.prepare_sym_xform = prepare_ccm_xform;
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_SHA:
test_ops.prepare_sym_op = prepare_auth_op;
test_ops.prepare_sym_xform = prepare_sha_xform;
if (info.interim_info.sha_data.test_type == SHA_MCT)
test_ops.test = fips_mct_sha_test;
else
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_AES_XTS:
test_ops.prepare_sym_op = prepare_cipher_op;
test_ops.prepare_sym_xform = prepare_xts_xform;
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_RSA:
test_ops.prepare_asym_op = prepare_rsa_op;
test_ops.prepare_asym_xform = prepare_rsa_xform;
test_ops.test = fips_generic_test;
break;
case FIPS_TEST_ALGO_ECDSA:
if (info.op == FIPS_TEST_ASYM_KEYGEN) {
test_ops.prepare_asym_op = prepare_ecfpm_op;
test_ops.prepare_asym_xform = prepare_ecfpm_xform;
test_ops.test = fips_generic_test;
} else {
test_ops.prepare_asym_op = prepare_ecdsa_op;
test_ops.prepare_asym_xform = prepare_ecdsa_xform;
test_ops.test = fips_generic_test;
}
break;
default:
if (strstr(info.file_name, "TECB") ||
strstr(info.file_name, "TCBC")) {
info.algo = FIPS_TEST_ALGO_TDES;
test_ops.prepare_sym_op = prepare_cipher_op;
test_ops.prepare_sym_xform = prepare_tdes_xform;
if (info.interim_info.tdes_data.test_type == TDES_MCT)
test_ops.test = fips_mct_tdes_test;
else
test_ops.test = fips_generic_test;
break;
}
return -1;
}
return 0;
}
static void
print_test_block(void)
{
uint32_t i;
for (i = 0; i < info.nb_vec_lines; i++)
printf("%s\n", info.vec[i]);
printf("\n");
}
static int
fips_test_one_file(void)
{
int fetch_ret = 0, ret;
ret = init_test_ops();
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Init test op\n", ret);
return ret;
}
while (ret >= 0 && fetch_ret == 0) {
fetch_ret = fips_test_fetch_one_block();
if (fetch_ret < 0) {
RTE_LOG(ERR, USER1,
"Error %i: Fetch block\n",
fetch_ret);
ret = fetch_ret;
goto error_one_case;
}
if (info.nb_vec_lines == 0) {
if (fetch_ret == -EOF)
break;
fprintf(info.fp_wr, "\n");
continue;
}
ret = fips_test_parse_one_case();
switch (ret) {
case 0:
ret = test_ops.test();
if (ret == 0)
break;
RTE_LOG(ERR, USER1,
"Error %i: test block\n",
ret);
goto error_one_case;
case 1:
break;
default:
RTE_LOG(ERR, USER1,
"Error %i: Parse block\n",
ret);
goto error_one_case;
}
continue;
error_one_case:
print_test_block();
}
fips_test_clear();
if (env.digest) {
env.digest = NULL;
env.digest_len = 0;
}
return ret;
}
#ifdef USE_JANSSON
static int
fips_test_json_init_writeback(void)
{
json_t *session_info, *session_write;
session_info = json_array_get(json_info.json_root, 0);
session_write = json_object();
json_info.json_write_root = json_array();
json_object_set(session_write, "jwt",
json_object_get(session_info, "jwt"));
json_object_set(session_write, "url",
json_object_get(session_info, "url"));
json_object_set(session_write, "isSample",
json_object_get(session_info, "isSample"));
json_info.is_sample = json_boolean_value(
json_object_get(session_info, "isSample"));
json_array_append_new(json_info.json_write_root, session_write);
return 0;
}
static int
fips_test_one_test_case(void)
{
int ret;
ret = fips_test_parse_one_json_case();
switch (ret) {
case 0:
ret = test_ops.test();
if ((ret == 0) || (ret == -EPERM || ret == -ENOTSUP))
break;
RTE_LOG(ERR, USER1,
"Error %i: test block\n",
ret);
break;
default:
RTE_LOG(ERR, USER1,
"Error %i: Parse block\n",
ret);
}
return ret;
}
static int
fips_test_one_test_group(void)
{
int ret;
json_t *tests, *write_tests;
size_t test_idx, tests_size;
write_tests = json_array();
json_info.json_write_group = json_object();
json_object_set(json_info.json_write_group, "tgId",
json_object_get(json_info.json_test_group, "tgId"));
json_object_set_new(json_info.json_write_group, "tests", write_tests);
switch (info.algo) {
case FIPS_TEST_ALGO_AES_GMAC:
case FIPS_TEST_ALGO_AES_GCM:
ret = parse_test_gcm_json_init();
break;
case FIPS_TEST_ALGO_HMAC:
ret = parse_test_hmac_json_init();
break;
case FIPS_TEST_ALGO_AES_CMAC:
ret = parse_test_cmac_json_init();
break;
case FIPS_TEST_ALGO_AES_XTS:
ret = parse_test_xts_json_init();
break;
case FIPS_TEST_ALGO_AES_CBC:
case FIPS_TEST_ALGO_AES_CTR:
case FIPS_TEST_ALGO_AES:
ret = parse_test_aes_json_init();
break;
case FIPS_TEST_ALGO_SHA:
ret = parse_test_sha_json_init();
break;
case FIPS_TEST_ALGO_TDES:
ret = parse_test_tdes_json_init();
break;
case FIPS_TEST_ALGO_RSA:
ret = parse_test_rsa_json_init();
break;
case FIPS_TEST_ALGO_ECDSA:
ret = parse_test_ecdsa_json_init();
break;
default:
return -EINVAL;
}
if (ret < 0)
return ret;
ret = fips_test_parse_one_json_group();
if (ret < 0)
return ret;
ret = init_test_ops();
if (ret < 0)
return ret;
tests = json_object_get(json_info.json_test_group, "tests");
tests_size = json_array_size(tests);
for (test_idx = 0; test_idx < tests_size; test_idx++) {
json_info.json_test_case = json_array_get(tests, test_idx);
if (fips_test_one_test_case() == 0)
json_array_append_new(write_tests, json_info.json_write_case);
}
return 0;
}
static int
fips_test_one_vector_set(void)
{
int ret;
json_t *test_groups, *write_groups, *write_version, *write_set, *mode;
size_t group_idx, num_groups;
test_groups = json_object_get(json_info.json_vector_set, "testGroups");
num_groups = json_array_size(test_groups);
json_info.json_write_set = json_array();
write_version = json_object();
json_object_set_new(write_version, "acvVersion", json_string(ACVVERSION));
json_array_append_new(json_info.json_write_set, write_version);
write_set = json_object();
json_array_append(json_info.json_write_set, write_set);
write_groups = json_array();
json_object_set(write_set, "vsId",
json_object_get(json_info.json_vector_set, "vsId"));
json_object_set(write_set, "algorithm",
json_object_get(json_info.json_vector_set, "algorithm"));
mode = json_object_get(json_info.json_vector_set, "mode");
if (mode != NULL)
json_object_set_new(write_set, "mode", mode);
json_object_set(write_set, "revision",
json_object_get(json_info.json_vector_set, "revision"));
json_object_set_new(write_set, "isSample",
json_boolean(json_info.is_sample));
json_object_set_new(write_set, "testGroups", write_groups);
ret = fips_test_parse_one_json_vector_set();
if (ret < 0) {
RTE_LOG(ERR, USER1,
"Error: Unsupported or invalid vector set algorithm: %s\n",
json_string_value(json_object_get(json_info.json_vector_set, "algorithm")));
return ret;
}
for (group_idx = 0; group_idx < num_groups; group_idx++) {
json_info.json_test_group = json_array_get(test_groups, group_idx);
ret = fips_test_one_test_group();
json_array_append_new(write_groups, json_info.json_write_group);
}
return 0;
}
static int
fips_test_one_json_file(void)
{
size_t vector_set_idx, root_size;
root_size = json_array_size(json_info.json_root);
fips_test_json_init_writeback();
for (vector_set_idx = 1; vector_set_idx < root_size; vector_set_idx++) {
json_info.json_vector_set = json_array_get(json_info.json_root, vector_set_idx);
fips_test_one_vector_set();
json_array_append_new(json_info.json_write_root, json_info.json_write_set);
json_incref(json_info.json_write_set);
}
json_dumpf(json_info.json_write_root, info.fp_wr, JSON_INDENT(4));
json_decref(json_info.json_write_root);
return 0;
}
#endif
__rte_noreturn void rte_exit(int exit_code, const char *format,...) __rte_format_printf(2
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, void *sess)
static struct rte_crypto_op * rte_crypto_op_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type)
static int rte_crypto_op_attach_asym_session(struct rte_crypto_op *op, struct rte_cryptodev_asym_session *sess)
struct rte_mempool * rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type, unsigned nb_elts, unsigned cache_size, uint16_t priv_size, int socket_id)
static void rte_crypto_op_free(struct rte_crypto_op *op)
@ RTE_CRYPTO_OP_TYPE_ASYMMETRIC
@ RTE_CRYPTO_OP_TYPE_SYMMETRIC
static void __rte_crypto_op_reset(struct rte_crypto_op *op, enum rte_crypto_op_type type)
@ RTE_CRYPTO_ASYM_OP_SIGN
@ RTE_CRYPTO_ASYM_OP_VERIFY
@ RTE_CRYPTO_ASYM_XFORM_RSA
@ RTE_CRYPTO_ASYM_XFORM_ECDSA
@ RTE_CRYPTO_ASYM_XFORM_ECFPM
@ RTE_CRYPTO_RSA_PADDING_PKCS1_5
rte_crypto_auth_algorithm
@ RTE_CRYPTO_AUTH_AES_CMAC
@ RTE_CRYPTO_AUTH_AES_GMAC
@ RTE_CRYPTO_CIPHER_OP_DECRYPT
@ RTE_CRYPTO_CIPHER_OP_ENCRYPT
@ RTE_CRYPTO_SYM_XFORM_AUTH
@ RTE_CRYPTO_SYM_XFORM_AEAD
@ RTE_CRYPTO_SYM_XFORM_CIPHER
@ RTE_CRYPTO_AEAD_AES_CCM
@ RTE_CRYPTO_AEAD_AES_GCM
@ RTE_CRYPTO_CIPHER_AES_XTS
@ RTE_CRYPTO_CIPHER_AES_CTR
@ RTE_CRYPTO_CIPHER_3DES_ECB
@ RTE_CRYPTO_CIPHER_AES_CBC
@ RTE_CRYPTO_CIPHER_3DES_CBC
@ RTE_CRYPTO_CIPHER_AES_ECB
@ RTE_CRYPTO_AUTH_OP_VERIFY
@ RTE_CRYPTO_AUTH_OP_GENERATE
@ RTE_CRYPTO_AEAD_OP_DECRYPT
@ RTE_CRYPTO_AEAD_OP_ENCRYPT
static uint16_t rte_cryptodev_dequeue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, uint16_t nb_ops)
int rte_cryptodev_close(uint8_t dev_id)
__rte_experimental struct rte_mempool * rte_cryptodev_asym_session_pool_create(const char *name, uint32_t nb_elts, uint32_t cache_size, uint16_t user_data_size, int socket_id)
uint8_t rte_cryptodev_count(void)
static uint16_t rte_cryptodev_enqueue_burst(uint8_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops, uint16_t nb_ops)
int rte_cryptodev_start(uint8_t dev_id)
unsigned int rte_cryptodev_is_valid_dev(uint8_t dev_id)
unsigned int rte_cryptodev_sym_get_private_session_size(uint8_t dev_id)
void rte_cryptodev_stop(uint8_t dev_id)
const char * rte_cryptodev_name_get(uint8_t dev_id)
#define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP
#define RTE_CRYPTODEV_FF_IN_PLACE_SGL
int rte_cryptodev_sym_capability_check_auth(const struct rte_cryptodev_symmetric_capability *capability, uint16_t key_size, uint16_t digest_size, uint16_t iv_size)
int rte_cryptodev_configure(uint8_t dev_id, struct rte_cryptodev_config *config)
void * rte_cryptodev_sym_session_create(uint8_t dev_id, struct rte_crypto_sym_xform *xforms, struct rte_mempool *mp)
__rte_experimental int rte_cryptodev_asym_session_create(uint8_t dev_id, struct rte_crypto_asym_xform *xforms, struct rte_mempool *mp, void **session)
__rte_experimental int rte_cryptodev_asym_session_free(uint8_t dev_id, void *sess)
int rte_cryptodev_get_dev_id(const char *name)
int rte_cryptodev_sym_capability_check_aead(const struct rte_cryptodev_symmetric_capability *capability, uint16_t key_size, uint16_t digest_size, uint16_t aad_size, uint16_t iv_size)
int rte_cryptodev_sym_capability_check_cipher(const struct rte_cryptodev_symmetric_capability *capability, uint16_t key_size, uint16_t iv_size)
__rte_experimental int rte_cryptodev_asym_xform_capability_check_optype(const struct rte_cryptodev_asymmetric_xform_capability *capability, enum rte_crypto_asym_op_type op_type)
#define RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT
__rte_experimental const struct rte_cryptodev_asymmetric_xform_capability * rte_cryptodev_asym_capability_get(uint8_t dev_id, const struct rte_cryptodev_asym_capability_idx *idx)
int rte_cryptodev_queue_pair_setup(uint8_t dev_id, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf, int socket_id)
__rte_experimental struct rte_mempool * rte_cryptodev_sym_session_pool_create(const char *name, uint32_t nb_elts, uint32_t elt_size, uint32_t cache_size, uint16_t priv_size, int socket_id)
void rte_cryptodev_info_get(uint8_t dev_id, struct rte_cryptodev_info *dev_info)
#define rte_crypto_op_ctod_offset(c, t, o)
int rte_cryptodev_sym_session_free(uint8_t dev_id, void *sess)
const struct rte_cryptodev_symmetric_capability * rte_cryptodev_sym_capability_get(uint8_t dev_id, const struct rte_cryptodev_sym_capability_idx *idx)
int rte_eal_init(int argc, char **argv)
int rte_eal_cleanup(void)
unsigned int rte_socket_id(void)
#define RTE_LOG(l, t,...)
void * rte_zmalloc(const char *type, size_t size, unsigned align) __rte_alloc_size(2)
void void rte_free(void *ptr)
void * rte_malloc(const char *type, size_t size, unsigned align) __rte_alloc_size(2)
rte_iova_t rte_malloc_virt2iova(const void *addr)
static void rte_pktmbuf_free(struct rte_mbuf *m)
#define rte_pktmbuf_data_len(m)
static char * rte_pktmbuf_append(struct rte_mbuf *m, uint16_t len)
#define rte_pktmbuf_pkt_len(m)
struct rte_mempool * rte_pktmbuf_pool_create(const char *name, unsigned n, unsigned cache_size, uint16_t priv_size, uint16_t data_room_size, int socket_id)
static struct rte_mbuf * rte_pktmbuf_alloc(struct rte_mempool *mp)
static int rte_pktmbuf_chain(struct rte_mbuf *head, struct rte_mbuf *tail)
#define rte_pktmbuf_mtod(m, t)
#define RTE_MBUF_MAX_NB_SEGS
static void * rte_memcpy(void *dst, const void *src, size_t n)
void rte_mempool_free(struct rte_mempool *mp)
static void rte_pause(void)
struct rte_crypto_asym_xform * xform
enum rte_crypto_asym_op_type op_type
struct rte_crypto_ec_point q
struct rte_crypto_ec_point r
struct rte_crypto_sym_op sym[0]
struct rte_crypto_asym_op asym[0]
enum rte_crypto_asym_op_type op_type
struct rte_crypto_rsa_padding padding
enum rte_crypto_auth_algorithm hash
enum rte_crypto_rsa_padding_type type
struct rte_crypto_sym_op::@84::@86::@89 data
struct rte_crypto_sym_op::@84::@86::@90 digest
struct rte_crypto_sym_op::@84::@86::@91 aad
struct rte_mempool * mp_session