DPDK  22.11.0-rc0
rte_crypto_sym.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2020 Intel Corporation
3  */
4 
5 #ifndef _RTE_CRYPTO_SYM_H_
6 #define _RTE_CRYPTO_SYM_H_
7 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include <string.h>
22 
23 #include <rte_mbuf.h>
24 #include <rte_memory.h>
25 #include <rte_mempool.h>
26 #include <rte_common.h>
27 
35  void *base;
39  uint32_t len;
41  uint32_t tot_len;
42 };
43 
52  uint32_t num;
53 };
54 
61  void *va;
63 };
64 
72  uint32_t num;
81 
82  __extension__
83  union {
88  };
89 
95  int32_t *status;
96 };
97 
103  uint64_t raw;
104  struct {
105  struct {
106  uint16_t head;
107  uint16_t tail;
108  } auth, cipher;
109  } ofs;
110 };
111 
176 };
177 
179 extern const char *
181 
188 };
189 
191 extern const char *
193 
209  struct {
210  const uint8_t *data;
211  uint16_t length;
212  } key;
244  struct {
245  uint16_t offset;
271  uint16_t length;
286  } iv;
288  uint32_t dataunit_len;
299 };
300 
377 };
378 
380 extern const char *
382 
387 };
388 
390 extern const char *
392 
406  struct {
407  const uint8_t *data;
408  uint16_t length;
409  } key;
417  struct {
418  uint16_t offset;
434  uint16_t length;
452  } iv;
454  uint16_t digest_length;
464 };
465 
466 
481 };
482 
484 extern const char *
486 
493 };
494 
496 extern const char *
498 
499 struct rte_crypto_aead_xform {
502  enum rte_crypto_aead_algorithm algo;
505  struct {
506  const uint8_t *data;
507  uint16_t length;
508  } key;
509 
510  struct {
511  uint16_t offset;
531  uint16_t length;
547  } iv;
549  uint16_t digest_length;
550 
551  uint16_t aad_length;
557 };
558 
565 };
566 
580  ;
582  union {
585  struct rte_crypto_cipher_xform cipher;
587  struct rte_crypto_aead_xform aead;
589  };
590 };
591 
593 
625  struct rte_mbuf *m_src;
626  struct rte_mbuf *m_dst;
629  union {
634  struct rte_security_session *sec_session;
636  };
637 
639  union {
640  struct {
641  struct {
642  uint32_t offset;
647  uint32_t length;
652  } data;
653  struct {
654  uint8_t *data;
676  } digest;
677  struct {
678  uint8_t *data;
709  rte_iova_t phys_addr;
710  } aad;
712  } aead;
713 
714  struct {
715  struct {
716  struct {
717  uint32_t offset;
733  uint32_t length;
750  } data;
751  } cipher;
752 
753  struct {
754  struct {
755  uint32_t offset;
781  uint32_t length;
805  } data;
808  struct {
809  uint8_t *data;
880  rte_iova_t phys_addr;
882  } digest;
883  } auth;
884  };
885  };
886 };
887 
888 
894 static inline void
896 {
897  memset(op, 0, sizeof(*op));
898 }
899 
900 
911 static inline struct rte_crypto_sym_xform *
913  void *priv_data, uint8_t nb_xforms)
914 {
915  struct rte_crypto_sym_xform *xform;
916 
917  sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
918 
919  do {
921  xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
922  } while (xform);
923 
924  return sym_op->xform;
925 }
926 
927 
934 static inline int
936  struct rte_cryptodev_sym_session *sess)
937 {
938  sym_op->session = sess;
939 
940  return 0;
941 }
942 
961 __rte_experimental
962 static inline int
963 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
964  struct rte_crypto_vec vec[], uint32_t num)
965 {
966  uint32_t i;
967  struct rte_mbuf *nseg;
968  uint32_t left;
969  uint32_t seglen;
970 
971  /* assuming that requested data starts in the first segment */
972  RTE_ASSERT(mb->data_len > ofs);
973 
974  if (mb->nb_segs > num)
975  return -mb->nb_segs;
976 
977  vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
978  vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
979  vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
980 
981  /* whole data lies in the first segment */
982  seglen = mb->data_len - ofs;
983  if (len <= seglen) {
984  vec[0].len = len;
985  return 1;
986  }
987 
988  /* data spread across segments */
989  vec[0].len = seglen;
990  left = len - seglen;
991  for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
992 
993  vec[i].base = rte_pktmbuf_mtod(nseg, void *);
994  vec[i].iova = rte_pktmbuf_iova(nseg);
995  vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
996 
997  seglen = nseg->data_len;
998  if (left <= seglen) {
999  /* whole requested data is completed */
1000  vec[i].len = left;
1001  left = 0;
1002  i++;
1003  break;
1004  }
1005 
1006  /* use whole segment */
1007  vec[i].len = seglen;
1008  left -= seglen;
1009  }
1010 
1011  RTE_ASSERT(left == 0);
1012  return i;
1013 }
1014 
1015 
1016 #ifdef __cplusplus
1017 }
1018 #endif
1019 
1020 #endif /* _RTE_CRYPTO_SYM_H_ */
struct rte_mbuf * next
static __rte_experimental int rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len, struct rte_crypto_vec vec[], uint32_t num)
struct rte_crypto_va_iova_ptr * auth_iv
struct rte_security_session * sec_session
uint64_t rte_iova_t
Definition: rte_common.h:458
#define rte_pktmbuf_iova(m)
uint16_t data_len
static void __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
struct rte_mbuf * m_src
#define rte_pktmbuf_iova_offset(m, o)
static uint16_t rte_pktmbuf_headroom(const struct rte_mbuf *m)
Definition: rte_mbuf.h:1477
rte_crypto_auth_operation
const char * rte_crypto_cipher_operation_strings[]
struct rte_crypto_sgl * dest_sgl
uint32_t tot_len
uint16_t nb_segs
const char * rte_crypto_aead_operation_strings[]
rte_crypto_cipher_operation
#define rte_pktmbuf_mtod_offset(m, t, o)
const char * rte_crypto_aead_algorithm_strings[]
static struct rte_crypto_sym_xform * __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op, void *priv_data, uint8_t nb_xforms)
rte_crypto_aead_operation
#define rte_pktmbuf_mtod(m, t)
struct rte_mbuf * m_dst
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, struct rte_cryptodev_sym_session *sess)
struct rte_crypto_va_iova_ptr * aad
uint16_t buf_len
struct rte_cryptodev_sym_session * session
#define RTE_STD_C11
Definition: rte_common.h:39
struct rte_crypto_vec * vec
rte_crypto_auth_algorithm
rte_crypto_sym_xform_type
const char * rte_crypto_auth_algorithm_strings[]
const uint8_t * data
struct rte_crypto_sym_xform * xform
enum rte_crypto_sym_xform_type type
const char * rte_crypto_auth_operation_strings[]
struct rte_crypto_va_iova_ptr * iv
struct rte_crypto_va_iova_ptr * digest
struct rte_crypto_sgl * src_sgl
struct rte_crypto_sym_xform * next
rte_iova_t phys_addr
rte_iova_t iova
rte_crypto_aead_algorithm
const char * rte_crypto_cipher_algorithm_strings[]
rte_crypto_cipher_algorithm