FD.io VPP  v19.04.4-rc0-5-ge88582fac
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 #define foreach_crypto_cipher_alg \
24  _(DES_CBC, "des-cbc") \
25  _(3DES_CBC, "3des-cbc") \
26  _(AES_128_CBC, "aes-128-cbc") \
27  _(AES_192_CBC, "aes-192-cbc") \
28  _(AES_256_CBC, "aes-256-cbc")
29 
30 #define foreach_crypto_aead_alg \
31  _(AES_128_GCM, "aes-128-gcm") \
32  _(AES_192_GCM, "aes-192-gcm") \
33  _(AES_256_GCM, "aes-256-gcm")
34 
35 #define foreach_crypto_hmac_alg \
36  _(MD5, "md5") \
37  _(SHA1, "sha-1") \
38  _(SHA224, "sha-224") \
39  _(SHA256, "sha-256") \
40  _(SHA384, "sha-384") \
41  _(SHA512, "sha-512")
42 
43 
44 #define foreach_crypto_op_type \
45  _(ENCRYPT, "encrypt") \
46  _(DECRYPT, "decrypt") \
47  _(AEAD_ENCRYPT, "aead-encrypt") \
48  _(AEAD_DECRYPT, "aead-decrypt") \
49  _(HMAC, "hmac")
50 
51 typedef enum
52 {
53 #define _(n, s) VNET_CRYPTO_OP_TYPE_##n,
55 #undef _
58 
59 #define foreach_crypto_op_status \
60  _(PENDING, "pending") \
61  _(COMPLETED, "completed") \
62  _(FAIL_NO_HANDLER, "no-handler") \
63  _(FAIL_BAD_HMAC, "bad-hmac") \
64  _(FAIL_DECRYPT, "decrypt-fail")
65 
66 typedef enum
67 {
68 #define _(n, s) VNET_CRYPTO_OP_STATUS_##n,
70 #undef _
73 
74 /* *INDENT-OFF* */
75 typedef enum
76 {
77 #define _(n, s) VNET_CRYPTO_ALG_##n,
80 #undef _
81 #define _(n, s) VNET_CRYPTO_ALG_HMAC_##n,
83 #undef _
86 
87 typedef enum
88 {
90 #define _(n, s) VNET_CRYPTO_OP_##n##_ENC, VNET_CRYPTO_OP_##n##_DEC,
93 #undef _
94 #define _(n, s) VNET_CRYPTO_OP_##n##_HMAC,
96 #undef _
99 /* *INDENT-ON* */
100 
101 typedef struct
102 {
103  char *name;
106 
107 typedef struct
108 {
109  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
113 #define VNET_CRYPTO_OP_FLAG_INIT_IV (1 << 0)
114 #define VNET_CRYPTO_OP_FLAG_HMAC_CHECK (1 << 1)
117  u8 key_len, iv_len, digest_len, tag_len;
118  u8 *key;
119  u8 *iv;
120  u8 *src;
121  u8 *dst;
122  u8 *aad;
123  u8 *tag;
127 
128 typedef struct
129 {
134 
135 typedef struct
136 {
137  CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
140 
142  vnet_crypto_op_t * ops[], u32 n_ops);
143 
145  char *desc);
146 
148  u32 provider_index,
151  f);
152 
153 typedef struct
154 {
155  char *name;
156  char *desc;
157  int priority;
160 
161 typedef struct
162 {
171 
173 
175  u32 n_jobs);
176 
178  u32 n_ops);
179 
180 
181 int vnet_crypto_set_handler (char *ops_handler_name, char *engine);
182 
188 
191 {
192  if (CLIB_DEBUG > 0)
193  clib_memset (op, 0xfe, sizeof (*op));
194  op->op = type;
195  op->flags = 0;
196 }
197 
200 {
203  return od->type;
204 }
205 
206 #endif /* included_vnet_crypto_crypto_h */
207 
208 /*
209  * fd.io coding-style-patch-verification: ON
210  *
211  * Local Variables:
212  * eval: (c-set-style "gnu")
213  * End:
214  */
#define foreach_crypto_op_status
Definition: crypto.h:59
format_function_t format_vnet_crypto_op_type
Definition: crypto.h:186
vnet_crypto_engine_t * engines
Definition: crypto.h:167
#define CLIB_CACHE_LINE_ALIGN_MARK(mark)
Definition: cache.h:60
uword * alg_index_by_name
Definition: crypto.h:169
vnet_crypto_thread_t * threads
Definition: crypto.h:164
vnet_crypto_op_data_t opt_data[VNET_CRYPTO_N_OP_IDS]
Definition: crypto.h:166
vnet_crypto_alg_data_t * algs
Definition: crypto.h:163
format_function_t format_vnet_crypto_op
Definition: crypto.h:185
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
format_function_t format_vnet_crypto_alg
Definition: crypto.h:183
u16 vlib_error_t
Definition: error.h:43
clib_bitmap_t * act_queues
Definition: crypto.h:138
unsigned char u8
Definition: types.h:56
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
vnet_crypto_op_type_t
Definition: crypto.h:51
#define static_always_inline
Definition: clib.h:99
#define foreach_crypto_aead_alg
Definition: crypto.h:30
vlib_error_t * vnet_crypto_register_ops_handler(vlib_main_t *vm, u32 provider_index, vnet_crypto_op_id_t opt, vnet_crypto_ops_handler_t *f)
Definition: crypto.c:133
vnet_crypto_alg_t alg
Definition: crypto.h:131
static_always_inline void vnet_crypto_op_init(vnet_crypto_op_t *op, vnet_crypto_op_id_t type)
Definition: crypto.h:190
#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:35
unsigned int u32
Definition: types.h:88
vnet_crypto_op_id_t op
Definition: crypto.h:110
vnet_crypto_alg_t
Definition: crypto.h:75
uword user_data
Definition: crypto.h:125
unsigned short u16
Definition: types.h:57
u8 name[64]
Definition: memclnt.api:152
u8 len
Definition: ip_types.api:49
vlib_main_t * vm
Definition: buffer.c:312
u32() vnet_crypto_ops_handler_t(vlib_main_t *vm, vnet_crypto_op_t *ops[], u32 n_ops)
Definition: crypto.h:141
vnet_crypto_op_status_t
Definition: crypto.h:66
format_function_t format_vnet_crypto_op_status
Definition: crypto.h:187
uword * engine_index_by_name
Definition: crypto.h:168
u32 vnet_crypto_submit_ops(vlib_main_t *vm, vnet_crypto_op_t **jobs, u32 n_jobs)
static_always_inline vnet_crypto_op_type_t vnet_crypto_get_op_type(vnet_crypto_op_id_t id)
Definition: crypto.h:199
format_function_t format_vnet_crypto_engine
Definition: crypto.h:184
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:44
vnet_crypto_op_type_t type
Definition: crypto.h:130
vnet_crypto_op_status_t status
Definition: crypto.h:111
vnet_crypto_op_id_t
Definition: crypto.h:87
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:165
#define foreach_crypto_cipher_alg
Definition: crypto.h:23