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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef included_vnet_crypto_crypto_h
17 #define included_vnet_crypto_crypto_h
19 #define VNET_CRYPTO_RING_SIZE 512
21 #include <vlib/vlib.h>
23 #define foreach_crypto_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")
30 #define foreach_hmac_alg \
33 _(SHA224, "sha-224") \
34 _(SHA256, "sha-256") \
35 _(SHA384, "sha-384") \
41 #define _(n, s) VNET_CRYPTO_ALG_##n,
44 #define _(n, s) VNET_CRYPTO_ALG_##n,
52 VNET_CRYPTO_OP_NONE = 0,
53 #define _(n, s) VNET_CRYPTO_OP_##n##_ENC, VNET_CRYPTO_OP_##n##_DEC,
56 #define _(n, s) VNET_CRYPTO_OP_##n##_HMAC,
59 VNET_CRYPTO_N_OP_TYPES,
60 } __attribute__ ((packed)) vnet_crypto_op_type_t;
63 STATIC_ASSERT (sizeof (vnet_crypto_op_type_t) <= 2,
64 "crypto op type > 2 bytes");
69 } vnet_crypto_alg_data_t;
73 VNET_CRYPTO_OP_STATUS_PENDING,
74 VNET_CRYPTO_OP_STATUS_COMPLETED,
75 VNET_CRYPTO_OP_STATUS_FAIL_NO_HANDLER,
76 } __attribute__ ((packed)) vnet_crypto_op_status_t;
78 STATIC_ASSERT (sizeof (vnet_crypto_op_status_t) == 1,
79 "crypto op status > 1 byte");
83 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
84 vnet_crypto_op_type_t op;
85 vnet_crypto_op_status_t status;
86 u8 key_len, hmac_trunc_len;
88 #define VNET_CRYPTO_OP_FLAG_INIT_IV 1
99 vnet_crypto_alg_t alg;
101 u32 active_engine_index;
102 } vnet_crypto_op_type_data_t;
106 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
110 vnet_crypto_alg_t alg:8;
111 vnet_crypto_op_type_t op:8;
112 vnet_crypto_op_t *jobs[0];
113 } vnet_crypto_queue_t;
117 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
118 clib_bitmap_t *act_queues;
119 vnet_crypto_queue_t *queues[VNET_CRYPTO_N_OP_TYPES];
120 } vnet_crypto_thread_t;
122 typedef u32 (vnet_crypto_ops_handler_t) (vlib_main_t * vm,
123 vnet_crypto_op_t * ops[], u32 n_ops);
125 u32 vnet_crypto_register_engine (vlib_main_t * vm, char *name, int prio,
128 vlib_error_t *vnet_crypto_register_ops_handler (vlib_main_t * vm,
130 vnet_crypto_op_type_t opt,
131 vnet_crypto_ops_handler_t *
139 vnet_crypto_ops_handler_t *ops_handlers[VNET_CRYPTO_N_OP_TYPES];
140 } vnet_crypto_engine_t;
144 vnet_crypto_alg_data_t *algs;
145 vnet_crypto_thread_t *threads;
146 vnet_crypto_ops_handler_t **ops_handlers;
147 vnet_crypto_op_type_data_t opt_data[VNET_CRYPTO_N_OP_TYPES];
148 vnet_crypto_engine_t *engines;
149 uword *engine_index_by_name;
150 uword *ops_handler_index_by_name;
151 } vnet_crypto_main_t;
153 extern vnet_crypto_main_t crypto_main;
155 u32 vnet_crypto_submit_ops (vlib_main_t * vm, vnet_crypto_op_t ** jobs,
158 u32 vnet_crypto_process_ops (vlib_main_t * vm, vnet_crypto_op_t ops[],
162 int vnet_crypto_set_handler (char *ops_handler_name, char *engine);
164 format_function_t format_vnet_crypto_alg;
165 format_function_t format_vnet_crypto_engine;
166 format_function_t format_vnet_crypto_op;
168 #endif /* included_vnet_crypto_crypto_h */
171 * fd.io coding-style-patch-verification: ON
174 * eval: (c-set-style "gnu")