FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
main.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2019 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <vlib/vlib.h>
19 #include <vnet/plugin/plugin.h>
20 #include <vnet/crypto/crypto.h>
22 
24 
25 static void
28 {
31 
32  /** TODO: add linked alg support **/
33  if (key->type == VNET_CRYPTO_KEY_TYPE_LINK)
34  return;
35 
36  if (cm->key_fn[key->alg] == 0)
37  return;
38 
39  if (kop == VNET_CRYPTO_KEY_OP_DEL)
40  {
41  if (idx >= vec_len (cm->key_data))
42  return;
43 
44  if (cm->key_data[idx] == 0)
45  return;
46 
47  clib_mem_free_s (cm->key_data[idx]);
48  cm->key_data[idx] = 0;
49  return;
50  }
51 
53 
54  if (kop == VNET_CRYPTO_KEY_OP_MODIFY && cm->key_data[idx])
55  {
56  clib_mem_free_s (cm->key_data[idx]);
57  }
58 
59  cm->key_data[idx] = cm->key_fn[key->alg] (key);
60 }
61 
64 {
67  clib_error_t *error = 0;
68 
69  if (clib_cpu_supports_x86_aes () == 0 &&
70  clib_cpu_supports_aarch64_aes () == 0)
71  return 0;
72 
75 
77  vnet_crypto_register_engine (vm, "native", 100,
78  "Native ISA Optimized Crypto");
79 
80  if (0);
81 #if __x86_64__
82  else if (crypto_native_aes_cbc_init_icl && clib_cpu_supports_vaes ())
83  error = crypto_native_aes_cbc_init_icl (vm);
84  else if (crypto_native_aes_cbc_init_skx && clib_cpu_supports_avx512f ())
85  error = crypto_native_aes_cbc_init_skx (vm);
86  else if (crypto_native_aes_cbc_init_hsw && clib_cpu_supports_avx2 ())
87  error = crypto_native_aes_cbc_init_hsw (vm);
89  error = crypto_native_aes_cbc_init_slm (vm);
90 #endif
91 #if __aarch64__
92  else if (crypto_native_aes_cbc_init_neon)
93  error = crypto_native_aes_cbc_init_neon (vm);
94 #endif
95  else
96  error = clib_error_return (0, "No AES CBC implemenation available");
97 
98  if (error)
99  goto error;
100 
101 #if __x86_64__
102  if (clib_cpu_supports_pclmulqdq ())
103  {
104  if (crypto_native_aes_gcm_init_icl && clib_cpu_supports_vaes ())
105  error = crypto_native_aes_gcm_init_icl (vm);
106  else if (crypto_native_aes_gcm_init_skx && clib_cpu_supports_avx512f ())
107  error = crypto_native_aes_gcm_init_skx (vm);
108  else if (crypto_native_aes_gcm_init_hsw && clib_cpu_supports_avx2 ())
109  error = crypto_native_aes_gcm_init_hsw (vm);
111  error = crypto_native_aes_gcm_init_slm (vm);
112  else
113  error = clib_error_return (0, "No AES GCM implemenation available");
114 
115  if (error)
116  goto error;
117  }
118 #endif
119 #if __aarch64__
120  if (crypto_native_aes_gcm_init_neon)
121  error = crypto_native_aes_gcm_init_neon (vm);
122  else
123  error = clib_error_return (0, "No AES GCM implemenation available");
124 
125  if (error)
126  goto error;
127 #endif
128 
131 
132 
133 error:
134  if (error)
136 
137  return error;
138 }
139 
140 /* *INDENT-OFF* */
142 {
143  .runs_after = VLIB_INITS ("vnet_crypto_init"),
144 };
145 /* *INDENT-ON* */
146 
147 #include <vpp/app/version.h>
148 
149 /* *INDENT-OFF* */
151  .version = VPP_BUILD_VER,
152  .description = "Intel IA32 Software Crypto Engine",
153 };
154 /* *INDENT-ON* */
155 
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "gnu")
161  * End:
162  */
VLIB_PLUGIN_REGISTER()
#define VNET_CRYPTO_KEY_TYPE_LINK
Definition: crypto.h:192
crypto_native_key_fn_t * key_fn[VNET_CRYPTO_N_ALGS]
Definition: crypto_native.h:33
crypto_native_per_thread_data_t * per_thread_data
Definition: crypto_native.h:32
vlib_main_t * vm
Definition: in2out_ed.c:1582
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:520
void vnet_crypto_register_key_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_key_handler_t *key_handler)
Definition: crypto.c:307
vnet_crypto_key_op_t
Definition: crypto.h:108
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define clib_error_return(e, args...)
Definition: error.h:99
vnet_crypto_main_t * cm
Definition: quic_crypto.c:53
vnet_crypto_alg_t alg
Definition: crypto.h:182
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
clib_error_t * crypto_native_aes_cbc_init_slm(vlib_main_t *vm)
Definition: aes_cbc.c:485
u32 vnet_crypto_key_index_t
Definition: crypto.h:346
static void clib_mem_free_s(void *p)
Definition: mem.h:253
clib_error_t * crypto_native_init(vlib_main_t *vm)
Definition: main.c:63
typedef key
Definition: ipsec_types.api:85
static_always_inline vnet_crypto_key_t * vnet_crypto_get_key(vnet_crypto_key_index_t index)
Definition: crypto.h:516
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * crypto_native_aes_gcm_init_slm(vlib_main_t *vm)
Definition: aes_gcm.c:1211
crypto_native_main_t crypto_native_main
Definition: main.c:23
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
u32 vnet_crypto_register_engine(vlib_main_t *vm, char *name, int prio, char *desc)
Definition: crypto.c:112
#define VLIB_INITS(...)
Definition: init.h:357
static void crypto_native_key_handler(vlib_main_t *vm, vnet_crypto_key_op_t kop, vnet_crypto_key_index_t idx)
Definition: main.c:26