DPDK 25.03.0-rc0
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#include <rte_mbuf.h>
16#include <rte_memory.h>
17#include <rte_mempool.h>
18#include <rte_common.h>
19
20#include "rte_crypto_sym.h"
21#include "rte_crypto_asym.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
35};
36
54};
55
65};
66
67/* Auxiliary flags related to crypto operation */
68#define RTE_CRYPTO_OP_AUX_FLAGS_SESS_SOFT_EXPIRY (1 << 0)
76/* Auxiliary flags related to IPsec offload with RTE_SECURITY */
77
78#define RTE_CRYPTO_OP_AUX_FLAGS_IPSEC_SOFT_EXPIRY RTE_CRYPTO_OP_AUX_FLAGS_SESS_SOFT_EXPIRY
92 __extension__
93 union {
94 uint64_t raw;
95 __extension__
96 struct {
97 uint8_t type;
99 uint8_t status;
107 uint8_t sess_type;
109 uint8_t aux_flags;
126 union {
127 struct {
145 } tls_record;
147 } param1;
149 uint8_t reserved[1];
161 };
162 };
169/* empty structures do not have zero size in C++ leading to compilation errors
170 * with clang about structure/union having different sizes in C and C++.
171 * While things are clearer with an explicit union, since each field is
172 * zero-sized it's not actually needed, so omit it for C++
173 */
174#ifndef __cplusplus
175 __extension__
176 union {
177#endif
184#ifndef __cplusplus
185 };
186#endif
187};
188
195static inline void
197{
198 op->type = type;
201
202 switch (type) {
205 break;
207 memset(op->asym, 0, sizeof(struct rte_crypto_asym_op));
208 break;
210 default:
211 break;
212 }
213}
214
221 uint16_t priv_size;
223};
224
225
234static inline uint16_t
236{
237 struct rte_crypto_op_pool_private *priv =
239
240 return priv->priv_size;
241}
242
243
263struct rte_mempool *
265 unsigned nb_elts, unsigned cache_size, uint16_t priv_size,
266 int socket_id);
267
279static inline int
281 enum rte_crypto_op_type type,
282 struct rte_crypto_op **ops, uint16_t nb_ops)
283{
284 struct rte_crypto_op_pool_private *priv;
285
286 priv = (struct rte_crypto_op_pool_private *) rte_mempool_get_priv(mempool);
287 if (unlikely(priv->type != type &&
289 return -EINVAL;
290
291 if (rte_mempool_get_bulk(mempool, (void **)ops, nb_ops) == 0)
292 return nb_ops;
293
294 return 0;
295}
296
307static inline struct rte_crypto_op *
309{
310 struct rte_crypto_op *op = NULL;
311 int retval;
312
314 if (unlikely(retval != 1))
315 return NULL;
316
318
319 return op;
320}
321
322
337static inline unsigned
340 struct rte_crypto_op **ops, uint16_t nb_ops)
341{
342 int i;
343
345 != nb_ops))
346 return 0;
347
348 for (i = 0; i < nb_ops; i++)
350
351 return nb_ops;
352}
353
354
355
367static inline void *
369{
370 uint32_t priv_size;
371
372 if (likely(op->mempool != NULL)) {
374
375 if (likely(priv_size >= size)) {
377 return (void *)((uint8_t *)(op + 1) +
378 sizeof(struct rte_crypto_sym_op));
380 return (void *)((uint8_t *)(op + 1) +
381 sizeof(struct rte_crypto_asym_op));
382 }
383 }
384
385 return NULL;
386}
387
397static inline void
399{
400 if (op != NULL && op->mempool != NULL)
401 rte_mempool_put(op->mempool, op);
402}
403
415static inline struct rte_crypto_op *
417{
418 if (unlikely(m == NULL))
419 return NULL;
420
421 /*
422 * check that the mbuf's private data size is sufficient to contain a
423 * crypto operation
424 */
425 if (unlikely(m->priv_size < (sizeof(struct rte_crypto_op) +
426 sizeof(struct rte_crypto_sym_op))))
427 return NULL;
428
429 /* private data starts immediately after the mbuf header in the mbuf. */
430 struct rte_crypto_op *op = (struct rte_crypto_op *)(m + 1);
431
433
434 op->mempool = NULL;
435 op->sym->m_src = m;
436
437 return op;
438}
439
449static inline struct rte_crypto_sym_xform *
450rte_crypto_op_sym_xforms_alloc(struct rte_crypto_op *op, uint8_t nb_xforms)
451{
452 void *priv_data;
453 uint32_t size;
454
456 return NULL;
457
458 size = sizeof(struct rte_crypto_sym_xform) * nb_xforms;
459
460 priv_data = __rte_crypto_op_get_priv_data(op, size);
461 if (priv_data == NULL)
462 return NULL;
463
464 return __rte_crypto_sym_op_sym_xforms_alloc(op->sym, priv_data,
465 nb_xforms);
466}
467
468
475static inline int
477{
479 return -1;
480
482
484}
485
492static inline int
494 struct rte_cryptodev_asym_session *sess)
495{
497 return -1;
498
500 op->asym->session = sess;
501 return 0;
502}
503
504#ifdef __cplusplus
505}
506#endif
507
508#endif /* _RTE_CRYPTO_H_ */
#define likely(x)
#define unlikely(x)
uint64_t rte_iova_t
Definition: rte_common.h:658
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, void *sess)
Definition: rte_crypto.h:476
static uint16_t __rte_crypto_op_get_priv_data_size(struct rte_mempool *mempool)
Definition: rte_crypto.h:235
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:338
static struct rte_crypto_op * rte_crypto_op_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type)
Definition: rte_crypto.h:308
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:280
static int rte_crypto_op_attach_asym_session(struct rte_crypto_op *op, struct rte_cryptodev_asym_session *sess)
Definition: rte_crypto.h:493
rte_crypto_op_sess_type
Definition: rte_crypto.h:61
@ RTE_CRYPTO_OP_SESSIONLESS
Definition: rte_crypto.h:63
@ RTE_CRYPTO_OP_SECURITY_SESSION
Definition: rte_crypto.h:64
@ RTE_CRYPTO_OP_WITH_SESSION
Definition: rte_crypto.h:62
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:450
static void rte_crypto_op_free(struct rte_crypto_op *op)
Definition: rte_crypto.h:398
static void * __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size)
Definition: rte_crypto.h:368
rte_crypto_op_type
Definition: rte_crypto.h:28
@ RTE_CRYPTO_OP_TYPE_ASYMMETRIC
Definition: rte_crypto.h:33
@ RTE_CRYPTO_OP_TYPE_SYMMETRIC
Definition: rte_crypto.h:31
@ RTE_CRYPTO_OP_TYPE_UNDEFINED
Definition: rte_crypto.h:29
static struct rte_crypto_op * rte_crypto_sym_op_alloc_from_mbuf_priv_data(struct rte_mbuf *m)
Definition: rte_crypto.h:416
static void __rte_crypto_op_reset(struct rte_crypto_op *op, enum rte_crypto_op_type type)
Definition: rte_crypto.h:196
rte_crypto_op_status
Definition: rte_crypto.h:38
@ RTE_CRYPTO_OP_STATUS_AUTH_FAILED
Definition: rte_crypto.h:43
@ RTE_CRYPTO_OP_STATUS_INVALID_SESSION
Definition: rte_crypto.h:45
@ RTE_CRYPTO_OP_STATUS_SUCCESS
Definition: rte_crypto.h:39
@ RTE_CRYPTO_OP_STATUS_ERROR
Definition: rte_crypto.h:52
@ RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
Definition: rte_crypto.h:41
@ RTE_CRYPTO_OP_STATUS_INVALID_ARGS
Definition: rte_crypto.h:50
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, void *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:1679
static __rte_always_inline void rte_mempool_put(struct rte_mempool *mp, void *obj)
Definition: rte_mempool.h:1487
static void * rte_mempool_get_priv(struct rte_mempool *mp)
Definition: rte_mempool.h:1861
struct rte_cryptodev_asym_session * session
enum rte_crypto_op_type type
Definition: rte_crypto.h:219
uint8_t content_type
Definition: rte_crypto.h:128
struct rte_mempool * mempool
Definition: rte_crypto.h:163
union rte_crypto_op::@81::@85::@87 param1
uint8_t type
Definition: rte_crypto.h:97
struct rte_crypto_sym_op sym[0]
Definition: rte_crypto.h:178
uint16_t private_data_offset
Definition: rte_crypto.h:153
uint8_t aux_flags
Definition: rte_crypto.h:109
uint8_t sess_type
Definition: rte_crypto.h:107
struct rte_crypto_op::@81::@85::@87::@88 tls_record
struct rte_crypto_asym_op asym[0]
Definition: rte_crypto.h:181
rte_iova_t phys_addr
Definition: rte_crypto.h:166
uint8_t reserved[1]
Definition: rte_crypto.h:149
uint8_t status
Definition: rte_crypto.h:99
struct rte_mbuf * m_src
uint16_t priv_size
char name[RTE_MEMPOOL_NAMESIZE]
Definition: rte_mempool.h:231
uint32_t cache_size
Definition: rte_mempool.h:241