DPDK
25.11.3
Toggle main menu visibility
Loading...
Searching...
No Matches
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
13
14
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
24
extern
"C"
{
25
#endif
26
28
enum
rte_crypto_op_type
{
29
RTE_CRYPTO_OP_TYPE_UNDEFINED
,
31
RTE_CRYPTO_OP_TYPE_SYMMETRIC
,
33
RTE_CRYPTO_OP_TYPE_ASYMMETRIC
35
};
36
38
enum
rte_crypto_op_status
{
39
RTE_CRYPTO_OP_STATUS_SUCCESS
,
41
RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
,
43
RTE_CRYPTO_OP_STATUS_AUTH_FAILED
,
45
RTE_CRYPTO_OP_STATUS_INVALID_SESSION
,
50
RTE_CRYPTO_OP_STATUS_INVALID_ARGS
,
52
RTE_CRYPTO_OP_STATUS_ERROR
,
54
};
55
61
enum
rte_crypto_op_sess_type
{
62
RTE_CRYPTO_OP_WITH_SESSION
,
63
RTE_CRYPTO_OP_SESSIONLESS
,
64
RTE_CRYPTO_OP_SECURITY_SESSION
65
};
66
67
/* Auxiliary flags related to crypto operation */
68
#define RTE_CRYPTO_OP_AUX_FLAGS_SESS_SOFT_EXPIRY (1 << 0)
75
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
80
91
struct
rte_crypto_op
{
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
{
128
uint8_t content_type;
145
} tls_record;
147
} param1;
149
uint8_t reserved[1];
153
uint16_t private_data_offset;
161
};
162
};
163
struct
rte_mempool
*
mempool
;
165
166
rte_iova_t
phys_addr
;
168
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
178
struct
rte_crypto_sym_op
sym[0];
180
181
struct
rte_crypto_asym_op
asym[0];
183
184
#ifndef __cplusplus
185
};
186
#endif
187
};
188
195
static
inline
void
196
__rte_crypto_op_reset
(
struct
rte_crypto_op
*op,
enum
rte_crypto_op_type
type)
197
{
198
op->type = type;
199
op->status =
RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
;
200
op->sess_type =
RTE_CRYPTO_OP_SESSIONLESS
;
201
202
switch
(type) {
203
case
RTE_CRYPTO_OP_TYPE_SYMMETRIC
:
204
__rte_crypto_sym_op_reset(op->sym);
205
break
;
206
case
RTE_CRYPTO_OP_TYPE_ASYMMETRIC
:
207
memset(op->asym, 0,
sizeof
(
struct
rte_crypto_asym_op
));
208
break
;
209
case
RTE_CRYPTO_OP_TYPE_UNDEFINED
:
210
default
:
211
break
;
212
}
213
}
214
218
struct
rte_crypto_op_pool_private
{
219
enum
rte_crypto_op_type
type
;
221
uint16_t
priv_size
;
223
};
224
225
234
static
inline
uint16_t
235
__rte_crypto_op_get_priv_data_size
(
struct
rte_mempool
*mempool)
236
{
237
struct
rte_crypto_op_pool_private
*priv =
238
(
struct
rte_crypto_op_pool_private
*) rte_mempool_get_priv(mempool);
239
240
return
priv->
priv_size
;
241
}
242
243
263
struct
rte_mempool
*
264
rte_crypto_op_pool_create
(
const
char
*
name
,
enum
rte_crypto_op_type
type,
265
unsigned
nb_elts,
unsigned
cache_size
, uint16_t priv_size,
266
int
socket_id
);
267
279
static
inline
int
280
__rte_crypto_op_raw_bulk_alloc
(
struct
rte_mempool
*mempool,
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
&&
288
priv->
type
!=
RTE_CRYPTO_OP_TYPE_UNDEFINED
))
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
307
static
inline
struct
rte_crypto_op
*
308
rte_crypto_op_alloc
(
struct
rte_mempool
*
mempool
,
enum
rte_crypto_op_type
type)
309
{
310
struct
rte_crypto_op
*op = NULL;
311
int
retval;
312
313
retval =
__rte_crypto_op_raw_bulk_alloc
(
mempool
, type, &op, 1);
314
if
(
unlikely
(retval != 1))
315
return
NULL;
316
317
__rte_crypto_op_reset
(op, type);
318
319
return
op;
320
}
321
322
336
337
static
inline
unsigned
338
rte_crypto_op_bulk_alloc
(
struct
rte_mempool
*
mempool
,
339
enum
rte_crypto_op_type
type,
340
struct
rte_crypto_op
**ops, uint16_t nb_ops)
341
{
342
int
i;
343
344
if
(
unlikely
(
__rte_crypto_op_raw_bulk_alloc
(
mempool
, type, ops, nb_ops)
345
!= nb_ops))
346
return
0;
347
348
for
(i = 0; i < nb_ops; i++)
349
__rte_crypto_op_reset
(ops[i], type);
350
351
return
nb_ops;
352
}
353
354
355
367
static
inline
void
*
368
__rte_crypto_op_get_priv_data
(
struct
rte_crypto_op
*op, uint32_t size)
369
{
370
uint32_t priv_size;
371
372
if
(
likely
(op->
mempool
!= NULL)) {
373
priv_size =
__rte_crypto_op_get_priv_data_size
(op->
mempool
);
374
375
if
(
likely
(priv_size >= size)) {
376
if
(op->type ==
RTE_CRYPTO_OP_TYPE_SYMMETRIC
)
377
return
(
void
*)((uint8_t *)(op + 1) +
378
sizeof
(
struct
rte_crypto_sym_op
));
379
if
(op->type ==
RTE_CRYPTO_OP_TYPE_ASYMMETRIC
)
380
return
(
void
*)((uint8_t *)(op + 1) +
381
sizeof
(
struct
rte_crypto_asym_op
));
382
}
383
}
384
385
return
NULL;
386
}
387
397
static
inline
void
398
rte_crypto_op_free
(
struct
rte_crypto_op
*op)
399
{
400
if
(op != NULL && op->
mempool
!= NULL)
401
rte_mempool_put(op->
mempool
, op);
402
}
403
415
static
inline
struct
rte_crypto_op
*
416
rte_crypto_sym_op_alloc_from_mbuf_priv_data
(
struct
rte_mbuf
*m)
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
432
__rte_crypto_op_reset
(op,
RTE_CRYPTO_OP_TYPE_SYMMETRIC
);
433
434
op->
mempool
= NULL;
435
op->sym->m_src = m;
436
437
return
op;
438
}
439
449
static
inline
struct
rte_crypto_sym_xform
*
450
rte_crypto_op_sym_xforms_alloc
(
struct
rte_crypto_op
*op, uint8_t nb_xforms)
451
{
452
void
*priv_data;
453
uint32_t size;
454
455
if
(
unlikely
(op->type !=
RTE_CRYPTO_OP_TYPE_SYMMETRIC
))
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
475
static
inline
int
476
rte_crypto_op_attach_sym_session
(
struct
rte_crypto_op
*op,
void
*sess)
477
{
478
if
(
unlikely
(op->type !=
RTE_CRYPTO_OP_TYPE_SYMMETRIC
))
479
return
-1;
480
481
op->sess_type =
RTE_CRYPTO_OP_WITH_SESSION
;
482
483
return
__rte_crypto_sym_op_attach_sym_session(op->sym, sess);
484
}
485
492
static
inline
int
493
rte_crypto_op_attach_asym_session
(
struct
rte_crypto_op
*op,
494
struct
rte_cryptodev_asym_session *sess)
495
{
496
if
(
unlikely
(op->type !=
RTE_CRYPTO_OP_TYPE_ASYMMETRIC
))
497
return
-1;
498
499
op->sess_type =
RTE_CRYPTO_OP_WITH_SESSION
;
500
op->asym->session = sess;
501
return
0;
502
}
503
504
#ifdef __cplusplus
505
}
506
#endif
507
508
#endif
/* _RTE_CRYPTO_H_ */
likely
#define likely(x)
Definition
rte_branch_prediction.h:26
unlikely
#define unlikely(x)
Definition
rte_branch_prediction.h:43
rte_common.h
rte_iova_t
uint64_t rte_iova_t
Definition
rte_common.h:786
rte_crypto_op_attach_sym_session
static int rte_crypto_op_attach_sym_session(struct rte_crypto_op *op, void *sess)
Definition
rte_crypto.h:476
__rte_crypto_op_get_priv_data_size
static uint16_t __rte_crypto_op_get_priv_data_size(struct rte_mempool *mempool)
Definition
rte_crypto.h:235
rte_crypto_op_bulk_alloc
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
rte_crypto_op_alloc
static struct rte_crypto_op * rte_crypto_op_alloc(struct rte_mempool *mempool, enum rte_crypto_op_type type)
Definition
rte_crypto.h:308
__rte_crypto_op_raw_bulk_alloc
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
rte_crypto_op_attach_asym_session
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
rte_crypto_op_sess_type
Definition
rte_crypto.h:61
RTE_CRYPTO_OP_SESSIONLESS
@ RTE_CRYPTO_OP_SESSIONLESS
Definition
rte_crypto.h:63
RTE_CRYPTO_OP_SECURITY_SESSION
@ RTE_CRYPTO_OP_SECURITY_SESSION
Definition
rte_crypto.h:64
RTE_CRYPTO_OP_WITH_SESSION
@ RTE_CRYPTO_OP_WITH_SESSION
Definition
rte_crypto.h:62
rte_crypto_op_pool_create
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)
rte_crypto_op_sym_xforms_alloc
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
rte_crypto_op_free
static void rte_crypto_op_free(struct rte_crypto_op *op)
Definition
rte_crypto.h:398
__rte_crypto_op_get_priv_data
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
rte_crypto_op_type
Definition
rte_crypto.h:28
RTE_CRYPTO_OP_TYPE_ASYMMETRIC
@ RTE_CRYPTO_OP_TYPE_ASYMMETRIC
Definition
rte_crypto.h:33
RTE_CRYPTO_OP_TYPE_SYMMETRIC
@ RTE_CRYPTO_OP_TYPE_SYMMETRIC
Definition
rte_crypto.h:31
RTE_CRYPTO_OP_TYPE_UNDEFINED
@ RTE_CRYPTO_OP_TYPE_UNDEFINED
Definition
rte_crypto.h:29
rte_crypto_sym_op_alloc_from_mbuf_priv_data
static struct rte_crypto_op * rte_crypto_sym_op_alloc_from_mbuf_priv_data(struct rte_mbuf *m)
Definition
rte_crypto.h:416
__rte_crypto_op_reset
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
rte_crypto_op_status
Definition
rte_crypto.h:38
RTE_CRYPTO_OP_STATUS_AUTH_FAILED
@ RTE_CRYPTO_OP_STATUS_AUTH_FAILED
Definition
rte_crypto.h:43
RTE_CRYPTO_OP_STATUS_INVALID_SESSION
@ RTE_CRYPTO_OP_STATUS_INVALID_SESSION
Definition
rte_crypto.h:45
RTE_CRYPTO_OP_STATUS_SUCCESS
@ RTE_CRYPTO_OP_STATUS_SUCCESS
Definition
rte_crypto.h:39
RTE_CRYPTO_OP_STATUS_ERROR
@ RTE_CRYPTO_OP_STATUS_ERROR
Definition
rte_crypto.h:52
RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
@ RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
Definition
rte_crypto.h:41
RTE_CRYPTO_OP_STATUS_INVALID_ARGS
@ RTE_CRYPTO_OP_STATUS_INVALID_ARGS
Definition
rte_crypto.h:50
rte_crypto_asym.h
rte_crypto_sym.h
rte_mbuf.h
rte_memory.h
rte_mempool.h
rte_crypto_asym_op
Definition
rte_crypto_asym.h:1096
rte_crypto_op_pool_private
Definition
rte_crypto.h:218
rte_crypto_op_pool_private::priv_size
uint16_t priv_size
Definition
rte_crypto.h:221
rte_crypto_op_pool_private::type
enum rte_crypto_op_type type
Definition
rte_crypto.h:219
rte_crypto_op
Definition
rte_crypto.h:91
rte_crypto_op::mempool
struct rte_mempool * mempool
Definition
rte_crypto.h:163
rte_crypto_op::phys_addr
rte_iova_t phys_addr
Definition
rte_crypto.h:166
rte_crypto_sym_op
Definition
rte_crypto_sym.h:628
rte_crypto_sym_xform
Definition
rte_crypto_sym.h:581
rte_mbuf
Definition
rte_mbuf_core.h:475
rte_mbuf::priv_size
uint16_t priv_size
Definition
rte_mbuf_core.h:683
rte_mempool
Definition
rte_mempool.h:230
rte_mempool::socket_id
int socket_id
Definition
rte_mempool.h:239
rte_mempool::name
char name[RTE_MEMPOOL_NAMESIZE]
Definition
rte_mempool.h:231
rte_mempool::cache_size
uint32_t cache_size
Definition
rte_mempool.h:241
lib
cryptodev
rte_crypto.h
Generated by
1.18.0