DPDK 21.11.9
rte_crypto.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2017 Intel Corporation
3 */
4
5#ifndef _RTE_CRYPTO_H_
6#define _RTE_CRYPTO_H_
7
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19
20#include <rte_mbuf.h>
21#include <rte_memory.h>
22#include <rte_mempool.h>
23#include <rte_common.h>
24
25#include "rte_crypto_sym.h"
26#include "rte_crypto_asym.h"
27
36};
37
55};
56
66};
67
68/* Auxiliary flags related to IPsec offload with RTE_SECURITY */
69
70#define RTE_CRYPTO_OP_AUX_FLAGS_IPSEC_SOFT_EXPIRY (1 << 0)
84 __extension__
85 union {
86 uint64_t raw;
87 __extension__
88 struct {
89 uint8_t type;
91 uint8_t status;
99 uint8_t sess_type;
101 uint8_t aux_flags;
106 uint8_t reserved[2];
118 };
119 };
126/* empty structures do not have zero size in C++ leading to compilation errors
127 * with clang about structure/union having different sizes in C and C++.
128 * While things are clearer with an explicit union, since each field is
129 * zero-sized it's not actually needed, so omit it for C++
130 */
131#ifndef __cplusplus
132 __extension__
133 union {
134#endif
141#ifndef __cplusplus
142 };
143#endif
144};
145
152static inline void
154{
155 op->type = type;
158
159 switch (type) {
162 break;
164 memset(op->asym, 0, sizeof(struct rte_crypto_asym_op));
165 break;
167 default:
168 break;
169 }
170}
171
178 uint16_t priv_size;
180};
181
182
191static inline uint16_t
193{
194 struct rte_crypto_op_pool_private *priv =
196
197 return priv->priv_size;
198}
199
200
220extern struct rte_mempool *
222 unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
223 int socket_id);
224
236static inline int
238 enum rte_crypto_op_type type,
239 struct rte_crypto_op **ops, uint16_t nb_ops)
240{
241 struct rte_crypto_op_pool_private *priv;
242
243 priv = (struct rte_crypto_op_pool_private *) rte_mempool_get_priv(mempool);
244 if (unlikely(priv->type != type &&
246 return -EINVAL;
247
248 if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
249 return nb_ops;
250
251 return 0;
252}
253
264static inline struct rte_crypto_op *
266{
267 struct rte_crypto_op *op = NULL;
268 int retval;
269
271 if (unlikely(retval != 1))
272 return NULL;
273
275
276 return op;
277}
278
279
294static inline unsigned
297 struct rte_crypto_op **ops, uint16_t nb_ops)
298{
299 int i;
300
302 != nb_ops))
303 return 0;
304
305 for (i = 0; i < nb_ops; i++)
307
308 return nb_ops;
309}
310
311
312
324static inline void *
326{
327 uint32_t priv_size;
328
329 if (likely(op->mempool != NULL)) {
331
332 if (likely(priv_size >= size)) {
334 return (void *)((uint8_t *)(op + 1) +
335 sizeof(struct rte_crypto_sym_op));
337 return (void *)((uint8_t *)(op + 1) +
338 sizeof(struct rte_crypto_asym_op));
339 }
340 }
341
342 return NULL;
343}
344
352static inline void
354{
355 if (op != NULL && op->mempool != NULL)
356 rte_mempool_put(op->mempool, op);
357}
358
370static inline struct rte_crypto_op *
372{
373 if (unlikely(m == NULL))
374 return NULL;
375
376 /*
377 * check that the mbuf's private data size is sufficient to contain a
378 * crypto operation
379 */
380 if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
381 sizeof(struct rte_crypto_sym_op))))
382 return NULL;
383
384 /* private data starts immediately after the mbuf header in the mbuf. */
385 struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
386
388
389 op->mempool = NULL;
390 op->sym->m_src = m;
391
392 return op;
393}
394
404static inline struct rte_crypto_sym_xform *
405rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
406{
407 void *priv_data;
408 uint32_t size;
409
411 return NULL;
412
413 size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
414
415 priv_data = __rte_crypto_op_get_priv_data(op, size);
416 if (priv_data == NULL)
417 return NULL;
418
419 return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
420 nb_xforms);
421}
422
423
430static inline int
432 struct rte_cryptodev_sym_session *sess)
433{
435 return -1;
436
438
440}
441
448static inline int
450 struct rte_cryptodev_asym_session *sess)
451{
453 return -1;
454
456 op->asym->session = sess;
457 return 0;
458}
459
460#ifdef __cplusplus
461}
462#endif
463
464#endif /* _RTE_CRYPTO_H_ */
#define likely(x)
#define unlikely(x)
uint64_t rte_iova_t
Definition: rte_common.h:438
static uint16_t __rte_crypto_op_get_priv_data_size(struct rte_mempool *mempool)
Definition: rte_crypto.h:192
static unsigned rte_crypto_op_bulk_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type, struct rte_crypto_op **ops, uint16_t nb_ops)
Definition: rte_crypto.h:295
static struct rte_crypto_op * rte_crypto_op_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type)
Definition: rte_crypto.h:265
static int __rte_crypto_op_raw_bulk_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type, struct rte_crypto_op **ops, uint16_t nb_ops)
Definition: rte_crypto.h:237
static int rte_crypto_op_attach_asym_session(struct rte_crypto_op *op, struct rte_cryptodev_asym_session *sess)
Definition: rte_crypto.h:449
rte_crypto_op_sess_type
Definition: rte_crypto.h:62
@ RTE_CRYPTO_OP_SESSIONLESS
Definition: rte_crypto.h:64
@ RTE_CRYPTO_OP_SECURITY_SESSION
Definition: rte_crypto.h:65
@ RTE_CRYPTO_OP_WITH_SESSION
Definition: rte_crypto.h:63
struct rte_mempool * rte_crypto_op_pool_create(const char *name, enum rte_crypto_op_type type, unsigned nb_elts, unsigned cache_size, uint16_t priv_size, int socket_id)
static struct rte_crypto_sym_xform * rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
Definition: rte_crypto.h:405
static void rte_crypto_op_free(struct rte_crypto_op *op)
Definition: rte_crypto.h:353
static void * __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size)
Definition: rte_crypto.h:325
rte_crypto_op_type
Definition: rte_crypto.h:29
@ RTE_CRYPTO_OP_TYPE_ASYMMETRIC
Definition: rte_crypto.h:34
@ RTE_CRYPTO_OP_TYPE_SYMMETRIC
Definition: rte_crypto.h:32
@ RTE_CRYPTO_OP_TYPE_UNDEFINED
Definition: rte_crypto.h:30
static struct rte_crypto_op * rte_crypto_sym_op_alloc_from_mbuf_priv_data(struct rte_mbuf *m)
Definition: rte_crypto.h:371
static void __rte_crypto_op_reset(struct rte_crypto_op *op, enum rte_crypto_op_type type)
Definition: rte_crypto.h:153
rte_crypto_op_status
Definition: rte_crypto.h:39
@ RTE_CRYPTO_OP_STATUS_AUTH_FAILED
Definition: rte_crypto.h:44
@ RTE_CRYPTO_OP_STATUS_INVALID_SESSION
Definition: rte_crypto.h:46
@ RTE_CRYPTO_OP_STATUS_SUCCESS
Definition: rte_crypto.h:40
@ RTE_CRYPTO_OP_STATUS_ERROR
Definition: rte_crypto.h:53
@ RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
Definition: rte_crypto.h:42
@ RTE_CRYPTO_OP_STATUS_INVALID_ARGS
Definition: rte_crypto.h:51
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, struct rte_cryptodev_sym_session *sess)
Definition: rte_crypto.h:431
static void __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
static int __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, struct rte_cryptodev_sym_session *sess)
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)
static __rte_always_inline int rte_mempool_get_bulk(struct rte_mempool *mp, void **obj_table, unsigned int n)
Definition: rte_mempool.h:1580
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1444
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1762
struct rte_cryptodev_asym_session * session
enum rte_crypto_op_type type
Definition: rte_crypto.h:176
struct rte_mempool * mempool
Definition: rte_crypto.h:120
uint8_t type
Definition: rte_crypto.h:89
struct rte_crypto_sym_op sym[0]
Definition: rte_crypto.h:135
uint16_t private_data_offset
Definition: rte_crypto.h:110
uint8_t reserved[2]
Definition: rte_crypto.h:106
uint8_t aux_flags
Definition: rte_crypto.h:101
uint8_t sess_type
Definition: rte_crypto.h:99
struct rte_crypto_asym_op asym[0]
Definition: rte_crypto.h:138
rte_iova_t phys_addr
Definition: rte_crypto.h:123
uint8_t status
Definition: rte_crypto.h:91
struct rte_mbuf * m_src
uint16_t priv_size
char name[RTE_MEMPOOL_NAMESIZE]
Definition: rte_mempool.h:213
uint32_t cache_size
Definition: rte_mempool.h:224