DPDK  20.05.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;
40 };
41 
50  uint32_t num;
51 };
52 
61  void **iv;
63  void **aad;
65  void **digest;
71  int32_t *status;
73  uint32_t num;
74 };
75 
81  uint64_t raw;
82  struct {
83  struct {
84  uint16_t head;
85  uint16_t tail;
86  } auth, cipher;
87  } ofs;
88 };
89 
142  RTE_CRYPTO_CIPHER_LIST_END
143 
144 };
145 
147 extern const char *
149 
156 };
157 
159 extern const char *
161 
177  struct {
178  const uint8_t *data;
179  uint16_t length;
180  } key;
204  struct {
205  uint16_t offset;
231  uint16_t length;
246  } iv;
247 };
248 
315  RTE_CRYPTO_AUTH_LIST_END
316 };
317 
319 extern const char *
321 
326 };
327 
329 extern const char *
331 
345  struct {
346  const uint8_t *data;
347  uint16_t length;
348  } key;
356  struct {
357  uint16_t offset;
373  uint16_t length;
391  } iv;
393  uint16_t digest_length;
403 };
404 
405 
412  RTE_CRYPTO_AEAD_LIST_END
413 };
414 
416 extern const char *
418 
425 };
426 
428 extern const char *
430 
431 struct rte_crypto_aead_xform {
434  enum rte_crypto_aead_algorithm algo;
437  struct {
438  const uint8_t *data;
439  uint16_t length;
440  } key;
441 
442  struct {
443  uint16_t offset;
458  uint16_t length;
472  } iv;
474  uint16_t digest_length;
475 
476  uint16_t aad_length;
482 };
483 
490 };
491 
505  ;
507  union {
510  struct rte_crypto_cipher_xform cipher;
512  struct rte_crypto_aead_xform aead;
514  };
515 };
516 
518 
550  struct rte_mbuf *m_src;
551  struct rte_mbuf *m_dst;
554  union {
559  struct rte_security_session *sec_session;
561  };
562 
564  union {
565  struct {
566  struct {
567  uint32_t offset;
572  uint32_t length;
577  } data;
578  struct {
579  uint8_t *data;
601  } digest;
602  struct {
603  uint8_t *data;
634  rte_iova_t phys_addr;
635  } aad;
637  } aead;
638 
639  struct {
640  struct {
641  struct {
642  uint32_t offset;
658  uint32_t length;
674  } data;
675  } cipher;
676 
677  struct {
678  struct {
679  uint32_t offset;
697  uint32_t length;
715  } data;
718  struct {
719  uint8_t *data;
790  rte_iova_t phys_addr;
792  } digest;
793  } auth;
794  };
795  };
796 };
797 
798 
804 static inline void
806 {
807  memset(op, 0, sizeof(*op));
808 }
809 
810 
821 static inline struct rte_crypto_sym_xform *
823  void *priv_data, uint8_t nb_xforms)
824 {
825  struct rte_crypto_sym_xform *xform;
826 
827  sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
828 
829  do {
831  xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
832  } while (xform);
833 
834  return sym_op->xform;
835 }
836 
837 
844 static inline int
846  struct rte_cryptodev_sym_session *sess)
847 {
848  sym_op->session = sess;
849 
850  return 0;
851 }
852 
871 __rte_experimental
872 static inline int
873 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
874  struct rte_crypto_vec vec[], uint32_t num)
875 {
876  uint32_t i;
877  struct rte_mbuf *nseg;
878  uint32_t left;
879  uint32_t seglen;
880 
881  /* assuming that requested data starts in the first segment */
882  RTE_ASSERT(mb->data_len > ofs);
883 
884  if (mb->nb_segs > num)
885  return -mb->nb_segs;
886 
887  vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
888  vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
889 
890  /* whole data lies in the first segment */
891  seglen = mb->data_len - ofs;
892  if (len <= seglen) {
893  vec[0].len = len;
894  return 1;
895  }
896 
897  /* data spread across segments */
898  vec[0].len = seglen;
899  left = len - seglen;
900  for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
901 
902  vec[i].base = rte_pktmbuf_mtod(nseg, void *);
903  vec[i].iova = rte_pktmbuf_iova(nseg);
904 
905  seglen = nseg->data_len;
906  if (left <= seglen) {
907  /* whole requested data is completed */
908  vec[i].len = left;
909  left = 0;
910  break;
911  }
912 
913  /* use whole segment */
914  vec[i].len = seglen;
915  left -= seglen;
916  }
917 
918  RTE_ASSERT(left == 0);
919  return i + 1;
920 }
921 
922 
923 #ifdef __cplusplus
924 }
925 #endif
926 
927 #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_security_session * sec_session
uint64_t rte_iova_t
Definition: rte_common.h:365
#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_cryptodev_sym_session * session
#define RTE_STD_C11
Definition: rte_common.h:40
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_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