FD.io VPP  v21.01.1
Vector Packet Processing
crypto.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 #include <stdbool.h>
17 #include <vlib/vlib.h>
18 #include <vnet/crypto/crypto.h>
19 
21 
23 crypto_set_op_status (vnet_crypto_op_t * ops[], u32 n_ops, int status)
24 {
25  while (n_ops--)
26  {
27  ops[0]->status = status;
28  ops++;
29  }
30 }
31 
36  vnet_crypto_op_t * ops[],
37  vnet_crypto_op_chunk_t * chunks,
38  u32 n_ops)
39 {
40  u32 rv = 0;
41  if (n_ops == 0)
42  return 0;
43 
44  if (chunks)
45  {
46 
47  if (cm->chained_ops_handlers[opt] == 0)
48  crypto_set_op_status (ops, n_ops,
49  VNET_CRYPTO_OP_STATUS_FAIL_NO_HANDLER);
50  else
51  rv = (cm->chained_ops_handlers[opt]) (vm, ops, chunks, n_ops);
52  }
53  else
54  {
55  if (cm->ops_handlers[opt] == 0)
56  crypto_set_op_status (ops, n_ops,
57  VNET_CRYPTO_OP_STATUS_FAIL_NO_HANDLER);
58  else
59  rv = (cm->ops_handlers[opt]) (vm, ops, n_ops);
60  }
61  return rv;
62 }
63 
66  vnet_crypto_op_chunk_t * chunks, u32 n_ops)
67 {
69  const int op_q_size = VLIB_FRAME_SIZE;
70  vnet_crypto_op_t *op_queue[op_q_size];
71  vnet_crypto_op_id_t opt, current_op_type = ~0;
72  u32 n_op_queue = 0;
73  u32 rv = 0, i;
74 
75  ASSERT (n_ops >= 1);
76 
77  for (i = 0; i < n_ops; i++)
78  {
79  opt = ops[i].op;
80 
81  if (current_op_type != opt || n_op_queue >= op_q_size)
82  {
83  rv += vnet_crypto_process_ops_call_handler (vm, cm, current_op_type,
84  op_queue, chunks,
85  n_op_queue);
86  n_op_queue = 0;
87  current_op_type = opt;
88  }
89 
90  op_queue[n_op_queue++] = &ops[i];
91  }
92 
93  rv += vnet_crypto_process_ops_call_handler (vm, cm, current_op_type,
94  op_queue, chunks, n_op_queue);
95  return rv;
96 }
97 
98 u32
100 {
101  return vnet_crypto_process_ops_inline (vm, ops, 0, n_ops);
102 }
103 
104 u32
106  vnet_crypto_op_chunk_t * chunks, u32 n_ops)
107 {
108  return vnet_crypto_process_ops_inline (vm, ops, chunks, n_ops);
109 }
110 
111 u32
113  char *desc)
114 {
117 
118  vec_add2 (cm->engines, p, 1);
119  p->name = name;
120  p->desc = desc;
121  p->priority = prio;
122 
123  hash_set_mem (cm->engine_index_by_name, p->name, p - cm->engines);
124 
125  return p - cm->engines;
126 }
127 
130  vnet_crypto_op_id_t id, u32 ei,
132 {
135 
136  if (oct == CRYPTO_OP_BOTH || oct == CRYPTO_OP_CHAINED)
137  {
138  if (ce->chained_ops_handlers[id])
139  {
142  }
143  }
144 
145  if (oct == CRYPTO_OP_BOTH || oct == CRYPTO_OP_SIMPLE)
146  {
147  if (ce->ops_handlers[id])
148  {
150  cm->ops_handlers[id] = ce->ops_handlers[id];
151  }
152  }
153 }
154 
155 int
156 vnet_crypto_set_handler2 (char *alg_name, char *engine,
158 {
159  uword *p;
162  int i;
163 
164  p = hash_get_mem (cm->alg_index_by_name, alg_name);
165  if (!p)
166  return -1;
167 
168  ad = vec_elt_at_index (cm->algs, p[0]);
169 
170  p = hash_get_mem (cm->engine_index_by_name, engine);
171  if (!p)
172  return -1;
173 
174  for (i = 0; i < VNET_CRYPTO_OP_N_TYPES; i++)
175  {
177  vnet_crypto_op_id_t id = ad->op_by_type[i];
178  if (id == 0)
179  continue;
180 
181  od = cm->opt_data + id;
182  crypto_set_active_engine (od, id, p[0], oct);
183  }
184 
185  return 0;
186 }
187 
188 int
190 {
192 
193  return (alg < vec_len (cm->ops_handlers) && NULL != cm->ops_handlers[alg]);
194 }
195 
196 void
201  cfn)
202 {
204  vnet_crypto_engine_t *ae, *e = vec_elt_at_index (cm->engines, engine_index);
205  vnet_crypto_op_data_t *otd = cm->opt_data + opt;
210 
211  if (fn)
212  {
213  e->ops_handlers[opt] = fn;
214  if (otd->active_engine_index_simple == ~0)
215  {
216  otd->active_engine_index_simple = engine_index;
217  cm->ops_handlers[opt] = fn;
218  }
219 
221  if (ae->priority < e->priority)
222  crypto_set_active_engine (otd, opt, engine_index, CRYPTO_OP_SIMPLE);
223  }
224 
225  if (cfn)
226  {
227  e->chained_ops_handlers[opt] = cfn;
228  if (otd->active_engine_index_chained == ~0)
229  {
230  otd->active_engine_index_chained = engine_index;
231  cm->chained_ops_handlers[opt] = cfn;
232  }
233 
235  if (ae->priority < e->priority)
236  crypto_set_active_engine (otd, opt, engine_index, CRYPTO_OP_CHAINED);
237  }
238 
239  return;
240 }
241 
242 void
246 {
247  vnet_crypto_register_ops_handler_inline (vm, engine_index, opt, fn, 0);
248 }
249 
250 void
254  fn)
255 {
256  vnet_crypto_register_ops_handler_inline (vm, engine_index, opt, 0, fn);
257 }
258 
259 void
264 {
265  vnet_crypto_register_ops_handler_inline (vm, engine_index, opt, fn, cfn);
266 }
267 
268 void
271  vnet_crypto_frame_enqueue_t * enqueue_hdl,
272  vnet_crypto_frame_dequeue_t * dequeue_hdl)
273 {
275  vnet_crypto_engine_t *ae, *e = vec_elt_at_index (cm->engines, engine_index);
281 
282  /* both enqueue hdl and dequeue hdl should present */
283  if (!enqueue_hdl && !dequeue_hdl)
284  return;
285 
286  e->enqueue_handlers[opt] = enqueue_hdl;
287  e->dequeue_handlers[opt] = dequeue_hdl;
288  if (otd->active_engine_index_async == ~0)
289  {
290  otd->active_engine_index_async = engine_index;
291  cm->enqueue_handlers[opt] = enqueue_hdl;
292  cm->dequeue_handlers[opt] = dequeue_hdl;
293  }
294 
296  if (ae->priority < e->priority)
297  {
298  otd->active_engine_index_async = engine_index;
299  cm->enqueue_handlers[opt] = enqueue_hdl;
300  cm->dequeue_handlers[opt] = dequeue_hdl;
301  }
302 
303  return;
304 }
305 
306 void
308  vnet_crypto_key_handler_t * key_handler)
309 {
311  vnet_crypto_engine_t *e = vec_elt_at_index (cm->engines, engine_index);
312  e->key_op_handler = key_handler;
313  return;
314 }
315 
316 static int
318 {
319  switch (alg)
320  {
321  case VNET_CRYPTO_N_ALGS:
322  return 0;
324  return 1;
325 
326 #define _(n, s, l) \
327  case VNET_CRYPTO_ALG_##n: \
328  if ((l) == length) \
329  return 1; \
330  break;
332 #undef _
333  /* HMAC allows any key length */
334 #define _(n, s) \
335  case VNET_CRYPTO_ALG_HMAC_##n: \
336  return 1;
338 #undef _
339  }
340 
341  return 0;
342 }
343 
344 u32
346  u16 length)
347 {
348  u32 index;
350  vnet_crypto_engine_t *engine;
352 
353  if (!vnet_crypto_key_len_check (alg, length))
354  return ~0;
355 
356  pool_get_zero (cm->keys, key);
357  index = key - cm->keys;
359  key->alg = alg;
360  vec_validate_aligned (key->data, length - 1, CLIB_CACHE_LINE_BYTES);
361  clib_memcpy (key->data, data, length);
362  /* *INDENT-OFF* */
363  vec_foreach (engine, cm->engines)
364  if (engine->key_op_handler)
365  engine->key_op_handler (vm, VNET_CRYPTO_KEY_OP_ADD, index);
366  /* *INDENT-ON* */
367  return index;
368 }
369 
370 void
372 {
374  vnet_crypto_engine_t *engine;
376 
377  /* *INDENT-OFF* */
378  vec_foreach (engine, cm->engines)
379  if (engine->key_op_handler)
380  engine->key_op_handler (vm, VNET_CRYPTO_KEY_OP_DEL, index);
381  /* *INDENT-ON* */
382 
383  if (key->type == VNET_CRYPTO_KEY_TYPE_DATA)
384  {
385  clib_memset (key->data, 0, vec_len (key->data));
386  vec_free (key->data);
387  }
388  else if (key->type == VNET_CRYPTO_KEY_TYPE_LINK)
389  {
390  key->index_crypto = key->index_integ = 0;
391  }
392 
393  pool_put (cm->keys, key);
394 }
395 
399 {
400 #define _(c, h, s, k ,d) \
401  if (crypto_alg == VNET_CRYPTO_ALG_##c && \
402  integ_alg == VNET_CRYPTO_ALG_HMAC_##h) \
403  return VNET_CRYPTO_ALG_##c##_##h##_TAG##d;
405 #undef _
406  return ~0;
407 }
408 
409 u32
411  vnet_crypto_key_index_t index_crypto,
412  vnet_crypto_key_index_t index_integ)
413 {
414  u32 index;
416  vnet_crypto_engine_t *engine;
417  vnet_crypto_key_t *key_crypto, *key_integ, *key;
418  vnet_crypto_async_alg_t linked_alg;
419 
420  key_crypto = pool_elt_at_index (cm->keys, index_crypto);
421  key_integ = pool_elt_at_index (cm->keys, index_integ);
422 
423  if (!key_crypto || !key_integ)
424  return ~0;
425 
426  linked_alg = vnet_crypto_link_algs (key_crypto->alg, key_integ->alg);
427  if (linked_alg == ~0)
428  return ~0;
429 
430  pool_get_zero (cm->keys, key);
431  index = key - cm->keys;
433  key->index_crypto = index_crypto;
434  key->index_integ = index_integ;
435  key->async_alg = linked_alg;
436 
437  /* *INDENT-OFF* */
438  vec_foreach (engine, cm->engines)
439  if (engine->key_op_handler)
440  engine->key_op_handler (vm, VNET_CRYPTO_KEY_OP_ADD, index);
441  /* *INDENT-ON* */
442 
443  return index;
444 }
445 
446 clib_error_t *
448 {
451  u32 skip_master = vlib_num_workers () > 0, i;
452  vlib_node_state_t state = VLIB_NODE_STATE_DISABLED;
453  u8 state_change = 0;
454 
456  if (is_enable && cm->async_refcnt > 0)
457  {
458  state_change = 1;
459  state =
460  cm->dispatch_mode ==
461  VNET_CRYPTO_ASYNC_DISPATCH_POLLING ? VLIB_NODE_STATE_POLLING :
462  VLIB_NODE_STATE_INTERRUPT;
463  }
464 
465  if (!is_enable && cm->async_refcnt == 0)
466  {
467  state_change = 1;
468  state = VLIB_NODE_STATE_DISABLED;
469  }
470 
471  if (state_change)
472  for (i = skip_master; i < tm->n_vlib_mains; i++)
473  {
474  if (state !=
477  }
478  return 0;
479 }
480 
484 {
487 
488  if (ce->enqueue_handlers[id] && ce->dequeue_handlers[id])
489  {
490  od->active_engine_index_async = ei;
493  }
494 }
495 
496 int
497 vnet_crypto_set_async_handler2 (char *alg_name, char *engine)
498 {
499  uword *p;
502  int i;
503 
504  p = hash_get_mem (cm->async_alg_index_by_name, alg_name);
505  if (!p)
506  return -1;
507 
508  ad = vec_elt_at_index (cm->async_algs, p[0]);
509 
510  p = hash_get_mem (cm->engine_index_by_name, engine);
511  if (!p)
512  return -1;
513 
514  for (i = 0; i < VNET_CRYPTO_ASYNC_OP_N_TYPES; i++)
515  {
518  if (id == 0)
519  continue;
520 
521  od = cm->async_opt_data + id;
522  crypto_set_active_async_engine (od, id, p[0]);
523  }
524 
525  return 0;
526 }
527 
528 u32
530 {
533  vlib_node_t *cc, *pn;
534  uword index = vec_len (cm->next_nodes);
535 
536  pn = vlib_get_node_by_name (vm, (u8 *) post_node_name);
537  if (!pn)
538  return ~0;
539 
540  /* *INDENT-OFF* */
541  vec_foreach (cm->next_nodes, nn)
542  {
543  if (nn->node_idx == pn->index)
544  return nn->next_idx;
545  }
546  /* *INDENT-ON* */
547 
548  vec_validate (cm->next_nodes, index);
549  nn = vec_elt_at_index (cm->next_nodes, index);
550 
551  cc = vlib_get_node_by_name (vm, (u8 *) "crypto-dispatch");
552  nn->next_idx = vlib_node_add_named_next (vm, cc->index, post_node_name);
553  nn->node_idx = pn->index;
554 
555  return nn->next_idx;
556 }
557 
558 void
560 {
563  u32 skip_master = vlib_num_workers () > 0, i;
564  vlib_node_state_t state = VLIB_NODE_STATE_DISABLED;
565  u8 state_change = 0;
566 
568  if (is_enable && cm->async_refcnt == 0)
569  {
570  state_change = 1;
571  state =
573  VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_INTERRUPT;
574  }
575  if (!is_enable && cm->async_refcnt == 1)
576  {
577  state_change = 1;
578  state = VLIB_NODE_STATE_DISABLED;
579  }
580 
581  if (state_change)
582  for (i = skip_master; i < tm->n_vlib_mains; i++)
583  {
584  if (state !=
587  }
588 
589  if (is_enable)
590  cm->async_refcnt += 1;
591  else if (cm->async_refcnt > 0)
592  cm->async_refcnt -= 1;
593 }
594 
595 void
597 {
599  u32 skip_master = vlib_num_workers () > 0, i;
601  vlib_node_state_t state = VLIB_NODE_STATE_DISABLED;
602 
604  cm->dispatch_mode = mode;
606  {
607  state =
608  cm->async_refcnt == 0 ?
609  VLIB_NODE_STATE_DISABLED : VLIB_NODE_STATE_INTERRUPT;
610  }
611  else if (mode == VNET_CRYPTO_ASYNC_DISPATCH_POLLING)
612  {
613  state =
614  cm->async_refcnt == 0 ?
615  VLIB_NODE_STATE_DISABLED : VLIB_NODE_STATE_POLLING;
616  }
617 
618  for (i = skip_master; i < tm->n_vlib_mains; i++)
619  {
620  if (state != vlib_node_get_state (vlib_mains[i], cm->crypto_node_index))
622  }
623 }
624 
625 int
627 {
629 
630  return (op < vec_len (cm->enqueue_handlers) &&
631  NULL != cm->enqueue_handlers[op]);
632 }
633 
634 static void
636  vnet_crypto_op_id_t did, char *name, u8 is_aead)
637 {
638  vnet_crypto_op_type_t eopt, dopt;
640 
641  cm->algs[alg].name = name;
642  cm->opt_data[eid].alg = cm->opt_data[did].alg = alg;
644  cm->opt_data[did].active_engine_index_simple = ~0;
647  if (is_aead)
648  {
649  eopt = VNET_CRYPTO_OP_TYPE_AEAD_ENCRYPT;
650  dopt = VNET_CRYPTO_OP_TYPE_AEAD_DECRYPT;
651  }
652  else
653  {
654  eopt = VNET_CRYPTO_OP_TYPE_ENCRYPT;
655  dopt = VNET_CRYPTO_OP_TYPE_DECRYPT;
656  }
657  cm->opt_data[eid].type = eopt;
658  cm->opt_data[did].type = dopt;
659  cm->algs[alg].op_by_type[eopt] = eid;
660  cm->algs[alg].op_by_type[dopt] = did;
661  hash_set_mem (cm->alg_index_by_name, name, alg);
662 }
663 
664 static void
666  vnet_crypto_op_id_t id, char *name)
667 {
669  cm->algs[alg].name = name;
670  cm->algs[alg].op_by_type[VNET_CRYPTO_OP_TYPE_HMAC] = id;
671  cm->opt_data[id].alg = alg;
674  cm->opt_data[id].type = VNET_CRYPTO_OP_TYPE_HMAC;
675  hash_set_mem (cm->alg_index_by_name, name, alg);
676 }
677 
678 static void
681  vnet_crypto_async_op_id_t did, char *name)
682 {
684 
685  cm->async_algs[alg].name = name;
686  cm->async_algs[alg].op_by_type[VNET_CRYPTO_ASYNC_OP_TYPE_ENCRYPT] = eid;
687  cm->async_algs[alg].op_by_type[VNET_CRYPTO_ASYNC_OP_TYPE_DECRYPT] = did;
688  cm->async_opt_data[eid].type = VNET_CRYPTO_ASYNC_OP_TYPE_ENCRYPT;
689  cm->async_opt_data[eid].alg = alg;
692  cm->async_opt_data[did].type = VNET_CRYPTO_ASYNC_OP_TYPE_DECRYPT;
693  cm->async_opt_data[did].alg = alg;
696  hash_set_mem (cm->async_alg_index_by_name, name, alg);
697 }
698 
699 clib_error_t *
701 {
704  vnet_crypto_thread_t *ct = 0;
705 
707  cm->engine_index_by_name = hash_create_string ( /* size */ 0,
708  sizeof (uword));
709  cm->alg_index_by_name = hash_create_string (0, sizeof (uword));
712  vec_foreach (ct, cm->threads)
717 
718 #define _(n, s, l) \
719  vnet_crypto_init_cipher_data (VNET_CRYPTO_ALG_##n, \
720  VNET_CRYPTO_OP_##n##_ENC, \
721  VNET_CRYPTO_OP_##n##_DEC, s, 0);
723 #undef _
724 #define _(n, s, l) \
725  vnet_crypto_init_cipher_data (VNET_CRYPTO_ALG_##n, \
726  VNET_CRYPTO_OP_##n##_ENC, \
727  VNET_CRYPTO_OP_##n##_DEC, s, 1);
729 #undef _
730 #define _(n, s) \
731  vnet_crypto_init_hmac_data (VNET_CRYPTO_ALG_HMAC_##n, \
732  VNET_CRYPTO_OP_##n##_HMAC, "hmac-" s);
734 #undef _
735 #define _(n, s, k, t, a) \
736  vnet_crypto_init_async_data (VNET_CRYPTO_ALG_##n##_TAG##t##_AAD##a, \
737  VNET_CRYPTO_OP_##n##_TAG##t##_AAD##a##_ENC, \
738  VNET_CRYPTO_OP_##n##_TAG##t##_AAD##a##_DEC, \
739  s);
741 #undef _
742 #define _(c, h, s, k ,d) \
743  vnet_crypto_init_async_data (VNET_CRYPTO_ALG_##c##_##h##_TAG##d, \
744  VNET_CRYPTO_OP_##c##_##h##_TAG##d##_ENC, \
745  VNET_CRYPTO_OP_##c##_##h##_TAG##d##_DEC, \
746  s);
748 #undef _
749  cm->crypto_node_index =
750  vlib_get_node_by_name (vm, (u8 *) "crypto-dispatch")->index;
751 
752  return 0;
753 }
754 
756 
757 /*
758  * fd.io coding-style-patch-verification: ON
759  *
760  * Local Variables:
761  * eval: (c-set-style "gnu")
762  * End:
763  */
u32 vnet_crypto_process_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], u32 n_ops)
Definition: crypto.c:99
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:509
static void vnet_crypto_init_async_data(vnet_crypto_async_alg_t alg, vnet_crypto_async_op_id_t eid, vnet_crypto_async_op_id_t did, char *name)
Definition: crypto.c:679
int() vnet_crypto_frame_enqueue_t(vlib_main_t *vm, vnet_crypto_async_frame_t *frame)
async crypto function handlers
Definition: crypto.h:362
uword * async_alg_index_by_name
Definition: crypto.h:434
void vnet_crypto_set_async_dispatch_mode(u8 mode)
Definition: crypto.c:596
vnet_crypto_engine_t * engines
Definition: crypto.h:430
vnet_crypto_thread_t * threads
Definition: crypto.h:422
uword * alg_index_by_name
Definition: crypto.h:433
#define foreach_crypto_link_async_alg
Definition: crypto.h:87
vnet_crypto_async_op_id_t op_by_type[VNET_CRYPTO_ASYNC_OP_N_TYPES]
Definition: crypto.h:298
static_always_inline void crypto_set_active_engine(vnet_crypto_op_data_t *od, vnet_crypto_op_id_t id, u32 ei, crypto_op_class_type_t oct)
Definition: crypto.c:129
static_always_inline void crypto_set_op_status(vnet_crypto_op_t *ops[], u32 n_ops, int status)
Definition: crypto.c:23
#define VNET_CRYPTO_KEY_TYPE_LINK
Definition: crypto.h:192
vnet_crypto_op_data_t opt_data[VNET_CRYPTO_N_OP_IDS]
Definition: crypto.h:428
u32() vnet_crypto_chained_ops_handler_t(vlib_main_t *vm, vnet_crypto_op_t *ops[], vnet_crypto_op_chunk_t *chunks, u32 n_ops)
Definition: crypto.h:348
int vnet_crypto_set_async_handler2(char *alg_name, char *engine)
Definition: crypto.c:497
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:254
static_always_inline void crypto_set_active_async_engine(vnet_crypto_async_op_data_t *od, vnet_crypto_async_op_id_t id, u32 ei)
Definition: crypto.c:482
vnet_crypto_alg_data_t * algs
Definition: crypto.h:421
vnet_crypto_frame_enqueue_t ** enqueue_handlers
Definition: crypto.h:425
#define CLIB_MEMORY_STORE_BARRIER()
Definition: clib.h:136
static uword vlib_node_add_named_next(vlib_main_t *vm, uword node, char *name)
Definition: node_funcs.h:1185
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:280
vnet_crypto_op_id_t op_by_type[VNET_CRYPTO_OP_N_TYPES]
Definition: crypto.h:220
vnet_crypto_async_alg_data_t * async_algs
Definition: crypto.h:435
vnet_crypto_async_op_type_t type
Definition: crypto.h:290
void vnet_crypto_request_async_mode(int is_enable)
Definition: crypto.c:559
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:630
#define hash_set_mem(h, key, value)
Definition: hash.h:275
vnet_crypto_async_alg_t vnet_crypto_link_algs(vnet_crypto_alg_t crypto_alg, vnet_crypto_alg_t integ_alg)
Definition: crypto.c:397
vnet_crypto_frame_dequeue_t * dequeue_handlers[VNET_CRYPTO_ASYNC_OP_N_IDS]
Definition: crypto.h:410
vlib_main_t * vm
Definition: in2out_ed.c:1580
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:520
static void vnet_crypto_init_hmac_data(vnet_crypto_alg_t alg, vnet_crypto_op_id_t id, char *name)
Definition: crypto.c:665
vlib_main_t ** vlib_mains
Definition: buffer.c:332
unsigned char u8
Definition: types.h:56
u8 data[128]
Definition: ipsec_types.api:90
u8 id[64]
Definition: dhcp.api:160
#define VNET_CRYPTO_ASYNC_DISPATCH_POLLING
Definition: crypto.h:439
#define clib_memcpy(d, s, n)
Definition: string.h:180
int vnet_crypto_is_set_handler(vnet_crypto_alg_t alg)
Definition: crypto.c:189
void vnet_crypto_register_ops_handlers(vlib_main_t *vm, u32 engine_index, vnet_crypto_op_id_t opt, vnet_crypto_ops_handler_t *fn, vnet_crypto_chained_ops_handler_t *cfn)
Definition: crypto.c:260
#define clib_bitmap_validate(v, n_bits)
Definition: bitmap.h:115
vnet_crypto_op_type_t
Definition: crypto.h:56
void vnet_crypto_register_async_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_async_op_id_t opt, vnet_crypto_frame_enqueue_t *enqueue_hdl, vnet_crypto_frame_dequeue_t *dequeue_hdl)
Definition: crypto.c:269
void vnet_crypto_register_key_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_key_handler_t *key_handler)
Definition: crypto.c:307
#define static_always_inline
Definition: clib.h:109
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define pool_alloc_aligned(P, N, A)
Allocate N more free elements to pool (general version).
Definition: pool.h:337
#define foreach_crypto_aead_alg
Definition: crypto.h:35
int vnet_crypto_set_handler2(char *alg_name, char *engine, crypto_op_class_type_t oct)
Definition: crypto.c:156
u32 active_engine_index_chained
Definition: crypto.h:285
vnet_crypto_alg_t alg
Definition: crypto.h:283
#define VNET_CRYPTO_KEY_TYPE_DATA
Definition: crypto.h:191
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
typedef eid
Definition: lisp_types.api:59
#define foreach_crypto_hmac_alg
Definition: crypto.h:41
unsigned int u32
Definition: types.h:88
#define VLIB_FRAME_SIZE
Definition: node.h:378
u32 vnet_crypto_key_add(vlib_main_t *vm, vnet_crypto_alg_t alg, u8 *data, u16 length)
Definition: crypto.c:345
vnet_crypto_op_id_t op
Definition: crypto.h:234
vnet_crypto_alg_t
Definition: crypto.h:124
vnet_crypto_chained_ops_handler_t ** chained_ops_handlers
Definition: crypto.h:424
#define hash_create_string(elts, value_bytes)
Definition: hash.h:690
static vlib_node_state_t vlib_node_get_state(vlib_main_t *vm, u32 node_index)
Get node dispatch state.
Definition: node_funcs.h:218
clib_error_t * crypto_dispatch_enable_disable(int is_enable)
Definition: crypto.c:447
vnet_crypto_main_t * cm
Definition: quic_crypto.c:53
#define VNET_CRYPTO_ASYNC_DISPATCH_INTERRUPT
Definition: crypto.h:440
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
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:356
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
u8 integ_alg
Definition: ikev2_types.api:59
vnet_crypto_key_handler_t * key_op_handler
Definition: crypto.h:405
vnet_crypto_async_next_node_t * next_nodes
Definition: crypto.h:437
unsigned short u16
Definition: types.h:57
void vnet_crypto_key_del(vlib_main_t *vm, vnet_crypto_key_index_t index)
Definition: crypto.c:371
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:301
u32 vnet_crypto_register_post_node(vlib_main_t *vm, char *post_node_name)
async crypto register functions
Definition: crypto.c:529
void vnet_crypto_register_ops_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_op_id_t opt, vnet_crypto_ops_handler_t *fn)
Definition: crypto.c:243
u32 active_engine_index_simple
Definition: crypto.h:284
vnet_crypto_alg_t alg
Definition: crypto.h:182
vnet_crypto_async_frame_t * frame_pool
Definition: crypto.h:341
vl_api_tunnel_mode_t mode
Definition: gre.api:48
vnet_crypto_async_alg_t async_alg
Definition: crypto.h:188
static_always_inline u32 vnet_crypto_process_ops_inline(vlib_main_t *vm, vnet_crypto_op_t ops[], vnet_crypto_op_chunk_t *chunks, u32 n_ops)
Definition: crypto.c:65
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
u32 crypto_node_index
Definition: crypto.h:438
vnet_crypto_frame_dequeue_t ** dequeue_handlers
Definition: crypto.h:426
static int vnet_crypto_key_len_check(vnet_crypto_alg_t alg, u16 length)
Definition: crypto.c:317
vnet_crypto_chained_ops_handler_t * chained_ops_handlers[VNET_CRYPTO_N_OP_IDS]
Definition: crypto.h:408
u32() vnet_crypto_ops_handler_t(vlib_main_t *vm, vnet_crypto_op_t *ops[], u32 n_ops)
Definition: crypto.h:353
string name[64]
Definition: ip.api:44
crypto_op_class_type_t
Definition: crypto.h:210
static_always_inline u32 vnet_crypto_process_ops_call_handler(vlib_main_t *vm, vnet_crypto_main_t *cm, vnet_crypto_op_id_t opt, vnet_crypto_op_t *ops[], vnet_crypto_op_chunk_t *chunks, u32 n_ops)
Definition: crypto.c:33
vnet_crypto_async_alg_t alg
Definition: crypto.h:291
#define ASSERT(truth)
uword * engine_index_by_name
Definition: crypto.h:432
u32 vnet_crypto_process_chained_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], vnet_crypto_op_chunk_t *chunks, u32 n_ops)
Definition: crypto.c:105
clib_bitmap_t * async_active_ids
Definition: crypto.h:427
u32 vnet_crypto_key_index_t
Definition: crypto.h:346
#define foreach_crypto_aead_async_alg
async crypto
Definition: crypto.h:76
static void vlib_node_set_state(vlib_main_t *vm, u32 node_index, vlib_node_state_t new_state)
Set node dispatch state.
Definition: node_funcs.h:174
char const int length
Definition: cJSON.h:163
vnet_crypto_async_op_data_t async_opt_data[VNET_CRYPTO_ASYNC_OP_N_IDS]
Definition: crypto.h:429
static void vnet_crypto_init_cipher_data(vnet_crypto_alg_t alg, vnet_crypto_op_id_t eid, vnet_crypto_op_id_t did, char *name, u8 is_aead)
Definition: crypto.c:635
vnet_crypto_async_op_id_t
Definition: crypto.h:159
void vnet_crypto_register_ops_handler_inline(vlib_main_t *vm, u32 engine_index, vnet_crypto_op_id_t opt, vnet_crypto_ops_handler_t *fn, vnet_crypto_chained_ops_handler_t *cfn)
Definition: crypto.c:197
typedef key
Definition: ipsec_types.api:86
u32 vnet_crypto_key_add_linked(vlib_main_t *vm, vnet_crypto_key_index_t index_crypto, vnet_crypto_key_index_t index_integ)
Use 2 created keys to generate new key for linked algs (cipher + integ) The returned key index is to ...
Definition: crypto.c:410
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vnet_crypto_async_frame_t *() vnet_crypto_frame_dequeue_t(vlib_main_t *vm, u32 *nb_elts_processed, u32 *enqueue_thread_idx)
Definition: crypto.h:365
u64 uword
Definition: types.h:112
vnet_crypto_op_type_t type
Definition: crypto.h:282
u32 index
Definition: flow_types.api:221
int vnet_crypto_is_set_async_handler(vnet_crypto_async_op_id_t op)
Definition: crypto.c:626
void vnet_crypto_register_chained_ops_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_op_id_t opt, vnet_crypto_chained_ops_handler_t *fn)
Definition: crypto.c:251
#define hash_get_mem(h, key)
Definition: hash.h:269
vnet_crypto_ops_handler_t * ops_handlers[VNET_CRYPTO_N_OP_IDS]
Definition: crypto.h:406
vnet_crypto_frame_enqueue_t * enqueue_handlers[VNET_CRYPTO_ASYNC_OP_N_IDS]
Definition: crypto.h:409
vnet_crypto_op_status_t status
Definition: crypto.h:235
vnet_crypto_op_id_t
Definition: crypto.h:196
vlib_node_state_t
Definition: node.h:250
vnet_crypto_key_t * keys
Definition: crypto.h:431
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
static u32 vlib_num_workers()
Definition: threads.h:377
#define vec_foreach(var, vec)
Vector iterator.
vnet_crypto_ops_handler_t ** ops_handlers
Definition: crypto.h:423
#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
vnet_crypto_async_alg_t
Definition: crypto.h:145
vnet_crypto_main_t crypto_main
Definition: crypto.c:20
clib_error_t * vnet_crypto_init(vlib_main_t *vm)
Definition: crypto.c:700
#define foreach_crypto_cipher_alg
Definition: crypto.h:24