DPDK  26.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 #include <string.h>
18 
19 #include <rte_compat.h>
20 #include <rte_mbuf.h>
21 #include <rte_memory.h>
22 #include <rte_mempool.h>
23 #include <rte_common.h>
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
36  void *base;
40  uint32_t len;
42  uint32_t tot_len;
43 };
44 
53  uint32_t num;
54 };
55 
62  void *va;
63  rte_iova_t iova;
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 
190 };
191 
198 };
199 
201 extern const char *
203 
219  struct {
220  const uint8_t *data;
221  uint16_t length;
222  } key;
254  struct {
255  uint16_t offset;
281  uint16_t length;
296  } iv;
298  uint32_t dataunit_len;
309 };
310 
392  RTE_CRYPTO_AUTH_SM3_HMAC,
402 };
403 
408 };
409 
411 extern const char *
413 
427  struct {
428  const uint8_t *data;
429  uint16_t length;
430  } key;
438  struct {
439  uint16_t offset;
455  uint16_t length;
473  } iv;
475  uint16_t digest_length;
485 };
486 
487 
511 };
512 
519 };
520 
522 extern const char *
524 
525 struct rte_crypto_aead_xform {
528  enum rte_crypto_aead_algorithm algo;
531  struct {
532  const uint8_t *data;
533  uint16_t length;
534  } key;
535 
536  struct {
537  uint16_t offset;
557  uint16_t length;
573  } iv;
575  uint16_t digest_length;
576 
577  uint16_t aad_length;
583 };
584 
591 };
592 
602 /* Structure rte_crypto_sym_xform 8< */
607  ;
608  union {
613  struct rte_crypto_aead_xform aead;
615  };
616 };
617 /* >8 End of structure rte_crypto_sym_xform. */
618 
649 /* Structure rte_crypto_sym_op 8< */
651  struct rte_mbuf *m_src;
652  struct rte_mbuf *m_dst;
654  union {
655  void *session;
659  };
660 
661  union {
662  struct {
663  struct {
664  uint32_t offset;
669  uint32_t length;
674  } data;
675  struct {
676  uint8_t *data;
698  } digest;
699  struct {
700  uint8_t *data;
722  } aad;
724  } aead;
725 
726  struct {
727  struct {
728  struct {
729  uint32_t offset;
748  uint32_t length;
769  } data;
770  } cipher;
771 
772  struct {
773  struct {
774  uint32_t offset;
803  uint32_t length;
830  } data;
833  struct {
834  uint8_t *data;
907  } digest;
908  } auth;
909  };
910  };
911 };
912 /* >8 End of structure rte_crypto_sym_op. */
913 
914 
920 static inline void
922 {
923  memset(op, 0, sizeof(*op));
924 }
925 
926 
937 static inline struct rte_crypto_sym_xform *
939  void *priv_data, uint8_t nb_xforms)
940 {
941  struct rte_crypto_sym_xform *xform;
942 
943  sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
944 
945  do {
947  xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
948  } while (xform);
949 
950  return sym_op->xform;
951 }
952 
953 
960 static inline int
962 {
963  sym_op->session = sess;
964 
965  return 0;
966 }
967 
986 __rte_experimental
987 static inline int
988 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
989  struct rte_crypto_vec vec[], uint32_t num)
990 {
991  uint32_t i;
992  struct rte_mbuf *nseg;
993  uint32_t left;
994  uint32_t seglen;
995 
996  /* assuming that requested data starts in the first segment */
997  RTE_ASSERT(mb->data_len > ofs);
998 
999  if (mb->nb_segs > num)
1000  return -mb->nb_segs;
1001 
1002  vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
1003  vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
1004  vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
1005 
1006  /* whole data lies in the first segment */
1007  seglen = mb->data_len - ofs;
1008  if (len <= seglen) {
1009  vec[0].len = len;
1010  return 1;
1011  }
1012 
1013  /* data spread across segments */
1014  vec[0].len = seglen;
1015  left = len - seglen;
1016  for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
1017 
1018  vec[i].base = rte_pktmbuf_mtod(nseg, void *);
1019  vec[i].iova = rte_pktmbuf_iova(nseg);
1020  vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
1021 
1022  seglen = nseg->data_len;
1023  if (left <= seglen) {
1024  /* whole requested data is completed */
1025  vec[i].len = left;
1026  left = 0;
1027  i++;
1028  break;
1029  }
1030 
1031  /* use whole segment */
1032  vec[i].len = seglen;
1033  left -= seglen;
1034  }
1035 
1036  RTE_ASSERT(left == 0);
1037  return i;
1038 }
1039 
1040 
1041 #ifdef __cplusplus
1042 }
1043 #endif
1044 
1045 #endif /* _RTE_CRYPTO_SYM_H_ */
enum rte_crypto_cipher_operation op
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_crypto_sym_op::@125::@127::@130 data
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, void *sess)
struct rte_crypto_auth_xform auth
uint64_t rte_iova_t
Definition: rte_common.h:774
#define rte_pktmbuf_iova(m)
uint16_t data_len
struct rte_crypto_cipher_xform cipher
static void __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
enum rte_crypto_auth_operation 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:1615
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
enum rte_crypto_auth_algorithm algo
#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_cipher_xform::@116 iv
struct rte_crypto_aead_xform aead
struct rte_crypto_va_iova_ptr * aad
uint16_t buf_len
struct rte_crypto_sym_op::@125::@127::@132 aad
struct rte_crypto_auth_xform::@117 key
struct rte_crypto_vec * vec
rte_crypto_auth_algorithm
rte_crypto_sym_xform_type
struct rte_crypto_sym_op::@125::@127::@131 digest
struct rte_crypto_auth_xform::@118 iv
const uint8_t * data
struct rte_crypto_sym_xform * xform
struct rte_crypto_cipher_xform::@115 key
enum rte_crypto_sym_xform_type type
enum rte_crypto_cipher_algorithm algo
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