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 {
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;
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;
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_ */
__rte_crypto_sym_op_reset
static void __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
Definition: rte_crypto_sym.h:805
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:609
rte_crypto_sym_xform::auth
struct rte_crypto_auth_xform auth
Definition: rte_crypto_sym.h:508
rte_crypto_auth_algorithm_strings
const char * rte_crypto_auth_algorithm_strings[]
RTE_CRYPTO_CIPHER_KASUMI_F8
Definition: rte_crypto_sym.h:116
rte_crypto_cipher_xform::op
enum rte_crypto_cipher_operation op
Definition: rte_crypto_sym.h:169
rte_crypto_cipher_algorithm
rte_crypto_cipher_algorithm
Definition: rte_crypto_sym.h:91
rte_memory.h
rte_crypto_sym_ofs
Definition: rte_crypto_sym.h:80
RTE_CRYPTO_CIPHER_ARC4
Definition: rte_crypto_sym.h:113
RTE_CRYPTO_AUTH_AES_GMAC
Definition: rte_crypto_sym.h:258
RTE_CRYPTO_CIPHER_3DES_ECB
Definition: rte_crypto_sym.h:99
rte_crypto_auth_xform::iv
struct rte_crypto_auth_xform::@101 iv
rte_iova_t
uint64_t rte_iova_t
Definition: rte_common.h:385
RTE_CRYPTO_AEAD_AES_CCM
Definition: rte_crypto_sym.h:408
RTE_CRYPTO_CIPHER_NULL
Definition: rte_crypto_sym.h:92
rte_pktmbuf_iova
#define rte_pktmbuf_iova(m)
Definition: rte_mbuf_core.h:762
RTE_CRYPTO_CIPHER_AES_XTS
Definition: rte_crypto_sym.h:110
RTE_CRYPTO_AUTH_SHA512
Definition: rte_crypto_sym.h:287
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:347
rte_crypto_cipher_xform::algo
enum rte_crypto_cipher_algorithm algo
Definition: rte_crypto_sym.h:174
RTE_CRYPTO_AUTH_KASUMI_F9
Definition: rte_crypto_sym.h:263
rte_crypto_sym_vec::iv
void ** iv
Definition: rte_crypto_sym.h:61
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:323
RTE_CRYPTO_AUTH_AES_CMAC
Definition: rte_crypto_sym.h:256
rte_crypto_cipher_xform::data
const uint8_t * data
Definition: rte_crypto_sym.h:178
RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED
Definition: rte_crypto_sym.h:486
rte_crypto_cipher_xform::iv
struct rte_crypto_cipher_xform::@99 iv
rte_crypto_sym_vec::num
uint32_t num
Definition: rte_crypto_sym.h:73
RTE_CRYPTO_AUTH_SHA512_HMAC
Definition: rte_crypto_sym.h:289
rte_crypto_sym_op::phys_addr
rte_iova_t phys_addr
Definition: rte_crypto_sym.h:599
rte_mbuf::data_len
uint16_t data_len
Definition: rte_mbuf_core.h:549
RTE_CRYPTO_AUTH_SHA3_224
Definition: rte_crypto_sym.h:298
rte_crypto_sym_op::aad
struct rte_crypto_sym_op::@108::@110::@115 aad
__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:845
RTE_CRYPTO_AUTH_SHA3_384
Definition: rte_crypto_sym.h:306
RTE_CRYPTO_AUTH_AES_CBC_MAC
Definition: rte_crypto_sym.h:254
RTE_CRYPTO_CIPHER_3DES_CTR
Definition: rte_crypto_sym.h:97
rte_crypto_sgl
Definition: rte_crypto_sym.h:46
RTE_CRYPTO_AUTH_SHA1_HMAC
Definition: rte_crypto_sym.h:273
RTE_CRYPTO_CIPHER_DES_CBC
Definition: rte_crypto_sym.h:125
rte_crypto_sym_op::xform
struct rte_crypto_sym_xform * xform
Definition: rte_crypto_sym.h:557
RTE_CRYPTO_AEAD_OP_ENCRYPT
Definition: rte_crypto_sym.h:421
RTE_CRYPTO_CIPHER_ZUC_EEA3
Definition: rte_crypto_sym.h:122
rte_mbuf
Definition: rte_mbuf_core.h:467
RTE_CRYPTO_AUTH_ZUC_EIA3
Definition: rte_crypto_sym.h:295
rte_crypto_sym_op::m_src
struct rte_mbuf * m_src
Definition: rte_crypto_sym.h:550
RTE_CRYPTO_AUTH_OP_VERIFY
Definition: rte_crypto_sym.h:324
rte_crypto_auth_xform::op
enum rte_crypto_auth_operation op
Definition: rte_crypto_sym.h:340
RTE_CRYPTO_CIPHER_AES_CTR
Definition: rte_crypto_sym.h:104
RTE_CRYPTO_CIPHER_DES_DOCSISBPI
Definition: rte_crypto_sym.h:135
__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:822
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:726
rte_crypto_sym_op::length
uint32_t length
Definition: rte_crypto_sym.h:572
RTE_CRYPTO_CIPHER_AES_CBC
Definition: rte_crypto_sym.h:102
rte_crypto_sym_vec
Definition: rte_crypto_sym.h:57
RTE_CRYPTO_AUTH_SNOW3G_UIA2
Definition: rte_crypto_sym.h:292
RTE_CRYPTO_CIPHER_AES_ECB
Definition: rte_crypto_sym.h:106
rte_mbuf::nb_segs
uint16_t nb_segs
Definition: rte_mbuf_core.h:502
RTE_CRYPTO_AUTH_SHA384
Definition: rte_crypto_sym.h:283
rte_crypto_sym_op::data
uint8_t * data
Definition: rte_crypto_sym.h:579
rte_crypto_cipher_xform::offset
uint16_t offset
Definition: rte_crypto_sym.h:205
rte_crypto_cipher_operation
rte_crypto_cipher_operation
Definition: rte_crypto_sym.h:151
rte_pktmbuf_mtod
#define rte_pktmbuf_mtod(m, t)
Definition: rte_mbuf_core.h:741
rte_crypto_cipher_xform::length
uint16_t length
Definition: rte_crypto_sym.h:179
RTE_CRYPTO_AUTH_AES_XCBC_MAC
Definition: rte_crypto_sym.h:260
rte_crypto_cipher_xform
Definition: rte_crypto_sym.h:168
rte_crypto_sym_op::sec_session
struct rte_security_session * sec_session
Definition: rte_crypto_sym.h:559
rte_crypto_sym_vec::digest
void ** digest
Definition: rte_crypto_sym.h:65
rte_crypto_aead_algorithm
rte_crypto_aead_algorithm
Definition: rte_crypto_sym.h:407
rte_common.h
RTE_CRYPTO_AUTH_SHA224
Definition: rte_crypto_sym.h:275
RTE_CRYPTO_CIPHER_AES_F8
Definition: rte_crypto_sym.h:108
RTE_CRYPTO_AUTH_MD5
Definition: rte_crypto_sym.h:266
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:512
RTE_CRYPTO_AUTH_SHA256
Definition: rte_crypto_sym.h:279
rte_crypto_sym_xform
Definition: rte_crypto_sym.h:501
RTE_CRYPTO_AUTH_SHA1
Definition: rte_crypto_sym.h:271
rte_crypto_auth_xform::digest_length
uint16_t digest_length
Definition: rte_crypto_sym.h:393
rte_crypto_auth_xform
Definition: rte_crypto_sym.h:339
RTE_CRYPTO_AUTH_SHA224_HMAC
Definition: rte_crypto_sym.h:277
RTE_CRYPTO_AUTH_NULL
Definition: rte_crypto_sym.h:251
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:504
rte_crypto_sym_op::digest
struct rte_crypto_sym_op::@108::@110::@114 digest
RTE_CRYPTO_AUTH_MD5_HMAC
Definition: rte_crypto_sym.h:268
RTE_CRYPTO_AEAD_AES_GCM
Definition: rte_crypto_sym.h:410
RTE_CRYPTO_SYM_XFORM_AUTH
Definition: rte_crypto_sym.h:487
rte_cryptodev_sym_session
Definition: rte_cryptodev.h:976
rte_crypto_sym_xform_type
rte_crypto_sym_xform_type
Definition: rte_crypto_sym.h:485
rte_mempool.h
RTE_CRYPTO_SYM_XFORM_CIPHER
Definition: rte_crypto_sym.h:488
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:567
rte_crypto_vec
Definition: rte_crypto_sym.h:33
rte_crypto_sym_op::data
struct rte_crypto_sym_op::@108::@110::@113 data
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:873
rte_crypto_aead_operation
rte_crypto_aead_operation
Definition: rte_crypto_sym.h:420
rte_crypto_sym_op::session
struct rte_cryptodev_sym_session * session
Definition: rte_crypto_sym.h:555
rte_mbuf.h
RTE_CRYPTO_AUTH_SHA3_512_HMAC
Definition: rte_crypto_sym.h:312
rte_crypto_sym_vec::sgl
struct rte_crypto_sgl * sgl
Definition: rte_crypto_sym.h:59
RTE_CRYPTO_AEAD_OP_DECRYPT
Definition: rte_crypto_sym.h:423
RTE_CRYPTO_CIPHER_OP_ENCRYPT
Definition: rte_crypto_sym.h:152
rte_crypto_auth_algorithm
rte_crypto_auth_algorithm
Definition: rte_crypto_sym.h:250
RTE_CRYPTO_CIPHER_OP_DECRYPT
Definition: rte_crypto_sym.h:154
RTE_CRYPTO_CIPHER_3DES_CBC
Definition: rte_crypto_sym.h:95
RTE_CRYPTO_SYM_XFORM_AEAD
Definition: rte_crypto_sym.h:489
RTE_CRYPTO_CIPHER_AES_DOCSISBPI
Definition: rte_crypto_sym.h:128
rte_crypto_sym_vec::aad
void ** aad
Definition: rte_crypto_sym.h:63
rte_crypto_sym_xform::next
struct rte_crypto_sym_xform * next
Definition: rte_crypto_sym.h:502
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:71
rte_pktmbuf_iova_offset
#define rte_pktmbuf_iova_offset(m, o)
Definition: rte_mbuf_core.h:752
rte_crypto_auth_xform::algo
enum rte_crypto_auth_algorithm algo
Definition: rte_crypto_sym.h:342
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:510
RTE_CRYPTO_AUTH_SHA3_384_HMAC
Definition: rte_crypto_sym.h:308
RTE_CRYPTO_CIPHER_SNOW3G_UEA2
Definition: rte_crypto_sym.h:119
RTE_CRYPTO_AUTH_SHA3_256
Definition: rte_crypto_sym.h:302
rte_crypto_auth_xform::data
const uint8_t * data
Definition: rte_crypto_sym.h:346
RTE_CRYPTO_AUTH_SHA3_256_HMAC
Definition: rte_crypto_sym.h:304
RTE_CRYPTO_AUTH_SHA384_HMAC
Definition: rte_crypto_sym.h:285
RTE_CRYPTO_AUTH_OP_GENERATE
Definition: rte_crypto_sym.h:325
rte_crypto_aead_operation_strings
const char * rte_crypto_aead_operation_strings[]
RTE_CRYPTO_AUTH_SHA256_HMAC
Definition: rte_crypto_sym.h:281
rte_crypto_sym_op
Definition: rte_crypto_sym.h:549
rte_crypto_sym_op::m_dst
struct rte_mbuf * m_dst
Definition: rte_crypto_sym.h:551
RTE_CRYPTO_AUTH_SHA3_512
Definition: rte_crypto_sym.h:310
rte_crypto_auth_xform::key
struct rte_crypto_auth_xform::@100 key
rte_crypto_cipher_operation_strings
const char * rte_crypto_cipher_operation_strings[]
rte_crypto_cipher_xform::key
struct rte_crypto_cipher_xform::@98 key
RTE_CRYPTO_AUTH_SHA3_224_HMAC
Definition: rte_crypto_sym.h:300
rte_crypto_auth_xform::offset
uint16_t offset
Definition: rte_crypto_sym.h:357