From patchwork Thu Oct 26 08:15:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 133378 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 CD18843206; Thu, 26 Oct 2023 10:15:29 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9EA7B427E6; Thu, 26 Oct 2023 10:15:25 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id CAF53427E6 for ; Thu, 26 Oct 2023 10:15:24 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39Q71eTV017512; Thu, 26 Oct 2023 01:15:24 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=vbGV2/d7rgWazlRc61BSSUChbTwG1SVjJZ6GBq/Jg3E=; b=h6hz1d6MlJIjfPz6BznxWYGS3l+Xph5ESdhnJuIPqWA5aLR7r7HQnkWwQCu78B15w3Ix YYHp1fTfyQ6zdIFQEsUJVGVH9EX+9GnsDN2rU3YtEGcTJVIQr2C+lKJZVsC+Pd01oyeR BUAvHmgrQiYcj7jDXIJWTyaG9uTZBq+LNTzDq74l18bhdhs1i+axsoHZI4InQeYyW+oA AZNJvuEiZcx1qTAkAKml8C5EGURGTsTZIXhE9ImmVr0/lz0lpxUyoJo87uuxav8KNra0 YsGMpPejD4KuZFNMdGQwraK6zxXOfbbSyQFkdtwl74IiOeMPFwe6Tk1+8QviXmJ5hqmA OA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3txcsr1b2g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 26 Oct 2023 01:15:23 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 26 Oct 2023 01:15:21 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Thu, 26 Oct 2023 01:15:21 -0700 Received: from BG-LT91401.marvell.com (BG-LT91401.marvell.com [10.28.168.34]) by maili.marvell.com (Postfix) with ESMTP id 366A63F70C7; Thu, 26 Oct 2023 01:15:18 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Akhil Goyal , Fan Zhang , Gowrishankar Muthukrishnan Subject: [PATCH v1 1/4] test/cryptodev: add ECDH tests Date: Thu, 26 Oct 2023 13:45:09 +0530 Message-ID: <3e1d2557d1d4be04d886b4842ec09969ae202942.1698307299.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: cGy-Xgl2SyO5e_cp1XBthUUSy2KBmxs6 X-Proofpoint-GUID: cGy-Xgl2SyO5e_cp1XBthUUSy2KBmxs6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-26_05,2023-10-25_01,2023-05-22_02 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 Add ECDH tests. Signed-off-by: Gowrishankar Muthukrishnan --- app/test/test_cryptodev_asym.c | 729 +++++++++++++++++++ app/test/test_cryptodev_asym_util.h | 12 + app/test/test_cryptodev_ecdh_test_vectors.h | 577 +++++++++++++++ app/test/test_cryptodev_ecdsa_test_vectors.h | 3 + 4 files changed, 1321 insertions(+) create mode 100644 app/test/test_cryptodev_ecdh_test_vectors.h diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c index c6334380d7..965e71d0bc 100644 --- a/app/test/test_cryptodev_asym.c +++ b/app/test/test_cryptodev_asym.c @@ -17,6 +17,7 @@ #include "test_cryptodev.h" #include "test_cryptodev_dh_test_vectors.h" #include "test_cryptodev_dsa_test_vectors.h" +#include "test_cryptodev_ecdh_test_vectors.h" #include "test_cryptodev_ecdsa_test_vectors.h" #include "test_cryptodev_ecpm_test_vectors.h" #include "test_cryptodev_mod_test_vectors.h" @@ -1806,6 +1807,732 @@ test_ecpm_all_curve(void) return overall_status; } +static int +test_ecdh_priv_key_generate(enum curve curve_id) +{ + struct crypto_testsuite_params_asym *ts_params = &testsuite_params; + const struct rte_cryptodev_asymmetric_xform_capability *capa; + struct rte_mempool *sess_mpool = ts_params->session_mpool; + struct rte_mempool *op_mpool = ts_params->op_mpool; + struct rte_cryptodev_asym_capability_idx idx; + uint8_t dev_id = ts_params->valid_devs[0]; + struct rte_crypto_asym_xform xform = {0}; + struct rte_crypto_op *result_op = NULL; + uint8_t output_buf[TEST_DATA_SIZE]; + struct rte_crypto_asym_op *asym_op; + struct rte_crypto_op *op = NULL; + int ret, status = TEST_SUCCESS; + uint16_t output_buflen = 0; + void *sess = NULL; + int curve; + + /* Check ECDH capability */ + idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH; + capa = rte_cryptodev_asym_capability_get(dev_id, &idx); + if (capa == NULL) + return -ENOTSUP; + + if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE))) + return -ENOTSUP; + + switch (curve_id) { + case SECP192R1: + curve = RTE_CRYPTO_EC_GROUP_SECP192R1; + output_buflen = 24; + break; + case SECP224R1: + curve = RTE_CRYPTO_EC_GROUP_SECP224R1; + output_buflen = 28; + break; + case SECP256R1: + curve = RTE_CRYPTO_EC_GROUP_SECP256R1; + output_buflen = 32; + break; + case SECP384R1: + curve = RTE_CRYPTO_EC_GROUP_SECP384R1; + output_buflen = 48; + break; + case SECP521R1: + curve = RTE_CRYPTO_EC_GROUP_SECP521R1; + output_buflen = 66; + break; + default: + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Unsupported curve id\n"); + status = TEST_FAILED; + goto exit; + } + + /* Setup crypto op data structure */ + op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); + if (op == NULL) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to allocate asymmetric crypto " + "operation struct\n"); + status = TEST_FAILED; + goto exit; + } + asym_op = op->asym; + + /* Setup asym xform */ + xform.next = NULL; + xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; + xform.ec.curve_id = curve; + + ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); + if (ret < 0) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Session creation failed\n"); + status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; + goto exit; + } + + /* Attach asymmetric crypto session to crypto operations */ + rte_crypto_op_attach_asym_session(op, sess); + + /* Populate op with operational details */ + asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE; + + /* Init out buf */ + asym_op->ecdh.priv_key.data = output_buf; + asym_op->ecdh.priv_key.length = output_buflen; + + 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\n"); + status = TEST_FAILED; + goto 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\n"); + status = TEST_FAILED; + goto exit; + } + + if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to process asym crypto op\n"); + status = TEST_FAILED; + goto exit; + } + + asym_op = result_op->asym; + + debug_hexdump(stdout, "priv_key:", + asym_op->ecdh.priv_key.data, asym_op->ecdh.priv_key.length); + +exit: + if (sess != NULL) + rte_cryptodev_asym_session_free(dev_id, sess); + rte_crypto_op_free(op); + return status; +} + +static int +test_ecdh_pub_key_generate(enum curve curve_id) +{ + struct crypto_testsuite_params_asym *ts_params = &testsuite_params; + const struct rte_cryptodev_asymmetric_xform_capability *capa; + struct rte_mempool *sess_mpool = ts_params->session_mpool; + struct rte_mempool *op_mpool = ts_params->op_mpool; + struct crypto_testsuite_ecdh_params input_params; + struct rte_cryptodev_asym_capability_idx idx; + uint8_t dev_id = ts_params->valid_devs[0]; + struct rte_crypto_asym_xform xform = {0}; + struct rte_crypto_op *result_op = NULL; + uint8_t output_buf_x[TEST_DATA_SIZE]; + uint8_t output_buf_y[TEST_DATA_SIZE]; + struct rte_crypto_asym_op *asym_op; + struct rte_crypto_op *op = NULL; + int ret, status = TEST_SUCCESS; + void *sess = NULL; + + /* Check ECDH capability */ + idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH; + capa = rte_cryptodev_asym_capability_get(dev_id, &idx); + if (capa == NULL) + return -ENOTSUP; + + if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE))) + return -ENOTSUP; + + switch (curve_id) { + case SECP192R1: + input_params = ecdh_param_secp192r1; + break; + case SECP224R1: + input_params = ecdh_param_secp224r1; + break; + case SECP256R1: + input_params = ecdh_param_secp256r1; + break; + case SECP384R1: + input_params = ecdh_param_secp384r1; + break; + case SECP521R1: + input_params = ecdh_param_secp521r1; + break; + default: + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Unsupported curve id\n"); + status = TEST_FAILED; + goto exit; + } + + debug_hexdump(stdout, "pkey:", + input_params.pkey_A.data, input_params.pkey_A.length); + + /* Setup crypto op data structure */ + op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); + if (op == NULL) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to allocate asymmetric crypto " + "operation struct\n"); + status = TEST_FAILED; + goto exit; + } + asym_op = op->asym; + + /* Setup asym xform */ + xform.next = NULL; + xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; + xform.ec.curve_id = input_params.curve; + xform.ec.pkey.data = input_params.pkey_A.data; + xform.ec.pkey.length = input_params.pkey_A.length; + + ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); + if (ret < 0) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Session creation failed\n"); + status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; + goto exit; + } + + /* Attach asymmetric crypto session to crypto operations */ + rte_crypto_op_attach_asym_session(op, sess); + + /* Populate op with operational details */ + asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE; + + /* Init out buf */ + asym_op->ecdh.pub_key.x.data = output_buf_x; + asym_op->ecdh.pub_key.y.data = output_buf_y; + + 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\n"); + status = TEST_FAILED; + goto 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\n"); + status = TEST_FAILED; + goto exit; + } + + if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to process asym crypto op\n"); + status = TEST_FAILED; + goto exit; + } + + asym_op = result_op->asym; + + debug_hexdump(stdout, "qx:", + asym_op->ecdh.pub_key.x.data, asym_op->ecdh.pub_key.x.length); + debug_hexdump(stdout, "qy:", + asym_op->ecdh.pub_key.y.data, asym_op->ecdh.pub_key.y.length); + + ret = verify_ecdh_secret(input_params.pubkey_qA_x.data, + input_params.pubkey_qA_y.data, result_op); + if (ret) { + status = TEST_FAILED; + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "ECDH public key generation failed.\n"); + goto exit; + } + +exit: + if (sess != NULL) + rte_cryptodev_asym_session_free(dev_id, sess); + rte_crypto_op_free(op); + return status; +} + +static int +test_ecdh_pub_key_verify(enum curve curve_id) +{ + struct crypto_testsuite_params_asym *ts_params = &testsuite_params; + const struct rte_cryptodev_asymmetric_xform_capability *capa; + struct rte_mempool *sess_mpool = ts_params->session_mpool; + struct rte_mempool *op_mpool = ts_params->op_mpool; + struct crypto_testsuite_ecdh_params input_params; + struct rte_cryptodev_asym_capability_idx idx; + uint8_t dev_id = ts_params->valid_devs[0]; + struct rte_crypto_asym_xform xform = {0}; + struct rte_crypto_op *result_op = NULL; + struct rte_crypto_asym_op *asym_op; + struct rte_crypto_op *op = NULL; + int ret, status = TEST_SUCCESS; + void *sess = NULL; + + /* Check ECDH capability */ + idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH; + capa = rte_cryptodev_asym_capability_get(dev_id, &idx); + if (capa == NULL) + return -ENOTSUP; + + if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY))) + return -ENOTSUP; + + switch (curve_id) { + case SECP192R1: + input_params = ecdh_param_secp192r1; + break; + case SECP224R1: + input_params = ecdh_param_secp224r1; + break; + case SECP256R1: + input_params = ecdh_param_secp256r1; + break; + case SECP384R1: + input_params = ecdh_param_secp384r1; + break; + case SECP521R1: + input_params = ecdh_param_secp521r1; + break; + default: + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Unsupported curve id\n"); + status = TEST_FAILED; + goto exit; + } + + debug_hexdump(stdout, "qx:", + input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length); + debug_hexdump(stdout, "qy:", + input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length); + + /* Setup crypto op data structure */ + op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); + if (op == NULL) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to allocate asymmetric crypto " + "operation struct\n"); + status = TEST_FAILED; + goto exit; + } + asym_op = op->asym; + + /* Setup asym xform */ + xform.next = NULL; + xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; + xform.ec.curve_id = input_params.curve; + + ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); + if (ret < 0) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Session creation failed\n"); + status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; + goto exit; + } + + /* Attach asymmetric crypto session to crypto operations */ + rte_crypto_op_attach_asym_session(op, sess); + + /* Populate op with operational details */ + asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY; + asym_op->ecdh.pub_key.x.data = input_params.pubkey_qA_x.data; + asym_op->ecdh.pub_key.x.length = input_params.pubkey_qA_x.length; + asym_op->ecdh.pub_key.y.data = input_params.pubkey_qA_y.data; + asym_op->ecdh.pub_key.y.length = input_params.pubkey_qA_y.length; + + 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\n"); + status = TEST_FAILED; + goto 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\n"); + status = TEST_FAILED; + goto exit; + } + + if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to process asym crypto op\n"); + status = TEST_FAILED; + goto exit; + } + +exit: + if (sess != NULL) + rte_cryptodev_asym_session_free(dev_id, sess); + rte_crypto_op_free(op); + return status; +} + +static int +test_ecdh_shared_secret(enum curve curve_id) +{ + struct crypto_testsuite_params_asym *ts_params = &testsuite_params; + const struct rte_cryptodev_asymmetric_xform_capability *capa; + struct rte_mempool *sess_mpool = ts_params->session_mpool; + struct rte_mempool *op_mpool = ts_params->op_mpool; + struct crypto_testsuite_ecdh_params input_params; + struct rte_cryptodev_asym_capability_idx idx; + uint8_t dev_id = ts_params->valid_devs[0]; + struct rte_crypto_asym_xform xform = {0}; + struct rte_crypto_op *result_op = NULL; + uint8_t output_buf_x[TEST_DATA_SIZE]; + uint8_t output_buf_y[TEST_DATA_SIZE]; + struct rte_crypto_asym_op *asym_op; + struct rte_crypto_op *op = NULL; + int ret, status = TEST_SUCCESS; + void *sess = NULL; + + /* Check ECDH capability */ + idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH; + capa = rte_cryptodev_asym_capability_get(dev_id, &idx); + if (capa == NULL) + return -ENOTSUP; + + if (!(capa->op_types & (1 << RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE))) + return -ENOTSUP; + + switch (curve_id) { + case SECP192R1: + input_params = ecdh_param_secp192r1; + break; + case SECP224R1: + input_params = ecdh_param_secp224r1; + break; + case SECP256R1: + input_params = ecdh_param_secp256r1; + break; + case SECP384R1: + input_params = ecdh_param_secp384r1; + break; + case SECP521R1: + input_params = ecdh_param_secp521r1; + break; + default: + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Unsupported curve id\n"); + status = TEST_FAILED; + goto exit; + } + + /* zA = dA.QB */ + debug_hexdump(stdout, "pkey:", + input_params.pkey_A.data, input_params.pkey_A.length); + debug_hexdump(stdout, "qx:", + input_params.pubkey_qB_x.data, input_params.pubkey_qB_x.length); + debug_hexdump(stdout, "qy:", + input_params.pubkey_qB_y.data, input_params.pubkey_qB_y.length); + + /* Setup crypto op data structure */ + op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); + if (op == NULL) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to allocate asymmetric crypto " + "operation struct\n"); + status = TEST_FAILED; + goto exit; + } + asym_op = op->asym; + + /* Setup asym xform */ + xform.next = NULL; + xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; + xform.ec.curve_id = input_params.curve; + xform.ec.pkey.data = input_params.pkey_A.data; + xform.ec.pkey.length = input_params.pkey_A.length; + xform.ec.q.x.data = input_params.pubkey_qB_x.data; + xform.ec.q.x.length = input_params.pubkey_qB_x.length; + xform.ec.q.y.data = input_params.pubkey_qB_y.data; + xform.ec.q.y.length = input_params.pubkey_qB_y.length; + + ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); + if (ret < 0) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Session creation failed\n"); + status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; + goto exit; + } + + /* Attach asymmetric crypto session to crypto operations */ + rte_crypto_op_attach_asym_session(op, sess); + + /* Populate op with operational details */ + asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE; + + /* Init out buf */ + asym_op->ecdh.shared_secret.x.data = output_buf_x; + asym_op->ecdh.shared_secret.y.data = output_buf_y; + + 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\n"); + status = TEST_FAILED; + goto 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\n"); + status = TEST_FAILED; + goto exit; + } + + if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to process asym crypto op\n"); + status = TEST_FAILED; + goto exit; + } + + asym_op = result_op->asym; + + debug_hexdump(stdout, "secret_x:", + asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length); + debug_hexdump(stdout, "secret_y:", + asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length); + + ret = verify_ecdh_secret(input_params.secret_x.data, + input_params.secret_y.data, result_op); + if (ret) { + status = TEST_FAILED; + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "ECDH shared secret compute failed.\n"); + goto exit; + } + + if (sess != NULL) + rte_cryptodev_asym_session_free(dev_id, sess); + rte_crypto_op_free(op); + + /* zB = dB.QA */ + debug_hexdump(stdout, "pkey:", + input_params.pkey_B.data, input_params.pkey_B.length); + debug_hexdump(stdout, "qx:", + input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length); + debug_hexdump(stdout, "qy:", + input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length); + + /* Setup crypto op data structure */ + op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC); + if (op == NULL) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to allocate asymmetric crypto " + "operation struct\n"); + status = TEST_FAILED; + goto exit; + } + asym_op = op->asym; + + /* Setup asym xform */ + xform.next = NULL; + xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH; + xform.ec.curve_id = input_params.curve; + xform.ec.pkey.data = input_params.pkey_B.data; + xform.ec.pkey.length = input_params.pkey_B.length; + xform.ec.q.x.data = input_params.pubkey_qA_x.data; + xform.ec.q.x.length = input_params.pubkey_qA_x.length; + xform.ec.q.y.data = input_params.pubkey_qA_y.data; + xform.ec.q.y.length = input_params.pubkey_qA_y.length; + + ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess); + if (ret < 0) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Session creation failed\n"); + status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED; + goto exit; + } + + /* Attach asymmetric crypto session to crypto operations */ + rte_crypto_op_attach_asym_session(op, sess); + + /* Populate op with operational details */ + asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE; + + /* Init out buf */ + asym_op->ecdh.shared_secret.x.data = output_buf_x; + asym_op->ecdh.shared_secret.y.data = output_buf_y; + + 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\n"); + status = TEST_FAILED; + goto 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\n"); + status = TEST_FAILED; + goto exit; + } + + if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "Failed to process asym crypto op\n"); + status = TEST_FAILED; + goto exit; + } + + asym_op = result_op->asym; + + debug_hexdump(stdout, "secret_x:", + asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length); + debug_hexdump(stdout, "secret_y:", + asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length); + + ret = verify_ecdh_secret(input_params.secret_x.data, + input_params.secret_y.data, result_op); + if (ret) { + status = TEST_FAILED; + RTE_LOG(ERR, USER1, + "line %u FAILED: %s", __LINE__, + "ECDH shared secret compute failed.\n"); + goto exit; + } + +exit: + if (sess != NULL) + rte_cryptodev_asym_session_free(dev_id, sess); + rte_crypto_op_free(op); + return status; +} + +static int +test_ecdh_all_curve(void) +{ + int status, overall_status = TEST_SUCCESS; + enum curve curve_id; + int test_index = 0; + const char *msg; + + for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { + status = test_ecdh_priv_key_generate(curve_id); + if (status == TEST_SUCCESS) { + msg = "succeeded"; + } else { + msg = "failed"; + overall_status = status; + } + printf(" %u) TestCase ECDH private key generation for Curve %s %s\n", + test_index ++, curve[curve_id], msg); + } + + for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { + status = test_ecdh_pub_key_generate(curve_id); + if (status == TEST_SUCCESS) { + msg = "succeeded"; + } else { + msg = "failed"; + overall_status = status; + } + printf(" %u) TestCase ECDH public key generation for Curve %s %s\n", + test_index ++, curve[curve_id], msg); + } + + for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { + status = test_ecdh_pub_key_verify(curve_id); + if (status == TEST_SUCCESS) { + msg = "succeeded"; + } else { + msg = "failed"; + overall_status = status; + } + printf(" %u) TestCase ECDH public key verification for Curve %s %s\n", + test_index ++, curve[curve_id], msg); + } + + for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) { + status = test_ecdh_shared_secret(curve_id); + if (status == TEST_SUCCESS) { + msg = "succeeded"; + } else { + msg = "failed"; + overall_status = status; + } + printf(" %u) TestCase ECDH shared secret compute for Curve %s %s\n", + test_index ++, curve[curve_id], msg); + } + + return overall_status; +} + static int test_sm2_sign(void) { @@ -2848,6 +3575,8 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { test_ecdsa_sign_verify_all_curve), TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign), TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify), + TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, + test_ecdh_all_curve), TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_ecpm_all_curve), 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 83dc265dd7..07e6e831e8 100644 --- a/app/test/test_cryptodev_asym_util.h +++ b/app/test/test_cryptodev_asym_util.h @@ -57,4 +57,16 @@ static inline int verify_ecpm(uint8_t *result_x, uint8_t *result_y, return 0; } + +static inline int verify_ecdh_secret(uint8_t *result_x, uint8_t *result_y, + struct rte_crypto_op *result_op) +{ + if (memcmp(result_x, result_op->asym->ecdh.shared_secret.x.data, + result_op->asym->ecdh.shared_secret.x.length) || + memcmp(result_y, result_op->asym->ecdh.shared_secret.y.data, + result_op->asym->ecdh.shared_secret.y.length)) + return -1; + + return 0; +} #endif /* TEST_CRYPTODEV_ASYM_TEST_UTIL_H__ */ diff --git a/app/test/test_cryptodev_ecdh_test_vectors.h b/app/test/test_cryptodev_ecdh_test_vectors.h new file mode 100644 index 0000000000..5f22fbddcb --- /dev/null +++ b/app/test/test_cryptodev_ecdh_test_vectors.h @@ -0,0 +1,577 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (C) 2023 Marvell International Ltd. + */ + +#ifndef __TEST_CRYPTODEV_ECDH_TEST_VECTORS_H__ +#define __TEST_CRYPTODEV_ECDH_TEST_VECTORS_H__ + +#include "rte_crypto_asym.h" + +#ifndef __TEST_CRYPTODEV_EC_CURVES__ +#define __TEST_CRYPTODEV_EC_CURVES__ +/* EC curve id */ +enum curve { + SECP192R1, + SECP224R1, + SECP256R1, + SECP384R1, + SECP521R1, + END_OF_CURVE_LIST +}; + +const char *curve[] = { + "SECP192R1", + "SECP224R1", + "SECP256R1", + "SECP384R1", + "SECP521R1" +}; +#endif + +struct crypto_testsuite_ecdh_params { + rte_crypto_param pubkey_qA_x; + rte_crypto_param pubkey_qA_y; + rte_crypto_param pkey_A; + rte_crypto_param pubkey_qB_x; + rte_crypto_param pubkey_qB_y; + rte_crypto_param pkey_B; + rte_crypto_param secret_x; + rte_crypto_param secret_y; + int curve; +}; + +/* + * Test vector reference: + * https://datatracker.ietf.org/doc/html/rfc5114.html + * Appendix A. + */ + +/** SECP192R1 (P-192 NIST) test vector */ + +static uint8_t dA_secp192r1[] = { + 0x32, 0x3F, 0xA3, 0x16, 0x9D, 0x8E, 0x9C, 0x65, + 0x93, 0xF5, 0x94, 0x76, 0xBC, 0x14, 0x20, 0x00, + 0xAB, 0x5B, 0xE0, 0xE2, 0x49, 0xC4, 0x34, 0x26 +}; + +static uint8_t x_qA_secp192r1[] = { + 0xCD, 0x46, 0x48, 0x9E, 0xCF, 0xD6, 0xC1, 0x05, + 0xE7, 0xB3, 0xD3, 0x25, 0x66, 0xE2, 0xB1, 0x22, + 0xE2, 0x49, 0xAB, 0xAA, 0xDD, 0x87, 0x06, 0x12 +}; + +static uint8_t y_qA_secp192r1[] = { + 0x68, 0x88, 0x7B, 0x48, 0x77, 0xDF, 0x51, 0xDD, + 0x4D, 0xC3, 0xD6, 0xFD, 0x11, 0xF0, 0xA2, 0x6F, + 0x8F, 0xD3, 0x84, 0x43, 0x17, 0x91, 0x6E, 0x9A +}; + +static uint8_t dB_secp192r1[] = { + 0x63, 0x1F, 0x95, 0xBB, 0x4A, 0x67, 0x63, 0x2C, + 0x9C, 0x47, 0x6E, 0xEE, 0x9A, 0xB6, 0x95, 0xAB, + 0x24, 0x0A, 0x04, 0x99, 0x30, 0x7F, 0xCF, 0x62 +}; + +static uint8_t x_qB_secp192r1[] = { + 0x51, 0x9A, 0x12, 0x16, 0x80, 0xE0, 0x04, 0x54, + 0x66, 0xBA, 0x21, 0xDF, 0x2E, 0xEE, 0x47, 0xF5, + 0x97, 0x3B, 0x50, 0x05, 0x77, 0xEF, 0x13, 0xD5 +}; + +static uint8_t y_qB_secp192r1[] = { + 0xFF, 0x61, 0x3A, 0xB4, 0xD6, 0x4C, 0xEE, 0x3A, + 0x20, 0x87, 0x5B, 0xDB, 0x10, 0xF9, 0x53, 0xF6, + 0xB3, 0x0C, 0xA0, 0x72, 0xC6, 0x0A, 0xA5, 0x7F +}; + +static uint8_t x_Z_secp192r1[] = { + 0xAD, 0x42, 0x01, 0x82, 0x63, 0x3F, 0x85, 0x26, + 0xBF, 0xE9, 0x54, 0xAC, 0xDA, 0x37, 0x6F, 0x05, + 0xE5, 0xFF, 0x4F, 0x83, 0x7F, 0x54, 0xFE, 0xBE +}; + +static uint8_t y_Z_secp192r1[] = { + 0x43, 0x71, 0x54, 0x5E, 0xD7, 0x72, 0xA5, 0x97, + 0x41, 0xD0, 0xED, 0xA3, 0x2C, 0x67, 0x11, 0x12, + 0xB7, 0xFD, 0xDD, 0x51, 0x46, 0x1F, 0xCF, 0x32 +}; + +/** ECDH SECP192R1 elliptic curve param */ + +struct crypto_testsuite_ecdh_params ecdh_param_secp192r1 = { + .pubkey_qA_x = { + .data = x_qA_secp192r1, + .length = sizeof(x_qA_secp192r1), + }, + .pubkey_qA_y = { + .data = y_qA_secp192r1, + .length = sizeof(y_qA_secp192r1), + }, + .pubkey_qB_x = { + .data = x_qB_secp192r1, + .length = sizeof(x_qB_secp192r1), + }, + .pubkey_qB_y = { + .data = y_qB_secp192r1, + .length = sizeof(y_qB_secp192r1), + }, + .pkey_A = { + .data = dA_secp192r1, + .length = sizeof(dA_secp192r1), + }, + .pkey_B = { + .data = dB_secp192r1, + .length = sizeof(dB_secp192r1), + }, + .secret_x = { + .data = x_Z_secp192r1, + .length = sizeof(x_Z_secp192r1), + }, + .secret_y = { + .data = y_Z_secp192r1, + .length = sizeof(y_Z_secp192r1), + }, + .curve = RTE_CRYPTO_EC_GROUP_SECP192R1 +}; + +/** SECP224R1 (P-224 NIST) test vector */ + +static uint8_t dA_secp224r1[] = { + 0xB5, 0x58, 0xEB, 0x6C, 0x28, 0x8D, 0xA7, 0x07, + 0xBB, 0xB4, 0xF8, 0xFB, 0xAE, 0x2A, 0xB9, 0xE9, + 0xCB, 0x62, 0xE3, 0xBC, 0x5C, 0x75, 0x73, 0xE2, + 0x2E, 0x26, 0xD3, 0x7F +}; + +static uint8_t x_qA_secp224r1[] = { + 0x49, 0xDF, 0xEF, 0x30, 0x9F, 0x81, 0x48, 0x8C, + 0x30, 0x4C, 0xFF, 0x5A, 0xB3, 0xEE, 0x5A, 0x21, + 0x54, 0x36, 0x7D, 0xC7, 0x83, 0x31, 0x50, 0xE0, + 0xA5, 0x1F, 0x3E, 0xEB +}; + +static uint8_t y_qA_secp224r1[] = { + 0x4F, 0x2B, 0x5E, 0xE4, 0x57, 0x62, 0xC4, 0xF6, + 0x54, 0xC1, 0xA0, 0xC6, 0x7F, 0x54, 0xCF, 0x88, + 0xB0, 0x16, 0xB5, 0x1B, 0xCE, 0x3D, 0x7C, 0x22, + 0x8D, 0x57, 0xAD, 0xB4, +}; + +static uint8_t dB_secp224r1[] = { + 0xAC, 0x3B, 0x1A, 0xDD, 0x3D, 0x97, 0x70, 0xE6, + 0xF6, 0xA7, 0x08, 0xEE, 0x9F, 0x3B, 0x8E, 0x0A, + 0xB3, 0xB4, 0x80, 0xE9, 0xF2, 0x7F, 0x85, 0xC8, + 0x8B, 0x5E, 0x6D, 0x18, +}; + +static uint8_t x_qB_secp224r1[] = { + 0x6B, 0x3A, 0xC9, 0x6A, 0x8D, 0x0C, 0xDE, 0x6A, + 0x55, 0x99, 0xBE, 0x80, 0x32, 0xED, 0xF1, 0x0C, + 0x16, 0x2D, 0x0A, 0x8A, 0xD2, 0x19, 0x50, 0x6D, + 0xCD, 0x42, 0xA2, 0x07, +}; + +static uint8_t y_qB_secp224r1[] = { + 0xD4, 0x91, 0xBE, 0x99, 0xC2, 0x13, 0xA7, 0xD1, + 0xCA, 0x37, 0x06, 0xDE, 0xBF, 0xE3, 0x05, 0xF3, + 0x61, 0xAF, 0xCB, 0xB3, 0x3E, 0x26, 0x09, 0xC8, + 0xB1, 0x61, 0x8A, 0xD5 +}; + +static uint8_t x_Z_secp224r1[] = { + 0x52, 0x27, 0x2F, 0x50, 0xF4, 0x6F, 0x4E, 0xDC, + 0x91, 0x51, 0x56, 0x90, 0x92, 0xF4, 0x6D, 0xF2, + 0xD9, 0x6E, 0xCC, 0x3B, 0x6D, 0xC1, 0x71, 0x4A, + 0x4E, 0xA9, 0x49, 0xFA +}; + +static uint8_t y_Z_secp224r1[] = { + 0x5F, 0x30, 0xC6, 0xAA, 0x36, 0xDD, 0xC4, 0x03, + 0xC0, 0xAC, 0xB7, 0x12, 0xBB, 0x88, 0xF1, 0x76, + 0x3C, 0x30, 0x46, 0xF6, 0xD9, 0x19, 0xBD, 0x9C, + 0x52, 0x43, 0x22, 0xBF +}; + +/** ECDH SECP224R1 elliptic curve param */ + +struct crypto_testsuite_ecdh_params ecdh_param_secp224r1 = { + .pubkey_qA_x = { + .data = x_qA_secp224r1, + .length = sizeof(x_qA_secp224r1), + }, + .pubkey_qA_y = { + .data = y_qA_secp224r1, + .length = sizeof(y_qA_secp224r1), + }, + .pubkey_qB_x = { + .data = x_qB_secp224r1, + .length = sizeof(x_qB_secp224r1), + }, + .pubkey_qB_y = { + .data = y_qB_secp224r1, + .length = sizeof(y_qB_secp224r1), + }, + .pkey_A = { + .data = dA_secp224r1, + .length = sizeof(dA_secp224r1), + }, + .pkey_B = { + .data = dB_secp224r1, + .length = sizeof(dB_secp224r1), + }, + .secret_x = { + .data = x_Z_secp224r1, + .length = sizeof(x_Z_secp224r1), + }, + .secret_y = { + .data = y_Z_secp224r1, + .length = sizeof(y_Z_secp224r1), + }, + .curve = RTE_CRYPTO_EC_GROUP_SECP224R1 +}; + +/** SECP256R1 (P-256 NIST) test vector */ + +static uint8_t dA_secp256r1[] = { + 0x81, 0x42, 0x64, 0x14, 0x5F, 0x2F, 0x56, 0xF2, + 0xE9, 0x6A, 0x8E, 0x33, 0x7A, 0x12, 0x84, 0x99, + 0x3F, 0xAF, 0x43, 0x2A, 0x5A, 0xBC, 0xE5, 0x9E, + 0x86, 0x7B, 0x72, 0x91, 0xD5, 0x07, 0xA3, 0xAF +}; + +static uint8_t x_qA_secp256r1[] = { + 0x2A, 0xF5, 0x02, 0xF3, 0xBE, 0x89, 0x52, 0xF2, + 0xC9, 0xB5, 0xA8, 0xD4, 0x16, 0x0D, 0x09, 0xE9, + 0x71, 0x65, 0xBE, 0x50, 0xBC, 0x42, 0xAE, 0x4A, + 0x5E, 0x8D, 0x3B, 0x4B, 0xA8, 0x3A, 0xEB, 0x15 +}; + +static uint8_t y_qA_secp256r1[] = { + 0xEB, 0x0F, 0xAF, 0x4C, 0xA9, 0x86, 0xC4, 0xD3, + 0x86, 0x81, 0xA0, 0xF9, 0x87, 0x2D, 0x79, 0xD5, + 0x67, 0x95, 0xBD, 0x4B, 0xFF, 0x6E, 0x6D, 0xE3, + 0xC0, 0xF5, 0x01, 0x5E, 0xCE, 0x5E, 0xFD, 0x85 +}; + +static uint8_t dB_secp256r1[] = { + 0x2C, 0xE1, 0x78, 0x8E, 0xC1, 0x97, 0xE0, 0x96, + 0xDB, 0x95, 0xA2, 0x00, 0xCC, 0x0A, 0xB2, 0x6A, + 0x19, 0xCE, 0x6B, 0xCC, 0xAD, 0x56, 0x2B, 0x8E, + 0xEE, 0x1B, 0x59, 0x37, 0x61, 0xCF, 0x7F, 0x41 +}; + +static uint8_t x_qB_secp256r1[] = { + 0xB1, 0x20, 0xDE, 0x4A, 0xA3, 0x64, 0x92, 0x79, + 0x53, 0x46, 0xE8, 0xDE, 0x6C, 0x2C, 0x86, 0x46, + 0xAE, 0x06, 0xAA, 0xEA, 0x27, 0x9F, 0xA7, 0x75, + 0xB3, 0xAB, 0x07, 0x15, 0xF6, 0xCE, 0x51, 0xB0 +}; + +static uint8_t y_qB_secp256r1[] = { + 0x9F, 0x1B, 0x7E, 0xEC, 0xE2, 0x0D, 0x7B, 0x5E, + 0xD8, 0xEC, 0x68, 0x5F, 0xA3, 0xF0, 0x71, 0xD8, + 0x37, 0x27, 0x02, 0x70, 0x92, 0xA8, 0x41, 0x13, + 0x85, 0xC3, 0x4D, 0xDE, 0x57, 0x08, 0xB2, 0xB6 +}; + +static uint8_t x_Z_secp256r1[] = { + 0xDD, 0x0F, 0x53, 0x96, 0x21, 0x9D, 0x1E, 0xA3, + 0x93, 0x31, 0x04, 0x12, 0xD1, 0x9A, 0x08, 0xF1, + 0xF5, 0x81, 0x1E, 0x9D, 0xC8, 0xEC, 0x8E, 0xEA, + 0x7F, 0x80, 0xD2, 0x1C, 0x82, 0x0C, 0x27, 0x88 +}; + +static uint8_t y_Z_secp256r1[] = { + 0x03, 0x57, 0xDC, 0xCD, 0x4C, 0x80, 0x4D, 0x0D, + 0x8D, 0x33, 0xAA, 0x42, 0xB8, 0x48, 0x83, 0x4A, + 0xA5, 0x60, 0x5F, 0x9A, 0xB0, 0xD3, 0x72, 0x39, + 0xA1, 0x15, 0xBB, 0xB6, 0x47, 0x93, 0x6F, 0x50 +}; + +/** ECDH SECP256R1 elliptic curve param */ + +struct crypto_testsuite_ecdh_params ecdh_param_secp256r1 = { + .pubkey_qA_x = { + .data = x_qA_secp256r1, + .length = sizeof(x_qA_secp256r1), + }, + .pubkey_qA_y = { + .data = y_qA_secp256r1, + .length = sizeof(y_qA_secp256r1), + }, + .pubkey_qB_x = { + .data = x_qB_secp256r1, + .length = sizeof(x_qB_secp256r1), + }, + .pubkey_qB_y = { + .data = y_qB_secp256r1, + .length = sizeof(y_qB_secp256r1), + }, + .pkey_A = { + .data = dA_secp256r1, + .length = sizeof(dA_secp256r1), + }, + .pkey_B = { + .data = dB_secp256r1, + .length = sizeof(dB_secp256r1), + }, + .secret_x = { + .data = x_Z_secp256r1, + .length = sizeof(x_Z_secp256r1), + }, + .secret_y = { + .data = y_Z_secp256r1, + .length = sizeof(y_Z_secp256r1), + }, + .curve = RTE_CRYPTO_EC_GROUP_SECP256R1 +}; + +/** SECP384R1 (P-384 NIST) test vector */ + +static uint8_t dA_secp384r1[] = { + 0xD2, 0x73, 0x35, 0xEA, 0x71, 0x66, 0x4A, 0xF2, + 0x44, 0xDD, 0x14, 0xE9, 0xFD, 0x12, 0x60, 0x71, + 0x5D, 0xFD, 0x8A, 0x79, 0x65, 0x57, 0x1C, 0x48, + 0xD7, 0x09, 0xEE, 0x7A, 0x79, 0x62, 0xA1, 0x56, + 0xD7, 0x06, 0xA9, 0x0C, 0xBC, 0xB5, 0xDF, 0x29, + 0x86, 0xF0, 0x5F, 0xEA, 0xDB, 0x93, 0x76, 0xF1 +}; + +static uint8_t x_qA_secp384r1[] = { + 0x79, 0x31, 0x48, 0xF1, 0x78, 0x76, 0x34, 0xD5, + 0xDA, 0x4C, 0x6D, 0x90, 0x74, 0x41, 0x7D, 0x05, + 0xE0, 0x57, 0xAB, 0x62, 0xF8, 0x20, 0x54, 0xD1, + 0x0E, 0xE6, 0xB0, 0x40, 0x3D, 0x62, 0x79, 0x54, + 0x7E, 0x6A, 0x8E, 0xA9, 0xD1, 0xFD, 0x77, 0x42, + 0x7D, 0x01, 0x6F, 0xE2, 0x7A, 0x8B, 0x8C, 0x66 +}; + +static uint8_t y_qA_secp384r1[] = { + 0xC6, 0xC4, 0x12, 0x94, 0x33, 0x1D, 0x23, 0xE6, + 0xF4, 0x80, 0xF4, 0xFB, 0x4C, 0xD4, 0x05, 0x04, + 0xC9, 0x47, 0x39, 0x2E, 0x94, 0xF4, 0xC3, 0xF0, + 0x6B, 0x8F, 0x39, 0x8B, 0xB2, 0x9E, 0x42, 0x36, + 0x8F, 0x7A, 0x68, 0x59, 0x23, 0xDE, 0x3B, 0x67, + 0xBA, 0xCE, 0xD2, 0x14, 0xA1, 0xA1, 0xD1, 0x28 +}; + +static uint8_t dB_secp384r1[] = { + 0x52, 0xD1, 0x79, 0x1F, 0xDB, 0x4B, 0x70, 0xF8, + 0x9C, 0x0F, 0x00, 0xD4, 0x56, 0xC2, 0xF7, 0x02, + 0x3B, 0x61, 0x25, 0x26, 0x2C, 0x36, 0xA7, 0xDF, + 0x1F, 0x80, 0x23, 0x11, 0x21, 0xCC, 0xE3, 0xD3, + 0x9B, 0xE5, 0x2E, 0x00, 0xC1, 0x94, 0xA4, 0x13, + 0x2C, 0x4A, 0x6C, 0x76, 0x8B, 0xCD, 0x94, 0xD2 +}; + +static uint8_t x_qB_secp384r1[] = { + 0x5C, 0xD4, 0x2A, 0xB9, 0xC4, 0x1B, 0x53, 0x47, + 0xF7, 0x4B, 0x8D, 0x4E, 0xFB, 0x70, 0x8B, 0x3D, + 0x5B, 0x36, 0xDB, 0x65, 0x91, 0x53, 0x59, 0xB4, + 0x4A, 0xBC, 0x17, 0x64, 0x7B, 0x6B, 0x99, 0x99, + 0x78, 0x9D, 0x72, 0xA8, 0x48, 0x65, 0xAE, 0x2F, + 0x22, 0x3F, 0x12, 0xB5, 0xA1, 0xAB, 0xC1, 0x20 +}; + +static uint8_t y_qB_secp384r1[] = { + 0xE1, 0x71, 0x45, 0x8F, 0xEA, 0xA9, 0x39, 0xAA, + 0xA3, 0xA8, 0xBF, 0xAC, 0x46, 0xB4, 0x04, 0xBD, + 0x8F, 0x6D, 0x5B, 0x34, 0x8C, 0x0F, 0xA4, 0xD8, + 0x0C, 0xEC, 0xA1, 0x63, 0x56, 0xCA, 0x93, 0x32, + 0x40, 0xBD, 0xE8, 0x72, 0x34, 0x15, 0xA8, 0xEC, + 0xE0, 0x35, 0xB0, 0xED, 0xF3, 0x67, 0x55, 0xDE +}; + +static uint8_t x_Z_secp384r1[] = { + 0x5E, 0xA1, 0xFC, 0x4A, 0xF7, 0x25, 0x6D, 0x20, + 0x55, 0x98, 0x1B, 0x11, 0x05, 0x75, 0xE0, 0xA8, + 0xCA, 0xE5, 0x31, 0x60, 0x13, 0x7D, 0x90, 0x4C, + 0x59, 0xD9, 0x26, 0xEB, 0x1B, 0x84, 0x56, 0xE4, + 0x27, 0xAA, 0x8A, 0x45, 0x40, 0x88, 0x4C, 0x37, + 0xDE, 0x15, 0x9A, 0x58, 0x02, 0x8A, 0xBC, 0x0E +}; + +static uint8_t y_Z_secp384r1[] = { + 0x0C, 0xC5, 0x9E, 0x4B, 0x04, 0x64, 0x14, 0xA8, + 0x1C, 0x8A, 0x3B, 0xDF, 0xDC, 0xA9, 0x25, 0x26, + 0xC4, 0x87, 0x69, 0xDD, 0x8D, 0x31, 0x27, 0xCA, + 0xA9, 0x9B, 0x36, 0x32, 0xD1, 0x91, 0x39, 0x42, + 0xDE, 0x36, 0x2E, 0xAF, 0xAA, 0x96, 0x23, 0x79, + 0x37, 0x4D, 0x9F, 0x3F, 0x06, 0x68, 0x41, 0xCA +}; + +/** ECDH SECP384R1 elliptic curve param */ + +struct crypto_testsuite_ecdh_params ecdh_param_secp384r1 = { + .pubkey_qA_x = { + .data = x_qA_secp384r1, + .length = sizeof(x_qA_secp384r1), + }, + .pubkey_qA_y = { + .data = y_qA_secp384r1, + .length = sizeof(y_qA_secp384r1), + }, + .pubkey_qB_x = { + .data = x_qB_secp384r1, + .length = sizeof(x_qB_secp384r1), + }, + .pubkey_qB_y = { + .data = y_qB_secp384r1, + .length = sizeof(y_qB_secp384r1), + }, + .pkey_A = { + .data = dA_secp384r1, + .length = sizeof(dA_secp384r1), + }, + .pkey_B = { + .data = dB_secp384r1, + .length = sizeof(dB_secp384r1), + }, + .secret_x = { + .data = x_Z_secp384r1, + .length = sizeof(x_Z_secp384r1), + }, + .secret_y = { + .data = y_Z_secp384r1, + .length = sizeof(y_Z_secp384r1), + }, + .curve = RTE_CRYPTO_EC_GROUP_SECP384R1 +}; + +/** SECP521R1 (P-521 NIST) test vector */ + +static uint8_t dA_secp521r1[] = { + 0x01, 0x13, 0xF8, 0x2D, 0xA8, 0x25, 0x73, 0x5E, + 0x3D, 0x97, 0x27, 0x66, 0x83, 0xB2, 0xB7, 0x42, + 0x77, 0xBA, 0xD2, 0x73, 0x35, 0xEA, 0x71, 0x66, + 0x4A, 0xF2, 0x43, 0x0C, 0xC4, 0xF3, 0x34, 0x59, + 0xB9, 0x66, 0x9E, 0xE7, 0x8B, 0x3F, 0xFB, 0x9B, + 0x86, 0x83, 0x01, 0x5D, 0x34, 0x4D, 0xCB, 0xFE, + 0xF6, 0xFB, 0x9A, 0xF4, 0xC6, 0xC4, 0x70, 0xBE, + 0x25, 0x45, 0x16, 0xCD, 0x3C, 0x1A, 0x1F, 0xB4, + 0x73, 0x62 +}; + +static uint8_t x_qA_secp521r1[] = { + 0x01, 0xEB, 0xB3, 0x4D, 0xD7, 0x57, 0x21, 0xAB, + 0xF8, 0xAD, 0xC9, 0xDB, 0xED, 0x17, 0x88, 0x9C, + 0xBB, 0x97, 0x65, 0xD9, 0x0A, 0x7C, 0x60, 0xF2, + 0xCE, 0xF0, 0x07, 0xBB, 0x0F, 0x2B, 0x26, 0xE1, + 0x48, 0x81, 0xFD, 0x44, 0x42, 0xE6, 0x89, 0xD6, + 0x1C, 0xB2, 0xDD, 0x04, 0x6E, 0xE3, 0x0E, 0x3F, + 0xFD, 0x20, 0xF9, 0xA4, 0x5B, 0xBD, 0xF6, 0x41, + 0x3D, 0x58, 0x3A, 0x2D, 0xBF, 0x59, 0x92, 0x4F, + 0xD3, 0x5C +}; + +static uint8_t y_qA_secp521r1[] = { + 0x00, 0xF6, 0xB6, 0x32, 0xD1, 0x94, 0xC0, 0x38, + 0x8E, 0x22, 0xD8, 0x43, 0x7E, 0x55, 0x8C, 0x55, + 0x2A, 0xE1, 0x95, 0xAD, 0xFD, 0x15, 0x3F, 0x92, + 0xD7, 0x49, 0x08, 0x35, 0x1B, 0x2F, 0x8C, 0x4E, + 0xDA, 0x94, 0xED, 0xB0, 0x91, 0x6D, 0x1B, 0x53, + 0xC0, 0x20, 0xB5, 0xEE, 0xCA, 0xED, 0x1A, 0x5F, + 0xC3, 0x8A, 0x23, 0x3E, 0x48, 0x30, 0x58, 0x7B, + 0xB2, 0xEE, 0x34, 0x89, 0xB3, 0xB4, 0x2A, 0x5A, + 0x86, 0xA4 +}; + +static uint8_t dB_secp521r1[] = { + 0x00, 0xCE, 0xE3, 0x48, 0x0D, 0x86, 0x45, 0xA1, + 0x7D, 0x24, 0x9F, 0x27, 0x76, 0xD2, 0x8B, 0xAE, + 0x61, 0x69, 0x52, 0xD1, 0x79, 0x1F, 0xDB, 0x4B, + 0x70, 0xF7, 0xC3, 0x37, 0x87, 0x32, 0xAA, 0x1B, + 0x22, 0x92, 0x84, 0x48, 0xBC, 0xD1, 0xDC, 0x24, + 0x96, 0xD4, 0x35, 0xB0, 0x10, 0x48, 0x06, 0x6E, + 0xBE, 0x4F, 0x72, 0x90, 0x3C, 0x36, 0x1B, 0x1A, + 0x9D, 0xC1, 0x19, 0x3D, 0xC2, 0xC9, 0xD0, 0x89, + 0x1B, 0x96 +}; + +static uint8_t x_qB_secp521r1[] = { + 0x01, 0x0E, 0xBF, 0xAF, 0xC6, 0xE8, 0x5E, 0x08, + 0xD2, 0x4B, 0xFF, 0xFC, 0xC1, 0xA4, 0x51, 0x1D, + 0xB0, 0xE6, 0x34, 0xBE, 0xEB, 0x1B, 0x6D, 0xEC, + 0x8C, 0x59, 0x39, 0xAE, 0x44, 0x76, 0x62, 0x01, + 0xAF, 0x62, 0x00, 0x43, 0x0B, 0xA9, 0x7C, 0x8A, + 0xC6, 0xA0, 0xE9, 0xF0, 0x8B, 0x33, 0xCE, 0x7E, + 0x9F, 0xEE, 0xB5, 0xBA, 0x4E, 0xE5, 0xE0, 0xD8, + 0x15, 0x10, 0xC2, 0x42, 0x95, 0xB8, 0xA0, 0x8D, + 0x02, 0x35 +}; + +static uint8_t y_qB_secp521r1[] = { + 0x00, 0xA4, 0xA6, 0xEC, 0x30, 0x0D, 0xF9, 0xE2, + 0x57, 0xB0, 0x37, 0x2B, 0x5E, 0x7A, 0xBF, 0xEF, + 0x09, 0x34, 0x36, 0x71, 0x9A, 0x77, 0x88, 0x7E, + 0xBB, 0x0B, 0x18, 0xCF, 0x80, 0x99, 0xB9, 0xF4, + 0x21, 0x2B, 0x6E, 0x30, 0xA1, 0x41, 0x9C, 0x18, + 0xE0, 0x29, 0xD3, 0x68, 0x63, 0xCC, 0x9D, 0x44, + 0x8F, 0x4D, 0xBA, 0x4D, 0x2A, 0x0E, 0x60, 0x71, + 0x1B, 0xE5, 0x72, 0x91, 0x5F, 0xBD, 0x4F, 0xEF, + 0x26, 0x95 +}; + +static uint8_t x_Z_secp521r1[] = { + 0x00, 0xCD, 0xEA, 0x89, 0x62, 0x1C, 0xFA, 0x46, + 0xB1, 0x32, 0xF9, 0xE4, 0xCF, 0xE2, 0x26, 0x1C, + 0xDE, 0x2D, 0x43, 0x68, 0xEB, 0x56, 0x56, 0x63, + 0x4C, 0x7C, 0xC9, 0x8C, 0x7A, 0x00, 0xCD, 0xE5, + 0x4E, 0xD1, 0x86, 0x6A, 0x0D, 0xD3, 0xE6, 0x12, + 0x6C, 0x9D, 0x2F, 0x84, 0x5D, 0xAF, 0xF8, 0x2C, + 0xEB, 0x1D, 0xA0, 0x8F, 0x5D, 0x87, 0x52, 0x1B, + 0xB0, 0xEB, 0xEC, 0xA7, 0x79, 0x11, 0x16, 0x9C, + 0x20, 0xCC +}; + +static uint8_t y_Z_secp521r1[] = { + 0x00, 0xF9, 0xA7, 0x16, 0x41, 0x02, 0x9B, 0x7F, + 0xC1, 0xA8, 0x08, 0xAD, 0x07, 0xCD, 0x48, 0x61, + 0xE8, 0x68, 0x61, 0x4B, 0x86, 0x5A, 0xFB, 0xEC, + 0xAB, 0x1F, 0x2B, 0xD4, 0xD8, 0xB5, 0x5E, 0xBC, + 0xB5, 0xE3, 0xA5, 0x31, 0x43, 0xCE, 0xB2, 0xC5, + 0x11, 0xB1, 0xAE, 0x0A, 0xF5, 0xAC, 0x82, 0x7F, + 0x60, 0xF2, 0xFD, 0x87, 0x25, 0x65, 0xAC, 0x5C, + 0xA0, 0xA1, 0x64, 0x03, 0x8F, 0xE9, 0x80, 0xA7, + 0xE4, 0xBD +}; + +/** ECDH SECP521R1 elliptic curve param */ + +struct crypto_testsuite_ecdh_params ecdh_param_secp521r1 = { + .pubkey_qA_x = { + .data = x_qA_secp521r1, + .length = sizeof(x_qA_secp521r1), + }, + .pubkey_qA_y = { + .data = y_qA_secp521r1, + .length = sizeof(y_qA_secp521r1), + }, + .pubkey_qB_x = { + .data = x_qB_secp521r1, + .length = sizeof(x_qB_secp521r1), + }, + .pubkey_qB_y = { + .data = y_qB_secp521r1, + .length = sizeof(y_qB_secp521r1), + }, + .pkey_A = { + .data = dA_secp521r1, + .length = sizeof(dA_secp521r1), + }, + .pkey_B = { + .data = dB_secp521r1, + .length = sizeof(dB_secp521r1), + }, + .secret_x = { + .data = x_Z_secp521r1, + .length = sizeof(x_Z_secp521r1), + }, + .secret_y = { + .data = y_Z_secp521r1, + .length = sizeof(y_Z_secp521r1), + }, + .curve = RTE_CRYPTO_EC_GROUP_SECP521R1 +}; + +#endif /* __TEST_CRYPTODEV_ECDSA_TEST_VECTORS_H__ */ diff --git a/app/test/test_cryptodev_ecdsa_test_vectors.h b/app/test/test_cryptodev_ecdsa_test_vectors.h index 55fbda5979..9ac3189ce7 100644 --- a/app/test/test_cryptodev_ecdsa_test_vectors.h +++ b/app/test/test_cryptodev_ecdsa_test_vectors.h @@ -7,6 +7,8 @@ #include "rte_crypto_asym.h" +#ifndef __TEST_CRYPTODEV_EC_CURVES__ +#define __TEST_CRYPTODEV_EC_CURVES__ /* EC curve id */ enum curve { SECP192R1, @@ -22,6 +24,7 @@ const char *curve[] = {"SECP192R1", "SECP256R1", "SECP384R1", "SECP521R1"}; +#endif struct crypto_testsuite_ecdsa_params { rte_crypto_param pubkey_qx; From patchwork Thu Oct 26 08:15:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 133379 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 732F343206; Thu, 26 Oct 2023 10:15:41 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3B23842DFF; Thu, 26 Oct 2023 10:15:28 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id DB4F342DEA for ; Thu, 26 Oct 2023 10:15:26 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39Q71eTW017512; Thu, 26 Oct 2023 01:15:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=K9O3M69nniP7/08w3X/Vdcm017LL5whMYKdZU+bQsgU=; b=k+e8n6nN/xH8/P3wUxsUBKWrr3VyDTfQO6WlvERWYQ2ToGK/OpWgtYlHefoNAkAKmYDC EvxRgs5tIQHqsLg0xgW7ihlUysLdVV9skl0qpSTfYOruEzJScX178PDxaBeb/E7+TJCa JjivfWgPQV3fl7J906Zn6m7HRmDbbrCr4kaZcCDO4YDz3NZ0d20ap1vTbnIfzz+IhBhp CFxFxcH/pC2Y8ZvUI4dbS9fmL+OAfbkNRXKq94lX3WjC+aqxA0QDTJWfTrwoqS2Yq9Qs aInHWdkSPUtTK+qVpOsh9YerI0zNcgDZQMIaYWqdTjuRxkOufqij1UOjyKoQv86FVYlA 8g== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3txcsr1b2k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 26 Oct 2023 01:15:26 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 26 Oct 2023 01:15:24 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Thu, 26 Oct 2023 01:15:24 -0700 Received: from BG-LT91401.marvell.com (BG-LT91401.marvell.com [10.28.168.34]) by maili.marvell.com (Postfix) with ESMTP id 54F9F3F704D; Thu, 26 Oct 2023 01:15:22 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Akhil Goyal , Fan Zhang , Gowrishankar Muthukrishnan Subject: [PATCH v1 2/4] crypto/cnxk: use generic EC opcodes Date: Thu, 26 Oct 2023 13:45:10 +0530 Message-ID: <2b4e2e189aed1dba8de03742b752267f9e9ad973.1698307299.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: swpvs9yUKJSMp1eup4I7_-fy6kFwy_8b X-Proofpoint-GUID: swpvs9yUKJSMp1eup4I7_-fy6kFwy_8b X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-26_05,2023-10-25_01,2023-05-22_02 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 Use generic EC opcodes for sign and verify ops in ECDSA and SM2 implementations. Signed-off-by: Gowrishankar Muthukrishnan --- drivers/common/cnxk/roc_ae.h | 14 +++++++--- drivers/crypto/cnxk/cnxk_ae.h | 50 +++++++++++++++++++---------------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/drivers/common/cnxk/roc_ae.h b/drivers/common/cnxk/roc_ae.h index d459c5e680..eaf12ab254 100644 --- a/drivers/common/cnxk/roc_ae.h +++ b/drivers/common/cnxk/roc_ae.h @@ -5,9 +5,11 @@ #ifndef __ROC_AE_H__ #define __ROC_AE_H__ +#include "roc_platform.h" + /* AE opcodes */ #define ROC_AE_MAJOR_OP_MODEX 0x03 -#define ROC_AE_MAJOR_OP_ECDSA 0x04 +#define ROC_AE_MAJOR_OP_EC 0x04 #define ROC_AE_MAJOR_OP_ECC 0x05 #define ROC_AE_MINOR_OP_MODEX 0x01 #define ROC_AE_MINOR_OP_PKCS_ENC 0x02 @@ -15,8 +17,8 @@ #define ROC_AE_MINOR_OP_PKCS_DEC 0x04 #define ROC_AE_MINOR_OP_PKCS_DEC_CRT 0x05 #define ROC_AE_MINOR_OP_MODEX_CRT 0x06 -#define ROC_AE_MINOR_OP_ECDSA_SIGN 0x01 -#define ROC_AE_MINOR_OP_ECDSA_VERIFY 0x02 +#define ROC_AE_MINOR_OP_EC_SIGN 0x01 +#define ROC_AE_MINOR_OP_EC_VERIFY 0x02 #define ROC_AE_MINOR_OP_ECC_UMP 0x03 #define ROC_AE_MINOR_OP_ECC_FPM 0x04 @@ -38,6 +40,12 @@ typedef enum { ROC_AE_EC_ID_PMAX } roc_ae_ec_id; +/* EC param1 fields */ +#define ROC_AE_EC_PARAM1_ECDSA (0 << 7) +#define ROC_AE_EC_PARAM1_SM2 (1 << 7) +#define ROC_AE_EC_PARAM1_NIST (0 << 6) +#define ROC_AE_EC_PARAM1_NONNIST (1 << 6) + /* Prime and order fields of built-in elliptic curves */ struct roc_ae_ec_group { struct { diff --git a/drivers/crypto/cnxk/cnxk_ae.h b/drivers/crypto/cnxk/cnxk_ae.h index 09468d58b0..6e61ccb0c5 100644 --- a/drivers/crypto/cnxk/cnxk_ae.h +++ b/drivers/crypto/cnxk/cnxk_ae.h @@ -588,8 +588,8 @@ cnxk_ae_ecdsa_sign_prep(struct rte_crypto_ecdsa_op_param *ecdsa, dptr += p_align; /* Setup opcodes */ - w4.s.opcode_major = ROC_AE_MAJOR_OP_ECDSA; - w4.s.opcode_minor = ROC_AE_MINOR_OP_ECDSA_SIGN; + w4.s.opcode_major = ROC_AE_MAJOR_OP_EC; + w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_SIGN; w4.s.param1 = curveid | (message_len << 8); w4.s.param2 = (p_align << 8) | k_len; @@ -683,8 +683,8 @@ cnxk_ae_ecdsa_verify_prep(struct rte_crypto_ecdsa_op_param *ecdsa, dptr += p_align; /* Setup opcodes */ - w4.s.opcode_major = ROC_AE_MAJOR_OP_ECDSA; - w4.s.opcode_minor = ROC_AE_MINOR_OP_ECDSA_VERIFY; + w4.s.opcode_major = ROC_AE_MAJOR_OP_EC; + w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_VERIFY; w4.s.param1 = curveid | (message_len << 8); w4.s.param2 = 0; @@ -719,9 +719,9 @@ cnxk_ae_enqueue_ecdsa_op(struct rte_crypto_op *op, static __rte_always_inline void cnxk_ae_sm2_sign_prep(struct rte_crypto_sm2_op_param *sm2, - struct roc_ae_buf_ptr *meta_buf, - uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp, - struct cnxk_ae_sess *sess, struct cpt_inst_s *inst) + struct roc_ae_buf_ptr *meta_buf, + uint64_t fpm_table_iova, struct roc_ae_ec_group *ec_grp, + struct cnxk_ae_sess *sess, struct cpt_inst_s *inst) { uint16_t message_len = sm2->message.length; uint16_t pkey_len = sess->ec_ctx.pkey.length; @@ -787,10 +787,12 @@ cnxk_ae_sm2_sign_prep(struct rte_crypto_sm2_op_param *sm2, dptr += p_align; /* Setup opcodes */ - w4.s.opcode_major = ROC_AE_MAJOR_OP_ECDSA; - w4.s.opcode_minor = ROC_AE_MINOR_OP_ECDSA_SIGN; + w4.s.opcode_major = ROC_AE_MAJOR_OP_EC; + w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_SIGN; - w4.s.param1 = 2 | 1 << 7 | 1 << 6 | (message_len << 8); + /* prime length of SM2 curve is same as that of P256. */ + w4.s.param1 = ROC_AE_EC_ID_P256 | + ROC_AE_EC_PARAM1_SM2 | ROC_AE_EC_PARAM1_NONNIST | (message_len << 8); w4.s.param2 = (p_align << 8) | k_len; w4.s.dlen = dlen; @@ -800,10 +802,10 @@ cnxk_ae_sm2_sign_prep(struct rte_crypto_sm2_op_param *sm2, static __rte_always_inline void cnxk_ae_sm2_verify_prep(struct rte_crypto_sm2_op_param *sm2, - struct roc_ae_buf_ptr *meta_buf, - uint64_t fpm_table_iova, - struct roc_ae_ec_group *ec_grp, struct cnxk_ae_sess *sess, - struct cpt_inst_s *inst) + struct roc_ae_buf_ptr *meta_buf, + uint64_t fpm_table_iova, + struct roc_ae_ec_group *ec_grp, struct cnxk_ae_sess *sess, + struct cpt_inst_s *inst) { uint32_t message_len = sm2->message.length; uint16_t o_offset, r_offset, s_offset; @@ -881,10 +883,12 @@ cnxk_ae_sm2_verify_prep(struct rte_crypto_sm2_op_param *sm2, dptr += p_align; /* Setup opcodes */ - w4.s.opcode_major = ROC_AE_MAJOR_OP_ECDSA; - w4.s.opcode_minor = ROC_AE_MINOR_OP_ECDSA_VERIFY; + w4.s.opcode_major = ROC_AE_MAJOR_OP_EC; + w4.s.opcode_minor = ROC_AE_MINOR_OP_EC_VERIFY; - w4.s.param1 = 2 | 1 << 7 | 1 << 6 | (message_len << 8); + /* prime length of SM2 curve is same as that of P256. */ + w4.s.param1 = ROC_AE_EC_ID_P256 | + ROC_AE_EC_PARAM1_SM2 | ROC_AE_EC_PARAM1_NONNIST | (message_len << 8); w4.s.param2 = 0; w4.s.dlen = dlen; @@ -894,20 +898,20 @@ cnxk_ae_sm2_verify_prep(struct rte_crypto_sm2_op_param *sm2, static __rte_always_inline int __rte_hot cnxk_ae_enqueue_sm2_op(struct rte_crypto_op *op, - struct roc_ae_buf_ptr *meta_buf, - struct cnxk_ae_sess *sess, uint64_t *fpm_iova, - struct roc_ae_ec_group **ec_grp, - struct cpt_inst_s *inst) + struct roc_ae_buf_ptr *meta_buf, + struct cnxk_ae_sess *sess, uint64_t *fpm_iova, + struct roc_ae_ec_group **ec_grp, + struct cpt_inst_s *inst) { struct rte_crypto_sm2_op_param *sm2 = &op->asym->sm2; uint8_t curveid = sess->ec_ctx.curveid; if (sm2->op_type == RTE_CRYPTO_ASYM_OP_SIGN) cnxk_ae_sm2_sign_prep(sm2, meta_buf, fpm_iova[curveid], - ec_grp[curveid], sess, inst); + ec_grp[curveid], sess, inst); else if (sm2->op_type == RTE_CRYPTO_ASYM_OP_VERIFY) cnxk_ae_sm2_verify_prep(sm2, meta_buf, fpm_iova[curveid], - ec_grp[curveid], sess, inst); + ec_grp[curveid], sess, inst); else { op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; return -EINVAL; From patchwork Thu Oct 26 08:15:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 133380 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 AA2EC43206; Thu, 26 Oct 2023 10:15:50 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8D1D142E03; Thu, 26 Oct 2023 10:15:31 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 53A6642E03 for ; Thu, 26 Oct 2023 10:15:29 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39Q71eTX017512; Thu, 26 Oct 2023 01:15:28 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=4LxoQiGwYRnbKAEyusev/ZYG0jkdt7PPKuf0x2vuh2w=; b=JrYqobVwY3Sa4CfTLRYuuF25jBsM4bVX8QTHZGkK70EnNaI2sr2BdQDIMTLZw2wq8ph4 ODdEtkpMK2w5YoE8n+X0K28vPPycS6oYKR7w9AILBExPaPj/MtgM2r+fJ7ysqasNm7TG XUFoezjwBwWvDdBc8f1gP2sWmSxsGG537rPoMiHQOnqdzUbOO12AIjudESS0HMakymoU OvnQZO3VkVHYfw5HH/FcY7GEctQEEatA0SEKVz7g4WWj4P1+fuIJb4b7EMWcTrflY+Ha HV+0PVtKo9NQedR8J/NrQr8XLWHcoxw8neqsksUbMPf3dlM2hs6u3636OuV8ynsD5JWL AQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3txcsr1b2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 26 Oct 2023 01:15:28 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 26 Oct 2023 01:15:26 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Thu, 26 Oct 2023 01:15:26 -0700 Received: from BG-LT91401.marvell.com (BG-LT91401.marvell.com [10.28.168.34]) by maili.marvell.com (Postfix) with ESMTP id C38523F70BF; Thu, 26 Oct 2023 01:15:24 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Akhil Goyal , Fan Zhang , Gowrishankar Muthukrishnan Subject: [PATCH v1 3/4] crypto/cnxk: change order of ECFPM params Date: Thu, 26 Oct 2023 13:45:11 +0530 Message-ID: X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: dkOZKkoWYKCgknf2Pmn1gNXslFu1ylUX X-Proofpoint-GUID: dkOZKkoWYKCgknf2Pmn1gNXslFu1ylUX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-26_05,2023-10-25_01,2023-05-22_02 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 Change order of ECFPM params to match changes in v2.0 microcode. Signed-off-by: Gowrishankar Muthukrishnan --- drivers/crypto/cnxk/cnxk_ae.h | 49 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/drivers/crypto/cnxk/cnxk_ae.h b/drivers/crypto/cnxk/cnxk_ae.h index 6e61ccb0c5..f05ae4f4a1 100644 --- a/drivers/crypto/cnxk/cnxk_ae.h +++ b/drivers/crypto/cnxk/cnxk_ae.h @@ -923,7 +923,7 @@ static __rte_always_inline int cnxk_ae_ecfpm_prep(struct rte_crypto_ecpm_op_param *ecpm, struct roc_ae_buf_ptr *meta_buf, uint64_t *fpm_iova, struct roc_ae_ec_group *ec_grp, uint8_t curveid, - struct cpt_inst_s *inst, int cpt_ver) + struct cpt_inst_s *inst) { uint16_t scalar_align, p_align; uint16_t dlen, prime_len; @@ -942,34 +942,26 @@ cnxk_ae_ecfpm_prep(struct rte_crypto_ecpm_op_param *ecpm, scalar_align = RTE_ALIGN_CEIL(ecpm->scalar.length, 8); /* - * Set dlen = sum(prime, scalar length, table address and - * optionally ROUNDUP8(input point(x and y coordinates)). + * Set dlen = sum(ROUNDUP8(input point(x and y coordinates), prime, + * scalar length), * Please note point length is equivalent to prime of the curve */ - if (cpt_ver == ROC_CPT_REVISION_ID_96XX_B0 || cpt_ver == ROC_CPT_REVISION_ID_96XX_C0 || - cpt_ver == ROC_CPT_REVISION_ID_98XX) { - dlen = sizeof(fpm_table_iova) + 3 * p_align + scalar_align; - memset(dptr, 0, dlen); - *(uint64_t *)dptr = fpm_table_iova; - dptr += sizeof(fpm_table_iova); - memcpy(dptr, ecpm->scalar.data, ecpm->scalar.length); - dptr += scalar_align; - memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length); - dptr += p_align; - memcpy(dptr, ec_grp->consta.data, ec_grp->consta.length); - dptr += p_align; - memcpy(dptr, ec_grp->constb.data, ec_grp->constb.length); - dptr += p_align; - } else { - dlen = sizeof(fpm_table_iova) + p_align + scalar_align; - memset(dptr, 0, dlen); - memcpy(dptr, ecpm->scalar.data, ecpm->scalar.length); - dptr += scalar_align; - memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length); - dptr += p_align; - *(uint64_t *)dptr = fpm_table_iova; - dptr += sizeof(fpm_table_iova); - } + dlen = sizeof(fpm_table_iova) + 3 * p_align + scalar_align; + + memset(dptr, 0, dlen); + + *(uint64_t *)dptr = fpm_table_iova; + dptr += sizeof(fpm_table_iova); + + /* Copy scalar, prime */ + memcpy(dptr, ecpm->scalar.data, ecpm->scalar.length); + dptr += scalar_align; + memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length); + dptr += p_align; + memcpy(dptr, ec_grp->consta.data, ec_grp->consta.length); + dptr += p_align; + memcpy(dptr, ec_grp->constb.data, ec_grp->constb.length); + dptr += p_align; /* Setup opcodes */ w4.s.opcode_major = ROC_AE_MAJOR_OP_ECC; @@ -1224,8 +1216,7 @@ cnxk_ae_enqueue(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op, ret = cnxk_ae_ecfpm_prep(&asym_op->ecpm, &meta_buf, sess->cnxk_fpm_iova, sess->ec_grp[sess->ec_ctx.curveid], - sess->ec_ctx.curveid, inst, - sess->lf->roc_cpt->cpt_revision); + sess->ec_ctx.curveid, inst); if (unlikely(ret)) goto req_fail; break; From patchwork Thu Oct 26 08:15:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gowrishankar Muthukrishnan X-Patchwork-Id: 133381 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 039AA43206; Thu, 26 Oct 2023 10:15:58 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E89CF42DEA; Thu, 26 Oct 2023 10:15:32 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id E897140E5E for ; Thu, 26 Oct 2023 10:15:31 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39Q70U2f020548; Thu, 26 Oct 2023 01:15:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=+zPf4ZqF/mZideugJtnQVj4WbdbJK3vFMH7ZcLLi7FQ=; b=Ih51esZpsC79arQdpyY6IkfkHZ+arP7TDRyZ4PVY37plQlrfzBWWcyDobHfEJx734xKU WV+qKLJgWh7MajNMk5FwQNY0cZBOqHBUT5BZjuSXbq4vMipN7MOXYmRljR0Wo/fQL07E DGlbctioPDvYgw2yQkH0zd3D4MkdXdduhJWbmdXbb2qxz4TgY5l1SGtOwuTUR1DrvOBE M251WZfKtHWpBerkAT37Bs+SYYrXycMHH9bH0xk/np71tGxGyWo9na1p76S8H+vL1GIL Xzw78tyEkanV5Wprp10u12P5VK1Bw/rC52b51rhmueK2f7VCv/6vzOiJx0esZRG5EeZu gw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3txcsr1b2w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 26 Oct 2023 01:15:31 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 26 Oct 2023 01:15:29 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Thu, 26 Oct 2023 01:15:29 -0700 Received: from BG-LT91401.marvell.com (BG-LT91401.marvell.com [10.28.168.34]) by maili.marvell.com (Postfix) with ESMTP id 3E7693F704D; Thu, 26 Oct 2023 01:15:26 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Akhil Goyal , Fan Zhang , Gowrishankar Muthukrishnan Subject: [PATCH v1 4/4] crypto/cnxk: add ECDH support Date: Thu, 26 Oct 2023 13:45:12 +0530 Message-ID: <9571524d259f454ef7ed73ce1c8c28905ed93190.1698307299.git.gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: ITxEJqKfIURVRIMI3VIYg-wyGiub8Ian X-Proofpoint-GUID: ITxEJqKfIURVRIMI3VIYg-wyGiub8Ian X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-26_05,2023-10-25_01,2023-05-22_02 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 Add ECDH support in CNXK PMD. Signed-off-by: Gowrishankar Muthukrishnan --- doc/guides/cryptodevs/features/cn10k.ini | 1 + doc/guides/cryptodevs/features/cn9k.ini | 1 + drivers/common/cnxk/roc_ae.h | 7 + drivers/crypto/cnxk/cn10k_cryptodev_ops.c | 12 ++ drivers/crypto/cnxk/cnxk_ae.h | 143 ++++++++++++++++-- drivers/crypto/cnxk/cnxk_cryptodev.h | 2 +- .../crypto/cnxk/cnxk_cryptodev_capabilities.c | 14 ++ 7 files changed, 165 insertions(+), 15 deletions(-) diff --git a/doc/guides/cryptodevs/features/cn10k.ini b/doc/guides/cryptodevs/features/cn10k.ini index 4f542c6038..ea8a22eb46 100644 --- a/doc/guides/cryptodevs/features/cn10k.ini +++ b/doc/guides/cryptodevs/features/cn10k.ini @@ -102,6 +102,7 @@ DSA = Modular Exponentiation = Y Modular Inversion = Diffie-hellman = +ECDH = Y ECDSA = Y ECPM = Y SM2 = Y diff --git a/doc/guides/cryptodevs/features/cn9k.ini b/doc/guides/cryptodevs/features/cn9k.ini index bf0e1a98b2..d70771d9bd 100644 --- a/doc/guides/cryptodevs/features/cn9k.ini +++ b/doc/guides/cryptodevs/features/cn9k.ini @@ -96,6 +96,7 @@ DSA = Modular Exponentiation = Y Modular Inversion = Diffie-hellman = +ECDH = Y ECDSA = Y ECPM = Y diff --git a/drivers/common/cnxk/roc_ae.h b/drivers/common/cnxk/roc_ae.h index eaf12ab254..a9a08d9fb9 100644 --- a/drivers/common/cnxk/roc_ae.h +++ b/drivers/common/cnxk/roc_ae.h @@ -8,9 +8,11 @@ #include "roc_platform.h" /* AE opcodes */ +#define ROC_AE_MAJOR_OP_RANDOM 0x32 #define ROC_AE_MAJOR_OP_MODEX 0x03 #define ROC_AE_MAJOR_OP_EC 0x04 #define ROC_AE_MAJOR_OP_ECC 0x05 +#define ROC_AE_MINOR_OP_RANDOM 0x00 #define ROC_AE_MINOR_OP_MODEX 0x01 #define ROC_AE_MINOR_OP_PKCS_ENC 0x02 #define ROC_AE_MINOR_OP_PKCS_ENC_CRT 0x03 @@ -46,6 +48,11 @@ typedef enum { #define ROC_AE_EC_PARAM1_NIST (0 << 6) #define ROC_AE_EC_PARAM1_NONNIST (1 << 6) +typedef enum { + ROC_AE_ERR_ECC_PAI = 0x0b, + ROC_AE_ERR_ECC_POINT_NOT_ON_CURVE = 0x11 +} roc_ae_error_code; + /* Prime and order fields of built-in elliptic curves */ struct roc_ae_ec_group { struct { diff --git a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c index 5f181e8839..997110e3d3 100644 --- a/drivers/crypto/cnxk/cn10k_cryptodev_ops.c +++ b/drivers/crypto/cnxk/cn10k_cryptodev_ops.c @@ -860,6 +860,18 @@ cn10k_cpt_dequeue_post_process(struct cnxk_cpt_qp *qp, } return; + } else if (cop->type == RTE_CRYPTO_OP_TYPE_ASYMMETRIC && + cop->sess_type == RTE_CRYPTO_OP_WITH_SESSION && + cop->asym->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY) { + if (likely(compcode == CPT_COMP_GOOD)) { + if (uc_compcode == ROC_AE_ERR_ECC_POINT_NOT_ON_CURVE) { + cop->status = RTE_CRYPTO_OP_STATUS_ERROR; + return; + } else if (uc_compcode == ROC_AE_ERR_ECC_PAI) { + cop->status = RTE_CRYPTO_OP_STATUS_SUCCESS; + return; + } + } } if (likely(compcode == CPT_COMP_GOOD)) { diff --git a/drivers/crypto/cnxk/cnxk_ae.h b/drivers/crypto/cnxk/cnxk_ae.h index f05ae4f4a1..ea11e093bf 100644 --- a/drivers/crypto/cnxk/cnxk_ae.h +++ b/drivers/crypto/cnxk/cnxk_ae.h @@ -236,6 +236,7 @@ cnxk_ae_fill_session_parameters(struct cnxk_ae_sess *sess, break; case RTE_CRYPTO_ASYM_XFORM_ECDSA: /* Fall through */ + case RTE_CRYPTO_ASYM_XFORM_ECDH: case RTE_CRYPTO_ASYM_XFORM_ECPM: case RTE_CRYPTO_ASYM_XFORM_ECFPM: case RTE_CRYPTO_ASYM_XFORM_SM2: @@ -920,7 +921,7 @@ cnxk_ae_enqueue_sm2_op(struct rte_crypto_op *op, } static __rte_always_inline int -cnxk_ae_ecfpm_prep(struct rte_crypto_ecpm_op_param *ecpm, +cnxk_ae_ecfpm_prep(rte_crypto_param *scalar, struct roc_ae_buf_ptr *meta_buf, uint64_t *fpm_iova, struct roc_ae_ec_group *ec_grp, uint8_t curveid, struct cpt_inst_s *inst) @@ -939,7 +940,7 @@ cnxk_ae_ecfpm_prep(struct rte_crypto_ecpm_op_param *ecpm, inst->dptr = (uintptr_t)dptr; p_align = RTE_ALIGN_CEIL(prime_len, 8); - scalar_align = RTE_ALIGN_CEIL(ecpm->scalar.length, 8); + scalar_align = RTE_ALIGN_CEIL(scalar->length, 8); /* * Set dlen = sum(ROUNDUP8(input point(x and y coordinates), prime, @@ -954,7 +955,7 @@ cnxk_ae_ecfpm_prep(struct rte_crypto_ecpm_op_param *ecpm, dptr += sizeof(fpm_table_iova); /* Copy scalar, prime */ - memcpy(dptr, ecpm->scalar.data, ecpm->scalar.length); + memcpy(dptr, scalar->data, scalar->length); dptr += scalar_align; memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length); dptr += p_align; @@ -968,7 +969,7 @@ cnxk_ae_ecfpm_prep(struct rte_crypto_ecpm_op_param *ecpm, w4.s.opcode_minor = ROC_AE_MINOR_OP_ECC_FPM; w4.s.param1 = curveid | (1 << 8); - w4.s.param2 = ecpm->scalar.length; + w4.s.param2 = scalar->length; w4.s.dlen = dlen; inst->w4.u64 = w4.u64; @@ -978,13 +979,13 @@ cnxk_ae_ecfpm_prep(struct rte_crypto_ecpm_op_param *ecpm, } static __rte_always_inline int -cnxk_ae_ecpm_prep(struct rte_crypto_ecpm_op_param *ecpm, +cnxk_ae_ecpm_prep(rte_crypto_param *scalar, struct rte_crypto_ec_point *p, struct roc_ae_buf_ptr *meta_buf, struct roc_ae_ec_group *ec_grp, uint8_t curveid, struct cpt_inst_s *inst) { - uint16_t x1_len = ecpm->p.x.length; - uint16_t y1_len = ecpm->p.y.length; + uint16_t x1_len = p->x.length; + uint16_t y1_len = p->y.length; uint16_t scalar_align, p_align; uint16_t x1_offset, y1_offset; uint16_t dlen, prime_len; @@ -998,7 +999,7 @@ cnxk_ae_ecpm_prep(struct rte_crypto_ecpm_op_param *ecpm, inst->dptr = (uintptr_t)dptr; p_align = RTE_ALIGN_CEIL(prime_len, 8); - scalar_align = RTE_ALIGN_CEIL(ecpm->scalar.length, 8); + scalar_align = RTE_ALIGN_CEIL(scalar->length, 8); /* * Set dlen = sum(ROUNDUP8(input point(x and y coordinates), prime, @@ -1013,11 +1014,11 @@ cnxk_ae_ecpm_prep(struct rte_crypto_ecpm_op_param *ecpm, memset(dptr, 0, dlen); /* Copy input point, scalar, prime */ - memcpy(dptr + x1_offset, ecpm->p.x.data, x1_len); + memcpy(dptr + x1_offset, p->x.data, x1_len); dptr += p_align; - memcpy(dptr + y1_offset, ecpm->p.y.data, y1_len); + memcpy(dptr + y1_offset, p->y.data, y1_len); dptr += p_align; - memcpy(dptr, ecpm->scalar.data, ecpm->scalar.length); + memcpy(dptr, scalar->data, scalar->length); dptr += scalar_align; memcpy(dptr, ec_grp->prime.data, ec_grp->prime.length); dptr += p_align; @@ -1031,7 +1032,7 @@ cnxk_ae_ecpm_prep(struct rte_crypto_ecpm_op_param *ecpm, w4.s.opcode_minor = ROC_AE_MINOR_OP_ECC_UMP; w4.s.param1 = curveid; - w4.s.param2 = ecpm->scalar.length; + w4.s.param2 = scalar->length; w4.s.dlen = dlen; inst->w4.u64 = w4.u64; @@ -1040,6 +1041,78 @@ cnxk_ae_ecpm_prep(struct rte_crypto_ecpm_op_param *ecpm, return 0; } +static __rte_always_inline int +cnxk_ae_random_prep(uint16_t len, struct roc_ae_buf_ptr *meta_buf, + struct cpt_inst_s *inst) +{ + union cpt_inst_w4 w4; + uint8_t *dptr; + + /* Input buffer */ + dptr = meta_buf->vaddr; + inst->dptr = (uintptr_t)dptr; + + /* Setup opcodes */ + w4.s.opcode_major = ROC_AE_MAJOR_OP_RANDOM; + w4.s.opcode_minor = ROC_AE_MINOR_OP_RANDOM; + + w4.s.param1 = len; + w4.s.param2 = 0; + w4.s.dlen = 0; + + inst->w4.u64 = w4.u64; + inst->rptr = (uintptr_t)dptr; + + return 0; +} + +static __rte_always_inline int __rte_hot +cnxk_ae_enqueue_ecdh_op(struct rte_crypto_op *op, + struct roc_ae_buf_ptr *meta_buf, + struct cnxk_ae_sess *sess, uint64_t *fpm_iova, + struct roc_ae_ec_group **ec_grp, + struct cpt_inst_s *inst) +{ + struct rte_crypto_ecdh_op_param *ecdh = &op->asym->ecdh; + uint8_t curveid = sess->ec_ctx.curveid; + struct rte_crypto_ec_point point; + rte_crypto_uint scalar; + int ret = 0; + + switch (ecdh->ke_type) { + case RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE: + cnxk_ae_random_prep(ecdh->priv_key.length, meta_buf, inst); + break; + case RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE: + scalar.data = sess->ec_ctx.pkey.data; + scalar.length = sess->ec_ctx.pkey.length; + cnxk_ae_ecfpm_prep(&scalar, meta_buf, fpm_iova, ec_grp[curveid], + curveid, inst); + break; + case RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY: + scalar.data = ec_grp[curveid]->order.data; + scalar.length = ec_grp[curveid]->order.length; + cnxk_ae_ecpm_prep(&scalar, &ecdh->pub_key, meta_buf, + ec_grp[curveid], curveid, inst); + break; + case RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE: + scalar.data = sess->ec_ctx.pkey.data; + scalar.length = sess->ec_ctx.pkey.length; + point.x.data = sess->ec_ctx.q.x.data; + point.x.length = sess->ec_ctx.q.x.length; + point.y.data = sess->ec_ctx.q.y.data; + point.y.length = sess->ec_ctx.q.y.length; + cnxk_ae_ecpm_prep(&scalar, &point, meta_buf, + ec_grp[curveid], curveid, inst); + break; + default: + op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + ret = -EINVAL; + } + + return ret; +} + static __rte_always_inline void cnxk_ae_dequeue_rsa_op(struct rte_crypto_op *cop, uint8_t *rptr, struct rte_crypto_rsa_xform *rsa_ctx) @@ -1143,6 +1216,37 @@ cnxk_ae_dequeue_ecpm_op(struct rte_crypto_ecpm_op_param *ecpm, uint8_t *rptr, ecpm->r.y.length = prime_len; } +static __rte_always_inline void +cnxk_ae_dequeue_ecdh_op(struct rte_crypto_ecdh_op_param *ecdh, uint8_t *rptr, + struct roc_ae_ec_ctx *ec, + struct roc_ae_ec_group **ec_grp) +{ + int prime_len = ec_grp[ec->curveid]->prime.length; + + switch (ecdh->ke_type) { + case RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE: + memcpy(ecdh->priv_key.data, rptr, prime_len); + ecdh->priv_key.length = prime_len; + break; + case RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE: + memcpy(ecdh->pub_key.x.data, rptr, prime_len); + memcpy(ecdh->pub_key.y.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len); + ecdh->pub_key.x.length = prime_len; + ecdh->pub_key.y.length = prime_len; + break; + case RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY: + break; + case RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE: + memcpy(ecdh->shared_secret.x.data, rptr, prime_len); + memcpy(ecdh->shared_secret.y.data, rptr + RTE_ALIGN_CEIL(prime_len, 8), prime_len); + ecdh->shared_secret.x.length = prime_len; + ecdh->shared_secret.y.length = prime_len; + break; + default: + break; + } +} + static __rte_always_inline void * cnxk_ae_alloc_meta(struct roc_ae_buf_ptr *buf, struct rte_mempool *cpt_meta_pool, @@ -1206,20 +1310,27 @@ cnxk_ae_enqueue(struct cnxk_cpt_qp *qp, struct rte_crypto_op *op, goto req_fail; break; case RTE_CRYPTO_ASYM_XFORM_ECPM: - ret = cnxk_ae_ecpm_prep(&asym_op->ecpm, &meta_buf, + ret = cnxk_ae_ecpm_prep(&asym_op->ecpm.scalar, &asym_op->ecpm.p, &meta_buf, sess->ec_grp[sess->ec_ctx.curveid], sess->ec_ctx.curveid, inst); if (unlikely(ret)) goto req_fail; break; case RTE_CRYPTO_ASYM_XFORM_ECFPM: - ret = cnxk_ae_ecfpm_prep(&asym_op->ecpm, &meta_buf, + ret = cnxk_ae_ecfpm_prep(&asym_op->ecpm.scalar, &meta_buf, sess->cnxk_fpm_iova, sess->ec_grp[sess->ec_ctx.curveid], sess->ec_ctx.curveid, inst); if (unlikely(ret)) goto req_fail; break; + case RTE_CRYPTO_ASYM_XFORM_ECDH: + ret = cnxk_ae_enqueue_ecdh_op(op, &meta_buf, sess, + sess->cnxk_fpm_iova, + sess->ec_grp, inst); + if (unlikely(ret)) + goto req_fail; + break; default: op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; ret = -EINVAL; @@ -1262,6 +1373,10 @@ cnxk_ae_post_process(struct rte_crypto_op *cop, struct cnxk_ae_sess *sess, cnxk_ae_dequeue_ecpm_op(&op->ecpm, rptr, &sess->ec_ctx, sess->ec_grp); break; + case RTE_CRYPTO_ASYM_XFORM_ECDH: + cnxk_ae_dequeue_ecdh_op(&op->ecdh, rptr, &sess->ec_ctx, + sess->ec_grp); + break; default: cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; break; diff --git a/drivers/crypto/cnxk/cnxk_cryptodev.h b/drivers/crypto/cnxk/cnxk_cryptodev.h index 9a321aa8c9..d0ad881f2f 100644 --- a/drivers/crypto/cnxk/cnxk_cryptodev.h +++ b/drivers/crypto/cnxk/cnxk_cryptodev.h @@ -10,7 +10,7 @@ #include "roc_cpt.h" -#define CNXK_CPT_MAX_CAPS 54 +#define CNXK_CPT_MAX_CAPS 55 #define CNXK_SEC_CRYPTO_MAX_CAPS 16 #define CNXK_SEC_MAX_CAPS 9 #define CNXK_AE_EC_ID_MAX 9 diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c b/drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c index b4864f66bf..2676b52832 100644 --- a/drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c +++ b/drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c @@ -92,6 +92,20 @@ static const struct rte_cryptodev_capabilities caps_mul[] = { }, } }, + { /* ECDH */ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, + {.asym = { + .xform_capa = { + .xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH, + .op_types = ((1 << RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE) | + (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE) | + (1 << RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY) | + (1 << RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE) + ), + } + }, + } + }, }; static const struct rte_cryptodev_capabilities caps_sha1_sha2[] = {