DPDK  20.11.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;
60  rte_iova_t iova;
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 
198  struct {
199  const uint8_t *data;
200  uint16_t length;
201  } key;
225  struct {
226  uint16_t offset;
252  uint16_t length;
267  } iv;
268 };
269 
344 };
345 
347 extern const char *
349 
354 };
355 
357 extern const char *
359 
373  struct {
374  const uint8_t *data;
375  uint16_t length;
376  } key;
384  struct {
385  uint16_t offset;
401  uint16_t length;
419  } iv;
421  uint16_t digest_length;
431 };
432 
433 
448 };
449 
451 extern const char *
453 
460 };
461 
463 extern const char *
465 
466 struct rte_crypto_aead_xform {
469  enum rte_crypto_aead_algorithm algo;
472  struct {
473  const uint8_t *data;
474  uint16_t length;
475  } key;
476 
477  struct {
478  uint16_t offset;
498  uint16_t length;
514  } iv;
516  uint16_t digest_length;
517 
518  uint16_t aad_length;
524 };
525 
532 };
533 
547  ;
549  union {
554  struct rte_crypto_aead_xform aead;
556  };
557 };
558 
560 
592  struct rte_mbuf *m_src;
593  struct rte_mbuf *m_dst;
596  union {
601  struct rte_security_session *sec_session;
603  };
604 
606  union {
607  struct {
608  struct {
609  uint32_t offset;
614  uint32_t length;
619  } data;
620  struct {
621  uint8_t *data;
643  } digest;
644  struct {
645  uint8_t *data;
677  } aad;
679  } aead;
680 
681  struct {
682  struct {
683  struct {
684  uint32_t offset;
700  uint32_t length;
716  } data;
717  } cipher;
718 
719  struct {
720  struct {
721  uint32_t offset;
747  uint32_t length;
771  } data;
774  struct {
775  uint8_t *data;
848  } digest;
849  } auth;
850  };
851  };
852 };
853 
854 
860 static inline void
862 {
863  memset(op, 0, sizeof(*op));
864 }
865 
866 
877 static inline struct rte_crypto_sym_xform *
879  void *priv_data, uint8_t nb_xforms)
880 {
881  struct rte_crypto_sym_xform *xform;
882 
883  sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
884 
885  do {
887  xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
888  } while (xform);
889 
890  return sym_op->xform;
891 }
892 
893 
900 static inline int
902  struct rte_cryptodev_sym_session *sess)
903 {
904  sym_op->session = sess;
905 
906  return 0;
907 }
908 
927 __rte_experimental
928 static inline int
929 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
930  struct rte_crypto_vec vec[], uint32_t num)
931 {
932  uint32_t i;
933  struct rte_mbuf *nseg;
934  uint32_t left;
935  uint32_t seglen;
936 
937  /* assuming that requested data starts in the first segment */
938  RTE_ASSERT(mb->data_len > ofs);
939 
940  if (mb->nb_segs > num)
941  return -mb->nb_segs;
942 
943  vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
944  vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
945 
946  /* whole data lies in the first segment */
947  seglen = mb->data_len - ofs;
948  if (len <= seglen) {
949  vec[0].len = len;
950  return 1;
951  }
952 
953  /* data spread across segments */
954  vec[0].len = seglen;
955  left = len - seglen;
956  for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
957 
958  vec[i].base = rte_pktmbuf_mtod(nseg, void *);
959  vec[i].iova = rte_pktmbuf_iova(nseg);
960 
961  seglen = nseg->data_len;
962  if (left <= seglen) {
963  /* whole requested data is completed */
964  vec[i].len = left;
965  left = 0;
966  break;
967  }
968 
969  /* use whole segment */
970  vec[i].len = seglen;
971  left -= seglen;
972  }
973 
974  RTE_ASSERT(left == 0);
975  return i + 1;
976 }
977 
978 
979 #ifdef __cplusplus
980 }
981 #endif
982 
983 #endif /* _RTE_CRYPTO_SYM_H_ */
__rte_crypto_sym_op_reset
static void __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
Definition: rte_crypto_sym.h:861
rte_crypto_vec::iova
rte_iova_t iova
Definition: rte_crypto_sym.h:37
rte_mbuf::next
struct rte_mbuf * next
Definition: rte_mbuf_core.h:594
rte_crypto_sym_xform::auth
struct rte_crypto_auth_xform auth
Definition: rte_crypto_sym.h:550
rte_crypto_auth_algorithm_strings
const char * rte_crypto_auth_algorithm_strings[]
RTE_CRYPTO_CIPHER_KASUMI_F8
@ RTE_CRYPTO_CIPHER_KASUMI_F8
Definition: rte_crypto_sym.h:140
rte_crypto_cipher_xform::op
enum rte_crypto_cipher_operation op
Definition: rte_crypto_sym.h:190
rte_crypto_cipher_algorithm
rte_crypto_cipher_algorithm
Definition: rte_crypto_sym.h:115
rte_memory.h
rte_crypto_sym_op::data
struct rte_crypto_sym_op::@122::@124::@127 data
rte_crypto_sym_ofs
Definition: rte_crypto_sym.h:98
RTE_CRYPTO_CIPHER_ARC4
@ RTE_CRYPTO_CIPHER_ARC4
Definition: rte_crypto_sym.h:137
RTE_CRYPTO_AEAD_CHACHA20_POLY1305
@ RTE_CRYPTO_AEAD_CHACHA20_POLY1305
Definition: rte_crypto_sym.h:446
RTE_CRYPTO_AUTH_AES_GMAC
@ RTE_CRYPTO_AUTH_AES_GMAC
Definition: rte_crypto_sym.h:285
RTE_CRYPTO_CIPHER_3DES_ECB
@ RTE_CRYPTO_CIPHER_3DES_ECB
Definition: rte_crypto_sym.h:123
rte_iova_t
uint64_t rte_iova_t
Definition: rte_common.h:418
RTE_CRYPTO_AEAD_AES_CCM
@ RTE_CRYPTO_AEAD_AES_CCM
Definition: rte_crypto_sym.h:442
RTE_CRYPTO_CIPHER_NULL
@ RTE_CRYPTO_CIPHER_NULL
Definition: rte_crypto_sym.h:116
rte_crypto_cipher_xform::key
struct rte_crypto_cipher_xform::@112 key
rte_pktmbuf_iova
#define rte_pktmbuf_iova(m)
Definition: rte_mbuf_core.h:747
RTE_CRYPTO_CIPHER_AES_XTS
@ RTE_CRYPTO_CIPHER_AES_XTS
Definition: rte_crypto_sym.h:134
RTE_CRYPTO_AUTH_SHA512
@ RTE_CRYPTO_AUTH_SHA512
Definition: rte_crypto_sym.h:317
rte_crypto_auth_operation_strings
const char * rte_crypto_auth_operation_strings[]
rte_crypto_auth_xform::length
uint16_t length
Definition: rte_crypto_sym.h:375
rte_crypto_cipher_xform::algo
enum rte_crypto_cipher_algorithm algo
Definition: rte_crypto_sym.h:195
RTE_CRYPTO_AUTH_KASUMI_F9
@ RTE_CRYPTO_AUTH_KASUMI_F9
Definition: rte_crypto_sym.h:290
rte_crypto_vec::base
void * base
Definition: rte_crypto_sym.h:35
rte_crypto_auth_operation
rte_crypto_auth_operation
Definition: rte_crypto_sym.h:351
RTE_CRYPTO_AUTH_AES_CMAC
@ RTE_CRYPTO_AUTH_AES_CMAC
Definition: rte_crypto_sym.h:283
rte_crypto_sym_vec::aad
struct rte_crypto_va_iova_ptr * aad
Definition: rte_crypto_sym.h:83
rte_crypto_cipher_xform::data
const uint8_t * data
Definition: rte_crypto_sym.h:199
RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED
@ RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED
Definition: rte_crypto_sym.h:528
rte_crypto_sym_vec::num
uint32_t num
Definition: rte_crypto_sym.h:70
RTE_CRYPTO_AUTH_SHA512_HMAC
@ RTE_CRYPTO_AUTH_SHA512_HMAC
Definition: rte_crypto_sym.h:319
rte_crypto_sym_op::phys_addr
rte_iova_t phys_addr
Definition: rte_crypto_sym.h:641
rte_mbuf::data_len
uint16_t data_len
Definition: rte_mbuf_core.h:546
rte_crypto_sym_op::aad
struct rte_crypto_sym_op::@122::@124::@129 aad
RTE_CRYPTO_AUTH_SHA3_224
@ RTE_CRYPTO_AUTH_SHA3_224
Definition: rte_crypto_sym.h:328
__rte_crypto_sym_op_attach_sym_session
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, struct rte_cryptodev_sym_session *sess)
Definition: rte_crypto_sym.h:901
RTE_CRYPTO_AUTH_SHA3_384
@ RTE_CRYPTO_AUTH_SHA3_384
Definition: rte_crypto_sym.h:336
RTE_CRYPTO_AUTH_AES_CBC_MAC
@ RTE_CRYPTO_AUTH_AES_CBC_MAC
Definition: rte_crypto_sym.h:281
RTE_CRYPTO_CIPHER_3DES_CTR
@ RTE_CRYPTO_CIPHER_3DES_CTR
Definition: rte_crypto_sym.h:121
rte_crypto_sgl
Definition: rte_crypto_sym.h:46
RTE_CRYPTO_AUTH_SHA1_HMAC
@ RTE_CRYPTO_AUTH_SHA1_HMAC
Definition: rte_crypto_sym.h:300
RTE_CRYPTO_CIPHER_DES_CBC
@ RTE_CRYPTO_CIPHER_DES_CBC
Definition: rte_crypto_sym.h:149
rte_crypto_sym_op::xform
struct rte_crypto_sym_xform * xform
Definition: rte_crypto_sym.h:599
RTE_CRYPTO_AEAD_OP_ENCRYPT
@ RTE_CRYPTO_AEAD_OP_ENCRYPT
Definition: rte_crypto_sym.h:456
RTE_CRYPTO_CIPHER_ZUC_EEA3
@ RTE_CRYPTO_CIPHER_ZUC_EEA3
Definition: rte_crypto_sym.h:146
rte_mbuf
Definition: rte_mbuf_core.h:473
RTE_CRYPTO_AUTH_ZUC_EIA3
@ RTE_CRYPTO_AUTH_ZUC_EIA3
Definition: rte_crypto_sym.h:325
rte_crypto_sym_op::m_src
struct rte_mbuf * m_src
Definition: rte_crypto_sym.h:592
RTE_CRYPTO_AUTH_OP_VERIFY
@ RTE_CRYPTO_AUTH_OP_VERIFY
Definition: rte_crypto_sym.h:352
rte_crypto_auth_xform::op
enum rte_crypto_auth_operation op
Definition: rte_crypto_sym.h:368
RTE_CRYPTO_CIPHER_AES_CTR
@ RTE_CRYPTO_CIPHER_AES_CTR
Definition: rte_crypto_sym.h:128
RTE_CRYPTO_CIPHER_DES_DOCSISBPI
@ RTE_CRYPTO_CIPHER_DES_DOCSISBPI
Definition: rte_crypto_sym.h:159
__rte_crypto_sym_op_sym_xforms_alloc
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)
Definition: rte_crypto_sym.h:878
rte_crypto_vec::len
uint32_t len
Definition: rte_crypto_sym.h:39
rte_pktmbuf_mtod_offset
#define rte_pktmbuf_mtod_offset(m, t, o)
Definition: rte_mbuf_core.h:711
rte_crypto_sym_op::length
uint32_t length
Definition: rte_crypto_sym.h:614
RTE_CRYPTO_CIPHER_AES_CBC
@ RTE_CRYPTO_CIPHER_AES_CBC
Definition: rte_crypto_sym.h:126
rte_crypto_sym_vec
Definition: rte_crypto_sym.h:68
rte_crypto_auth_xform::key
struct rte_crypto_auth_xform::@114 key
RTE_CRYPTO_AUTH_SNOW3G_UIA2
@ RTE_CRYPTO_AUTH_SNOW3G_UIA2
Definition: rte_crypto_sym.h:322
RTE_CRYPTO_CIPHER_AES_ECB
@ RTE_CRYPTO_CIPHER_AES_ECB
Definition: rte_crypto_sym.h:130
rte_mbuf::nb_segs
uint16_t nb_segs
Definition: rte_mbuf_core.h:498
RTE_CRYPTO_AUTH_SHA384
@ RTE_CRYPTO_AUTH_SHA384
Definition: rte_crypto_sym.h:313
rte_crypto_sym_vec::auth_iv
struct rte_crypto_va_iova_ptr * auth_iv
Definition: rte_crypto_sym.h:81
rte_crypto_sym_op::data
uint8_t * data
Definition: rte_crypto_sym.h:621
rte_crypto_cipher_xform::offset
uint16_t offset
Definition: rte_crypto_sym.h:226
rte_crypto_cipher_operation
rte_crypto_cipher_operation
Definition: rte_crypto_sym.h:172
rte_pktmbuf_mtod
#define rte_pktmbuf_mtod(m, t)
Definition: rte_mbuf_core.h:726
rte_crypto_cipher_xform::length
uint16_t length
Definition: rte_crypto_sym.h:200
RTE_CRYPTO_AUTH_AES_XCBC_MAC
@ RTE_CRYPTO_AUTH_AES_XCBC_MAC
Definition: rte_crypto_sym.h:287
rte_crypto_cipher_xform
Definition: rte_crypto_sym.h:189
rte_crypto_sym_op::sec_session
struct rte_security_session * sec_session
Definition: rte_crypto_sym.h:601
rte_crypto_sym_vec::iv
struct rte_crypto_va_iova_ptr * iv
Definition: rte_crypto_sym.h:74
rte_crypto_aead_algorithm
rte_crypto_aead_algorithm
Definition: rte_crypto_sym.h:441
rte_common.h
rte_crypto_sym_vec::digest
struct rte_crypto_va_iova_ptr * digest
Definition: rte_crypto_sym.h:76
RTE_CRYPTO_AUTH_SHA224
@ RTE_CRYPTO_AUTH_SHA224
Definition: rte_crypto_sym.h:305
RTE_CRYPTO_CIPHER_AES_F8
@ RTE_CRYPTO_CIPHER_AES_F8
Definition: rte_crypto_sym.h:132
RTE_CRYPTO_AUTH_MD5
@ RTE_CRYPTO_AUTH_MD5
Definition: rte_crypto_sym.h:293
rte_crypto_sgl::num
uint32_t num
Definition: rte_crypto_sym.h:50
rte_crypto_sym_xform::aead
struct rte_crypto_aead_xform aead
Definition: rte_crypto_sym.h:554
rte_crypto_sym_op::digest
struct rte_crypto_sym_op::@122::@124::@128 digest
RTE_CRYPTO_AUTH_SHA256
@ RTE_CRYPTO_AUTH_SHA256
Definition: rte_crypto_sym.h:309
rte_crypto_sym_xform
Definition: rte_crypto_sym.h:543
RTE_CRYPTO_AUTH_SHA1
@ RTE_CRYPTO_AUTH_SHA1
Definition: rte_crypto_sym.h:298
rte_crypto_auth_xform::digest_length
uint16_t digest_length
Definition: rte_crypto_sym.h:421
rte_crypto_auth_xform
Definition: rte_crypto_sym.h:367
rte_crypto_auth_xform::iv
struct rte_crypto_auth_xform::@115 iv
RTE_CRYPTO_AUTH_SHA224_HMAC
@ RTE_CRYPTO_AUTH_SHA224_HMAC
Definition: rte_crypto_sym.h:307
RTE_CRYPTO_AUTH_NULL
@ RTE_CRYPTO_AUTH_NULL
Definition: rte_crypto_sym.h:278
RTE_STD_C11
#define RTE_STD_C11
Definition: rte_common.h:40
rte_crypto_sym_xform::type
enum rte_crypto_sym_xform_type type
Definition: rte_crypto_sym.h:546
RTE_CRYPTO_AUTH_MD5_HMAC
@ RTE_CRYPTO_AUTH_MD5_HMAC
Definition: rte_crypto_sym.h:295
RTE_CRYPTO_AEAD_AES_GCM
@ RTE_CRYPTO_AEAD_AES_GCM
Definition: rte_crypto_sym.h:444
RTE_CRYPTO_SYM_XFORM_AUTH
@ RTE_CRYPTO_SYM_XFORM_AUTH
Definition: rte_crypto_sym.h:529
rte_cryptodev_sym_session
Definition: rte_cryptodev.h:1002
rte_crypto_sym_xform_type
rte_crypto_sym_xform_type
Definition: rte_crypto_sym.h:527
rte_mempool.h
RTE_CRYPTO_SYM_XFORM_CIPHER
@ RTE_CRYPTO_SYM_XFORM_CIPHER
Definition: rte_crypto_sym.h:530
rte_crypto_sgl::vec
struct rte_crypto_vec * vec
Definition: rte_crypto_sym.h:48
rte_crypto_sym_op::offset
uint32_t offset
Definition: rte_crypto_sym.h:609
rte_crypto_vec
Definition: rte_crypto_sym.h:33
rte_crypto_mbuf_to_vec
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)
Definition: rte_crypto_sym.h:929
rte_crypto_aead_operation
rte_crypto_aead_operation
Definition: rte_crypto_sym.h:455
rte_crypto_sym_op::session
struct rte_cryptodev_sym_session * session
Definition: rte_crypto_sym.h:597
rte_mbuf.h
RTE_CRYPTO_AUTH_SHA3_512_HMAC
@ RTE_CRYPTO_AUTH_SHA3_512_HMAC
Definition: rte_crypto_sym.h:342
rte_crypto_sym_vec::sgl
struct rte_crypto_sgl * sgl
Definition: rte_crypto_sym.h:72
RTE_CRYPTO_AEAD_OP_DECRYPT
@ RTE_CRYPTO_AEAD_OP_DECRYPT
Definition: rte_crypto_sym.h:458
RTE_CRYPTO_CIPHER_OP_ENCRYPT
@ RTE_CRYPTO_CIPHER_OP_ENCRYPT
Definition: rte_crypto_sym.h:173
rte_crypto_auth_algorithm
rte_crypto_auth_algorithm
Definition: rte_crypto_sym.h:277
RTE_CRYPTO_CIPHER_OP_DECRYPT
@ RTE_CRYPTO_CIPHER_OP_DECRYPT
Definition: rte_crypto_sym.h:175
RTE_CRYPTO_CIPHER_3DES_CBC
@ RTE_CRYPTO_CIPHER_3DES_CBC
Definition: rte_crypto_sym.h:119
RTE_CRYPTO_SYM_XFORM_AEAD
@ RTE_CRYPTO_SYM_XFORM_AEAD
Definition: rte_crypto_sym.h:531
RTE_CRYPTO_CIPHER_AES_DOCSISBPI
@ RTE_CRYPTO_CIPHER_AES_DOCSISBPI
Definition: rte_crypto_sym.h:152
rte_crypto_sym_xform::next
struct rte_crypto_sym_xform * next
Definition: rte_crypto_sym.h:544
rte_crypto_cipher_algorithm_strings
const char * rte_crypto_cipher_algorithm_strings[]
rte_crypto_sym_vec::status
int32_t * status
Definition: rte_crypto_sym.h:91
rte_pktmbuf_iova_offset
#define rte_pktmbuf_iova_offset(m, o)
Definition: rte_mbuf_core.h:737
rte_crypto_auth_xform::algo
enum rte_crypto_auth_algorithm algo
Definition: rte_crypto_sym.h:370
rte_crypto_aead_algorithm_strings
const char * rte_crypto_aead_algorithm_strings[]
rte_crypto_sym_xform::cipher
struct rte_crypto_cipher_xform cipher
Definition: rte_crypto_sym.h:552
RTE_CRYPTO_AUTH_SHA3_384_HMAC
@ RTE_CRYPTO_AUTH_SHA3_384_HMAC
Definition: rte_crypto_sym.h:338
RTE_CRYPTO_CIPHER_SNOW3G_UEA2
@ RTE_CRYPTO_CIPHER_SNOW3G_UEA2
Definition: rte_crypto_sym.h:143
RTE_CRYPTO_AUTH_SHA3_256
@ RTE_CRYPTO_AUTH_SHA3_256
Definition: rte_crypto_sym.h:332
rte_crypto_auth_xform::data
const uint8_t * data
Definition: rte_crypto_sym.h:374
RTE_CRYPTO_AUTH_SHA3_256_HMAC
@ RTE_CRYPTO_AUTH_SHA3_256_HMAC
Definition: rte_crypto_sym.h:334
RTE_CRYPTO_AUTH_SHA384_HMAC
@ RTE_CRYPTO_AUTH_SHA384_HMAC
Definition: rte_crypto_sym.h:315
RTE_CRYPTO_AUTH_OP_GENERATE
@ RTE_CRYPTO_AUTH_OP_GENERATE
Definition: rte_crypto_sym.h:353
rte_crypto_aead_operation_strings
const char * rte_crypto_aead_operation_strings[]
RTE_CRYPTO_AUTH_SHA256_HMAC
@ RTE_CRYPTO_AUTH_SHA256_HMAC
Definition: rte_crypto_sym.h:311
rte_crypto_cipher_xform::iv
struct rte_crypto_cipher_xform::@113 iv
rte_crypto_sym_op
Definition: rte_crypto_sym.h:591
rte_crypto_sym_op::m_dst
struct rte_mbuf * m_dst
Definition: rte_crypto_sym.h:593
RTE_CRYPTO_AUTH_SHA3_512
@ RTE_CRYPTO_AUTH_SHA3_512
Definition: rte_crypto_sym.h:340
rte_crypto_cipher_operation_strings
const char * rte_crypto_cipher_operation_strings[]
RTE_CRYPTO_AUTH_SHA3_224_HMAC
@ RTE_CRYPTO_AUTH_SHA3_224_HMAC
Definition: rte_crypto_sym.h:330
rte_crypto_auth_xform::offset
uint16_t offset
Definition: rte_crypto_sym.h:385
rte_crypto_va_iova_ptr
Definition: rte_crypto_sym.h:58