crypto/qat: add named elliptic curves
[dpdk.git] / drivers / crypto / qat / qat_asym.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2022 Intel Corporation
3  */
4
5 #ifndef _QAT_ASYM_H_
6 #define _QAT_ASYM_H_
7
8 #include <cryptodev_pmd.h>
9 #include <rte_crypto_asym.h>
10 #include "icp_qat_fw_pke.h"
11 #include "qat_device.h"
12 #include "qat_crypto.h"
13 #include "icp_qat_fw.h"
14
15 /** Intel(R) QAT Asymmetric Crypto PMD driver name */
16 #define CRYPTODEV_NAME_QAT_ASYM_PMD     crypto_qat_asym
17
18 typedef uint64_t large_int_ptr;
19 #define MAX_PKE_PARAMS  8
20 #define QAT_PKE_MAX_LN_SIZE 512
21 #define _PKE_ALIGN_ __rte_aligned(8)
22
23 #define QAT_ASYM_MAX_PARAMS                     8
24 #define QAT_ASYM_MODINV_NUM_IN_PARAMS           2
25 #define QAT_ASYM_MODINV_NUM_OUT_PARAMS          1
26 #define QAT_ASYM_MODEXP_NUM_IN_PARAMS           3
27 #define QAT_ASYM_MODEXP_NUM_OUT_PARAMS          1
28 #define QAT_ASYM_RSA_NUM_IN_PARAMS              3
29 #define QAT_ASYM_RSA_NUM_OUT_PARAMS             1
30 #define QAT_ASYM_RSA_QT_NUM_IN_PARAMS           6
31
32 /**
33  * helper function to add an asym capability
34  * <name> <op type> <modlen (min, max, increment)>
35  **/
36 #define QAT_ASYM_CAP(n, o, l, r, i)                                     \
37         {                                                               \
38                 .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,                    \
39                 {.asym = {                                              \
40                         .xform_capa = {                                 \
41                                 .xform_type = RTE_CRYPTO_ASYM_XFORM_##n,\
42                                 .op_types = o,                          \
43                                 {                                       \
44                                 .modlen = {                             \
45                                 .min = l,                               \
46                                 .max = r,                               \
47                                 .increment = i                          \
48                                 }, }                                    \
49                         }                                               \
50                 },                                                      \
51                 }                                                       \
52         }
53
54 struct qat_asym_op_cookie {
55         size_t alg_bytesize;
56         uint64_t error;
57         rte_iova_t input_addr;
58         rte_iova_t output_addr;
59         large_int_ptr input_params_ptrs[MAX_PKE_PARAMS] _PKE_ALIGN_;
60         large_int_ptr output_params_ptrs[MAX_PKE_PARAMS] _PKE_ALIGN_;
61         union {
62                 uint8_t input_array[MAX_PKE_PARAMS][QAT_PKE_MAX_LN_SIZE];
63                 uint8_t input_buffer[MAX_PKE_PARAMS * QAT_PKE_MAX_LN_SIZE];
64         } _PKE_ALIGN_;
65         uint8_t output_array[MAX_PKE_PARAMS][QAT_PKE_MAX_LN_SIZE] _PKE_ALIGN_;
66 } _PKE_ALIGN_;
67
68 struct qat_asym_session {
69         struct icp_qat_fw_pke_request req_tmpl;
70         struct rte_crypto_asym_xform *xform;
71 };
72
73 static inline void
74 qat_fill_req_tmpl(struct icp_qat_fw_pke_request *qat_req)
75 {
76         memset(qat_req, 0, sizeof(*qat_req));
77         qat_req->pke_hdr.service_type = ICP_QAT_FW_COMN_REQ_CPM_FW_PKE;
78
79         qat_req->pke_hdr.hdr_flags =
80                         ICP_QAT_FW_COMN_HDR_FLAGS_BUILD
81                         (ICP_QAT_FW_COMN_REQ_FLAG_SET);
82 }
83
84 static inline void
85 qat_asym_build_req_tmpl(void *sess_private_data)
86 {
87         struct icp_qat_fw_pke_request *qat_req;
88         struct qat_asym_session *session = sess_private_data;
89
90         qat_req = &session->req_tmpl;
91         qat_fill_req_tmpl(qat_req);
92 }
93
94 int
95 qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused,
96                 struct rte_crypto_asym_xform *xform,
97                 struct rte_cryptodev_asym_session *sess);
98
99 unsigned int
100 qat_asym_session_get_private_size(struct rte_cryptodev *dev);
101
102 void
103 qat_asym_session_clear(struct rte_cryptodev *dev,
104                 struct rte_cryptodev_asym_session *sess);
105
106 void
107 qat_asym_init_op_cookie(void *cookie);
108
109 #endif /* _QAT_ASYM_H_ */