> diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
> index 5b16dcab56..b9034b637a 100644
> --- a/app/test/test_cryptodev_asym.c
> +++ b/app/test/test_cryptodev_asym.c
> @@ -64,6 +64,39 @@ static uint32_t test_index;
> 
>  static struct crypto_testsuite_params_asym testsuite_params = { NULL };
> 
> +static void
> +test_crypto_rand(int len, uint8_t *buffer) {
Just a minor suggestion on params order here (below), for ease in readability.
test_crypto_rand(uint8_t *buffer, int len)

> +     int i;
> +
> +     for (i = 0; i < len; ++i)
> +             buffer[i] = (uint8_t)(rand() % ((uint8_t)-1)) | 1; }
rand() % UINT8_MAX easier ?
Also } in next line.

> +
> +static int
> +process_crypto_request(uint8_t dev_id, struct rte_crypto_op **op,
> +                             struct rte_crypto_op **result_op)
> +{
> +     /* 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");
> +             return -1;
> +     }
> +
> +     while (rte_cryptodev_dequeue_burst(dev_id, 0, result_op, 1) == 0)
> +             rte_pause();
> +
> +     if (*result_op == NULL) {
> +             RTE_LOG(ERR, USER1,
> +                     "line %u FAILED: %s",
> +                     __LINE__, "Failed to process asym crypto op");
> +             return -1;
> +     }
> +     return 0;
> +}
> +
>  static int
>  queue_ops_rsa_sign_verify(void *sess)
>  {
> @@ -809,6 +842,8 @@ testsuite_setup(void)
>       test_vector.size = 0;
>       load_test_vectors();
> 
> +     srand(time(NULL));
> +
>       /* Device, op pool and session configuration for asymmetric crypto. 8<
> */
>       ts_params->op_mpool = rte_crypto_op_pool_create(
>                       "CRYPTO_ASYM_OP_POOL",
> @@ -2196,6 +2231,219 @@ test_ecpm_all_curve(void)
>       return overall_status;
>  }
> 
> +static void *
> +dh_alice_bob_set_session(uint8_t dev_id,
> +     struct rte_crypto_op *op,
> +     const struct test_dh_group *group)
> +{
> +     struct rte_crypto_asym_xform xform = { };
> +     void *sess = NULL;
> +     int ret = 0;
> +
> +     xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
> +     xform.dh.g.data = group->g.data;
> +     xform.dh.g.length = group->g.bytesize;
> +     xform.dh.p.data = group->p.data;
> +     xform.dh.p.length = group->p.bytesize;
> +     ret = rte_cryptodev_asym_session_create(dev_id, &xform,
> +                     testsuite_params.session_mpool, &sess);
> +     if (ret)
> +             return NULL;
> +
> +     rte_crypto_op_attach_asym_session(op, sess);
> +     return sess;
> +}
> +
> +static void
> +dh_alice_bob_gen_x(const struct test_dh_group *group,
> +     uint8_t *private_data)
> +{
> +     test_crypto_rand(group->priv_ff_size, private_data);
> +     if (private_data[0] > group->p.data[0])
> +             private_data[0] = group->p.data[0] - 1; }
} in next line.

> +
> +static int
> +dh_alice_bob_gen_y(struct rte_crypto_op *op,
> +     const char *name,
> +     const uint8_t dev_id,
Could this order be dev_id, name, op etc ??

> +     uint8_t *y,
> +     uint8_t *x,
> +     const int ff_size)
> +{
> +     struct rte_crypto_op *result_op;
> +     int ret = 0;
> +
> +     op->asym->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
> +     op->asym->dh.pub_key.data = y;
> +     op->asym->dh.priv_key.data = x;
> +     op->asym->dh.priv_key.length = ff_size;
> +
> +     ret = process_crypto_request(dev_id, &op, &result_op);
> +     TEST_ASSERT_SUCCESS(ret, "Failed to compute public key for %s",
> name);
> +
> +     return 0;
> +}
> +
> +static int
> +dh_alice_bob_shared_compute(uint8_t dev_id,
> +     const char *name,
> +     struct rte_crypto_op *op,
> +     uint8_t *secret,
> +     uint8_t *peer,
> +     uint32_t peer_size)
> +{
> +     struct rte_crypto_op *result_op;
> +     int ret = 0;
> +
> +     op->asym->dh.ke_type =
> RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
> +     op->asym->dh.pub_key.data = peer;
> +     op->asym->dh.pub_key.length = peer_size;
> +     op->asym->dh.shared_secret.data = secret;
> +
> +     ret = process_crypto_request(dev_id, &op, &result_op);
> +     TEST_ASSERT_SUCCESS(ret,
> +             "Failed to compute shared secret for %s",
> +             name);
> +
> +     return 0;
> +}
> +
> +/* Diffie-Hellman test to verify the processed data */ static int
Patch format incorrect ?

> +dh_alice_bob_verify(struct rte_crypto_op *alice_op,
> +     struct rte_crypto_op *bob_op)
> +{
> +     int ret = 0;
> +
> +     /* Verify processed data */
> +     ret = (alice_op->asym->dh.shared_secret.length ==
> +                     bob_op->asym->dh.shared_secret.length);
Is 0 length allowed ?

> +     if (!ret) {
> +             RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
> +                     "Alice's and Bob's shared secret length do not match.");
> +             return TEST_FAILED;
> +     }
> +     ret = memcmp(alice_op->asym->dh.shared_secret.data,
> +             alice_op->asym->dh.shared_secret.data,
> +             bob_op->asym->dh.shared_secret.length);
> +     if (ret) {
> +             RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
> +                     "Alice's and Bob's shared secret do not match.");
> +             return TEST_FAILED;
> +     }
> +     return TEST_SUCCESS;
> +}
> +
<cut..>

> +static const struct test_dh_group test_dh_ikev2group_24 = {
> +     .id = 0,
> +     /*
> +      * Officially 24, ikev2
> +      */
> +     .g = {
> +             .data = test_dh_ikev2group24_g,
> +             .bytesize = sizeof(test_dh_ikev2group24_g),
> +     },
> +     .p = {
> +             .data = test_dh_ikev2group24_p,
> +             .bytesize = sizeof(test_dh_ikev2group24_p),
> +     },
> +     .priv_ff_size = 32,
> +};
> +
Below are suppose to be 2/3 patch right ?

> +static const struct test_dh_group test_ecdh_secp256r1 = {
> +     .id = RTE_CRYPTO_EC_GROUP_SECP256R1,
> +     .priv_ff_size = 32,
> +};
> +static const struct test_dh_group test_ecdh_secp384r1 = {
> +     .id = RTE_CRYPTO_EC_GROUP_SECP384R1,
> +     .priv_ff_size = 48,
> +};
> +static const struct test_dh_group test_ecdh_secp521r1 = {
> +     .id = RTE_CRYPTO_EC_GROUP_SECP521R1,
> +     .priv_ff_size = 64,
> +};
> +
> +
>  #endif /* TEST_CRYPTODEV_DH_TEST_VECTORS_H__ */
> --
> 2.17.1

Reply via email to