xref: /dpdk/drivers/common/cnxk/roc_ae.h (revision a8ebe94f8cc11cda874cd0353a47e78279699d10)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4 
5 #ifndef __ROC_AE_H__
6 #define __ROC_AE_H__
7 
8 #include "roc_platform.h"
9 
10 /* AE opcodes */
11 #define ROC_AE_MAJOR_OP_RANDOM	     0x32
12 #define ROC_AE_MAJOR_OP_MODEX	     0x03
13 #define ROC_AE_MAJOR_OP_EC	     0x04
14 #define ROC_AE_MAJOR_OP_ECC	     0x05
15 #define ROC_AE_MAJOR_OP_EDDSA	     0x0A
16 #define ROC_AE_MINOR_OP_RANDOM	     0x00
17 #define ROC_AE_MINOR_OP_MODEX	     0x01
18 #define ROC_AE_MINOR_OP_PKCS_ENC     0x02
19 #define ROC_AE_MINOR_OP_PKCS_ENC_CRT 0x03
20 #define ROC_AE_MINOR_OP_PKCS_DEC     0x04
21 #define ROC_AE_MINOR_OP_PKCS_DEC_CRT 0x05
22 #define ROC_AE_MINOR_OP_MODEX_CRT    0x06
23 #define ROC_AE_MINOR_OP_EC_SIGN      0x01
24 #define ROC_AE_MINOR_OP_EC_VERIFY    0x02
25 #define ROC_AE_MINOR_OP_ECC_UMP	     0x03
26 #define ROC_AE_MINOR_OP_ECC_FPM	     0x04
27 #define ROC_AE_MINOR_OP_ED_SIGN      0x00
28 #define ROC_AE_MINOR_OP_ED_VERIFY    0x01
29 #define ROC_AE_MINOR_OP_ED_KEYGEN    0x02
30 
31 /**
32  * Enumeration roc_ae_ec_id
33  *
34  * Enumerates supported elliptic curves
35  */
36 typedef enum {
37 	ROC_AE_EC_ID_P192 = 0,
38 	ROC_AE_EC_ID_P224 = 1,
39 	ROC_AE_EC_ID_P256 = 2,
40 	ROC_AE_EC_ID_P384 = 3,
41 	ROC_AE_EC_ID_P521 = 4,
42 	ROC_AE_EC_ID_P160 = 5,
43 	ROC_AE_EC_ID_P320 = 6,
44 	ROC_AE_EC_ID_P512 = 7,
45 	ROC_AE_EC_ID_SM2  = 8,
46 	ROC_AE_EC_ID_ED25519 = 9,
47 	ROC_AE_EC_ID_ED448 = 10,
48 	ROC_AE_EC_ID_PMAX
49 } roc_ae_ec_id;
50 
51 /* EC param1 fields */
52 #define ROC_AE_EC_PARAM1_ECDSA     (0 << 7)
53 #define ROC_AE_EC_PARAM1_SM2       (1 << 7)
54 #define ROC_AE_EC_PARAM1_NIST      (0 << 6)
55 #define ROC_AE_EC_PARAM1_NONNIST   (1 << 6)
56 #define ROC_AE_ED_PARAM1_25519     (1 << 1)
57 #define ROC_AE_ED_PARAM1_448       (1 << 3)
58 #define ROC_AE_ED_PARAM1_KEYGEN_BIT      4
59 #define ROC_AE_EC_PARAM1_PH_BIT          5
60 
61 typedef enum {
62 	ROC_AE_ERR_ECC_PAI = 0x0b,
63 	ROC_AE_ERR_ECC_POINT_NOT_ON_CURVE = 0x11
64 } roc_ae_error_code;
65 
66 #define ROC_AE_EC_DATA_MAX 66
67 
68 /* Prime and order fields of built-in elliptic curves */
69 struct roc_ae_ec_group {
70 	struct {
71 		/* P521 maximum length */
72 		uint8_t data[ROC_AE_EC_DATA_MAX];
73 		unsigned int length;
74 	} prime;
75 
76 	struct {
77 		/* P521 maximum length */
78 		uint8_t data[ROC_AE_EC_DATA_MAX];
79 		unsigned int length;
80 	} order;
81 
82 	struct {
83 		/* P521 maximum length */
84 		uint8_t data[ROC_AE_EC_DATA_MAX];
85 		unsigned int length;
86 	} consta;
87 
88 	struct {
89 		/* P521 maximum length */
90 		uint8_t data[ROC_AE_EC_DATA_MAX];
91 		unsigned int length;
92 	} constb;
93 };
94 
95 struct roc_ae_ec_ctx {
96 	/* Prime length defined by microcode for EC operations */
97 	uint8_t curveid;
98 
99 	/* Private key */
100 	struct {
101 		uint8_t data[ROC_AE_EC_DATA_MAX];
102 		unsigned int length;
103 	} pkey;
104 
105 	/* Public key */
106 	struct {
107 		struct {
108 			uint8_t data[ROC_AE_EC_DATA_MAX];
109 			unsigned int length;
110 		} x;
111 		struct {
112 			uint8_t data[ROC_AE_EC_DATA_MAX];
113 			unsigned int length;
114 		} y;
115 	} q;
116 };
117 
118 /* Buffer pointer */
119 struct roc_ae_buf_ptr {
120 	void *vaddr;
121 };
122 
123 int __roc_api roc_ae_ec_grp_get(struct roc_ae_ec_group **tbl);
124 void __roc_api roc_ae_ec_grp_put(void);
125 #endif /* __ROC_AE_H__ */
126