DPDK
17.08.2
Main Page
Related Pages
Data Structures
Files
Examples
File List
Globals
lib
librte_cryptodev
rte_crypto.h
Go to the documentation of this file.
1
/*-
2
* BSD LICENSE
3
*
4
* Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
*
10
* * Redistributions of source code must retain the above copyright
11
* notice, this list of conditions and the following disclaimer.
12
* * Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in
14
* the documentation and/or other materials provided with the
15
* distribution.
16
* * Neither the name of Intel Corporation nor the names of its
17
* contributors may be used to endorse or promote products derived
18
* from this software without specific prior written permission.
19
*
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
*/
32
33
#ifndef _RTE_CRYPTO_H_
34
#define _RTE_CRYPTO_H_
35
43
#ifdef __cplusplus
44
extern
"C"
{
45
#endif
46
47
48
#include <
rte_mbuf.h
>
49
#include <
rte_memory.h
>
50
#include <
rte_mempool.h
>
51
#include <
rte_common.h
>
52
53
#include "
rte_crypto_sym.h
"
54
56
enum
rte_crypto_op_type
{
57
RTE_CRYPTO_OP_TYPE_UNDEFINED
,
59
RTE_CRYPTO_OP_TYPE_SYMMETRIC
,
61
};
62
64
enum
rte_crypto_op_status
{
65
RTE_CRYPTO_OP_STATUS_SUCCESS
,
67
RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
,
69
RTE_CRYPTO_OP_STATUS_AUTH_FAILED
,
71
RTE_CRYPTO_OP_STATUS_INVALID_SESSION
,
76
RTE_CRYPTO_OP_STATUS_INVALID_ARGS
,
78
RTE_CRYPTO_OP_STATUS_ERROR
,
80
};
81
87
enum
rte_crypto_op_sess_type
{
88
RTE_CRYPTO_OP_WITH_SESSION
,
89
RTE_CRYPTO_OP_SESSIONLESS
90
};
91
102
struct
rte_crypto_op
{
103
uint8_t
type
;
105
uint8_t
status
;
112
uint8_t
sess_type
;
115
uint8_t
reserved
[5];
117
struct
rte_mempool
*
mempool
;
120
phys_addr_t
phys_addr
;
123
RTE_STD_C11
124
union
{
125
struct
rte_crypto_sym_op
sym
[0];
127
};
128
};
129
136
static
inline
void
137
__rte_crypto_op_reset
(
struct
rte_crypto_op
*op,
enum
rte_crypto_op_type
type)
138
{
139
op->
type
= type;
140
op->
status
=
RTE_CRYPTO_OP_STATUS_NOT_PROCESSED
;
141
op->
sess_type
=
RTE_CRYPTO_OP_SESSIONLESS
;
142
143
switch
(type) {
144
case
RTE_CRYPTO_OP_TYPE_SYMMETRIC
:
145
__rte_crypto_sym_op_reset
(op->
sym
);
146
break
;
147
case
RTE_CRYPTO_OP_TYPE_UNDEFINED
:
148
default
:
149
break
;
150
}
151
}
152
156
struct
rte_crypto_op_pool_private
{
157
enum
rte_crypto_op_type
type
;
159
uint16_t
priv_size
;
161
};
162
163
172
static
inline
uint16_t
173
__rte_crypto_op_get_priv_data_size
(
struct
rte_mempool
*mempool)
174
{
175
struct
rte_crypto_op_pool_private
*priv =
176
(
struct
rte_crypto_op_pool_private
*)
rte_mempool_get_priv
(mempool);
177
178
return
priv->
priv_size
;
179
}
180
181
201
extern
struct
rte_mempool
*
202
rte_crypto_op_pool_create
(
const
char
*
name
,
enum
rte_crypto_op_type
type,
203
unsigned
nb_elts,
unsigned
cache_size
, uint16_t priv_size,
204
int
socket_id
);
205
217
static
inline
int
218
__rte_crypto_op_raw_bulk_alloc
(
struct
rte_mempool
*mempool,
219
enum
rte_crypto_op_type
type,
220
struct
rte_crypto_op
**ops, uint16_t nb_ops)
221
{
222
struct
rte_crypto_op_pool_private
*priv;
223
224
priv = (
struct
rte_crypto_op_pool_private
*)
rte_mempool_get_priv
(mempool);
225
if
(
unlikely
(priv->
type
!= type &&
226
priv->
type
!=
RTE_CRYPTO_OP_TYPE_UNDEFINED
))
227
return
-EINVAL;
228
229
if
(
rte_mempool_get_bulk
(mempool, (
void
**)ops, nb_ops) == 0)
230
return
nb_ops;
231
232
return
0;
233
}
234
245
static
inline
struct
rte_crypto_op
*
246
rte_crypto_op_alloc
(
struct
rte_mempool
*
mempool
,
enum
rte_crypto_op_type
type
)
247
{
248
struct
rte_crypto_op
*op = NULL;
249
int
retval;
250
251
retval =
__rte_crypto_op_raw_bulk_alloc
(mempool, type, &op, 1);
252
if
(
unlikely
(retval != 1))
253
return
NULL;
254
255
__rte_crypto_op_reset
(op, type);
256
257
return
op;
258
}
259
260
275
static
inline
unsigned
276
rte_crypto_op_bulk_alloc
(
struct
rte_mempool
*
mempool
,
277
enum
rte_crypto_op_type
type
,
278
struct
rte_crypto_op
**ops, uint16_t nb_ops)
279
{
280
int
i;
281
282
if
(
unlikely
(
__rte_crypto_op_raw_bulk_alloc
(mempool, type, ops, nb_ops)
283
!= nb_ops))
284
return
0;
285
286
for
(i = 0; i < nb_ops; i++)
287
__rte_crypto_op_reset
(ops[i], type);
288
289
return
nb_ops;
290
}
291
292
293
305
static
inline
void
*
306
__rte_crypto_op_get_priv_data
(
struct
rte_crypto_op
*op, uint32_t size)
307
{
308
uint32_t priv_size;
309
310
if
(
likely
(op->
mempool
!= NULL)) {
311
priv_size =
__rte_crypto_op_get_priv_data_size
(op->
mempool
);
312
313
if
(
likely
(priv_size >= size))
314
return
(
void
*)((uint8_t *)(op + 1) +
315
sizeof
(
struct
rte_crypto_sym_op
));
316
}
317
318
return
NULL;
319
}
320
328
static
inline
void
329
rte_crypto_op_free
(
struct
rte_crypto_op
*op)
330
{
331
if
(op != NULL && op->
mempool
!= NULL)
332
rte_mempool_put
(op->
mempool
, op);
333
}
334
346
static
inline
struct
rte_crypto_op
*
347
rte_crypto_sym_op_alloc_from_mbuf_priv_data
(
struct
rte_mbuf
*m)
348
{
349
if
(
unlikely
(m == NULL))
350
return
NULL;
351
352
/*
353
* check that the mbuf's private data size is sufficient to contain a
354
* crypto operation
355
*/
356
if
(
unlikely
(m->
priv_size
< (
sizeof
(
struct
rte_crypto_op
) +
357
sizeof
(
struct
rte_crypto_sym_op
))))
358
return
NULL;
359
360
/* private data starts immediately after the mbuf header in the mbuf. */
361
struct
rte_crypto_op
*op = (
struct
rte_crypto_op
*)(m + 1);
362
363
__rte_crypto_op_reset
(op,
RTE_CRYPTO_OP_TYPE_SYMMETRIC
);
364
365
op->
mempool
= NULL;
366
op->
sym
->
m_src
= m;
367
368
return
op;
369
}
370
380
static
inline
struct
rte_crypto_sym_xform
*
381
rte_crypto_op_sym_xforms_alloc
(
struct
rte_crypto_op
*op, uint8_t nb_xforms)
382
{
383
void
*priv_data;
384
uint32_t size;
385
386
if
(
unlikely
(op->
type
!=
RTE_CRYPTO_OP_TYPE_SYMMETRIC
))
387
return
NULL;
388
389
size =
sizeof
(
struct
rte_crypto_sym_xform
) * nb_xforms;
390
391
priv_data =
__rte_crypto_op_get_priv_data
(op, size);
392
if
(priv_data == NULL)
393
return
NULL;
394
395
return
__rte_crypto_sym_op_sym_xforms_alloc
(op->
sym
, priv_data,
396
nb_xforms);
397
}
398
399
406
static
inline
int
407
rte_crypto_op_attach_sym_session
(
struct
rte_crypto_op
*op,
408
struct
rte_cryptodev_sym_session
*sess)
409
{
410
if
(
unlikely
(op->
type
!=
RTE_CRYPTO_OP_TYPE_SYMMETRIC
))
411
return
-1;
412
413
op->
sess_type
=
RTE_CRYPTO_OP_WITH_SESSION
;
414
415
return
__rte_crypto_sym_op_attach_sym_session
(op->
sym
, sess);
416
}
417
418
#ifdef __cplusplus
419
}
420
#endif
421
422
#endif
/* _RTE_CRYPTO_H_ */
Generated by
1.8.1.2