]> git.droids-corp.org - dpdk.git/commitdiff
crypto/qat: add ECPM algorithm
authorArek Kusztal <arkadiuszx.kusztal@intel.com>
Mon, 21 Feb 2022 10:48:30 +0000 (10:48 +0000)
committerAkhil Goyal <gakhil@marvell.com>
Wed, 23 Feb 2022 09:17:06 +0000 (10:17 +0100)
This patch adds Elliptic Curve Multiplication
algorithm to Intel QuickAssist Technology PMD.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
doc/guides/cryptodevs/qat.rst
doc/guides/rel_notes/release_22_03.rst
drivers/common/qat/qat_adf/qat_pke.h
drivers/crypto/qat/qat_asym.c
drivers/crypto/qat/qat_asym.h

index 593c2471ed2c7cd6672d61615d9ad86ef32fad80..785e04132487e493deafe2517327aac569dd2c6f 100644 (file)
@@ -176,6 +176,7 @@ The QAT ASYM PMD has support for:
 * ``RTE_CRYPTO_ASYM_XFORM_MODINV``
 * ``RTE_CRYPTO_ASYM_XFORM_RSA``
 * ``RTE_CRYPTO_ASYM_XFORM_ECDSA``
+* ``RTE_CRYPTO_ASYM_XFORM_ECPM``
 
 Limitations
 ~~~~~~~~~~~
index ca66cbd9e576389dd3d244e75429856e82058e1e..36831ca4e467191323055b3d5594eaae60174065 100644 (file)
@@ -140,6 +140,7 @@ New Features
 
   * Added support for CPM2.0b (4942) devices.
   * Added ECDSA algorithm support.
+  * Added ECPM algorithm support.
 
 * **Added an API to retrieve event port id of ethdev Rx adapter.**
 
index 1fe5f6bd8e3ad9f9343a0644219decf5595851ee..092fc373de883dad8b66ea1550ca3caa4f224a60 100644 (file)
@@ -252,4 +252,24 @@ get_ecdsa_function(struct rte_crypto_asym_xform *xform)
        return qat_function;
 }
 
+static struct qat_asym_function
+get_ecpm_function(struct rte_crypto_asym_xform *xform)
+{
+       struct qat_asym_function qat_function;
+
+       switch (xform->ec.curve_id) {
+       case RTE_CRYPTO_EC_GROUP_SECP256R1:
+               qat_function.func_id = MATHS_POINT_MULTIPLICATION_GFP_L256;
+               qat_function.bytesize = 32;
+               break;
+       case RTE_CRYPTO_EC_GROUP_SECP521R1:
+               qat_function.func_id = MATHS_POINT_MULTIPLICATION_GFP_521;
+               qat_function.bytesize = 66;
+               break;
+       default:
+               qat_function.func_id = 0;
+       }
+       return qat_function;
+}
+
 #endif
index 24dd3ee57f98403b9c4fd213def6aec4138743ec..af96cc6bd230ac438194f0e34923efbc9b8bed2d 100644 (file)
@@ -83,7 +83,7 @@ static const struct rte_driver cryptodev_qat_asym_driver = {
                        what.length)
 
 #define SET_PKE_LN_EC(where, what, how, idx) \
-               rte_memcpy(&where[idx * RTE_ALIGN_CEIL(how, 8)] + \
+               rte_memcpy(where[idx] + \
                        RTE_ALIGN_CEIL(how, 8) - \
                        how, \
                        what.data, \
@@ -688,6 +688,84 @@ ecdsa_collect(struct rte_crypto_asym_op *asym_op,
        return RTE_CRYPTO_OP_STATUS_SUCCESS;
 }
 
+static int
+ecpm_set_input(struct rte_crypto_asym_op *asym_op,
+               struct icp_qat_fw_pke_request *qat_req,
+               struct qat_asym_op_cookie *cookie,
+               struct rte_crypto_asym_xform *xform)
+{
+       struct qat_asym_function qat_function;
+       uint32_t alg_bytesize, __rte_unused qat_alg_bytesize, func_id;
+       int curve_id;
+
+       curve_id = pick_curve(xform);
+       if (curve_id < 0) {
+               QAT_LOG(ERR, "Incorrect elliptic curve");
+               return -EINVAL;
+       }
+
+       qat_function = get_ecpm_function(xform);
+       func_id = qat_function.func_id;
+       if (func_id == 0) {
+               QAT_LOG(ERR, "Cannot obtain functionality id");
+               return -EINVAL;
+       }
+       alg_bytesize = qat_function.bytesize;
+       qat_alg_bytesize = RTE_ALIGN_CEIL(alg_bytesize, 8);
+
+       SET_PKE_LN(cookie->input_array, asym_op->ecpm.scalar,
+                       alg_bytesize, 0);
+       SET_PKE_LN(cookie->input_array, asym_op->ecpm.p.x,
+                       alg_bytesize, 1);
+       SET_PKE_LN(cookie->input_array, asym_op->ecpm.p.y,
+                       alg_bytesize, 2);
+       SET_PKE_LN_EC(cookie->input_array, curve[SECP256R1].a,
+                       alg_bytesize, 3);
+       SET_PKE_LN_EC(cookie->input_array, curve[SECP256R1].b,
+                       alg_bytesize, 4);
+       SET_PKE_LN_EC(cookie->input_array, curve[SECP256R1].p,
+                       alg_bytesize, 5);
+       SET_PKE_LN_EC(cookie->input_array, curve[SECP256R1].h,
+                       alg_bytesize, 6);
+
+       cookie->alg_bytesize = alg_bytesize;
+       qat_req->pke_hdr.cd_pars.func_id = func_id;
+       qat_req->input_param_count =
+                       QAT_ASYM_ECPM_IN_PARAMS;
+       qat_req->output_param_count =
+                       QAT_ASYM_ECPM_OUT_PARAMS;
+
+       HEXDUMP("k", cookie->input_array[0], qat_alg_bytesize);
+       HEXDUMP("xG", cookie->input_array[1], qat_alg_bytesize);
+       HEXDUMP("yG", cookie->input_array[2], qat_alg_bytesize);
+       HEXDUMP("a", cookie->input_array[3], qat_alg_bytesize);
+       HEXDUMP("b", cookie->input_array[4], qat_alg_bytesize);
+       HEXDUMP("q", cookie->input_array[5], qat_alg_bytesize);
+       HEXDUMP("h", cookie->input_array[6], qat_alg_bytesize);
+
+       return 0;
+}
+
+static uint8_t
+ecpm_collect(struct rte_crypto_asym_op *asym_op,
+               struct qat_asym_op_cookie *cookie)
+{
+       uint8_t *r = asym_op->ecpm.r.x.data;
+       uint8_t *s = asym_op->ecpm.r.y.data;
+       uint32_t alg_bytesize = cookie->alg_bytesize;
+
+       asym_op->ecpm.r.x.length = alg_bytesize;
+       asym_op->ecpm.r.y.length = alg_bytesize;
+       rte_memcpy(r, cookie->output_array[0], alg_bytesize);
+       rte_memcpy(s, cookie->output_array[1], alg_bytesize);
+
+       HEXDUMP("rX", cookie->output_array[0],
+               alg_bytesize);
+       HEXDUMP("rY", cookie->output_array[1],
+               alg_bytesize);
+       return RTE_CRYPTO_OP_STATUS_SUCCESS;
+}
+
 static int
 asym_set_input(struct rte_crypto_asym_op *asym_op,
                struct icp_qat_fw_pke_request *qat_req,
@@ -707,6 +785,9 @@ asym_set_input(struct rte_crypto_asym_op *asym_op,
        case RTE_CRYPTO_ASYM_XFORM_ECDSA:
                return ecdsa_set_input(asym_op, qat_req,
                                cookie, xform);
+       case RTE_CRYPTO_ASYM_XFORM_ECPM:
+               return ecpm_set_input(asym_op, qat_req,
+                               cookie, xform);
        default:
                QAT_LOG(ERR, "Invalid/unsupported asymmetric crypto xform");
                return -EINVAL;
@@ -783,6 +864,8 @@ qat_asym_collect_response(struct rte_crypto_op *rx_op,
                return rsa_collect(asym_op, cookie);
        case RTE_CRYPTO_ASYM_XFORM_ECDSA:
                return ecdsa_collect(asym_op, cookie);
+       case RTE_CRYPTO_ASYM_XFORM_ECPM:
+               return ecpm_collect(asym_op, cookie);
        default:
                QAT_LOG(ERR, "Not supported xform type");
                return  RTE_CRYPTO_OP_STATUS_ERROR;
index 5e926125f29fac591607e10754419728b6f5f1db..6267c53bea0ecfc552bc4c8f4155918a6a07b373 100644 (file)
@@ -32,6 +32,8 @@ typedef uint64_t large_int_ptr;
 #define QAT_ASYM_ECDSA_RS_SIGN_OUT_PARAMS      2
 #define QAT_ASYM_ECDSA_RS_VERIFY_IN_PARAMS     1
 #define QAT_ASYM_ECDSA_RS_VERIFY_OUT_PARAMS    0
+#define QAT_ASYM_ECPM_IN_PARAMS                        7
+#define QAT_ASYM_ECPM_OUT_PARAMS               2
 
 /**
  * helper function to add an asym capability