DPDK  25.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 
183 };
184 
191 };
192 
194 extern const char *
196 
212  struct {
213  const uint8_t *data;
214  uint16_t length;
215  } key;
247  struct {
248  uint16_t offset;
274  uint16_t length;
289  } iv;
291  uint32_t dataunit_len;
302 };
303 
385  RTE_CRYPTO_AUTH_SM3_HMAC,
387 };
388 
393 };
394 
396 extern const char *
398 
412  struct {
413  const uint8_t *data;
414  uint16_t length;
415  } key;
423  struct {
424  uint16_t offset;
440  uint16_t length;
458  } iv;
460  uint16_t digest_length;
470 };
471 
472 
489 };
490 
497 };
498 
500 extern const char *
502 
503 struct rte_crypto_aead_xform {
506  enum rte_crypto_aead_algorithm algo;
509  struct {
510  const uint8_t *data;
511  uint16_t length;
512  } key;
513 
514  struct {
515  uint16_t offset;
535  uint16_t length;
551  } iv;
553  uint16_t digest_length;
554 
555  uint16_t aad_length;
561 };
562 
569 };
570 
580 /* Structure rte_crypto_sym_xform 8< */
585  ;
586  union {
591  struct rte_crypto_aead_xform aead;
593  };
594 };
595 /* >8 End of structure rte_crypto_sym_xform. */
596 
627 /* Structure rte_crypto_sym_op 8< */
629  struct rte_mbuf *m_src;
630  struct rte_mbuf *m_dst;
632  union {
633  void *session;
637  };
638 
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;
700  } aad;
702  } aead;
703 
704  struct {
705  struct {
706  struct {
707  uint32_t offset;
723  uint32_t length;
741  } data;
742  } cipher;
743 
744  struct {
745  struct {
746  uint32_t offset;
772  uint32_t length;
796  } data;
799  struct {
800  uint8_t *data;
873  } digest;
874  } auth;
875  };
876  };
877 };
878 /* >8 End of structure rte_crypto_sym_op. */
879 
880 
886 static inline void
888 {
889  memset(op, 0, sizeof(*op));
890 }
891 
892 
903 static inline struct rte_crypto_sym_xform *
905  void *priv_data, uint8_t nb_xforms)
906 {
907  struct rte_crypto_sym_xform *xform;
908 
909  sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
910 
911  do {
913  xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
914  } while (xform);
915 
916  return sym_op->xform;
917 }
918 
919 
926 static inline int
928 {
929  sym_op->session = sess;
930 
931  return 0;
932 }
933 
952 __rte_experimental
953 static inline int
954 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
955  struct rte_crypto_vec vec[], uint32_t num)
956 {
957  uint32_t i;
958  struct rte_mbuf *nseg;
959  uint32_t left;
960  uint32_t seglen;
961 
962  /* assuming that requested data starts in the first segment */
963  RTE_ASSERT(mb->data_len > ofs);
964 
965  if (mb->nb_segs > num)
966  return -mb->nb_segs;
967 
968  vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
969  vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
970  vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
971 
972  /* whole data lies in the first segment */
973  seglen = mb->data_len - ofs;
974  if (len <= seglen) {
975  vec[0].len = len;
976  return 1;
977  }
978 
979  /* data spread across segments */
980  vec[0].len = seglen;
981  left = len - seglen;
982  for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
983 
984  vec[i].base = rte_pktmbuf_mtod(nseg, void *);
985  vec[i].iova = rte_pktmbuf_iova(nseg);
986  vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
987 
988  seglen = nseg->data_len;
989  if (left <= seglen) {
990  /* whole requested data is completed */
991  vec[i].len = left;
992  left = 0;
993  i++;
994  break;
995  }
996 
997  /* use whole segment */
998  vec[i].len = seglen;
999  left -= seglen;
1000  }
1001 
1002  RTE_ASSERT(left == 0);
1003  return i;
1004 }
1005 
1006 
1007 #ifdef __cplusplus
1008 }
1009 #endif
1010 
1011 #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
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:736
#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:1593
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_crypto_cipher_xform::@101 key
struct rte_mbuf * m_dst
struct rte_crypto_sym_op::@111::@113::@116 data
struct rte_crypto_aead_xform aead
struct rte_crypto_va_iova_ptr * aad
struct rte_crypto_auth_xform::@103 key
uint16_t buf_len
struct rte_crypto_cipher_xform::@102 iv
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
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
struct rte_crypto_auth_xform::@104 iv
struct rte_crypto_sym_op::@111::@113::@117 digest
rte_iova_t phys_addr
struct rte_crypto_sym_op::@111::@113::@118 aad
rte_iova_t iova
rte_crypto_aead_algorithm
rte_crypto_cipher_algorithm