FD.io VPP  v21.06-3-gbb25fbf28
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 {
134  vnet_crypto_engine_t *ce = vec_elt_at_index (cm->engines, ei);
135 
136  if (oct == CRYPTO_OP_BOTH || oct == CRYPTO_OP_CHAINED)
137  {
138  if (ce->chained_ops_handlers[id])
139  {
141  cm->chained_ops_handlers[id] = ce->chained_ops_handlers[id];
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  vnet_crypto_op_id_t opt = 0;
193  int i;
194 
195  if (alg > vec_len (cm->algs))
196  return 0;
197 
198  for (i = 0; i < VNET_CRYPTO_OP_N_TYPES; i++)
199  if ((opt = cm->algs[alg].op_by_type[i]) != 0)
200  break;
201 
202  return NULL != cm->ops_handlers[opt];
203 }
204 
205 void
210  cfn)
211 {
213  vnet_crypto_engine_t *ae, *e = vec_elt_at_index (cm->engines, engine_index);
214  vnet_crypto_op_data_t *otd = cm->opt_data + opt;
215  vec_validate_aligned (cm->ops_handlers, VNET_CRYPTO_N_OP_IDS - 1,
217  vec_validate_aligned (cm->chained_ops_handlers, VNET_CRYPTO_N_OP_IDS - 1,
219 
220  if (fn)
221  {
222  e->ops_handlers[opt] = fn;
223  if (otd->active_engine_index_simple == ~0)
224  {
225  otd->active_engine_index_simple = engine_index;
226  cm->ops_handlers[opt] = fn;
227  }
228 
229  ae = vec_elt_at_index (cm->engines, otd->active_engine_index_simple);
230  if (ae->priority < e->priority)
231  crypto_set_active_engine (otd, opt, engine_index, CRYPTO_OP_SIMPLE);
232  }
233 
234  if (cfn)
235  {
236  e->chained_ops_handlers[opt] = cfn;
237  if (otd->active_engine_index_chained == ~0)
238  {
239  otd->active_engine_index_chained = engine_index;
240  cm->chained_ops_handlers[opt] = cfn;
241  }
242 
243  ae = vec_elt_at_index (cm->engines, otd->active_engine_index_chained);
244  if (ae->priority < e->priority)
245  crypto_set_active_engine (otd, opt, engine_index, CRYPTO_OP_CHAINED);
246  }
247 
248  return;
249 }
250 
251 void
255 {
256  vnet_crypto_register_ops_handler_inline (vm, engine_index, opt, fn, 0);
257 }
258 
259 void
263  fn)
264 {
265  vnet_crypto_register_ops_handler_inline (vm, engine_index, opt, 0, fn);
266 }
267 
268 void
273 {
274  vnet_crypto_register_ops_handler_inline (vm, engine_index, opt, fn, cfn);
275 }
276 
277 void
280  vnet_crypto_frame_enqueue_t * enqueue_hdl,
281  vnet_crypto_frame_dequeue_t * dequeue_hdl)
282 {
284  vnet_crypto_engine_t *ae, *e = vec_elt_at_index (cm->engines, engine_index);
285  vnet_crypto_async_op_data_t *otd = cm->async_opt_data + opt;
290 
291  /* both enqueue hdl and dequeue hdl should present */
292  if (!enqueue_hdl && !dequeue_hdl)
293  return;
294 
295  e->enqueue_handlers[opt] = enqueue_hdl;
296  e->dequeue_handlers[opt] = dequeue_hdl;
297  if (otd->active_engine_index_async == ~0)
298  {
299  otd->active_engine_index_async = engine_index;
300  cm->enqueue_handlers[opt] = enqueue_hdl;
301  cm->dequeue_handlers[opt] = dequeue_hdl;
302  }
303 
304  ae = vec_elt_at_index (cm->engines, otd->active_engine_index_async);
305  if (ae->priority <= e->priority)
306  {
307  otd->active_engine_index_async = engine_index;
308  cm->enqueue_handlers[opt] = enqueue_hdl;
309  cm->dequeue_handlers[opt] = dequeue_hdl;
310  }
311 
312  return;
313 }
314 
315 void
317  vnet_crypto_key_handler_t * key_handler)
318 {
320  vnet_crypto_engine_t *e = vec_elt_at_index (cm->engines, engine_index);
321  e->key_op_handler = key_handler;
322  return;
323 }
324 
325 static int
327 {
328  switch (alg)
329  {
330  case VNET_CRYPTO_N_ALGS:
331  return 0;
333  return 1;
334 
335 #define _(n, s, l) \
336  case VNET_CRYPTO_ALG_##n: \
337  if ((l) == length) \
338  return 1; \
339  break;
341 #undef _
342  /* HMAC allows any key length */
343 #define _(n, s) \
344  case VNET_CRYPTO_ALG_HMAC_##n: \
345  return 1;
347 #undef _
348 
349 #define _(n, s) \
350  case VNET_CRYPTO_ALG_HASH_##n: \
351  return 1;
353 #undef _
354  }
355 
356  return 0;
357 }
358 
359 u32
361  u16 length)
362 {
363  u32 index;
365  vnet_crypto_engine_t *engine;
367 
368  if (!vnet_crypto_key_len_check (alg, length))
369  return ~0;
370 
371  pool_get_zero (cm->keys, key);
372  index = key - cm->keys;
374  key->alg = alg;
376  clib_memcpy (key->data, data, length);
377  /* *INDENT-OFF* */
378  vec_foreach (engine, cm->engines)
379  if (engine->key_op_handler)
381  /* *INDENT-ON* */
382  return index;
383 }
384 
385 void
387 {
389  vnet_crypto_engine_t *engine;
391 
392  /* *INDENT-OFF* */
393  vec_foreach (engine, cm->engines)
394  if (engine->key_op_handler)
396  /* *INDENT-ON* */
397 
398  if (key->type == VNET_CRYPTO_KEY_TYPE_DATA)
399  {
400  clib_memset (key->data, 0, vec_len (key->data));
401  vec_free (key->data);
402  }
403  else if (key->type == VNET_CRYPTO_KEY_TYPE_LINK)
404  {
405  key->index_crypto = key->index_integ = 0;
406  }
407 
408  pool_put (cm->keys, key);
409 }
410 
414 {
415 #define _(c, h, s, k ,d) \
416  if (crypto_alg == VNET_CRYPTO_ALG_##c && \
417  integ_alg == VNET_CRYPTO_ALG_HMAC_##h) \
418  return VNET_CRYPTO_ALG_##c##_##h##_TAG##d;
420 #undef _
421  return ~0;
422 }
423 
424 u32
426  vnet_crypto_key_index_t index_crypto,
427  vnet_crypto_key_index_t index_integ)
428 {
429  u32 index;
431  vnet_crypto_engine_t *engine;
432  vnet_crypto_key_t *key_crypto, *key_integ, *key;
433  vnet_crypto_async_alg_t linked_alg;
434 
435  key_crypto = pool_elt_at_index (cm->keys, index_crypto);
436  key_integ = pool_elt_at_index (cm->keys, index_integ);
437 
438  linked_alg = vnet_crypto_link_algs (key_crypto->alg, key_integ->alg);
439  if (linked_alg == ~0)
440  return ~0;
441 
442  pool_get_zero (cm->keys, key);
443  index = key - cm->keys;
445  key->index_crypto = index_crypto;
446  key->index_integ = index_integ;
447  key->async_alg = linked_alg;
448 
449  /* *INDENT-OFF* */
450  vec_foreach (engine, cm->engines)
451  if (engine->key_op_handler)
453  /* *INDENT-ON* */
454 
455  return index;
456 }
457 
458 clib_error_t *
460 {
463  u32 skip_master = vlib_num_workers () > 0, i;
464  vlib_node_state_t state = VLIB_NODE_STATE_DISABLED;
465  u8 state_change = 0;
466 
468  if (is_enable && cm->async_refcnt > 0)
469  {
470  state_change = 1;
471  state =
472  cm->dispatch_mode ==
473  VNET_CRYPTO_ASYNC_DISPATCH_POLLING ? VLIB_NODE_STATE_POLLING :
474  VLIB_NODE_STATE_INTERRUPT;
475  }
476 
477  if (!is_enable && cm->async_refcnt == 0)
478  {
479  state_change = 1;
480  state = VLIB_NODE_STATE_DISABLED;
481  }
482 
483  if (state_change)
484  for (i = skip_master; i < tm->n_vlib_mains; i++)
485  {
487  if (state != vlib_node_get_state (ovm, cm->crypto_node_index))
488  vlib_node_set_state (ovm, cm->crypto_node_index, state);
489  }
490  return 0;
491 }
492 
496 {
498  vnet_crypto_engine_t *ce = vec_elt_at_index (cm->engines, ei);
499 
500  if (ce->enqueue_handlers[id] && ce->dequeue_handlers[id])
501  {
502  od->active_engine_index_async = ei;
503  cm->enqueue_handlers[id] = ce->enqueue_handlers[id];
504  cm->dequeue_handlers[id] = ce->dequeue_handlers[id];
505  }
506 }
507 
508 int
509 vnet_crypto_set_async_handler2 (char *alg_name, char *engine)
510 {
511  uword *p;
514  int i;
515 
516  p = hash_get_mem (cm->async_alg_index_by_name, alg_name);
517  if (!p)
518  return -1;
519 
520  ad = vec_elt_at_index (cm->async_algs, p[0]);
521 
522  p = hash_get_mem (cm->engine_index_by_name, engine);
523  if (!p)
524  return -1;
525 
526  for (i = 0; i < VNET_CRYPTO_ASYNC_OP_N_TYPES; i++)
527  {
530  if (id == 0)
531  continue;
532 
533  od = cm->async_opt_data + id;
534  crypto_set_active_async_engine (od, id, p[0]);
535  }
536 
537  return 0;
538 }
539 
540 u32
542 {
545  vlib_node_t *cc, *pn;
546  uword index = vec_len (cm->next_nodes);
547 
548  pn = vlib_get_node_by_name (vm, (u8 *) post_node_name);
549  if (!pn)
550  return ~0;
551 
552  /* *INDENT-OFF* */
553  vec_foreach (cm->next_nodes, nn)
554  {
555  if (nn->node_idx == pn->index)
556  return nn->next_idx;
557  }
558  /* *INDENT-ON* */
559 
560  vec_validate (cm->next_nodes, index);
561  nn = vec_elt_at_index (cm->next_nodes, index);
562 
563  cc = vlib_get_node_by_name (vm, (u8 *) "crypto-dispatch");
564  nn->next_idx = vlib_node_add_named_next (vm, cc->index, post_node_name);
565  nn->node_idx = pn->index;
566 
567  return nn->next_idx;
568 }
569 
570 void
572 {
575  u32 skip_master = vlib_num_workers () > 0, i;
576  vlib_node_state_t state = VLIB_NODE_STATE_DISABLED;
577  u8 state_change = 0;
578 
580  if (is_enable && cm->async_refcnt == 0)
581  {
582  state_change = 1;
583  state =
584  cm->dispatch_mode == VNET_CRYPTO_ASYNC_DISPATCH_POLLING ?
585  VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_INTERRUPT;
586  }
587  if (!is_enable && cm->async_refcnt == 1)
588  {
589  state_change = 1;
590  state = VLIB_NODE_STATE_DISABLED;
591  }
592 
593  if (state_change)
594  for (i = skip_master; i < tm->n_vlib_mains; i++)
595  {
597  if (state != vlib_node_get_state (ovm, cm->crypto_node_index))
598  vlib_node_set_state (ovm, cm->crypto_node_index, state);
599  }
600 
601  if (is_enable)
602  cm->async_refcnt += 1;
603  else if (cm->async_refcnt > 0)
604  cm->async_refcnt -= 1;
605 }
606 
607 void
609 {
611  u32 skip_master = vlib_num_workers () > 0, i;
613  vlib_node_state_t state = VLIB_NODE_STATE_DISABLED;
614 
616  cm->dispatch_mode = mode;
618  {
619  state =
620  cm->async_refcnt == 0 ?
621  VLIB_NODE_STATE_DISABLED : VLIB_NODE_STATE_INTERRUPT;
622  }
624  {
625  state =
626  cm->async_refcnt == 0 ?
627  VLIB_NODE_STATE_DISABLED : VLIB_NODE_STATE_POLLING;
628  }
629 
630  for (i = skip_master; i < tm->n_vlib_mains; i++)
631  {
633  if (state != vlib_node_get_state (ovm, cm->crypto_node_index))
634  vlib_node_set_state (ovm, cm->crypto_node_index, state);
635  }
636 }
637 
638 int
640 {
642 
643  return (op < vec_len (cm->enqueue_handlers) &&
644  NULL != cm->enqueue_handlers[op]);
645 }
646 
647 static void
649  vnet_crypto_op_id_t did, char *name, u8 is_aead)
650 {
651  vnet_crypto_op_type_t eopt, dopt;
653 
654  cm->algs[alg].name = name;
655  cm->opt_data[eid].alg = cm->opt_data[did].alg = alg;
656  cm->opt_data[eid].active_engine_index_simple = ~0;
657  cm->opt_data[did].active_engine_index_simple = ~0;
658  cm->opt_data[eid].active_engine_index_chained = ~0;
659  cm->opt_data[did].active_engine_index_chained = ~0;
660  if (is_aead)
661  {
662  eopt = VNET_CRYPTO_OP_TYPE_AEAD_ENCRYPT;
663  dopt = VNET_CRYPTO_OP_TYPE_AEAD_DECRYPT;
664  }
665  else
666  {
667  eopt = VNET_CRYPTO_OP_TYPE_ENCRYPT;
668  dopt = VNET_CRYPTO_OP_TYPE_DECRYPT;
669  }
670  cm->opt_data[eid].type = eopt;
671  cm->opt_data[did].type = dopt;
672  cm->algs[alg].op_by_type[eopt] = eid;
673  cm->algs[alg].op_by_type[dopt] = did;
674  hash_set_mem (cm->alg_index_by_name, name, alg);
675 }
676 
677 static void
679  char *name)
680 {
682  cm->algs[alg].name = name;
683  cm->algs[alg].op_by_type[VNET_CRYPTO_OP_TYPE_HASH] = id;
684  cm->opt_data[id].alg = alg;
685  cm->opt_data[id].active_engine_index_simple = ~0;
686  cm->opt_data[id].active_engine_index_chained = ~0;
687  cm->opt_data[id].type = VNET_CRYPTO_OP_TYPE_HASH;
688  hash_set_mem (cm->alg_index_by_name, name, alg);
689 }
690 
691 static void
693  vnet_crypto_op_id_t id, char *name)
694 {
696  cm->algs[alg].name = name;
697  cm->algs[alg].op_by_type[VNET_CRYPTO_OP_TYPE_HMAC] = id;
698  cm->opt_data[id].alg = alg;
699  cm->opt_data[id].active_engine_index_simple = ~0;
700  cm->opt_data[id].active_engine_index_chained = ~0;
701  cm->opt_data[id].type = VNET_CRYPTO_OP_TYPE_HMAC;
702  hash_set_mem (cm->alg_index_by_name, name, alg);
703 }
704 
705 static void
708  vnet_crypto_async_op_id_t did, char *name)
709 {
711 
712  cm->async_algs[alg].name = name;
713  cm->async_algs[alg].op_by_type[VNET_CRYPTO_ASYNC_OP_TYPE_ENCRYPT] = eid;
714  cm->async_algs[alg].op_by_type[VNET_CRYPTO_ASYNC_OP_TYPE_DECRYPT] = did;
715  cm->async_opt_data[eid].type = VNET_CRYPTO_ASYNC_OP_TYPE_ENCRYPT;
716  cm->async_opt_data[eid].alg = alg;
717  cm->async_opt_data[eid].active_engine_index_async = ~0;
718  cm->async_opt_data[eid].active_engine_index_async = ~0;
719  cm->async_opt_data[did].type = VNET_CRYPTO_ASYNC_OP_TYPE_DECRYPT;
720  cm->async_opt_data[did].alg = alg;
721  cm->async_opt_data[did].active_engine_index_async = ~0;
722  cm->async_opt_data[did].active_engine_index_async = ~0;
723  hash_set_mem (cm->async_alg_index_by_name, name, alg);
724 }
725 
726 clib_error_t *
728 {
731  vnet_crypto_thread_t *ct = 0;
732 
733  cm->dispatch_mode = VNET_CRYPTO_ASYNC_DISPATCH_POLLING;
734  cm->engine_index_by_name = hash_create_string ( /* size */ 0,
735  sizeof (uword));
736  cm->alg_index_by_name = hash_create_string (0, sizeof (uword));
737  cm->async_alg_index_by_name = hash_create_string (0, sizeof (uword));
739  vec_foreach (ct, cm->threads)
745 
746 #define _(n, s, l) \
747  vnet_crypto_init_cipher_data (VNET_CRYPTO_ALG_##n, \
748  VNET_CRYPTO_OP_##n##_ENC, \
749  VNET_CRYPTO_OP_##n##_DEC, s, 0);
751 #undef _
752 #define _(n, s, l) \
753  vnet_crypto_init_cipher_data (VNET_CRYPTO_ALG_##n, \
754  VNET_CRYPTO_OP_##n##_ENC, \
755  VNET_CRYPTO_OP_##n##_DEC, s, 1);
757 #undef _
758 #define _(n, s) \
759  vnet_crypto_init_hmac_data (VNET_CRYPTO_ALG_HMAC_##n, \
760  VNET_CRYPTO_OP_##n##_HMAC, "hmac-" s);
762 #undef _
763 #define _(n, s) \
764  vnet_crypto_init_hash_data (VNET_CRYPTO_ALG_HASH_##n, \
765  VNET_CRYPTO_OP_##n##_HASH, s);
767 #undef _
768 #define _(n, s, k, t, a) \
769  vnet_crypto_init_async_data (VNET_CRYPTO_ALG_##n##_TAG##t##_AAD##a, \
770  VNET_CRYPTO_OP_##n##_TAG##t##_AAD##a##_ENC, \
771  VNET_CRYPTO_OP_##n##_TAG##t##_AAD##a##_DEC, \
772  s);
774 #undef _
775 #define _(c, h, s, k ,d) \
776  vnet_crypto_init_async_data (VNET_CRYPTO_ALG_##c##_##h##_TAG##d, \
777  VNET_CRYPTO_OP_##c##_##h##_TAG##d##_ENC, \
778  VNET_CRYPTO_OP_##c##_##h##_TAG##d##_DEC, \
779  s);
781 #undef _
782  cm->crypto_node_index =
783  vlib_get_node_by_name (vm, (u8 *) "crypto-dispatch")->index;
784 
785  return 0;
786 }
787 
789 
790 /*
791  * fd.io coding-style-patch-verification: ON
792  *
793  * Local Variables:
794  * eval: (c-set-style "gnu")
795  * End:
796  */
vnet_crypto_engine_t
Definition: crypto.h:432
vlib.h
vnet_crypto_init_cipher_data
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:648
vnet_crypto_frame_dequeue_t
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:397
VNET_CRYPTO_KEY_OP_DEL
@ VNET_CRYPTO_KEY_OP_DEL
Definition: crypto.h:132
vnet_crypto_register_async_handler
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:278
vnet_crypto_async_alg_data_t
Definition: crypto.h:320
vlib_num_workers
static u32 vlib_num_workers()
Definition: threads.h:354
vnet_crypto_thread_t::frame_pool
vnet_crypto_async_frame_t * frame_pool
Definition: crypto.h:373
crypto_op_class_type_t
crypto_op_class_type_t
Definition: crypto.h:235
vnet_crypto_async_next_node_t
Definition: crypto.h:445
crypto.h
foreach_crypto_aead_async_alg
#define foreach_crypto_aead_async_alg
async crypto
Definition: crypto.h:85
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
vnet_crypto_key_del
void vnet_crypto_key_del(vlib_main_t *vm, vnet_crypto_key_index_t index)
Definition: crypto.c:386
foreach_crypto_link_async_alg
#define foreach_crypto_link_async_alg
Definition: crypto.h:96
VNET_CRYPTO_ASYNC_OP_N_IDS
@ VNET_CRYPTO_ASYNC_OP_N_IDS
Definition: crypto.h:195
VNET_CRYPTO_ASYNC_OP_N_TYPES
@ VNET_CRYPTO_ASYNC_OP_N_TYPES
Definition: crypto.h:165
vnet_crypto_register_ops_handler
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:252
vlib_node_set_state
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:175
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
name
string name[64]
Definition: fib.api:25
vnet_crypto_main_t
Definition: crypto.h:451
vnet_crypto_op_t::status
vnet_crypto_op_status_t status
Definition: crypto.h:260
foreach_crypto_hash_alg
#define foreach_crypto_hash_alg
Definition: crypto.h:42
VNET_CRYPTO_ALG_NONE
@ VNET_CRYPTO_ALG_NONE
Definition: crypto.h:147
vnet_crypto_async_alg_t
vnet_crypto_async_alg_t
Definition: crypto.h:168
VLIB_FRAME_SIZE
#define VLIB_FRAME_SIZE
Definition: node.h:368
vnet_crypto_is_set_async_handler
int vnet_crypto_is_set_async_handler(vnet_crypto_async_op_id_t op)
Definition: crypto.c:639
VNET_CRYPTO_N_ASYNC_ALGS
@ VNET_CRYPTO_N_ASYNC_ALGS
Definition: crypto.h:179
vnet_crypto_key_handler_t
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:388
u16
unsigned short u16
Definition: types.h:57
vnet_crypto_key_index_t
u32 vnet_crypto_key_index_t
Definition: crypto.h:378
foreach_crypto_hmac_alg
#define foreach_crypto_hmac_alg
Definition: crypto.h:49
mode
vl_api_tunnel_mode_t mode
Definition: gre.api:48
VNET_CRYPTO_OP_N_TYPES
@ VNET_CRYPTO_OP_N_TYPES
Definition: crypto.h:70
vnet_crypto_register_chained_ops_handler
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:260
pool_put
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:305
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
hash_create_string
#define hash_create_string(elts, value_bytes)
Definition: hash.h:689
state
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
vnet_crypto_async_alg_data_t::op_by_type
vnet_crypto_async_op_id_t op_by_type[VNET_CRYPTO_ASYNC_OP_N_TYPES]
Definition: crypto.h:323
CRYPTO_OP_SIMPLE
@ CRYPTO_OP_SIMPLE
Definition: crypto.h:237
VNET_CRYPTO_ASYNC_DISPATCH_INTERRUPT
#define VNET_CRYPTO_ASYNC_DISPATCH_INTERRUPT
Definition: crypto.h:472
vnet_crypto_engine_t::desc
char * desc
Definition: crypto.h:435
vnet_crypto_process_ops_inline
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
vnet_crypto_register_engine
u32 vnet_crypto_register_engine(vlib_main_t *vm, char *name, int prio, char *desc)
Definition: crypto.c:112
eid
typedef eid
Definition: lisp_types.api:59
key
typedef key
Definition: ipsec_types.api:88
vnet_crypto_alg_data_t
Definition: crypto.h:242
vnet_crypto_op_t
Definition: crypto.h:255
vnet_crypto_init
clib_error_t * vnet_crypto_init(vlib_main_t *vm)
Definition: crypto.c:727
VNET_CRYPTO_ASYNC_DISPATCH_POLLING
#define VNET_CRYPTO_ASYNC_DISPATCH_POLLING
Definition: crypto.h:471
crypto_set_op_status
static_always_inline void crypto_set_op_status(vnet_crypto_op_t *ops[], u32 n_ops, int status)
Definition: crypto.c:23
vlib_thread_main_t::n_vlib_mains
u32 n_vlib_mains
Definition: threads.h:283
vnet_crypto_key_len_check
static int vnet_crypto_key_len_check(vnet_crypto_alg_t alg, u16 length)
Definition: crypto.c:326
vnet_crypto_process_ops
u32 vnet_crypto_process_ops(vlib_main_t *vm, vnet_crypto_op_t ops[], u32 n_ops)
Definition: crypto.c:99
vnet_crypto_init_async_data
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:706
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vnet_crypto_frame_enqueue_t
int() vnet_crypto_frame_enqueue_t(vlib_main_t *vm, vnet_crypto_async_frame_t *frame)
async crypto function handlers
Definition: crypto.h:394
CLIB_MEMORY_STORE_BARRIER
#define CLIB_MEMORY_STORE_BARRIER()
Definition: clib.h:140
vlib_node_t::index
u32 index
Definition: node.h:269
vec_add2
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:644
vnet_crypto_set_async_dispatch_mode
void vnet_crypto_set_async_dispatch_mode(u8 mode)
Definition: crypto.c:608
vnet_crypto_op_data_t
Definition: crypto.h:305
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
vnet_crypto_key_add_linked
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:425
vnet_crypto_process_chained_ops
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
vnet_crypto_engine_t::enqueue_handlers
vnet_crypto_frame_enqueue_t * enqueue_handlers[VNET_CRYPTO_ASYNC_OP_N_IDS]
Definition: crypto.h:441
vnet_crypto_op_type_t
vnet_crypto_op_type_t
Definition: crypto.h:65
foreach_crypto_aead_alg
#define foreach_crypto_aead_alg
Definition: crypto.h:36
vec_validate_aligned
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:534
static_always_inline
#define static_always_inline
Definition: clib.h:112
vnet_crypto_op_t::op
vnet_crypto_op_id_t op
Definition: crypto.h:259
crypto_set_active_async_engine
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:494
VNET_CRYPTO_N_ALGS
@ VNET_CRYPTO_N_ALGS
Definition: crypto.h:157
uword
u64 uword
Definition: types.h:112
vnet_crypto_op_data_t::active_engine_index_simple
u32 active_engine_index_simple
Definition: crypto.h:309
hash_set_mem
#define hash_set_mem(h, key, value)
Definition: hash.h:275
vlib_node_state_t
vlib_node_state_t
Definition: node.h:239
vnet_crypto_init_hmac_data
static void vnet_crypto_init_hmac_data(vnet_crypto_alg_t alg, vnet_crypto_op_id_t id, char *name)
Definition: crypto.c:692
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
vnet_crypto_register_ops_handler_inline
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:206
vnet_crypto_op_id_t
vnet_crypto_op_id_t
Definition: crypto.h:219
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
vnet_crypto_request_async_mode
void vnet_crypto_request_async_mode(int is_enable)
Definition: crypto.c:571
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
vnet_crypto_chained_ops_handler_t
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:380
vnet_crypto_op_chunk_t
Definition: crypto.h:248
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
vnet_crypto_engine_t::key_op_handler
vnet_crypto_key_handler_t * key_op_handler
Definition: crypto.h:437
crypto_main
vnet_crypto_main_t crypto_main
Definition: crypto.c:20
pool_alloc_aligned
#define pool_alloc_aligned(P, N, A)
Allocate N more free elements to pool (general version).
Definition: pool.h:344
data
u8 data[128]
Definition: ipsec_types.api:92
vnet_crypto_is_set_handler
int vnet_crypto_is_set_handler(vnet_crypto_alg_t alg)
Definition: crypto.c:189
vnet_crypto_init_hash_data
static void vnet_crypto_init_hash_data(vnet_crypto_alg_t alg, vnet_crypto_op_id_t id, char *name)
Definition: crypto.c:678
clib_bitmap_validate
#define clib_bitmap_validate(v, n_bits)
Definition: bitmap.h:115
id
u8 id[64]
Definition: dhcp.api:160
vnet_crypto_op_data_t::active_engine_index_chained
u32 active_engine_index_chained
Definition: crypto.h:310
vnet_crypto_key_add
u32 vnet_crypto_key_add(vlib_main_t *vm, vnet_crypto_alg_t alg, u8 *data, u16 length)
Definition: crypto.c:360
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
index
u32 index
Definition: flow_types.api:221
vlib_get_node_by_name
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
VNET_CRYPTO_KEY_TYPE_DATA
#define VNET_CRYPTO_KEY_TYPE_DATA
Definition: crypto.h:214
vnet_crypto_async_op_data_t
Definition: crypto.h:313
vnet_crypto_register_key_handler
void vnet_crypto_register_key_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_key_handler_t *key_handler)
Definition: crypto.c:316
vnet_crypto_alg_data_t::op_by_type
vnet_crypto_op_id_t op_by_type[VNET_CRYPTO_OP_N_TYPES]
Definition: crypto.h:245
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vnet_crypto_key_t
Definition: crypto.h:198
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
integ_alg
u8 integ_alg
Definition: ikev2_types.api:59
vlib_thread_main_t
Definition: threads.h:264
crypto_set_active_engine
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
vnet_crypto_async_next_node_t::node_idx
u32 node_idx
Definition: crypto.h:447
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
VNET_CRYPTO_N_OP_IDS
@ VNET_CRYPTO_N_OP_IDS
Definition: crypto.h:231
vlib_node_add_named_next
static uword vlib_node_add_named_next(vlib_main_t *vm, uword node, char *name)
Definition: node_funcs.h:1189
vlib_get_main_by_index
static vlib_main_t * vlib_get_main_by_index(u32 thread_index)
Definition: global_funcs.h:29
vnet_crypto_set_async_handler2
int vnet_crypto_set_async_handler2(char *alg_name, char *engine)
Definition: crypto.c:509
vnet_crypto_engine_t::dequeue_handlers
vnet_crypto_frame_dequeue_t * dequeue_handlers[VNET_CRYPTO_ASYNC_OP_N_IDS]
Definition: crypto.h:442
vnet_crypto_engine_t::ops_handlers
vnet_crypto_ops_handler_t * ops_handlers[VNET_CRYPTO_N_OP_IDS]
Definition: crypto.h:438
crypto_dispatch_enable_disable
clib_error_t * crypto_dispatch_enable_disable(int is_enable)
Definition: crypto.c:459
length
char const int length
Definition: cJSON.h:163
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
pool_get_zero
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:258
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vnet_crypto_engine_t::priority
int priority
Definition: crypto.h:436
vnet_crypto_async_op_id_t
vnet_crypto_async_op_id_t
Definition: crypto.h:182
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vnet_crypto_register_post_node
u32 vnet_crypto_register_post_node(vlib_main_t *vm, char *post_node_name)
async crypto register functions
Definition: crypto.c:541
vnet_crypto_ops_handler_t
u32() vnet_crypto_ops_handler_t(vlib_main_t *vm, vnet_crypto_op_t *ops[], u32 n_ops)
Definition: crypto.h:385
vnet_crypto_engine_t::name
char * name
Definition: crypto.h:434
VNET_CRYPTO_KEY_OP_ADD
@ VNET_CRYPTO_KEY_OP_ADD
Definition: crypto.h:131
vnet_crypto_async_next_node_t::next_idx
u32 next_idx
Definition: crypto.h:448
rv
int __clib_unused rv
Definition: application.c:491
foreach_crypto_cipher_alg
#define foreach_crypto_cipher_alg
Definition: crypto.h:25
vnet_crypto_key_t::alg
vnet_crypto_alg_t alg
Definition: crypto.h:205
vnet_crypto_async_op_data_t::active_engine_index_async
u32 active_engine_index_async
Definition: crypto.h:317
CRYPTO_OP_BOTH
@ CRYPTO_OP_BOTH
Definition: crypto.h:239
vnet_crypto_alg_t
vnet_crypto_alg_t
Definition: crypto.h:145
vnet_crypto_thread_t
Definition: crypto.h:370
vnet_crypto_register_ops_handlers
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:269
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:56
vnet_crypto_link_algs
vnet_crypto_async_alg_t vnet_crypto_link_algs(vnet_crypto_alg_t crypto_alg, vnet_crypto_alg_t integ_alg)
Definition: crypto.c:412
vnet_crypto_process_ops_call_handler
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
CRYPTO_OP_CHAINED
@ CRYPTO_OP_CHAINED
Definition: crypto.h:238
vnet_crypto_set_handler2
int vnet_crypto_set_handler2(char *alg_name, char *engine, crypto_op_class_type_t oct)
Definition: crypto.c:156
VNET_CRYPTO_FRAME_POOL_SIZE
#define VNET_CRYPTO_FRAME_POOL_SIZE
Definition: crypto.h:22
VNET_CRYPTO_KEY_TYPE_LINK
#define VNET_CRYPTO_KEY_TYPE_LINK
Definition: crypto.h:215
vlib_node_get_state
static vlib_node_state_t vlib_node_get_state(vlib_main_t *vm, u32 node_index)
Get node dispatch state.
Definition: node_funcs.h:219
vnet_crypto_engine_t::chained_ops_handlers
vnet_crypto_chained_ops_handler_t * chained_ops_handlers[VNET_CRYPTO_N_OP_IDS]
Definition: crypto.h:440