DPDK  24.03.0
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_compat.h>
24 #include <rte_mbuf.h>
25 #include <rte_memory.h>
26 #include <rte_mempool.h>
27 #include <rte_common.h>
28 
36  void *base;
40  uint32_t len;
42  uint32_t tot_len;
43 };
44 
53  uint32_t num;
54 };
55 
62  void *va;
64 };
65 
73  uint32_t num;
82 
83  __extension__
84  union {
89  };
90 
96  int32_t *status;
97 };
98 
104  uint64_t raw;
105  struct {
106  struct {
107  uint16_t head;
108  uint16_t tail;
109  } auth, cipher;
110  } ofs;
111 };
112 
181 };
182 
189 };
190 
192 extern const char *
194 
210  struct {
211  const uint8_t *data;
212  uint16_t length;
213  } key;
245  struct {
246  uint16_t offset;
272  uint16_t length;
287  } iv;
289  uint32_t dataunit_len;
300 };
301 
383  RTE_CRYPTO_AUTH_SM3_HMAC,
385 };
386 
391 };
392 
394 extern const char *
396 
410  struct {
411  const uint8_t *data;
412  uint16_t length;
413  } key;
421  struct {
422  uint16_t offset;
438  uint16_t length;
456  } iv;
458  uint16_t digest_length;
468 };
469 
470 
485 };
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 
576 /* Structure rte_crypto_sym_xform 8< */
581  ;
582  union {
585  struct rte_crypto_cipher_xform cipher;
587  struct rte_crypto_aead_xform aead;
589  };
590 };
591 /* >8 End of structure rte_crypto_sym_xform. */
592 
623 /* Structure rte_crypto_sym_op 8< */
625  struct rte_mbuf *m_src;
626  struct rte_mbuf *m_dst;
628  union {
629  void *session;
633  };
634 
635  union {
636  struct {
637  struct {
638  uint32_t offset;
643  uint32_t length;
648  } data;
649  struct {
650  uint8_t *data;
672  } digest;
673  struct {
674  uint8_t *data;
695  rte_iova_t phys_addr;
696  } aad;
698  } aead;
699 
700  struct {
701  struct {
702  struct {
703  uint32_t offset;
719  uint32_t length;
737  } data;
738  } cipher;
739 
740  struct {
741  struct {
742  uint32_t offset;
768  uint32_t length;
792  } data;
795  struct {
796  uint8_t *data;
867  rte_iova_t phys_addr;
869  } digest;
870  } auth;
871  };
872  };
873 };
874 /* >8 End of structure rte_crypto_sym_op. */
875 
876 
882 static inline void
884 {
885  memset(op, 0, sizeof(*op));
886 }
887 
888 
899 static inline struct rte_crypto_sym_xform *
901  void *priv_data, uint8_t nb_xforms)
902 {
903  struct rte_crypto_sym_xform *xform;
904 
905  sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
906 
907  do {
909  xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
910  } while (xform);
911 
912  return sym_op->xform;
913 }
914 
915 
922 static inline int
924 {
925  sym_op->session = sess;
926 
927  return 0;
928 }
929 
948 __rte_experimental
949 static inline int
950 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
951  struct rte_crypto_vec vec[], uint32_t num)
952 {
953  uint32_t i;
954  struct rte_mbuf *nseg;
955  uint32_t left;
956  uint32_t seglen;
957 
958  /* assuming that requested data starts in the first segment */
959  RTE_ASSERT(mb->data_len > ofs);
960 
961  if (mb->nb_segs > num)
962  return -mb->nb_segs;
963 
964  vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
965  vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
966  vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
967 
968  /* whole data lies in the first segment */
969  seglen = mb->data_len - ofs;
970  if (len <= seglen) {
971  vec[0].len = len;
972  return 1;
973  }
974 
975  /* data spread across segments */
976  vec[0].len = seglen;
977  left = len - seglen;
978  for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
979 
980  vec[i].base = rte_pktmbuf_mtod(nseg, void *);
981  vec[i].iova = rte_pktmbuf_iova(nseg);
982  vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
983 
984  seglen = nseg->data_len;
985  if (left <= seglen) {
986  /* whole requested data is completed */
987  vec[i].len = left;
988  left = 0;
989  i++;
990  break;
991  }
992 
993  /* use whole segment */
994  vec[i].len = seglen;
995  left -= seglen;
996  }
997 
998  RTE_ASSERT(left == 0);
999  return i;
1000 }
1001 
1002 
1003 #ifdef __cplusplus
1004 }
1005 #endif
1006 
1007 #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
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, void *sess)
uint64_t rte_iova_t
Definition: rte_common.h:584
#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:1510
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)
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
struct rte_crypto_va_iova_ptr * aad
uint16_t buf_len
struct rte_crypto_vec * vec
rte_crypto_auth_algorithm
rte_crypto_sym_xform_type
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
rte_crypto_cipher_algorithm