DPDK  21.08.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_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;
40 };
41 
50  uint32_t num;
51 };
52 
59  void *va;
61 };
62 
70  uint32_t num;
77 
78  __extension__
79  union {
84  };
85 
91  int32_t *status;
92 };
93 
99  uint64_t raw;
100  struct {
101  struct {
102  uint16_t head;
103  uint16_t tail;
104  } auth, cipher;
105  } ofs;
106 };
107 
165 };
166 
168 extern const char *
170 
177 };
178 
180 extern const char *
182 
199  union { /* temporary anonymous union for ABI compatibility */
200 
201  struct {
202  const uint8_t *data;
203  uint16_t length;
204  } key;
238  struct { /* temporary anonymous struct for ABI compatibility */
239  const uint8_t *_key_data; /* reserved for key.data union */
240  uint16_t _key_length; /* reserved for key.length union */
241  /* next field can fill the padding hole */
242 
243  uint16_t dataunit_len;
255  }; }; /* temporary struct nested in union for ABI compatibility */
256 
257  struct {
258  uint16_t offset;
284  uint16_t length;
299  } iv;
300 };
301 
376 };
377 
379 extern const char *
381 
386 };
387 
389 extern const char *
391 
405  struct {
406  const uint8_t *data;
407  uint16_t length;
408  } key;
416  struct {
417  uint16_t offset;
433  uint16_t length;
451  } iv;
453  uint16_t digest_length;
463 };
464 
465 
480 };
481 
483 extern const char *
485 
492 };
493 
495 extern const char *
497 
498 struct rte_crypto_aead_xform {
501  enum rte_crypto_aead_algorithm algo;
504  struct {
505  const uint8_t *data;
506  uint16_t length;
507  } key;
508 
509  struct {
510  uint16_t offset;
530  uint16_t length;
546  } iv;
548  uint16_t digest_length;
549 
550  uint16_t aad_length;
556 };
557 
564 };
565 
579  ;
581  union {
584  struct rte_crypto_cipher_xform cipher;
586  struct rte_crypto_aead_xform aead;
588  };
589 };
590 
592 
624  struct rte_mbuf *m_src;
625  struct rte_mbuf *m_dst;
628  union {
633  struct rte_security_session *sec_session;
635  };
636 
638  union {
639  struct {
640  struct {
641  uint32_t offset;
646  uint32_t length;
651  } data;
652  struct {
653  uint8_t *data;
675  } digest;
676  struct {
677  uint8_t *data;
708  rte_iova_t phys_addr;
709  } aad;
711  } aead;
712 
713  struct {
714  struct {
715  struct {
716  uint32_t offset;
732  uint32_t length;
749  } data;
750  } cipher;
751 
752  struct {
753  struct {
754  uint32_t offset;
780  uint32_t length;
804  } data;
807  struct {
808  uint8_t *data;
879  rte_iova_t phys_addr;
881  } digest;
882  } auth;
883  };
884  };
885 };
886 
887 
893 static inline void
895 {
896  memset(op, 0, sizeof(*op));
897 }
898 
899 
910 static inline struct rte_crypto_sym_xform *
912  void *priv_data, uint8_t nb_xforms)
913 {
914  struct rte_crypto_sym_xform *xform;
915 
916  sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
917 
918  do {
920  xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
921  } while (xform);
922 
923  return sym_op->xform;
924 }
925 
926 
933 static inline int
935  struct rte_cryptodev_sym_session *sess)
936 {
937  sym_op->session = sess;
938 
939  return 0;
940 }
941 
960 __rte_experimental
961 static inline int
962 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
963  struct rte_crypto_vec vec[], uint32_t num)
964 {
965  uint32_t i;
966  struct rte_mbuf *nseg;
967  uint32_t left;
968  uint32_t seglen;
969 
970  /* assuming that requested data starts in the first segment */
971  RTE_ASSERT(mb->data_len > ofs);
972 
973  if (mb->nb_segs > num)
974  return -mb->nb_segs;
975 
976  vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
977  vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
978 
979  /* whole data lies in the first segment */
980  seglen = mb->data_len - ofs;
981  if (len <= seglen) {
982  vec[0].len = len;
983  return 1;
984  }
985 
986  /* data spread across segments */
987  vec[0].len = seglen;
988  left = len - seglen;
989  for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
990 
991  vec[i].base = rte_pktmbuf_mtod(nseg, void *);
992  vec[i].iova = rte_pktmbuf_iova(nseg);
993 
994  seglen = nseg->data_len;
995  if (left <= seglen) {
996  /* whole requested data is completed */
997  vec[i].len = left;
998  left = 0;
999  break;
1000  }
1001 
1002  /* use whole segment */
1003  vec[i].len = seglen;
1004  left -= seglen;
1005  }
1006 
1007  RTE_ASSERT(left == 0);
1008  return i + 1;
1009 }
1010 
1011 
1012 #ifdef __cplusplus
1013 }
1014 #endif
1015 
1016 #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:420
#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)
rte_crypto_auth_operation
const char * rte_crypto_cipher_operation_strings[]
uint16_t nb_segs
const char * rte_crypto_aead_operation_strings[]
rte_crypto_cipher_operation
#define rte_pktmbuf_mtod_offset(m, t, o)
struct rte_crypto_sgl * sgl
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
struct rte_cryptodev_sym_session * session
#define RTE_STD_C11
Definition: rte_common.h:42
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_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