FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
crypto.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef included_vnet_crypto_crypto_h
17 #define included_vnet_crypto_crypto_h
18 
19 #define VNET_CRYPTO_RING_SIZE 512
20 
21 #include <vlib/vlib.h>
22 
23 /* CRYPTO_ID, PRETTY_NAME, KEY_LENGTH_IN_BYTES */
24 #define foreach_crypto_cipher_alg \
25  _(DES_CBC, "des-cbc", 7) \
26  _(3DES_CBC, "3des-cbc", 24) \
27  _(AES_128_CBC, "aes-128-cbc", 16) \
28  _(AES_192_CBC, "aes-192-cbc", 24) \
29  _(AES_256_CBC, "aes-256-cbc", 32) \
30  _(AES_128_CTR, "aes-128-ctr", 16) \
31  _(AES_192_CTR, "aes-192-ctr", 24) \
32  _(AES_256_CTR, "aes-256-ctr", 32)
33 
34 /* CRYPTO_ID, PRETTY_NAME, KEY_LENGTH_IN_BYTES */
35 #define foreach_crypto_aead_alg \
36  _(AES_128_GCM, "aes-128-gcm", 16) \
37  _(AES_192_GCM, "aes-192-gcm", 24) \
38  _(AES_256_GCM, "aes-256-gcm", 32)
39 
40 #define foreach_crypto_hmac_alg \
41  _(MD5, "md5") \
42  _(SHA1, "sha-1") \
43  _(SHA224, "sha-224") \
44  _(SHA256, "sha-256") \
45  _(SHA384, "sha-384") \
46  _(SHA512, "sha-512")
47 
48 
49 #define foreach_crypto_op_type \
50  _(ENCRYPT, "encrypt") \
51  _(DECRYPT, "decrypt") \
52  _(AEAD_ENCRYPT, "aead-encrypt") \
53  _(AEAD_DECRYPT, "aead-decrypt") \
54  _(HMAC, "hmac")
55 
56 typedef enum
57 {
58 #define _(n, s) VNET_CRYPTO_OP_TYPE_##n,
60 #undef _
63 
64 #define foreach_crypto_op_status \
65  _(PENDING, "pending") \
66  _(COMPLETED, "completed") \
67  _(FAIL_NO_HANDLER, "no-handler") \
68  _(FAIL_BAD_HMAC, "bad-hmac")
69 
70 typedef enum
71 {
76 
77 typedef enum
78 {
79 #define _(n, s) VNET_CRYPTO_OP_STATUS_##n,
81 #undef _
84 
85 /* *INDENT-OFF* */
86 typedef enum
87 {
89 #define _(n, s, l) VNET_CRYPTO_ALG_##n,
92 #undef _
93 #define _(n, s) VNET_CRYPTO_ALG_HMAC_##n,
95 #undef _
98 
99 typedef struct
100 {
104 
105 typedef enum
106 {
108 #define _(n, s, l) VNET_CRYPTO_OP_##n##_ENC, VNET_CRYPTO_OP_##n##_DEC,
111 #undef _
112 #define _(n, s) VNET_CRYPTO_OP_##n##_HMAC,
114 #undef _
117 /* *INDENT-ON* */
118 
119 typedef struct
120 {
121  char *name;
124 
125 typedef struct
126 {
127  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
131 #define VNET_CRYPTO_OP_FLAG_INIT_IV (1 << 0)
132 #define VNET_CRYPTO_OP_FLAG_HMAC_CHECK (1 << 1)
136  u8 digest_len, tag_len;
137  u8 *iv;
138  u8 *src;
139  u8 *dst;
140  u8 *aad;
141  u8 *tag;
145 
146 typedef struct
147 {
152 
153 typedef struct
154 {
155  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
158 
160 
162  vnet_crypto_op_t * ops[], u32 n_ops);
163 
167 
169  char *desc);
170 
171 void vnet_crypto_register_ops_handler (vlib_main_t * vm, u32 engine_index,
174 void vnet_crypto_register_key_handler (vlib_main_t * vm, u32 engine_index,
176 
177 typedef struct
178 {
179  char *name;
180  char *desc;
181  int priority;
185 
186 typedef struct
187 {
197 
199 
201  u32 n_jobs);
202 
204  u32 n_ops);
205 
206 int vnet_crypto_set_handler (char *ops_handler_name, char *engine);
208 
210  u8 * data, u16 length);
212 
219 
222 {
223  if (CLIB_DEBUG > 0)
224  clib_memset (op, 0xfe, sizeof (*op));
225  op->op = type;
226  op->flags = 0;
227  op->key_index = ~0;
228 }
229 
232 {
235  vnet_crypto_op_data_t *od = cm->opt_data + id;
236  return od->type;
237 }
238 
241 {
243  return vec_elt_at_index (cm->keys, index);
244 }
245 
246 #endif /* included_vnet_crypto_crypto_h */
247 
248 /*
249  * fd.io coding-style-patch-verification: ON
250  *
251  * Local Variables:
252  * eval: (c-set-style "gnu")
253  * End:
254  */
#define foreach_crypto_op_status
Definition: crypto.h:64
format_function_t format_vnet_crypto_op_type
Definition: crypto.h:216
vnet_crypto_engine_t * engines
Definition: crypto.h:192
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
uword * alg_index_by_name
Definition: crypto.h:195
vnet_crypto_thread_t * threads
Definition: crypto.h:189
vnet_crypto_op_data_t opt_data[VNET_CRYPTO_N_OP_IDS]
Definition: crypto.h:191
vnet_crypto_alg_data_t * algs
Definition: crypto.h:188
format_function_t format_vnet_crypto_op
Definition: crypto.h:215
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
format_function_t format_vnet_crypto_alg
Definition: crypto.h:213
int vnet_crypto_is_set_handler(vnet_crypto_alg_t alg)
Definition: crypto.c:133
void vnet_crypto_register_key_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_key_handler_t *keyh)
Definition: crypto.c:169
void vnet_crypto_register_ops_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_op_id_t opt, vnet_crypto_ops_handler_t *oph)
Definition: crypto.c:141
clib_bitmap_t * act_queues
Definition: crypto.h:156
unsigned char u8
Definition: types.h:56
u8 id[64]
Definition: dhcp.api:160
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
vnet_crypto_op_type_t
Definition: crypto.h:56
u32 vnet_crypto_key_add(vlib_main_t *vm, vnet_crypto_alg_t alg, u8 *data, u16 length)
Definition: crypto.c:207
#define static_always_inline
Definition: clib.h:99
vnet_crypto_key_op_t
Definition: crypto.h:70
void vnet_crypto_key_del(vlib_main_t *vm, vnet_crypto_key_index_t index)
Definition: crypto.c:233
#define foreach_crypto_aead_alg
Definition: crypto.h:35
vnet_crypto_alg_t alg
Definition: crypto.h:149
static_always_inline void vnet_crypto_op_init(vnet_crypto_op_t *op, vnet_crypto_op_id_t type)
Definition: crypto.h:221
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u32 vnet_crypto_process_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], u32 n_ops)
Definition: crypto.c:46
#define foreach_crypto_hmac_alg
Definition: crypto.h:40
unsigned int u32
Definition: types.h:88
vnet_crypto_op_id_t op
Definition: crypto.h:128
vnet_crypto_alg_t
Definition: crypto.h:86
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vnet_crypto_main_t * cm
Definition: quic_crypto.c:41
void() vnet_crypto_key_handler_t(vlib_main_t *vm, vnet_crypto_key_op_t kop, vnet_crypto_key_index_t idx)
Definition: crypto.h:164
uword user_data
Definition: crypto.h:143
vnet_crypto_key_handler_t * key_op_handler
Definition: crypto.h:182
unsigned short u16
Definition: types.h:57
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:233
vlib_main_t * vm
Definition: in2out_ed.c:1810
vnet_crypto_alg_t alg
Definition: crypto.h:102
unformat_function_t unformat_vnet_crypto_alg
Definition: crypto.h:218
u32() vnet_crypto_ops_handler_t(vlib_main_t *vm, vnet_crypto_op_t *ops[], u32 n_ops)
Definition: crypto.h:161
string name[64]
Definition: ip.api:44
vnet_crypto_op_status_t
Definition: crypto.h:77
#define ASSERT(truth)
format_function_t format_vnet_crypto_op_status
Definition: crypto.h:217
uword * engine_index_by_name
Definition: crypto.h:194
u32 vnet_crypto_submit_ops(vlib_main_t *vm, vnet_crypto_op_t **jobs, u32 n_jobs)
u8 data[128]
Definition: ipsec_types.api:87
static_always_inline vnet_crypto_op_type_t vnet_crypto_get_op_type(vnet_crypto_op_id_t id)
Definition: crypto.h:231
u32 vnet_crypto_key_index_t
Definition: crypto.h:159
static_always_inline vnet_crypto_key_t * vnet_crypto_get_key(vnet_crypto_key_index_t index)
Definition: crypto.h:240
format_function_t format_vnet_crypto_engine
Definition: crypto.h:214
u64 uword
Definition: types.h:112
u32 vnet_crypto_register_engine(vlib_main_t *vm, char *name, int prio, char *desc)
Definition: crypto.c:78
#define foreach_crypto_op_type
Definition: crypto.h:49
vnet_crypto_op_type_t type
Definition: crypto.h:148
vnet_crypto_op_status_t status
Definition: crypto.h:129
vnet_crypto_op_id_t
Definition: crypto.h:105
vnet_crypto_key_t * keys
Definition: crypto.h:193
uword clib_bitmap_t
Definition: bitmap.h:50
int vnet_crypto_set_handler(char *ops_handler_name, char *engine)
Definition: crypto.c:95
vnet_crypto_main_t crypto_main
Definition: crypto.c:20
vnet_crypto_ops_handler_t ** ops_handlers
Definition: crypto.h:190
#define foreach_crypto_cipher_alg
Definition: crypto.h:24