Branch data Line data Source code
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 : :
8 : : /**
9 : : * @file rte_crypto_sym.h
10 : : *
11 : : * RTE Definitions for Symmetric Cryptography
12 : : *
13 : : * Defines symmetric cipher and authentication algorithms and modes, as well
14 : : * as supported symmetric crypto operation combinations.
15 : : */
16 : :
17 : : #include <string.h>
18 : :
19 : : #include <rte_compat.h>
20 : : #include <rte_mbuf.h>
21 : : #include <rte_memory.h>
22 : : #include <rte_mempool.h>
23 : : #include <rte_common.h>
24 : :
25 : : #ifdef __cplusplus
26 : : extern "C" {
27 : : #endif
28 : :
29 : : /**
30 : : * Crypto IO Vector (in analogy with struct iovec)
31 : : * Supposed be used to pass input/output data buffers for crypto data-path
32 : : * functions.
33 : : */
34 : : struct rte_crypto_vec {
35 : : /** virtual address of the data buffer */
36 : : void *base;
37 : : /** IOVA of the data buffer */
38 : : rte_iova_t iova;
39 : : /** length of the data buffer */
40 : : uint32_t len;
41 : : /** total buffer length */
42 : : uint32_t tot_len;
43 : : };
44 : :
45 : : /**
46 : : * Crypto scatter-gather list descriptor. Consists of a pointer to an array
47 : : * of Crypto IO vectors with its size.
48 : : */
49 : : struct rte_crypto_sgl {
50 : : /** start of an array of vectors */
51 : : struct rte_crypto_vec *vec;
52 : : /** size of an array of vectors */
53 : : uint32_t num;
54 : : };
55 : :
56 : : /**
57 : : * Crypto virtual and IOVA address descriptor, used to describe cryptographic
58 : : * data buffer without the length information. The length information is
59 : : * normally predefined during session creation.
60 : : */
61 : : struct rte_crypto_va_iova_ptr {
62 : : void *va;
63 : : rte_iova_t iova;
64 : : };
65 : :
66 : : /**
67 : : * Raw data operation descriptor.
68 : : * Supposed to be used with synchronous CPU crypto API call or asynchronous
69 : : * RAW data path API call.
70 : : */
71 : : struct rte_crypto_sym_vec {
72 : : /** number of operations to perform */
73 : : uint32_t num;
74 : : /** array of SGL vectors */
75 : : struct rte_crypto_sgl *src_sgl;
76 : : /** array of SGL vectors for OOP, keep it NULL for inplace*/
77 : : struct rte_crypto_sgl *dest_sgl;
78 : : /** array of pointers to cipher IV */
79 : : struct rte_crypto_va_iova_ptr *iv;
80 : : /** array of pointers to digest */
81 : : struct rte_crypto_va_iova_ptr *digest;
82 : :
83 : : __extension__
84 : : union {
85 : : /** array of pointers to auth IV, used for chain operation */
86 : : struct rte_crypto_va_iova_ptr *auth_iv;
87 : : /** array of pointers to AAD, used for AEAD operation */
88 : : struct rte_crypto_va_iova_ptr *aad;
89 : : };
90 : :
91 : : /**
92 : : * array of statuses for each operation:
93 : : * - 0 on success
94 : : * - errno on error
95 : : */
96 : : int32_t *status;
97 : : };
98 : :
99 : : /**
100 : : * used for cpu_crypto_process_bulk() to specify head/tail offsets
101 : : * for auth/cipher processing.
102 : : */
103 : : union rte_crypto_sym_ofs {
104 : : uint64_t raw;
105 : : struct {
106 : : struct {
107 : : uint16_t head;
108 : : uint16_t tail;
109 : : } auth, cipher;
110 : : } ofs;
111 : : };
112 : :
113 : : /** Symmetric Cipher Algorithms
114 : : *
115 : : * Note, to avoid ABI breakage across releases
116 : : * - LIST_END should not be added to this enum
117 : : * - the order of enums should not be changed
118 : : * - new algorithms should only be added to the end
119 : : */
120 : : enum rte_crypto_cipher_algorithm {
121 : : RTE_CRYPTO_CIPHER_NULL = 1,
122 : : /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
123 : :
124 : : RTE_CRYPTO_CIPHER_3DES_CBC,
125 : : /**< Triple DES algorithm in CBC mode */
126 : : RTE_CRYPTO_CIPHER_3DES_CTR,
127 : : /**< Triple DES algorithm in CTR mode */
128 : : RTE_CRYPTO_CIPHER_3DES_ECB,
129 : : /**< Triple DES algorithm in ECB mode */
130 : :
131 : : RTE_CRYPTO_CIPHER_AES_CBC,
132 : : /**< AES algorithm in CBC mode */
133 : : RTE_CRYPTO_CIPHER_AES_CTR,
134 : : /**< AES algorithm in Counter mode */
135 : : RTE_CRYPTO_CIPHER_AES_ECB,
136 : : /**< AES algorithm in ECB mode */
137 : : RTE_CRYPTO_CIPHER_AES_F8,
138 : : /**< AES algorithm in F8 mode */
139 : : RTE_CRYPTO_CIPHER_AES_XTS,
140 : : /**< AES algorithm in XTS mode */
141 : :
142 : : RTE_CRYPTO_CIPHER_ARC4,
143 : : /**< (A)RC4 cipher algorithm */
144 : :
145 : : RTE_CRYPTO_CIPHER_KASUMI_F8,
146 : : /**< KASUMI algorithm in F8 mode */
147 : :
148 : : RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
149 : : /**< SNOW 3G algorithm in UEA2 mode */
150 : :
151 : : RTE_CRYPTO_CIPHER_ZUC_EEA3,
152 : : /**< ZUC algorithm in EEA3 mode */
153 : :
154 : : RTE_CRYPTO_CIPHER_DES_CBC,
155 : : /**< DES algorithm in CBC mode */
156 : :
157 : : RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
158 : : /**< AES algorithm using modes required by
159 : : * DOCSIS Baseline Privacy Plus Spec.
160 : : * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
161 : : * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
162 : : */
163 : :
164 : : RTE_CRYPTO_CIPHER_DES_DOCSISBPI,
165 : : /**< DES algorithm using modes required by
166 : : * DOCSIS Baseline Privacy Plus Spec.
167 : : * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
168 : : * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
169 : : */
170 : :
171 : : RTE_CRYPTO_CIPHER_SM4_ECB,
172 : : /**< ShangMi 4 (SM4) algorithm in ECB mode */
173 : : RTE_CRYPTO_CIPHER_SM4_CBC,
174 : : /**< ShangMi 4 (SM4) algorithm in CBC mode */
175 : : RTE_CRYPTO_CIPHER_SM4_CTR,
176 : : /**< ShangMi 4 (SM4) algorithm in CTR mode */
177 : : RTE_CRYPTO_CIPHER_SM4_OFB,
178 : : /**< ShangMi 4 (SM4) algorithm in OFB mode */
179 : : RTE_CRYPTO_CIPHER_SM4_CFB,
180 : : /**< ShangMi 4 (SM4) algorithm in CFB mode */
181 : : RTE_CRYPTO_CIPHER_SM4_XTS
182 : : /**< ShangMi 4 (SM4) algorithm in XTS mode */
183 : : };
184 : :
185 : : /** Symmetric Cipher Direction */
186 : : enum rte_crypto_cipher_operation {
187 : : RTE_CRYPTO_CIPHER_OP_ENCRYPT,
188 : : /**< Encrypt cipher operation */
189 : : RTE_CRYPTO_CIPHER_OP_DECRYPT
190 : : /**< Decrypt cipher operation */
191 : : };
192 : :
193 : : /** Cipher operation name strings */
194 : : extern const char *
195 : : rte_crypto_cipher_operation_strings[];
196 : :
197 : : /**
198 : : * Symmetric Cipher Setup Data.
199 : : *
200 : : * This structure contains data relating to Cipher (Encryption and Decryption)
201 : : * use to create a session.
202 : : */
203 : : struct rte_crypto_cipher_xform {
204 : : enum rte_crypto_cipher_operation op;
205 : : /**< This parameter determines if the cipher operation is an encrypt or
206 : : * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
207 : : * only encrypt operations are valid.
208 : : */
209 : : enum rte_crypto_cipher_algorithm algo;
210 : : /**< Cipher algorithm */
211 : :
212 : : struct {
213 : : const uint8_t *data; /**< pointer to key data */
214 : : uint16_t length; /**< key length in bytes */
215 : : } key;
216 : : /**< Cipher key
217 : : *
218 : : * In case the PMD supports RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY, the
219 : : * original key data provided may be wrapped(encrypted) using key wrap
220 : : * algorithm such as AES key wrap (rfc3394) and hence length of the key
221 : : * may increase beyond the PMD advertised supported key size.
222 : : * PMD shall validate the key length and report EMSGSIZE error while
223 : : * configuring the session and application can skip checking the
224 : : * capability key length in such cases.
225 : : *
226 : : * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
227 : : * point to a concatenation of the AES encryption key followed by a
228 : : * keymask. As per RFC3711, the keymask should be padded with trailing
229 : : * bytes to match the length of the encryption key used.
230 : : *
231 : : * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
232 : : * 192 bits (24 bytes) or 256 bits (32 bytes).
233 : : *
234 : : * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
235 : : * should be set to the combined length of the encryption key and the
236 : : * keymask. Since the keymask and the encryption key are the same size,
237 : : * key.length should be set to 2 x the AES encryption key length.
238 : : *
239 : : * For the AES-XTS mode of operation:
240 : : * - Two keys must be provided and key.length refers to total length of
241 : : * the two keys.
242 : : * - key.data must point to the two keys concatenated together
243 : : * (key1 || key2).
244 : : * - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
245 : : * - Both keys must have the same size.
246 : : */
247 : : struct {
248 : : uint16_t offset;
249 : : /**< Starting point for Initialisation Vector or Counter,
250 : : * specified as number of bytes from start of crypto
251 : : * operation (rte_crypto_op).
252 : : *
253 : : * - For block ciphers in CBC or F8 mode, or for KASUMI
254 : : * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
255 : : * Initialisation Vector (IV) value.
256 : : *
257 : : * - For block ciphers in CTR mode, this is the counter.
258 : : *
259 : : * - For CCM mode, the first byte is reserved, and the
260 : : * nonce should be written starting at &iv[1] (to allow
261 : : * space for the implementation to write in the flags
262 : : * in the first byte). Note that a full 16 bytes should
263 : : * be allocated, even though the length field will
264 : : * have a value less than this. Note that the PMDs may
265 : : * modify the memory reserved (the first byte and the
266 : : * final padding)
267 : : *
268 : : * - For AES-XTS, this is the 128bit tweak, i, from
269 : : * IEEE Std 1619-2007.
270 : : *
271 : : * For optimum performance, the data pointed to SHOULD
272 : : * be 8-byte aligned.
273 : : */
274 : : uint16_t length;
275 : : /**< Length of valid IV data.
276 : : *
277 : : * - For block ciphers in CBC or F8 mode, or for KASUMI
278 : : * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
279 : : * length of the IV (which must be the same as the
280 : : * block length of the cipher).
281 : : *
282 : : * - For block ciphers in CTR mode, this is the length
283 : : * of the counter (which must be the same as the block
284 : : * length of the cipher) or a 12-byte nonce (AES only)
285 : : *
286 : : * - For CCM mode, this is the length of the nonce,
287 : : * which can be in the range 7 to 13 inclusive.
288 : : */
289 : : } iv; /**< Initialisation vector parameters */
290 : :
291 : : uint32_t dataunit_len;
292 : : /**< When RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS is enabled,
293 : : * this is the data-unit length of the algorithm,
294 : : * otherwise or when the value is 0, use the operation length.
295 : : * The value should be in the range defined by the dataunit_set field
296 : : * in the cipher capability.
297 : : *
298 : : * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
299 : : * For-each data-unit in the operation, the tweak (IV) value is
300 : : * assigned consecutively starting from the operation assigned IV.
301 : : */
302 : : };
303 : :
304 : : /** Symmetric Authentication / Hash Algorithms
305 : : *
306 : : * Note, to avoid ABI breakage across releases
307 : : * - LIST_END should not be added to this enum
308 : : * - the order of enums should not be changed
309 : : * - new algorithms should only be added to the end
310 : : */
311 : : enum rte_crypto_auth_algorithm {
312 : : RTE_CRYPTO_AUTH_NULL = 1,
313 : : /**< NULL hash algorithm. */
314 : :
315 : : RTE_CRYPTO_AUTH_AES_CBC_MAC,
316 : : /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
317 : : RTE_CRYPTO_AUTH_AES_CMAC,
318 : : /**< AES CMAC algorithm. */
319 : : RTE_CRYPTO_AUTH_AES_GMAC,
320 : : /**< AES GMAC algorithm. */
321 : : RTE_CRYPTO_AUTH_AES_XCBC_MAC,
322 : : /**< AES XCBC algorithm. */
323 : :
324 : : RTE_CRYPTO_AUTH_KASUMI_F9,
325 : : /**< KASUMI algorithm in F9 mode. */
326 : :
327 : : RTE_CRYPTO_AUTH_MD5,
328 : : /**< MD5 algorithm */
329 : : RTE_CRYPTO_AUTH_MD5_HMAC,
330 : : /**< HMAC using MD5 algorithm */
331 : :
332 : : RTE_CRYPTO_AUTH_SHA1,
333 : : /**< 160 bit SHA algorithm. */
334 : : RTE_CRYPTO_AUTH_SHA1_HMAC,
335 : : /**< HMAC using 160 bit SHA algorithm.
336 : : * HMAC-SHA-1-96 can be generated by setting
337 : : * digest_length to 12 bytes in auth/aead xforms.
338 : : */
339 : : RTE_CRYPTO_AUTH_SHA224,
340 : : /**< 224 bit SHA algorithm. */
341 : : RTE_CRYPTO_AUTH_SHA224_HMAC,
342 : : /**< HMAC using 224 bit SHA algorithm. */
343 : : RTE_CRYPTO_AUTH_SHA256,
344 : : /**< 256 bit SHA algorithm. */
345 : : RTE_CRYPTO_AUTH_SHA256_HMAC,
346 : : /**< HMAC using 256 bit SHA algorithm. */
347 : : RTE_CRYPTO_AUTH_SHA384,
348 : : /**< 384 bit SHA algorithm. */
349 : : RTE_CRYPTO_AUTH_SHA384_HMAC,
350 : : /**< HMAC using 384 bit SHA algorithm. */
351 : : RTE_CRYPTO_AUTH_SHA512,
352 : : /**< 512 bit SHA algorithm. */
353 : : RTE_CRYPTO_AUTH_SHA512_HMAC,
354 : : /**< HMAC using 512 bit SHA algorithm. */
355 : :
356 : : RTE_CRYPTO_AUTH_SNOW3G_UIA2,
357 : : /**< SNOW 3G algorithm in UIA2 mode. */
358 : :
359 : : RTE_CRYPTO_AUTH_ZUC_EIA3,
360 : : /**< ZUC algorithm in EIA3 mode */
361 : :
362 : : RTE_CRYPTO_AUTH_SHA3_224,
363 : : /**< 224 bit SHA3 algorithm. */
364 : : RTE_CRYPTO_AUTH_SHA3_224_HMAC,
365 : : /**< HMAC using 224 bit SHA3 algorithm. */
366 : : RTE_CRYPTO_AUTH_SHA3_256,
367 : : /**< 256 bit SHA3 algorithm. */
368 : : RTE_CRYPTO_AUTH_SHA3_256_HMAC,
369 : : /**< HMAC using 256 bit SHA3 algorithm. */
370 : : RTE_CRYPTO_AUTH_SHA3_384,
371 : : /**< 384 bit SHA3 algorithm. */
372 : : RTE_CRYPTO_AUTH_SHA3_384_HMAC,
373 : : /**< HMAC using 384 bit SHA3 algorithm. */
374 : : RTE_CRYPTO_AUTH_SHA3_512,
375 : : /**< 512 bit SHA3 algorithm. */
376 : : RTE_CRYPTO_AUTH_SHA3_512_HMAC,
377 : : /**< HMAC using 512 bit SHA3 algorithm. */
378 : : RTE_CRYPTO_AUTH_SM3,
379 : : /**< ShangMi 3 (SM3) algorithm */
380 : :
381 : : RTE_CRYPTO_AUTH_SHAKE_128,
382 : : /**< 128 bit SHAKE algorithm. */
383 : : RTE_CRYPTO_AUTH_SHAKE_256,
384 : : /**< 256 bit SHAKE algorithm. */
385 : : RTE_CRYPTO_AUTH_SM3_HMAC,
386 : : /** < HMAC using ShangMi 3 (SM3) algorithm */
387 : : };
388 : :
389 : : /** Symmetric Authentication / Hash Operations */
390 : : enum rte_crypto_auth_operation {
391 : : RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */
392 : : RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */
393 : : };
394 : :
395 : : /** Authentication operation name strings */
396 : : extern const char *
397 : : rte_crypto_auth_operation_strings[];
398 : :
399 : : /**
400 : : * Authentication / Hash transform data.
401 : : *
402 : : * This structure contains data relating to an authentication/hash crypto
403 : : * transforms. The fields op, algo and digest_length are common to all
404 : : * authentication transforms and MUST be set.
405 : : */
406 : : struct rte_crypto_auth_xform {
407 : : enum rte_crypto_auth_operation op;
408 : : /**< Authentication operation type */
409 : : enum rte_crypto_auth_algorithm algo;
410 : : /**< Authentication algorithm selection */
411 : :
412 : : struct {
413 : : const uint8_t *data; /**< pointer to key data */
414 : : uint16_t length; /**< key length in bytes */
415 : : } key;
416 : : /**< Authentication key data.
417 : : * The authentication key length MUST be less than or equal to the
418 : : * block size of the algorithm. It is the callers responsibility to
419 : : * ensure that the key length is compliant with the standard being used
420 : : * (for example RFC 2104, FIPS 198a).
421 : : */
422 : :
423 : : struct {
424 : : uint16_t offset;
425 : : /**< Starting point for Initialisation Vector or Counter,
426 : : * specified as number of bytes from start of crypto
427 : : * operation (rte_crypto_op).
428 : : *
429 : : * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode
430 : : * this is the authentication Initialisation Vector
431 : : * (IV) value. For AES-GMAC IV description please refer
432 : : * to the field `length` in iv struct.
433 : : *
434 : : * - For KASUMI in F9 mode and other authentication
435 : : * algorithms, this field is not used.
436 : : *
437 : : * For optimum performance, the data pointed to SHOULD
438 : : * be 8-byte aligned.
439 : : */
440 : : uint16_t length;
441 : : /**< Length of valid IV data.
442 : : *
443 : : * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and
444 : : * for AES-GMAC, this is the length of the IV.
445 : : *
446 : : * - For KASUMI in F9 mode and other authentication
447 : : * algorithms, this field is not used.
448 : : *
449 : : * - For GMAC mode, this is either:
450 : : * 1) Number greater or equal to one, which means that IV
451 : : * is used and J0 will be computed internally, a minimum
452 : : * of 16 bytes must be allocated.
453 : : * 2) Zero, in which case data points to J0. In this case
454 : : * 16 bytes of J0 should be passed where J0 is defined
455 : : * by NIST SP800-38D.
456 : : *
457 : : */
458 : : } iv; /**< Initialisation vector parameters */
459 : :
460 : : uint16_t digest_length;
461 : : /**< Length of the digest to be returned. If the verify option is set,
462 : : * this specifies the length of the digest to be compared for the
463 : : * session.
464 : : *
465 : : * It is the caller's responsibility to ensure that the
466 : : * digest length is compliant with the hash algorithm being used.
467 : : * If the value is less than the maximum length allowed by the hash,
468 : : * the result shall be truncated.
469 : : */
470 : : };
471 : :
472 : :
473 : : /** Symmetric AEAD Algorithms
474 : : *
475 : : * Note, to avoid ABI breakage across releases
476 : : * - LIST_END should not be added to this enum
477 : : * - the order of enums should not be changed
478 : : * - new algorithms should only be added to the end
479 : : */
480 : : enum rte_crypto_aead_algorithm {
481 : : RTE_CRYPTO_AEAD_AES_CCM = 1,
482 : : /**< AES algorithm in CCM mode. */
483 : : RTE_CRYPTO_AEAD_AES_GCM,
484 : : /**< AES algorithm in GCM mode. */
485 : : RTE_CRYPTO_AEAD_CHACHA20_POLY1305,
486 : : /**< Chacha20 cipher with poly1305 authenticator */
487 : : RTE_CRYPTO_AEAD_SM4_GCM,
488 : : /**< SM4 cipher in GCM mode */
489 : : };
490 : :
491 : : /** Symmetric AEAD Operations */
492 : : enum rte_crypto_aead_operation {
493 : : RTE_CRYPTO_AEAD_OP_ENCRYPT,
494 : : /**< Encrypt and generate digest */
495 : : RTE_CRYPTO_AEAD_OP_DECRYPT
496 : : /**< Verify digest and decrypt */
497 : : };
498 : :
499 : : /** Authentication operation name strings */
500 : : extern const char *
501 : : rte_crypto_aead_operation_strings[];
502 : :
503 : : struct rte_crypto_aead_xform {
504 : : enum rte_crypto_aead_operation op;
505 : : /**< AEAD operation type */
506 : : enum rte_crypto_aead_algorithm algo;
507 : : /**< AEAD algorithm selection */
508 : :
509 : : struct {
510 : : const uint8_t *data; /**< pointer to key data */
511 : : uint16_t length; /**< key length in bytes */
512 : : } key;
513 : :
514 : : struct {
515 : : uint16_t offset;
516 : : /**< Starting point for Initialisation Vector or Counter,
517 : : * specified as number of bytes from start of crypto
518 : : * operation (rte_crypto_op).
519 : : *
520 : : * - For CCM mode, the first byte is reserved, and the
521 : : * nonce should be written starting at &iv[1] (to allow
522 : : * space for the implementation to write in the flags
523 : : * in the first byte). Note that a full 16 bytes should
524 : : * be allocated, even though the length field will
525 : : * have a value less than this.
526 : : *
527 : : * - For Chacha20-Poly1305 it is 96-bit nonce.
528 : : * PMD sets initial counter for Poly1305 key generation
529 : : * part to 0 and for Chacha20 encryption to 1 as per
530 : : * rfc8439 2.8. AEAD construction.
531 : : *
532 : : * For optimum performance, the data pointed to SHOULD
533 : : * be 8-byte aligned.
534 : : */
535 : : uint16_t length;
536 : : /**< Length of valid IV data.
537 : : *
538 : : * - For GCM mode, this is either:
539 : : * 1) Number greater or equal to one, which means that IV
540 : : * is used and J0 will be computed internally, a minimum
541 : : * of 16 bytes must be allocated.
542 : : * 2) Zero, in which case data points to J0. In this case
543 : : * 16 bytes of J0 should be passed where J0 is defined
544 : : * by NIST SP800-38D.
545 : : *
546 : : * - For CCM mode, this is the length of the nonce,
547 : : * which can be in the range 7 to 13 inclusive.
548 : : *
549 : : * - For Chacha20-Poly1305 this field is always 12.
550 : : */
551 : : } iv; /**< Initialisation vector parameters */
552 : :
553 : : uint16_t digest_length;
554 : :
555 : : uint16_t aad_length;
556 : : /**< The length of the additional authenticated data (AAD) in bytes.
557 : : * For CCM mode, this is the length of the actual AAD, even though
558 : : * it is required to reserve 18 bytes before the AAD and padding
559 : : * at the end of it, so a multiple of 16 bytes is allocated.
560 : : */
561 : : };
562 : :
563 : : /** Crypto transformation types */
564 : : enum rte_crypto_sym_xform_type {
565 : : RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
566 : : RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */
567 : : RTE_CRYPTO_SYM_XFORM_CIPHER, /**< Cipher xform */
568 : : RTE_CRYPTO_SYM_XFORM_AEAD /**< AEAD xform */
569 : : };
570 : :
571 : : /**
572 : : * Symmetric crypto transform structure.
573 : : *
574 : : * This is used to specify the crypto transforms required, multiple transforms
575 : : * can be chained together to specify a chain transforms such as authentication
576 : : * then cipher, or cipher then authentication. Each transform structure can
577 : : * hold a single transform, the type field is used to specify which transform
578 : : * is contained within the union
579 : : */
580 : : /* Structure rte_crypto_sym_xform 8< */
581 : : struct rte_crypto_sym_xform {
582 : : struct rte_crypto_sym_xform *next;
583 : : /**< next xform in chain */
584 : : enum rte_crypto_sym_xform_type type
585 : : ; /**< xform type */
586 : : union {
587 : : struct rte_crypto_auth_xform auth;
588 : : /**< Authentication / hash xform */
589 : : struct rte_crypto_cipher_xform cipher;
590 : : /**< Cipher xform */
591 : : struct rte_crypto_aead_xform aead;
592 : : /**< AEAD xform */
593 : : };
594 : : };
595 : : /* >8 End of structure rte_crypto_sym_xform. */
596 : :
597 : : /**
598 : : * Symmetric Cryptographic Operation.
599 : : *
600 : : * This structure contains data relating to performing symmetric cryptographic
601 : : * processing on a referenced mbuf data buffer.
602 : : *
603 : : * When a symmetric crypto operation is enqueued with the device for processing
604 : : * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
605 : : * which contains the source data which the crypto operation is to be performed
606 : : * on.
607 : : * While the mbuf is in use by a crypto operation no part of the mbuf should be
608 : : * changed by the application as the device may read or write to any part of the
609 : : * mbuf. In the case of hardware crypto devices some or all of the mbuf
610 : : * may be DMAed in and out of the device, so writing over the original data,
611 : : * though only the part specified by the rte_crypto_sym_op for transformation
612 : : * will be changed.
613 : : * Out-of-place (OOP) operation, where the source mbuf is different to the
614 : : * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
615 : : * The part copied includes all the parts of the source mbuf that will be
616 : : * operated on, based on the cipher.data.offset+cipher.data.length and
617 : : * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
618 : : * indicated by the cipher parameters will be transformed, any extra data around
619 : : * this indicated by the auth parameters will be copied unchanged from source to
620 : : * destination mbuf.
621 : : * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
622 : : * both source and destination mbufs. As these offsets are relative to the
623 : : * data_off parameter in each mbuf this can result in the data written to the
624 : : * destination buffer being at a different alignment, relative to buffer start,
625 : : * to the data in the source buffer.
626 : : */
627 : : /* Structure rte_crypto_sym_op 8< */
628 : : struct rte_crypto_sym_op {
629 : : struct rte_mbuf *m_src; /**< source mbuf */
630 : : struct rte_mbuf *m_dst; /**< destination mbuf */
631 : :
632 : : union {
633 : : void *session;
634 : : /**< Handle for the initialised crypto/security session context */
635 : : struct rte_crypto_sym_xform *xform;
636 : : /**< Session-less API crypto operation parameters */
637 : : };
638 : :
639 : : union {
640 : : struct {
641 : : struct {
642 : : uint32_t offset;
643 : : /**< Starting point for AEAD processing, specified as
644 : : * number of bytes from start of packet in source
645 : : * buffer.
646 : : */
647 : : uint32_t length;
648 : : /**< The message length, in bytes, of the source buffer
649 : : * on which the cryptographic operation will be
650 : : * computed.
651 : : */
652 : : } data; /**< Data offsets and length for AEAD */
653 : : struct {
654 : : uint8_t *data;
655 : : /**< This points to the location where the digest result
656 : : * should be inserted (in the case of digest generation)
657 : : * or where the purported digest exists (in the case of
658 : : * digest verification).
659 : : *
660 : : * At session creation time, the client specified the
661 : : * digest result length with the digest_length member
662 : : * of the @ref rte_crypto_auth_xform structure. For
663 : : * physical crypto devices the caller must allocate at
664 : : * least digest_length of physically contiguous memory
665 : : * at this location.
666 : : *
667 : : * For digest generation, the digest result will
668 : : * overwrite any data at this location.
669 : : *
670 : : * @note
671 : : * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for
672 : : * "digest result" read "authentication tag T".
673 : : */
674 : : rte_iova_t phys_addr;
675 : : /**< Physical address of digest */
676 : : } digest; /**< Digest parameters */
677 : : struct {
678 : : uint8_t *data;
679 : : /**< Pointer to Additional Authenticated Data (AAD)
680 : : * needed for authenticated cipher mechanisms (CCM and
681 : : * GCM)
682 : : *
683 : : * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM),
684 : : * the caller should setup this field as follows:
685 : : *
686 : : * - the additional authentication data itself should
687 : : * be written starting at an offset of 18 bytes into
688 : : * the array, leaving room for the first block (16 bytes)
689 : : * and the length encoding in the first two bytes of the
690 : : * second block.
691 : : *
692 : : * - Note that PMDs may modify the memory reserved
693 : : * (first 18 bytes and the final padding).
694 : : *
695 : : * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the
696 : : * caller should setup this field as follows:
697 : : *
698 : : */
699 : : rte_iova_t phys_addr; /**< physical address */
700 : : } aad;
701 : : /**< Additional authentication parameters */
702 : : } aead;
703 : :
704 : : struct {
705 : : struct {
706 : : struct {
707 : : uint32_t offset;
708 : : /**< Starting point for cipher processing,
709 : : * specified as number of bytes from start
710 : : * of data in the source buffer.
711 : : * The result of the cipher operation will be
712 : : * written back into the output buffer
713 : : * starting at this location.
714 : : *
715 : : * @note
716 : : * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
717 : : * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
718 : : * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
719 : : * this field should be in bits. For
720 : : * digest-encrypted cases this must be
721 : : * an 8-bit multiple.
722 : : */
723 : : uint32_t length;
724 : : /**< The message length, in bytes, of the
725 : : * source buffer on which the cryptographic
726 : : * operation will be computed.
727 : : * This is also the same as the result length.
728 : : * For block ciphers, this must be a
729 : : * multiple of the block size,
730 : : * or for the AES-XTS a multiple of the data-unit length
731 : : * as described in xform.
732 : : *
733 : : * @note
734 : : * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
735 : : * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
736 : : * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
737 : : * this field should be in bits. For
738 : : * digest-encrypted cases this must be
739 : : * an 8-bit multiple.
740 : : */
741 : : } data; /**< Data offsets and length for ciphering */
742 : : } cipher;
743 : :
744 : : struct {
745 : : struct {
746 : : uint32_t offset;
747 : : /**< Starting point for hash processing,
748 : : * specified as number of bytes from start of
749 : : * packet in source buffer.
750 : : *
751 : : * @note
752 : : * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
753 : : * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
754 : : * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
755 : : * this field should be in bits. For
756 : : * digest-encrypted cases this must be
757 : : * an 8-bit multiple.
758 : : *
759 : : * @note
760 : : * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
761 : : * this offset should be such that
762 : : * data to authenticate starts at COUNT.
763 : : *
764 : : * @note
765 : : * For DOCSIS security protocol, this
766 : : * offset is the DOCSIS header length
767 : : * and, therefore, also the CRC offset
768 : : * i.e. the number of bytes into the
769 : : * packet at which CRC calculation
770 : : * should begin.
771 : : */
772 : : uint32_t length;
773 : : /**< The message length, in bytes, of the source
774 : : * buffer that the hash will be computed on.
775 : : *
776 : : * @note
777 : : * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
778 : : * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
779 : : * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
780 : : * this field should be in bits. For
781 : : * digest-encrypted cases this must be
782 : : * an 8-bit multiple.
783 : : *
784 : : * @note
785 : : * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
786 : : * the length should include the COUNT,
787 : : * FRESH, message, direction bit and padding
788 : : * (to be multiple of 8 bits).
789 : : *
790 : : * @note
791 : : * For DOCSIS security protocol, this
792 : : * is the CRC length i.e. the number of
793 : : * bytes in the packet over which the
794 : : * CRC should be calculated
795 : : */
796 : : } data;
797 : : /**< Data offsets and length for authentication */
798 : :
799 : : struct {
800 : : uint8_t *data;
801 : : /**< This points to the location where
802 : : * the digest result should be inserted
803 : : * (in the case of digest generation)
804 : : * or where the purported digest exists
805 : : * (in the case of digest verification).
806 : : *
807 : : * At session creation time, the client
808 : : * specified the digest result length with
809 : : * the digest_length member of the
810 : : * @ref rte_crypto_auth_xform structure.
811 : : * For physical crypto devices the caller
812 : : * must allocate at least digest_length of
813 : : * physically contiguous memory at this
814 : : * location.
815 : : *
816 : : * For digest generation, the digest result
817 : : * will overwrite any data at this location.
818 : : *
819 : : * @note
820 : : * Digest-encrypted case.
821 : : * Digest can be generated, appended to
822 : : * the end of raw data and encrypted
823 : : * together using chained digest
824 : : * generation
825 : : * (@ref RTE_CRYPTO_AUTH_OP_GENERATE)
826 : : * and encryption
827 : : * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT)
828 : : * xforms. Similarly, authentication
829 : : * of the raw data against appended,
830 : : * decrypted digest, can be performed
831 : : * using decryption
832 : : * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT)
833 : : * and digest verification
834 : : * (@ref RTE_CRYPTO_AUTH_OP_VERIFY)
835 : : * chained xforms.
836 : : * To perform those operations, a few
837 : : * additional conditions must be met:
838 : : * - caller must allocate at least
839 : : * digest_length of memory at the end of
840 : : * source and (in case of out-of-place
841 : : * operations) destination buffer; those
842 : : * buffers can be linear or split using
843 : : * scatter-gather lists,
844 : : * - digest data pointer must point to
845 : : * the end of source or (in case of
846 : : * out-of-place operations) destination
847 : : * data, which is pointer to the
848 : : * data buffer + auth.data.offset +
849 : : * auth.data.length,
850 : : * - cipher.data.offset +
851 : : * cipher.data.length must be greater
852 : : * than auth.data.offset +
853 : : * auth.data.length and is typically
854 : : * equal to auth.data.offset +
855 : : * auth.data.length + digest_length.
856 : : * - for wireless algorithms, i.e.
857 : : * SNOW 3G, KASUMI and ZUC, as the
858 : : * cipher.data.length,
859 : : * cipher.data.offset,
860 : : * auth.data.length and
861 : : * auth.data.offset are in bits, they
862 : : * must be 8-bit multiples.
863 : : *
864 : : * Note, that for security reasons, it
865 : : * is PMDs' responsibility to not
866 : : * leave an unencrypted digest in any
867 : : * buffer after performing auth-cipher
868 : : * operations.
869 : : *
870 : : */
871 : : rte_iova_t phys_addr;
872 : : /**< Physical address of digest */
873 : : } digest; /**< Digest parameters */
874 : : } auth;
875 : : };
876 : : };
877 : : };
878 : : /* >8 End of structure rte_crypto_sym_op. */
879 : :
880 : :
881 : : /**
882 : : * Reset the fields of a symmetric operation to their default values.
883 : : *
884 : : * @param op The crypto operation to be reset.
885 : : */
886 : : static inline void
887 : : __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
888 : : {
889 : : memset(op, 0, sizeof(*op));
890 : 8434 : }
891 : :
892 : :
893 : : /**
894 : : * Allocate space for symmetric crypto xforms in the private data space of the
895 : : * crypto operation. This also defaults the crypto xform type to
896 : : * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
897 : : * in the crypto operation
898 : : *
899 : : * @return
900 : : * - On success returns pointer to first crypto xform in crypto operations chain
901 : : * - On failure returns NULL
902 : : */
903 : : static inline struct rte_crypto_sym_xform *
904 : : __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
905 : : void *priv_data, uint8_t nb_xforms)
906 : : {
907 : : struct rte_crypto_sym_xform *xform;
908 : :
909 : 10 : sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
910 : :
911 : : do {
912 : 18 : xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
913 [ + + ]: 18 : xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
914 : : } while (xform);
915 : :
916 : 10 : return sym_op->xform;
917 : : }
918 : :
919 : :
920 : : /**
921 : : * Attach a session to a symmetric crypto operation
922 : : *
923 : : * @param sym_op crypto operation
924 : : * @param sess cryptodev session
925 : : */
926 : : static inline int
927 : : __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, void *sess)
928 : : {
929 : 234 : sym_op->session = sess;
930 : :
931 : : return 0;
932 : : }
933 : :
934 : : /**
935 : : * Converts portion of mbuf data into a vector representation.
936 : : * Each segment will be represented as a separate entry in *vec* array.
937 : : * Expects that provided *ofs* + *len* not to exceed mbuf's *pkt_len*.
938 : : * @param mb
939 : : * Pointer to the *rte_mbuf* object.
940 : : * @param ofs
941 : : * Offset within mbuf data to start with.
942 : : * @param len
943 : : * Length of data to represent.
944 : : * @param vec
945 : : * Pointer to an output array of IO vectors.
946 : : * @param num
947 : : * Size of an output array.
948 : : * @return
949 : : * - number of successfully filled entries in *vec* array.
950 : : * - negative number of elements in *vec* array required.
951 : : */
952 : : __rte_experimental
953 : : static inline int
954 : 0 : rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
955 : : struct rte_crypto_vec vec[], uint32_t num)
956 : : {
957 : : uint32_t i;
958 : : struct rte_mbuf *nseg;
959 : : uint32_t left;
960 : : uint32_t seglen;
961 : :
962 : : /* assuming that requested data starts in the first segment */
963 : : RTE_ASSERT(mb->data_len > ofs);
964 : :
965 [ # # ]: 0 : if (mb->nb_segs > num)
966 : 0 : return -mb->nb_segs;
967 : :
968 [ # # ]: 0 : vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
969 : 0 : vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
970 [ # # ]: 0 : vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
971 : :
972 : : /* whole data lies in the first segment */
973 : 0 : seglen = mb->data_len - ofs;
974 [ # # ]: 0 : if (len <= seglen) {
975 : 0 : vec[0].len = len;
976 : 0 : return 1;
977 : : }
978 : :
979 : : /* data spread across segments */
980 : 0 : vec[0].len = seglen;
981 : 0 : left = len - seglen;
982 [ # # ]: 0 : for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
983 : :
984 [ # # ]: 0 : vec[i].base = rte_pktmbuf_mtod(nseg, void *);
985 : 0 : vec[i].iova = rte_pktmbuf_iova(nseg);
986 [ # # ]: 0 : vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs;
987 : :
988 : 0 : seglen = nseg->data_len;
989 [ # # ]: 0 : if (left <= seglen) {
990 : : /* whole requested data is completed */
991 : 0 : vec[i].len = left;
992 : : left = 0;
993 : 0 : i++;
994 : 0 : break;
995 : : }
996 : :
997 : : /* use whole segment */
998 : 0 : vec[i].len = seglen;
999 : 0 : left -= seglen;
1000 : : }
1001 : :
1002 : : RTE_ASSERT(left == 0);
1003 : 0 : return i;
1004 : : }
1005 : :
1006 : :
1007 : : #ifdef __cplusplus
1008 : : }
1009 : : #endif
1010 : :
1011 : : #endif /* _RTE_CRYPTO_SYM_H_ */
|