/* SPDX-License-Identifier: BSD-3-Clause
* Copyright(c) 2018 Cavium Networks
+ * Copyright (c) 2019 Intel Corporation
*/
#include <rte_bus_vdev.h>
#define TEST_NUM_BUFS 10
#define TEST_NUM_SESSIONS 4
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
+#ifndef TEST_DATA_SIZE
+ #define TEST_DATA_SIZE 4096
+#endif
+#define ASYM_TEST_MSG_LEN 256
+#define TEST_VECTOR_SIZE 256
+
static int gbl_driver_id;
struct crypto_testsuite_params {
struct rte_mempool *op_mpool;
struct rte_crypto_op *op;
};
+union test_case_structure {
+ struct modex_test_data modex;
+ struct modinv_test_data modinv;
+};
+
+struct test_cases_array {
+ uint32_t size;
+ const void *address[TEST_VECTOR_SIZE];
+};
+static struct test_cases_array test_vector = {0, { NULL } };
+
+static uint32_t test_index;
+
static struct crypto_testsuite_params testsuite_params = { NULL };
static int
-test_rsa_sign_verify(void)
+queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
{
struct crypto_testsuite_params *ts_params = &testsuite_params;
struct rte_mempool *op_mpool = ts_params->op_mpool;
- struct rte_mempool *sess_mpool = ts_params->session_mpool;
uint8_t dev_id = ts_params->valid_devs[0];
- struct rte_crypto_asym_op *asym_op = NULL;
- struct rte_crypto_op *op = NULL, *result_op = NULL;
- struct rte_cryptodev_asym_session *sess = NULL;
+ struct rte_crypto_op *op, *result_op;
+ struct rte_crypto_asym_op *asym_op;
+ uint8_t output_buf[TEST_DATA_SIZE];
int status = TEST_SUCCESS;
- uint8_t output_buf[TEST_DATA_SIZE] = {0};
- uint8_t input_buf[TEST_DATA_SIZE] = {0};
-
- sess = rte_cryptodev_asym_session_create(sess_mpool);
-
- if (!sess) {
- RTE_LOG(ERR, USER1, "line %u "
- "FAILED: %s", __LINE__,
- "Session creation failed");
- status = TEST_FAILED;
- goto error_exit;
- }
-
- if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
- sess_mpool) < 0) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "unabled to config sym session");
- status = TEST_FAILED;
- goto error_exit;
- }
- /* set up crypto op data structure */
+ /* Set up crypto op data structure */
op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
if (!op) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__,
- "Failed to allocate asymmetric crypto "
- "operation struct");
- status = TEST_FAILED;
- goto error_exit;
+ RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
+ "operation struct\n");
+ return TEST_FAILED;
}
asym_op = op->asym;
+
/* Compute sign on the test vector */
asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
- memcpy(input_buf, &rsaplaintext.data,
- rsaplaintext.len);
- asym_op->rsa.message.data = input_buf;
+ asym_op->rsa.message.data = rsaplaintext.data;
asym_op->rsa.message.length = rsaplaintext.len;
+ asym_op->rsa.sign.length = 0;
asym_op->rsa.sign.data = output_buf;
- asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1;
+ asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
debug_hexdump(stdout, "message", asym_op->rsa.message.data,
- asym_op->rsa.message.length);
+ asym_op->rsa.message.length);
- /* attach asymmetric crypto session to crypto operations */
+ /* Attach asymmetric crypto session to crypto operations */
rte_crypto_op_attach_asym_session(op, sess);
- RTE_LOG(DEBUG, USER1, "Process ASYM operation");
+ RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
/* Process crypto operation */
if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "Error sending packet for operation");
+ RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
status = TEST_FAILED;
goto error_exit;
}
rte_pause();
if (result_op == NULL) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "Failed to process asym crypto op");
+ RTE_LOG(ERR, USER1, "Failed to process sign op\n");
status = TEST_FAILED;
goto error_exit;
}
+
debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
- asym_op->rsa.sign.length);
+ asym_op->rsa.sign.length);
asym_op = result_op->asym;
/* Verify sign */
asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
- asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2;
+ asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
/* Process crypto operation */
if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "Error sending packet for operation");
+ RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
status = TEST_FAILED;
goto error_exit;
}
rte_pause();
if (result_op == NULL) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "Failed to process asym crypto op");
+ RTE_LOG(ERR, USER1, "Failed to process verify op\n");
status = TEST_FAILED;
goto error_exit;
}
+
status = TEST_SUCCESS;
if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "Failed to process asym crypto op");
+ RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
status = TEST_FAILED;
- goto error_exit;
}
error_exit:
- if (sess) {
- rte_cryptodev_asym_session_clear(dev_id, sess);
- rte_cryptodev_asym_session_free(sess);
- }
-
- if (op)
- rte_crypto_op_free(op);
-
- TEST_ASSERT_EQUAL(status, 0, "Test failed");
+ rte_crypto_op_free(op);
return status;
}
static int
-test_rsa_enc_dec(void)
+queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
{
struct crypto_testsuite_params *ts_params = &testsuite_params;
struct rte_mempool *op_mpool = ts_params->op_mpool;
- struct rte_mempool *sess_mpool = ts_params->session_mpool;
uint8_t dev_id = ts_params->valid_devs[0];
- struct rte_crypto_asym_op *asym_op = NULL;
- struct rte_crypto_op *op = NULL, *result_op = NULL;
- struct rte_cryptodev_asym_session *sess = NULL;
- int status = TEST_SUCCESS;
- uint8_t input_buf[TEST_DATA_SIZE] = {0};
-
- sess = rte_cryptodev_asym_session_create(sess_mpool);
-
- if (!sess) {
- RTE_LOG(ERR, USER1, "line %u "
- "FAILED: %s", __LINE__,
- "Session creation failed");
- status = TEST_FAILED;
- goto error_exit;
- }
-
- if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
- sess_mpool) < 0) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "unabled to config sym session");
- status = TEST_FAILED;
- goto error_exit;
- }
+ struct rte_crypto_op *op, *result_op;
+ struct rte_crypto_asym_op *asym_op;
+ uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
+ int ret, status = TEST_SUCCESS;
- /* set up crypto op data structure */
+ /* Set up crypto op data structure */
op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
if (!op) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__,
- "Failed to allocate asymmetric crypto "
- "operation struct");
- status = TEST_FAILED;
- goto error_exit;
+ RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
+ "operation struct\n");
+ return TEST_FAILED;
}
asym_op = op->asym;
- /*Compute encryption on the test vector */
+
+ /* Compute encryption on the test vector */
asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
- memcpy(input_buf, rsaplaintext.data,
- rsaplaintext.len);
- asym_op->rsa.message.data = input_buf;
+ asym_op->rsa.message.data = rsaplaintext.data;
+ asym_op->rsa.cipher.data = cipher_buf;
+ asym_op->rsa.cipher.length = 0;
asym_op->rsa.message.length = rsaplaintext.len;
- asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2;
+ asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
debug_hexdump(stdout, "message", asym_op->rsa.message.data,
- asym_op->rsa.message.length);
+ asym_op->rsa.message.length);
- /* attach asymmetric crypto session to crypto operations */
+ /* Attach asymmetric crypto session to crypto operations */
rte_crypto_op_attach_asym_session(op, sess);
- RTE_LOG(DEBUG, USER1, "Process ASYM operation");
+ RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
/* Process crypto operation */
if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "Error sending packet for operation");
+ RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
status = TEST_FAILED;
goto error_exit;
}
rte_pause();
if (result_op == NULL) {
- RTE_LOG(ERR, USER1,
- "line %u FAILED: %s",
- __LINE__, "Failed to process asym crypto op");
+ RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
status = TEST_FAILED;
goto error_exit;
}
debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
- asym_op->rsa.message.length);
+ asym_op->rsa.message.length);
+
/* Use the resulted output as decryption Input vector*/
asym_op = result_op->asym;
+ asym_op->rsa.message.length = 0;
asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
- asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1;
+ asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
/* Process crypto operation */
if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
- RTE_LOG(ERR, USER1,
+ RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+
+ while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
+ rte_pause();
+
+ if (result_op == NULL) {
+ RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+ status = TEST_SUCCESS;
+ ret = rsa_verify(&rsaplaintext, result_op);
+ if (ret)
+ status = TEST_FAILED;
+
+error_exit:
+
+ rte_crypto_op_free(op);
+
+ return status;
+}
+static int
+test_cryptodev_asym_ver(union test_case_structure *data_tc,
+ struct rte_crypto_op *result_op)
+{
+ int status = TEST_SUCCESS;
+ int ret = 0;
+ uint8_t *data_expected = NULL, *data_received = NULL;
+ size_t data_size = 0;
+
+ switch (data_tc->modex.xform_type) {
+ case RTE_CRYPTO_ASYM_XFORM_MODEX:
+ data_expected = data_tc->modex.reminder.data;
+ data_received = result_op->asym->modex.result.data;
+ data_size = result_op->asym->modex.result.length;
+ break;
+ case RTE_CRYPTO_ASYM_XFORM_MODINV:
+ data_expected = data_tc->modinv.inverse.data;
+ data_received = result_op->asym->modinv.result.data;
+ data_size = result_op->asym->modinv.result.length;
+ break;
+ case RTE_CRYPTO_ASYM_XFORM_DH:
+ case RTE_CRYPTO_ASYM_XFORM_DSA:
+ case RTE_CRYPTO_ASYM_XFORM_RSA:
+ case RTE_CRYPTO_ASYM_XFORM_NONE:
+ case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
+ default:
+ break;
+ }
+ ret = memcmp(data_expected, data_received, data_size);
+ if (ret)
+ status = TEST_FAILED;
+
+ return status;
+}
+
+static int
+test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
+ union test_case_structure *data_tc,
+ char *test_msg)
+{
+ struct rte_crypto_asym_op *asym_op = NULL;
+ struct rte_crypto_op *op = NULL;
+ struct rte_crypto_op *result_op = NULL;
+ struct rte_crypto_asym_xform xform_tc;
+ struct rte_cryptodev_asym_session *sess = NULL;
+ struct rte_cryptodev_asym_capability_idx cap_idx;
+ const struct rte_cryptodev_asymmetric_xform_capability *capability;
+ uint8_t dev_id = ts_params->valid_devs[0];
+ uint8_t input[TEST_DATA_SIZE] = {0};
+ uint8_t *result = NULL;
+
+ int status = TEST_SUCCESS;
+
+ xform_tc.next = NULL;
+ xform_tc.xform_type = data_tc->modex.xform_type;
+
+ cap_idx.type = xform_tc.xform_type;
+ capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
+
+ if (capability == NULL) {
+ RTE_LOG(INFO, USER1,
+ "Device doesn't support MODEX. Test Skipped\n");
+ return -ENOTSUP;
+ }
+
+ /* Generate crypto op data structure */
+ op = rte_crypto_op_alloc(ts_params->op_mpool,
+ RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
+
+ if (!op) {
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
+ "line %u FAILED: %s",
+ __LINE__, "Failed to allocate asymmetric crypto "
+ "operation struct");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+
+ asym_op = op->asym;
+
+ switch (xform_tc.xform_type) {
+ case RTE_CRYPTO_ASYM_XFORM_MODEX:
+ result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
+ xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
+ xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
+ xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
+ xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
+ memcpy(input, data_tc->modex.base.data,
+ data_tc->modex.base.len);
+ asym_op->modex.base.data = input;
+ asym_op->modex.base.length = data_tc->modex.base.len;
+ asym_op->modex.result.data = result;
+ asym_op->modex.result.length = data_tc->modex.result_len;
+ if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
+ xform_tc.modex.modulus.length)) {
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
+ "line %u "
+ "FAILED: %s", __LINE__,
+ "Invalid MODULUS length specified");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+ break;
+ case RTE_CRYPTO_ASYM_XFORM_MODINV:
+ result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
+ xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
+ xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
+ memcpy(input, data_tc->modinv.base.data,
+ data_tc->modinv.base.len);
+ asym_op->modinv.base.data = input;
+ asym_op->modinv.base.length = data_tc->modinv.base.len;
+ asym_op->modinv.result.data = result;
+ asym_op->modinv.result.length = data_tc->modinv.result_len;
+ if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
+ xform_tc.modinv.modulus.length)) {
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
+ "line %u "
+ "FAILED: %s", __LINE__,
+ "Invalid MODULUS length specified");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+ break;
+ case RTE_CRYPTO_ASYM_XFORM_DH:
+ case RTE_CRYPTO_ASYM_XFORM_DSA:
+ case RTE_CRYPTO_ASYM_XFORM_RSA:
+ case RTE_CRYPTO_ASYM_XFORM_NONE:
+ case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
+ default:
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
+ "line %u "
+ "FAILED: %s", __LINE__,
+ "Invalid ASYM algorithm specified");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+
+ sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
+ if (!sess) {
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
+ "line %u "
+ "FAILED: %s", __LINE__,
+ "Session creation failed");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+
+ if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
+ ts_params->session_mpool) < 0) {
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
+ "line %u FAILED: %s",
+ __LINE__, "unabled to config sym session");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+
+ rte_crypto_op_attach_asym_session(op, sess);
+
+ RTE_LOG(DEBUG, USER1, "Process ASYM operation");
+
+ /* Process crypto operation */
+ if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
"line %u FAILED: %s",
__LINE__, "Error sending packet for operation");
status = TEST_FAILED;
rte_pause();
if (result_op == NULL) {
- RTE_LOG(ERR, USER1,
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
"line %u FAILED: %s",
__LINE__, "Failed to process asym crypto op");
status = TEST_FAILED;
goto error_exit;
}
- status = TEST_SUCCESS;
- int ret = 0;
- ret = rsa_verify(&rsaplaintext, result_op);
- if (ret)
+
+ if (test_cryptodev_asym_ver(data_tc, result_op) != TEST_SUCCESS) {
+ snprintf(test_msg, ASYM_TEST_MSG_LEN,
+ "line %u FAILED: %s",
+ __LINE__, "Verification failed ");
status = TEST_FAILED;
+ goto error_exit;
+ }
+
+ snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
error_exit:
+ if (sess != NULL) {
+ rte_cryptodev_asym_session_clear(dev_id, sess);
+ rte_cryptodev_asym_session_free(sess);
+ }
- if (sess) {
- rte_cryptodev_asym_session_clear(dev_id, sess);
- rte_cryptodev_asym_session_free(sess);
+ if (op != NULL)
+ rte_crypto_op_free(op);
+
+ if (result != NULL)
+ rte_free(result);
+
+ return status;
+}
+
+static int
+test_one_case(const void *test_case)
+{
+ int status = TEST_SUCCESS;
+ char test_msg[ASYM_TEST_MSG_LEN + 1];
+
+ /* Map the case to union */
+ union test_case_structure tc;
+ memcpy(&tc, test_case, sizeof(tc));
+
+ status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg);
+
+ printf(" %u) TestCase %s %s\n", test_index++,
+ tc.modex.description, test_msg);
+
+ return status;
+}
+
+static int
+load_test_vectors(void)
+{
+ uint32_t i = 0, v_size = 0;
+ /* Load MODEX vector*/
+ v_size = ARRAY_SIZE(modex_test_case);
+ for (i = 0; i < v_size; i++) {
+ if (test_vector.size >= (TEST_VECTOR_SIZE)) {
+ RTE_LOG(DEBUG, USER1,
+ "TEST_VECTOR_SIZE too small\n");
+ return -1;
+ }
+ test_vector.address[test_vector.size] = &modex_test_case[i];
+ test_vector.size++;
+ }
+ /* Load MODINV vector*/
+ v_size = ARRAY_SIZE(modinv_test_case);
+ for (i = 0; i < v_size; i++) {
+ if (test_vector.size >= (TEST_VECTOR_SIZE)) {
+ RTE_LOG(DEBUG, USER1,
+ "TEST_VECTOR_SIZE too small\n");
+ return -1;
+ }
+ test_vector.address[test_vector.size] = &modinv_test_case[i];
+ test_vector.size++;
}
+ return 0;
+}
- if (op)
- rte_crypto_op_free(op);
+static int
+test_one_by_one(void)
+{
+ int status = TEST_SUCCESS;
+ uint32_t i = 0;
+
+ /* Go through all test cases */
+ test_index = 0;
+ for (i = 0; i < test_vector.size; i++) {
+ if (test_one_case(test_vector.address[i]) != TEST_SUCCESS)
+ status = TEST_FAILED;
+ }
+
+ TEST_ASSERT_EQUAL(status, 0, "Test failed");
+ return status;
+}
+
+static int
+test_rsa_sign_verify(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct rte_mempool *sess_mpool = ts_params->session_mpool;
+ uint8_t dev_id = ts_params->valid_devs[0];
+ struct rte_cryptodev_asym_session *sess;
+ struct rte_cryptodev_info dev_info;
+ int status = TEST_SUCCESS;
+
+ /* Test case supports op with exponent key only,
+ * Check in PMD feature flag for RSA exponent key type support.
+ */
+ rte_cryptodev_info_get(dev_id, &dev_info);
+ if (!(dev_info.feature_flags &
+ RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
+ RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
+ "exponent key type. Test Skipped\n");
+ return -ENOTSUP;
+ }
+
+ sess = rte_cryptodev_asym_session_create(sess_mpool);
+
+ if (!sess) {
+ RTE_LOG(ERR, USER1, "Session creation failed for "
+ "sign_verify\n");
+ return TEST_FAILED;
+ }
+
+ if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
+ sess_mpool) < 0) {
+ RTE_LOG(ERR, USER1, "Unable to config asym session for "
+ "sign_verify\n");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+
+ status = queue_ops_rsa_sign_verify(sess);
+
+error_exit:
+
+ rte_cryptodev_asym_session_clear(dev_id, sess);
+ rte_cryptodev_asym_session_free(sess);
+
+ TEST_ASSERT_EQUAL(status, 0, "Test failed");
+
+ return status;
+}
+
+static int
+test_rsa_enc_dec(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct rte_mempool *sess_mpool = ts_params->session_mpool;
+ uint8_t dev_id = ts_params->valid_devs[0];
+ struct rte_cryptodev_asym_session *sess;
+ struct rte_cryptodev_info dev_info;
+ int status = TEST_SUCCESS;
+
+ /* Test case supports op with exponent key only,
+ * Check in PMD feature flag for RSA exponent key type support.
+ */
+ rte_cryptodev_info_get(dev_id, &dev_info);
+ if (!(dev_info.feature_flags &
+ RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
+ RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
+ "exponent key type. Test skipped\n");
+ return -ENOTSUP;
+ }
+
+ sess = rte_cryptodev_asym_session_create(sess_mpool);
+
+ if (!sess) {
+ RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
+ return TEST_FAILED;
+ }
+
+ if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
+ sess_mpool) < 0) {
+ RTE_LOG(ERR, USER1, "Unable to config asym session for "
+ "enc_dec\n");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+
+ status = queue_ops_rsa_enc_dec(sess);
+
+error_exit:
+
+ rte_cryptodev_asym_session_clear(dev_id, sess);
+ rte_cryptodev_asym_session_free(sess);
+
+ TEST_ASSERT_EQUAL(status, 0, "Test failed");
+
+ return status;
+}
+
+static int
+test_rsa_sign_verify_crt(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct rte_mempool *sess_mpool = ts_params->session_mpool;
+ uint8_t dev_id = ts_params->valid_devs[0];
+ struct rte_cryptodev_asym_session *sess;
+ struct rte_cryptodev_info dev_info;
+ int status = TEST_SUCCESS;
+
+ /* Test case supports op with quintuple format key only,
+ * Check im PMD feature flag for RSA quintuple key type support.
+ */
+ rte_cryptodev_info_get(dev_id, &dev_info);
+ if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
+ RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
+ "quintuple key type. Test skipped\n");
+ return -ENOTSUP;
+ }
+
+ sess = rte_cryptodev_asym_session_create(sess_mpool);
+
+ if (!sess) {
+ RTE_LOG(ERR, USER1, "Session creation failed for "
+ "sign_verify_crt\n");
+ status = TEST_FAILED;
+ return status;
+ }
+
+ if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
+ sess_mpool) < 0) {
+ RTE_LOG(ERR, USER1, "Unable to config asym session for "
+ "sign_verify_crt\n");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+ status = queue_ops_rsa_sign_verify(sess);
+
+error_exit:
+
+ rte_cryptodev_asym_session_clear(dev_id, sess);
+ rte_cryptodev_asym_session_free(sess);
+
+ TEST_ASSERT_EQUAL(status, 0, "Test failed");
+
+ return status;
+}
+
+static int
+test_rsa_enc_dec_crt(void)
+{
+ struct crypto_testsuite_params *ts_params = &testsuite_params;
+ struct rte_mempool *sess_mpool = ts_params->session_mpool;
+ uint8_t dev_id = ts_params->valid_devs[0];
+ struct rte_cryptodev_asym_session *sess;
+ struct rte_cryptodev_info dev_info;
+ int status = TEST_SUCCESS;
+
+ /* Test case supports op with quintuple format key only,
+ * Check in PMD feature flag for RSA quintuple key type support.
+ */
+ rte_cryptodev_info_get(dev_id, &dev_info);
+ if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
+ RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
+ "quintuple key type. Test skipped\n");
+ return -ENOTSUP;
+ }
+
+ sess = rte_cryptodev_asym_session_create(sess_mpool);
+
+ if (!sess) {
+ RTE_LOG(ERR, USER1, "Session creation failed for "
+ "enc_dec_crt\n");
+ return TEST_FAILED;
+ }
+
+ if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
+ sess_mpool) < 0) {
+ RTE_LOG(ERR, USER1, "Unable to config asym session for "
+ "enc_dec_crt\n");
+ status = TEST_FAILED;
+ goto error_exit;
+ }
+ status = queue_ops_rsa_enc_dec(sess);
+
+error_exit:
+
+ rte_cryptodev_asym_session_clear(dev_id, sess);
+ rte_cryptodev_asym_session_free(sess);
TEST_ASSERT_EQUAL(status, 0, "Test failed");
testsuite_setup(void)
{
struct crypto_testsuite_params *ts_params = &testsuite_params;
+ uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
struct rte_cryptodev_info info;
- uint32_t i = 0, nb_devs, dev_id;
- int ret;
+ int ret, dev_id = -1;
+ uint32_t i, nb_devs;
uint16_t qp_id;
memset(ts_params, 0, sizeof(*ts_params));
+ test_vector.size = 0;
+ load_test_vectors();
+
ts_params->op_mpool = rte_crypto_op_pool_create(
"CRYPTO_ASYM_OP_POOL",
RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
}
}
- nb_devs = rte_cryptodev_count();
+ /* Get list of valid crypto devs */
+ nb_devs = rte_cryptodev_devices_get(
+ rte_cryptodev_driver_name_get(gbl_driver_id),
+ valid_devs, RTE_CRYPTO_MAX_DEVS);
if (nb_devs < 1) {
RTE_LOG(ERR, USER1, "No crypto devices found?\n");
return TEST_FAILED;
}
- /* Create list of valid crypto devs */
- for (i = 0; i < nb_devs; i++) {
- rte_cryptodev_info_get(i, &info);
- if (info.driver_id == gbl_driver_id)
- ts_params->valid_devs[ts_params->valid_dev_count++] = i;
+ /*
+ * Get first valid asymmetric device found in test suite param and
+ * break
+ */
+ for (i = 0; i < nb_devs ; i++) {
+ rte_cryptodev_info_get(valid_devs[i], &info);
+ if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
+ dev_id = ts_params->valid_devs[0] = valid_devs[i];
+ break;
+ }
}
- if (ts_params->valid_dev_count < 1)
- return TEST_FAILED;
-
- /* Set up all the qps on the first of the valid devices found */
-
- dev_id = ts_params->valid_devs[0];
-
- rte_cryptodev_info_get(dev_id, &info);
-
- /* check if device support asymmetric, skip if not */
- if (!(info.feature_flags &
- RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
+ if (dev_id == -1) {
RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
- "Test Skipped.\n");
+ "Test skipped.\n");
return TEST_FAILED;
}
+ /* Set valid device count */
+ ts_params->valid_dev_count = nb_devs;
+
/* configure device with num qp */
ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
ts_params->conf.socket_id = SOCKET_ID_ANY;
+ ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
+ RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
&ts_params->conf),
"Failed to configure cryptodev %u with %u qps",
const struct rte_cryptodev_asymmetric_xform_capability *capability;
uint8_t input[TEST_DATA_SIZE] = {0};
int ret = 0;
+ uint8_t result[sizeof(mod_p)] = { 0 };
if (rte_cryptodev_asym_get_xform_enum(
&modinv_xform.xform_type, "modinv") < 0) {
RTE_LOG(ERR, USER1,
- "Invalid ASYNC algorithm specified\n");
+ "Invalid ASYM algorithm specified\n");
return -1;
}
capability = rte_cryptodev_asym_capability_get(dev_id,
&cap_idx);
+ if (capability == NULL) {
+ RTE_LOG(INFO, USER1,
+ "Device doesn't support MOD INV. Test Skipped\n");
+ return -ENOTSUP;
+ }
+
if (rte_cryptodev_asym_xform_capability_check_modlen(
capability,
modinv_xform.modinv.modulus.length)) {
RTE_LOG(ERR, USER1,
- "Invalid MODULOUS length specified\n");
- return -1;
+ "Invalid MODULUS length specified\n");
+ return -ENOTSUP;
}
sess = rte_cryptodev_asym_session_create(sess_mpool);
memcpy(input, base, sizeof(base));
asym_op->modinv.base.data = input;
asym_op->modinv.base.length = sizeof(base);
+ asym_op->modinv.result.data = result;
+ asym_op->modinv.result.length = sizeof(result);
/* attach asymmetric crypto session to crypto operations */
rte_crypto_op_attach_asym_session(op, sess);
const struct rte_cryptodev_asymmetric_xform_capability *capability;
uint8_t input[TEST_DATA_SIZE] = {0};
int ret = 0;
+ uint8_t result[sizeof(mod_p)] = { 0 };
if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
"modexp")
< 0) {
RTE_LOG(ERR, USER1,
- "Invalid ASYNC algorithm specified\n");
+ "Invalid ASYM algorithm specified\n");
return -1;
}
cap_idx.type = modex_xform.xform_type;
capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
+ if (capability == NULL) {
+ RTE_LOG(INFO, USER1,
+ "Device doesn't support MOD EXP. Test Skipped\n");
+ return -ENOTSUP;
+ }
+
if (rte_cryptodev_asym_xform_capability_check_modlen(
capability, modex_xform.modex.modulus.length)) {
RTE_LOG(ERR, USER1,
- "Invalid MODULOUS length specified\n");
- return -1;
+ "Invalid MODULUS length specified\n");
+ return -ENOTSUP;
}
/* generate crypto op data structure */
memcpy(input, base, sizeof(base));
asym_op->modex.base.data = input;
asym_op->modex.base.length = sizeof(base);
+ asym_op->modex.result.data = result;
+ asym_op->modex.result.length = sizeof(result);
/* attach asymmetric crypto session to crypto operations */
rte_crypto_op_attach_asym_session(op, sess);
TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
+ TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
+ TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
+ TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
+ TEST_CASES_END() /**< NULL terminate unit test array */
+ }
+};
+
+static struct unit_test_suite cryptodev_qat_asym_testsuite = {
+ .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
+ .setup = testsuite_setup,
+ .teardown = testsuite_teardown,
+ .unit_test_cases = {
+ TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
TEST_CASES_END() /**< NULL terminate unit test array */
}
};
return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
}
+static int
+test_cryptodev_qat_asym(void)
+{
+ gbl_driver_id = rte_cryptodev_driver_id_get(
+ RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
+
+ if (gbl_driver_id == -1) {
+ RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
+ "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
+ "in config file to run this testsuite.\n");
+ return TEST_FAILED;
+ }
+
+ return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
+}
+
REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
test_cryptodev_openssl_asym);
+
+REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);