4 * Copyright(c) 2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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.
33 #ifndef _RTE_CRYPTO_SYM_H_
34 #define _RTE_CRYPTO_SYM_H_
37 * @file rte_crypto_sym.h
39 * RTE Definitions for Symmetric Cryptography
41 * Defines symmetric cipher and authentication algorithms and modes, as well
42 * as supported symmetric crypto operation combinations.
50 #include <rte_memory.h>
51 #include <rte_mempool.h>
54 /** Symmetric Cipher Algorithms */
55 enum rte_crypto_cipher_algorithm {
56 RTE_CRYPTO_CIPHER_NULL = 1,
57 /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
59 RTE_CRYPTO_CIPHER_3DES_CBC,
60 /**< Triple DES algorithm in CBC mode */
61 RTE_CRYPTO_CIPHER_3DES_CTR,
62 /**< Triple DES algorithm in CTR mode */
63 RTE_CRYPTO_CIPHER_3DES_ECB,
64 /**< Triple DES algorithm in ECB mode */
66 RTE_CRYPTO_CIPHER_AES_CBC,
67 /**< AES algorithm in CBC mode */
68 RTE_CRYPTO_CIPHER_AES_CCM,
69 /**< AES algorithm in CCM mode. When this cipher algorithm is used the
70 * *RTE_CRYPTO_AUTH_AES_CCM* element of the
71 * *rte_crypto_hash_algorithm* enum MUST be used to set up the related
72 * *rte_crypto_auth_xform* structure in the session context or in
73 * the op_params of the crypto operation structure in the case of a
74 * session-less crypto operation
76 RTE_CRYPTO_CIPHER_AES_CTR,
77 /**< AES algorithm in Counter mode */
78 RTE_CRYPTO_CIPHER_AES_ECB,
79 /**< AES algorithm in ECB mode */
80 RTE_CRYPTO_CIPHER_AES_F8,
81 /**< AES algorithm in F8 mode */
82 RTE_CRYPTO_CIPHER_AES_GCM,
83 /**< AES algorithm in GCM mode. When this cipher algorithm is used the
84 * *RTE_CRYPTO_AUTH_AES_GCM* element of the
85 * *rte_crypto_auth_algorithm* enum MUST be used to set up the related
86 * *rte_crypto_auth_setup_data* structure in the session context or in
87 * the op_params of the crypto operation structure in the case of a
88 * session-less crypto operation.
90 RTE_CRYPTO_CIPHER_AES_XTS,
91 /**< AES algorithm in XTS mode */
93 RTE_CRYPTO_CIPHER_ARC4,
94 /**< (A)RC4 cipher algorithm */
96 RTE_CRYPTO_CIPHER_KASUMI_F8,
97 /**< Kasumi algorithm in F8 mode */
99 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
100 /**< SNOW3G algorithm in UEA2 mode */
102 RTE_CRYPTO_CIPHER_ZUC_EEA3
103 /**< ZUC algorithm in EEA3 mode */
106 /** Symmetric Cipher Direction */
107 enum rte_crypto_cipher_operation {
108 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
109 /**< Encrypt cipher operation */
110 RTE_CRYPTO_CIPHER_OP_DECRYPT
111 /**< Decrypt cipher operation */
116 * Symmetric Cipher Setup Data.
118 * This structure contains data relating to Cipher (Encryption and Decryption)
119 * use to create a session.
121 struct rte_crypto_cipher_xform {
122 enum rte_crypto_cipher_operation op;
123 /**< This parameter determines if the cipher operation is an encrypt or
124 * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
125 * only encrypt operations are valid.
127 enum rte_crypto_cipher_algorithm algo;
128 /**< Cipher algorithm */
131 uint8_t *data; /**< pointer to key data */
132 size_t length; /**< key length in bytes */
136 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
137 * point to a concatenation of the AES encryption key followed by a
138 * keymask. As per RFC3711, the keymask should be padded with trailing
139 * bytes to match the length of the encryption key used.
141 * For AES-XTS mode of operation, two keys must be provided and
142 * key.data must point to the two keys concatenated together (Key1 ||
143 * Key2). The cipher key length will contain the total size of both
146 * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
147 * 192 bits (24 bytes) or 256 bits (32 bytes).
149 * For the CCM mode of operation, the only supported key length is 128
152 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
153 * should be set to the combined length of the encryption key and the
154 * keymask. Since the keymask and the encryption key are the same size,
155 * key.length should be set to 2 x the AES encryption key length.
157 * For the AES-XTS mode of operation:
158 * - Two keys must be provided and key.length refers to total length of
160 * - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
161 * - Both keys must have the same size.
165 /** Symmetric Authentication / Hash Algorithms */
166 enum rte_crypto_auth_algorithm {
167 RTE_CRYPTO_AUTH_NULL = 1,
168 /**< NULL hash algorithm. */
170 RTE_CRYPTO_AUTH_AES_CBC_MAC,
171 /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
172 RTE_CRYPTO_AUTH_AES_CCM,
173 /**< AES algorithm in CCM mode. This is an authenticated cipher. When
174 * this hash algorithm is used, the *RTE_CRYPTO_CIPHER_AES_CCM*
175 * element of the *rte_crypto_cipher_algorithm* enum MUST be used to
176 * set up the related rte_crypto_cipher_setup_data structure in the
177 * session context or the corresponding parameter in the crypto
178 * operation data structures op_params parameter MUST be set for a
179 * session-less crypto operation.
181 RTE_CRYPTO_AUTH_AES_CMAC,
182 /**< AES CMAC algorithm. */
183 RTE_CRYPTO_AUTH_AES_GCM,
184 /**< AES algorithm in GCM mode. When this hash algorithm
185 * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
186 * rte_crypto_cipher_algorithm enum MUST be used to set up the related
187 * rte_crypto_cipher_setup_data structure in the session context, or
188 * the corresponding parameter in the crypto operation data structures
189 * op_params parameter MUST be set for a session-less crypto operation.
191 RTE_CRYPTO_AUTH_AES_GMAC,
192 /**< AES GMAC algorithm. When this hash algorithm
193 * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
194 * rte_crypto_cipher_algorithm enum MUST be used to set up the related
195 * rte_crypto_cipher_setup_data structure in the session context, or
196 * the corresponding parameter in the crypto operation data structures
197 * op_params parameter MUST be set for a session-less crypto operation.
199 RTE_CRYPTO_AUTH_AES_XCBC_MAC,
200 /**< AES XCBC algorithm. */
202 RTE_CRYPTO_AUTH_KASUMI_F9,
203 /**< Kasumi algorithm in F9 mode. */
206 /**< MD5 algorithm */
207 RTE_CRYPTO_AUTH_MD5_HMAC,
208 /**< HMAC using MD5 algorithm */
210 RTE_CRYPTO_AUTH_SHA1,
211 /**< 128 bit SHA algorithm. */
212 RTE_CRYPTO_AUTH_SHA1_HMAC,
213 /**< HMAC using 128 bit SHA algorithm. */
214 RTE_CRYPTO_AUTH_SHA224,
215 /**< 224 bit SHA algorithm. */
216 RTE_CRYPTO_AUTH_SHA224_HMAC,
217 /**< HMAC using 224 bit SHA algorithm. */
218 RTE_CRYPTO_AUTH_SHA256,
219 /**< 256 bit SHA algorithm. */
220 RTE_CRYPTO_AUTH_SHA256_HMAC,
221 /**< HMAC using 256 bit SHA algorithm. */
222 RTE_CRYPTO_AUTH_SHA384,
223 /**< 384 bit SHA algorithm. */
224 RTE_CRYPTO_AUTH_SHA384_HMAC,
225 /**< HMAC using 384 bit SHA algorithm. */
226 RTE_CRYPTO_AUTH_SHA512,
227 /**< 512 bit SHA algorithm. */
228 RTE_CRYPTO_AUTH_SHA512_HMAC,
229 /**< HMAC using 512 bit SHA algorithm. */
231 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
232 /**< SNOW3G algorithm in UIA2 mode. */
234 RTE_CRYPTO_AUTH_ZUC_EIA3,
235 /**< ZUC algorithm in EIA3 mode */
238 /** Symmetric Authentication / Hash Operations */
239 enum rte_crypto_auth_operation {
240 RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */
241 RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */
245 * Authentication / Hash transform data.
247 * This structure contains data relating to an authentication/hash crypto
248 * transforms. The fields op, algo and digest_length are common to all
249 * authentication transforms and MUST be set.
251 struct rte_crypto_auth_xform {
252 enum rte_crypto_auth_operation op;
253 /**< Authentication operation type */
254 enum rte_crypto_auth_algorithm algo;
255 /**< Authentication algorithm selection */
258 uint8_t *data; /**< pointer to key data */
259 size_t length; /**< key length in bytes */
261 /**< Authentication key data.
262 * The authentication key length MUST be less than or equal to the
263 * block size of the algorithm. It is the callers responsibility to
264 * ensure that the key length is compliant with the standard being used
265 * (for example RFC 2104, FIPS 198a).
268 uint32_t digest_length;
269 /**< Length of the digest to be returned. If the verify option is set,
270 * this specifies the length of the digest to be compared for the
273 * If the value is less than the maximum length allowed by the hash,
274 * the result shall be truncated. If the value is greater than the
275 * maximum length allowed by the hash then an error will be generated
276 * by *rte_cryptodev_sym_session_create* or by the
277 * *rte_cryptodev_sym_enqueue_burst* if using session-less APIs.
280 uint32_t add_auth_data_length;
281 /**< The length of the additional authenticated data (AAD) in bytes.
282 * The maximum permitted value is 240 bytes, unless otherwise specified
285 * This field must be specified when the hash algorithm is one of the
288 * - For SNOW3G (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2), this is the
289 * length of the IV (which should be 16).
291 * - For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM). In this case, this is
292 * the length of the Additional Authenticated Data (called A, in NIST
295 * - For CCM (@ref RTE_CRYPTO_AUTH_AES_CCM). In this case, this is
296 * the length of the associated data (called A, in NIST SP800-38C).
297 * Note that this does NOT include the length of any padding, or the
298 * 18 bytes reserved at the start of the above field to store the
299 * block B0 and the encoded length. The maximum permitted value in
300 * this case is 222 bytes.
303 * For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of operation
304 * this field is not used and should be set to 0. Instead the length
305 * of the AAD data is specified in the message length to hash field of
306 * the rte_crypto_sym_op_data structure.
310 /** Crypto transformation types */
311 enum rte_crypto_sym_xform_type {
312 RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
313 RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */
314 RTE_CRYPTO_SYM_XFORM_CIPHER /**< Cipher xform */
318 * Symmetric crypto transform structure.
320 * This is used to specify the crypto transforms required, multiple transforms
321 * can be chained together to specify a chain transforms such as authentication
322 * then cipher, or cipher then authentication. Each transform structure can
323 * hold a single transform, the type field is used to specify which transform
324 * is contained within the union
326 struct rte_crypto_sym_xform {
327 struct rte_crypto_sym_xform *next;
328 /**< next xform in chain */
329 enum rte_crypto_sym_xform_type type
332 struct rte_crypto_auth_xform auth;
333 /**< Authentication / hash xform */
334 struct rte_crypto_cipher_xform cipher;
340 * Crypto operation session type. This is used to specify whether a crypto
341 * operation has session structure attached for immutable parameters or if all
342 * operation information is included in the operation data structure.
344 enum rte_crypto_sym_op_sess_type {
345 RTE_CRYPTO_SYM_OP_WITH_SESSION, /**< Session based crypto operation */
346 RTE_CRYPTO_SYM_OP_SESSIONLESS /**< Session-less crypto operation */
351 * Cryptographic Operation Data.
353 * This structure contains data relating to performing cryptographic processing
354 * on a data buffer. This request is used with rte_crypto_sym_enqueue_burst()
355 * call for performing cipher, hash, or a combined hash and cipher operations.
357 struct rte_crypto_sym_op {
358 enum rte_crypto_sym_op_sess_type type;
359 enum rte_crypto_op_status status;
362 struct rte_mbuf *m; /**< Destination mbuf */
363 uint8_t offset; /**< Data offset */
367 struct rte_cryptodev_sym_session *session;
368 /**< Handle for the initialised session context */
369 struct rte_crypto_sym_xform *xform;
370 /**< Session-less API crypto operation parameters */
376 /**< Starting point for cipher processing, specified
377 * as number of bytes from start of data in the source
378 * buffer. The result of the cipher operation will be
379 * written back into the output buffer starting at
384 /**< The message length, in bytes, of the source buffer
385 * on which the cryptographic operation will be
386 * computed. This must be a multiple of the block size
387 * if a block cipher is being used. This is also the
388 * same as the result length.
391 * In the case of CCM @ref RTE_CRYPTO_AUTH_AES_CCM,
392 * this value should not include the length of the
393 * padding or the length of the MAC; the driver will
394 * compute the actual number of bytes over which the
395 * encryption will occur, which will include these
399 * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC, this
400 * field should be set to 0.
402 } to_cipher; /**< Data offsets and length for ciphering */
406 /**< Starting point for hash processing, specified as
407 * number of bytes from start of packet in source
411 * For CCM and GCM modes of operation, this field is
412 * ignored. The field @ref additional_auth field
413 * should be set instead.
415 * @note For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC)
416 * mode of operation, this field specifies the start
417 * of the AAD data in the source buffer.
421 /**< The message length, in bytes, of the source
422 * buffer that the hash will be computed on.
425 * For CCM and GCM modes of operation, this field is
426 * ignored. The field @ref additional_auth field
427 * should be set instead.
430 * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC mode
431 * of operation, this field specifies the length of
432 * the AAD data in the source buffer.
434 } to_hash; /**< Data offsets and length for authentication */
435 } data; /**< Details of data to be operated on */
439 /**< Initialisation Vector or Counter.
441 * - For block ciphers in CBC or F8 mode, or for Kasumi in F8
442 * mode, or for SNOW3G in UEA2 mode, this is the Initialisation
445 * - For block ciphers in CTR mode, this is the counter.
447 * - For GCM mode, this is either the IV (if the length is 96
448 * bits) or J0 (for other sizes), where J0 is as defined by
449 * NIST SP800-38D. Regardless of the IV length, a full 16 bytes
450 * needs to be allocated.
452 * - For CCM mode, the first byte is reserved, and the nonce
453 * should be written starting at &iv[1] (to allow space for the
454 * implementation to write in the flags in the first byte).
455 * Note that a full 16 bytes should be allocated, even though
456 * the length field will have a value less than this.
458 * - For AES-XTS, this is the 128bit tweak, i, from IEEE Std
461 * For optimum performance, the data pointed to SHOULD be
464 phys_addr_t phys_addr;
466 /**< Length of valid IV data.
468 * - For block ciphers in CBC or F8 mode, or for Kasumi in F8
469 * mode, or for SNOW3G in UEA2 mode, this is the length of the
470 * IV (which must be the same as the block length of the
473 * - For block ciphers in CTR mode, this is the length of the
474 * counter (which must be the same as the block length of the
477 * - For GCM mode, this is either 12 (for 96-bit IVs) or 16, in
478 * which case data points to J0.
480 * - For CCM mode, this is the length of the nonce, which can
481 * be in the range 7 to 13 inclusive.
483 } iv; /**< Initialisation vector parameters */
487 /**< If this member of this structure is set this is a
488 * pointer to the location where the digest result should be
489 * inserted (in the case of digest generation) or where the
490 * purported digest exists (in the case of digest
493 * At session creation time, the client specified the digest
494 * result length with the digest_length member of the @ref
495 * rte_crypto_auth_xform structure. For physical crypto
496 * devices the caller must allocate at least digest_length of
497 * physically contiguous memory at this location.
499 * For digest generation, the digest result will overwrite
500 * any data at this location.
503 * For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), for
504 * "digest result" read "authentication tag T".
506 * If this member is not set the digest result is understood
507 * to be in the destination buffer for digest generation, and
508 * in the source buffer for digest verification. The location
509 * of the digest result in this case is immediately following
510 * the region over which the digest is computed.
512 phys_addr_t phys_addr; /**< Physical address of digest */
513 uint32_t length; /**< Length of digest */
514 } digest; /**< Digest parameters */
518 /**< Pointer to Additional Authenticated Data (AAD) needed for
519 * authenticated cipher mechanisms (CCM and GCM), and to the IV
520 * for SNOW3G authentication
521 * (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2). For other
522 * authentication mechanisms this pointer is ignored.
524 * The length of the data pointed to by this field is set up
525 * for the session in the @ref rte_crypto_auth_xform structure
526 * as part of the @ref rte_cryptodev_sym_session_create function
527 * call. This length must not exceed 240 bytes.
529 * Specifically for CCM (@ref RTE_CRYPTO_AUTH_AES_CCM), the
530 * caller should setup this field as follows:
532 * - the nonce should be written starting at an offset of one
533 * byte into the array, leaving room for the implementation
534 * to write in the flags to the first byte.
536 * - the additional authentication data itself should be
537 * written starting at an offset of 18 bytes into the array,
538 * leaving room for the length encoding in the first two
539 * bytes of the second block.
541 * - the array should be big enough to hold the above fields,
542 * plus any padding to round this up to the nearest multiple
543 * of the block size (16 bytes). Padding will be added by
544 * the implementation.
546 * Finally, for GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), the
547 * caller should setup this field as follows:
549 * - the AAD is written in starting at byte 0
550 * - the array must be big enough to hold the AAD, plus any
551 * space to round this up to the nearest multiple of the
552 * block size (16 bytes).
555 * For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of
556 * operation, this field is not used and should be set to 0.
557 * Instead the AAD data should be placed in the source buffer.
559 phys_addr_t phys_addr; /**< physical address */
560 uint32_t length; /**< Length of digest */
562 /**< Additional authentication parameters */
564 struct rte_mempool *pool;
565 /**< mempool used to allocate crypto op */
568 /**< opaque pointer for user data */
573 * Reset the fields of a crypto operation to their default values.
575 * @param op The crypto operation to be reset.
578 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
580 op->type = RTE_CRYPTO_SYM_OP_SESSIONLESS;
585 /** Attach a session to a crypto operation */
587 rte_crypto_sym_op_attach_session(struct rte_crypto_sym_op *op,
588 struct rte_cryptodev_sym_session *sess)
591 op->type = RTE_CRYPTO_SYM_OP_WITH_SESSION;
598 #endif /* _RTE_CRYPTO_SYM_H_ */