From patchwork Sun May 28 17:35:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadiusz Kusztal X-Patchwork-Id: 127645 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9F71442BC4; Sun, 28 May 2023 19:36:04 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D55FF42D39; Sun, 28 May 2023 19:35:47 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mails.dpdk.org (Postfix) with ESMTP id 8553342B7E for ; Sun, 28 May 2023 19:35:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1685295345; x=1716831345; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eQoCIbJ4Iuujb53MIo6aqnUyqjsnJk/bHbAa38C+dnA=; b=gpFNOIdk4YqffcbsOe1eJ5QGr2aB4Q7IlX/wJqXo1Hk2ieso3j/5fU+f FD92rKIptmbugWBmocY+UvNU9MGkrbVQF5h6bxPqSpFn9gzSY4+sr+HFZ 8CgEmes2kgb+ZWMtBfrv2X7Zqob9cGgJmYXC3Qkfimz+az4eALSNpwVUX Ivz1s24rgPwXdswvT3a+/RgHf0C2ETEZeIPrAcz6EgZ9CHfW0ZBFWkQcC xAyr3H/uT8xYMHjSNtV9bwJ5evxrX5dis3DY+i2HQkRngVZZ2zur0yASn bkOnuSHdxv4SVClh2gyJMOmsy1upqUY9dijuaqMsjV293hibvkeI5V65M g==; X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="344041616" X-IronPort-AV: E=Sophos;i="6.00,198,1681196400"; d="scan'208";a="344041616" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 May 2023 10:35:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10724"; a="738892665" X-IronPort-AV: E=Sophos;i="6.00,198,1681196400"; d="scan'208";a="738892665" Received: from silpixa00401012.ir.intel.com ([10.243.22.82]) by orsmga001.jf.intel.com with ESMTP; 28 May 2023 10:35:43 -0700 From: Arek Kusztal To: dev@dpdk.org Cc: gakhil@marvell.com, kai.ji@intel.com, ciara.power@intel.com, Arek Kusztal Subject: [PATCH v2 3/4] app/test: refactor mod inv tests Date: Sun, 28 May 2023 17:35:30 +0000 Message-Id: <20230528173531.263548-4-arkadiuszx.kusztal@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230528173531.263548-1-arkadiuszx.kusztal@intel.com> References: <20230528173531.263548-1-arkadiuszx.kusztal@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Added new modular multiplicative inverse function. Now it handles changes to the generic setup. Signed-off-by: Arek Kusztal Acked-by: Ciara Power --- app/test/test_cryptodev_asym.c | 144 ++++++--------------- app/test/test_cryptodev_asym_util.h | 9 -- app/test/test_cryptodev_mod_test_vectors.h | 64 +-------- 3 files changed, 45 insertions(+), 172 deletions(-) diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c index dd670305ab..7a0124d7c7 100644 --- a/app/test/test_cryptodev_asym.c +++ b/app/test/test_cryptodev_asym.c @@ -594,17 +594,6 @@ static int load_test_vectors(void) { uint32_t i = 0, v_size = 0; - /* Load MODINV vector*/ - v_size = RTE_DIM(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++; - } /* Load RSA vector*/ v_size = RTE_DIM(rsa_test_case_list); for (i = 0; i < v_size; i++) { @@ -1339,32 +1328,26 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm) } static int -test_mod_inv(void) +modular_multiplicative_inverse(const void *test_data) { - struct rte_mempool *op_mpool = params->op_mpool; - struct rte_mempool *sess_mpool = params->session_mpool; - uint8_t dev_id = params->valid_devs[0]; - struct rte_crypto_asym_op *asym_op = NULL; - struct rte_crypto_op *op = NULL, *result_op = NULL; - void *sess = NULL; - int status = TEST_SUCCESS; + const struct modinv_test_data *vector = test_data; + uint8_t input[TEST_DATA_SIZE] = { 0 }; + uint8_t modulus[TEST_DATA_SIZE] = { 0 }; + uint8_t result[TEST_DATA_SIZE] = { 0 }; struct rte_cryptodev_asym_capability_idx cap_idx; 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 }; + struct rte_crypto_asym_xform xform = { }; + const uint8_t dev_id = params->valid_devs[0]; - if (rte_cryptodev_asym_get_xform_enum( - &modinv_xform.xform_type, "modinv") < 0) { - RTE_LOG(ERR, USER1, - "Invalid ASYM algorithm specified\n"); - return -1; - } + memcpy(input, vector->base.data, vector->base.len); + memcpy(modulus, vector->modulus.data, vector->modulus.len); - cap_idx.type = modinv_xform.xform_type; + xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV; + xform.modex.modulus.data = modulus; + xform.modex.modulus.length = vector->modulus.len; + cap_idx.type = 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 INV. Test Skipped\n"); @@ -1372,81 +1355,31 @@ test_mod_inv(void) } if (rte_cryptodev_asym_xform_capability_check_modlen( - capability, - modinv_xform.modinv.modulus.length)) { + capability, + xform.modinv.modulus.length)) { RTE_LOG(ERR, USER1, - "Invalid MODULUS length specified\n"); - return TEST_SKIPPED; - } - - ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess); - if (ret < 0) { - RTE_LOG(ERR, USER1, "line %u " - "FAILED: %s", __LINE__, - "Session creation failed"); - status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; - goto error_exit; - } - - /* generate 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; - } - - asym_op = op->asym; - 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); - - RTE_LOG(DEBUG, USER1, "Process ASYM operation"); - - /* 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"); - 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, - "line %u FAILED: %s", - __LINE__, "Failed to process asym crypto op"); - status = TEST_FAILED; - goto error_exit; + "Invalid MODULUS length specified\n"); + return TEST_SKIPPED; } - - ret = verify_modinv(mod_inv, result_op); - if (ret) { - RTE_LOG(ERR, USER1, - "operation verification failed\n"); - status = TEST_FAILED; + if (rte_cryptodev_asym_session_create(dev_id, &xform, + params->session_mpool, &self->sess) < 0) { + RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed", + __LINE__); + return TEST_FAILED; } + rte_crypto_op_attach_asym_session(self->op, self->sess); -error_exit: - if (sess) - rte_cryptodev_asym_session_free(dev_id, sess); - - rte_crypto_op_free(op); - - TEST_ASSERT_EQUAL(status, 0, "Test failed"); + self->op->asym->modinv.base.data = input; + self->op->asym->modinv.base.length = vector->base.len; + self->op->asym->modinv.result.data = result; - return status; + TEST_ASSERT_SUCCESS(send(&self->op, &self->result_op), + "Failed to process crypto op"); + TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->inverse.data, + self->result_op->asym->modinv.result.data, + self->result_op->asym->modinv.result.length, + "operation verification failed\n"); + return TEST_SUCCESS; } static int @@ -2142,7 +2075,6 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite = { test_rsa_enc_dec_crt), TEST_CASE_ST(setup_generic, teardown_generic, test_rsa_sign_verify_crt), - TEST_CASE_ST(setup_generic, teardown_generic, test_mod_inv), TEST_CASE_ST(setup_generic, teardown_generic, test_one_by_one), /* Modular Exponentiation */ TEST_CASE_NAMED_WITH_DATA( @@ -2161,6 +2093,11 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite = { "Modular Exponentiation (mod=448, base=50, exp=40, res=448)", setup_generic, teardown_generic, modular_exponentiation, &modex_test_case_m448_b50_e40), + /* Modular Multiplicative Inverse */ + TEST_CASE_NAMED_WITH_DATA( + "Modular Inverse (mod=128, base=20, exp=3, inv=128)", + setup_generic, teardown_generic, + modular_multiplicative_inverse, &modinv_test_case), TEST_CASES_END() /**< NULL terminate unit test array */ } }; @@ -2188,6 +2125,11 @@ static struct unit_test_suite cryptodev_qat_asym_testsuite = { "Modular Exponentiation (mod=448, base=50, exp=40, res=448)", setup_generic, teardown_generic, modular_exponentiation, &modex_test_case_m448_b50_e40), + /* Modular Multiplicative Inverse */ + TEST_CASE_NAMED_WITH_DATA( + "Modular Inverse (mod=128, base=20, exp=3, inv=128)", + setup_generic, teardown_generic, + modular_multiplicative_inverse, &modinv_test_case), TEST_CASES_END() /**< NULL terminate unit test array */ } }; diff --git a/app/test/test_cryptodev_asym_util.h b/app/test/test_cryptodev_asym_util.h index 8bdff2ddf8..19044a58ad 100644 --- a/app/test/test_cryptodev_asym_util.h +++ b/app/test/test_cryptodev_asym_util.h @@ -17,15 +17,6 @@ static inline int rsa_verify(struct rsa_test_data *rsa_param, return 0; } -static inline int verify_modinv(uint8_t *mod_inv, - struct rte_crypto_op *result_op) -{ - if (memcmp(mod_inv, result_op->asym->modinv.result.data, - result_op->asym->modinv.result.length)) - return -1; - return 0; -} - static inline int verify_ecdsa_sign(uint8_t *sign_r, uint8_t *sign_s, struct rte_crypto_op *result_op) { diff --git a/app/test/test_cryptodev_mod_test_vectors.h b/app/test/test_cryptodev_mod_test_vectors.h index aa5f3e5334..079d562c51 100644 --- a/app/test/test_cryptodev_mod_test_vectors.h +++ b/app/test/test_cryptodev_mod_test_vectors.h @@ -420,9 +420,9 @@ modex_test_data modex_test_case_m448_b50_e40 = { .result_len = 448 }; +/* ModInv #1 */ static const struct -modinv_test_data modinv_test_case[] = { -{ +modinv_test_data modinv_test_case = { .description = "Modular Inverse (mod=128, base=20, exp=3, inv=128)", .xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV, .base = { @@ -476,66 +476,6 @@ modinv_test_data modinv_test_case[] = { .len = 128 }, .result_len = 128 -} -}; - -/* modular operation test data */ -uint8_t base[] = { - 0xF8, 0xBA, 0x1A, 0x55, 0xD0, 0x2F, 0x85, - 0xAE, 0x96, 0x7B, 0xB6, 0x2F, 0xB6, 0xCD, - 0xA8, 0xEB, 0x7E, 0x78, 0xA0, 0x50 -}; - -/* MODEX data. 8< */ -uint8_t mod_p[] = { - 0x00, 0xb3, 0xa1, 0xaf, 0xb7, 0x13, 0x08, 0x00, - 0x0a, 0x35, 0xdc, 0x2b, 0x20, 0x8d, 0xa1, 0xb5, - 0xce, 0x47, 0x8a, 0xc3, 0x80, 0xf4, 0x7d, 0x4a, - 0xa2, 0x62, 0xfd, 0x61, 0x7f, 0xb5, 0xa8, 0xde, - 0x0a, 0x17, 0x97, 0xa0, 0xbf, 0xdf, 0x56, 0x5a, - 0x3d, 0x51, 0x56, 0x4f, 0x70, 0x70, 0x3f, 0x63, - 0x6a, 0x44, 0x5b, 0xad, 0x84, 0x0d, 0x3f, 0x27, - 0x6e, 0x3b, 0x34, 0x91, 0x60, 0x14, 0xb9, 0xaa, - 0x72, 0xfd, 0xa3, 0x64, 0xd2, 0x03, 0xa7, 0x53, - 0x87, 0x9e, 0x88, 0x0b, 0xc1, 0x14, 0x93, 0x1a, - 0x62, 0xff, 0xb1, 0x5d, 0x74, 0xcd, 0x59, 0x63, - 0x18, 0x11, 0x3d, 0x4f, 0xba, 0x75, 0xd4, 0x33, - 0x4e, 0x23, 0x6b, 0x7b, 0x57, 0x44, 0xe1, 0xd3, - 0x03, 0x13, 0xa6, 0xf0, 0x8b, 0x60, 0xb0, 0x9e, - 0xee, 0x75, 0x08, 0x9d, 0x71, 0x63, 0x13, 0xcb, - 0xa6, 0x81, 0x92, 0x14, 0x03, 0x22, 0x2d, 0xde, - 0x55 -}; - -/* Precomputed modular inverse for verification */ -uint8_t mod_inv[] = { - 0x52, 0xb1, 0xa3, 0x8c, 0xc5, 0x8a, 0xb9, 0x1f, - 0xb6, 0x82, 0xf5, 0x6a, 0x9a, 0xde, 0x8d, 0x2e, - 0x62, 0x4b, 0xac, 0x49, 0x21, 0x1d, 0x30, 0x4d, - 0x32, 0xac, 0x1f, 0x40, 0x6d, 0x52, 0xc7, 0x9b, - 0x6c, 0x0a, 0x82, 0x3a, 0x2c, 0xaf, 0x6b, 0x6d, - 0x17, 0xbe, 0x43, 0xed, 0x97, 0x78, 0xeb, 0x4c, - 0x92, 0x6f, 0xcf, 0xed, 0xb1, 0x09, 0xcb, 0x27, - 0xc2, 0xde, 0x62, 0xfd, 0x21, 0xe6, 0xbd, 0x4f, - 0xfe, 0x7a, 0x1b, 0x50, 0xfe, 0x10, 0x4a, 0xb0, - 0xb7, 0xcf, 0xdb, 0x7d, 0xca, 0xc2, 0xf0, 0x1c, - 0x39, 0x48, 0x6a, 0xb5, 0x4d, 0x8c, 0xfe, 0x63, - 0x91, 0x9c, 0x21, 0xc3, 0x0e, 0x76, 0xad, 0x44, - 0x8d, 0x54, 0x33, 0x99, 0xe1, 0x80, 0x19, 0xba, - 0xb5, 0xac, 0x7d, 0x9c, 0xce, 0x91, 0x2a, 0xd9, - 0x2c, 0xe1, 0x16, 0xd6, 0xd7, 0xcf, 0x9d, 0x05, - 0x9a, 0x66, 0x9a, 0x3a, 0xc1, 0xb8, 0x4b, 0xc3 -}; - -struct rte_crypto_asym_xform modinv_xform = { - .next = NULL, - .xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV, - .modinv = { - .modulus = { - .data = mod_p, - .length = sizeof(mod_p) - } - } }; #endif /* TEST_CRYPTODEV_MOD_TEST_VECTORS_H__ */