a718a7b6ab28afa9f1fa07dd4f7ed98073602982
[dpdk.git] / lib / librte_cryptodev / rte_crypto_sym.h
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_SYM_H_
34 #define _RTE_CRYPTO_SYM_H_
35
36 /**
37  * @file rte_crypto_sym.h
38  *
39  * RTE Definitions for Symmetric Cryptography
40  *
41  * Defines symmetric cipher and authentication algorithms and modes, as well
42  * as supported symmetric crypto operation combinations.
43  */
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #include <string.h>
50
51 #include <rte_mbuf.h>
52 #include <rte_memory.h>
53 #include <rte_mempool.h>
54 #include <rte_common.h>
55
56
57 /** Symmetric Cipher Algorithms */
58 enum rte_crypto_cipher_algorithm {
59         RTE_CRYPTO_CIPHER_NULL = 1,
60         /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
61
62         RTE_CRYPTO_CIPHER_3DES_CBC,
63         /**< Triple DES algorithm in CBC mode */
64         RTE_CRYPTO_CIPHER_3DES_CTR,
65         /**< Triple DES algorithm in CTR mode */
66         RTE_CRYPTO_CIPHER_3DES_ECB,
67         /**< Triple DES algorithm in ECB mode */
68
69         RTE_CRYPTO_CIPHER_AES_CBC,
70         /**< AES algorithm in CBC mode */
71         RTE_CRYPTO_CIPHER_AES_CCM,
72         /**< AES algorithm in CCM mode. When this cipher algorithm is used the
73          * *RTE_CRYPTO_AUTH_AES_CCM* element of the
74          * *rte_crypto_hash_algorithm* enum MUST be used to set up the related
75          * *rte_crypto_auth_xform* structure in the session context or in
76          * the op_params of the crypto operation structure in the case of a
77          * session-less crypto operation
78          */
79         RTE_CRYPTO_CIPHER_AES_CTR,
80         /**< AES algorithm in Counter mode */
81         RTE_CRYPTO_CIPHER_AES_ECB,
82         /**< AES algorithm in ECB mode */
83         RTE_CRYPTO_CIPHER_AES_F8,
84         /**< AES algorithm in F8 mode */
85         RTE_CRYPTO_CIPHER_AES_GCM,
86         /**< AES algorithm in GCM mode. When this cipher algorithm is used the
87          * *RTE_CRYPTO_AUTH_AES_GCM* element of the *rte_crypto_auth_algorithm*
88          * enum MUST be used to set up the related *rte_crypto_auth_setup_data*
89          * structure in the session context or in the op_params of the crypto
90          * operation structure in the case of a session-less crypto operation.
91          */
92         RTE_CRYPTO_CIPHER_AES_XTS,
93         /**< AES algorithm in XTS mode */
94
95         RTE_CRYPTO_CIPHER_ARC4,
96         /**< (A)RC4 cipher algorithm */
97
98         RTE_CRYPTO_CIPHER_KASUMI_F8,
99         /**< KASUMI algorithm in F8 mode */
100
101         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
102         /**< SNOW 3G algorithm in UEA2 mode */
103
104         RTE_CRYPTO_CIPHER_ZUC_EEA3,
105         /**< ZUC algorithm in EEA3 mode */
106
107         RTE_CRYPTO_CIPHER_DES_CBC,
108         /**< DES algorithm in CBC mode */
109
110         RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
111         /**< AES algorithm using modes required by
112          * DOCSIS Baseline Privacy Plus Spec.
113          * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
114          * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
115          */
116
117         RTE_CRYPTO_CIPHER_DES_DOCSISBPI,
118         /**< DES algorithm using modes required by
119          * DOCSIS Baseline Privacy Plus Spec.
120          * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
121          * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
122          */
123
124         RTE_CRYPTO_CIPHER_LIST_END
125
126 };
127
128 /** Cipher algorithm name strings */
129 extern const char *
130 rte_crypto_cipher_algorithm_strings[];
131
132 /** Symmetric Cipher Direction */
133 enum rte_crypto_cipher_operation {
134         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
135         /**< Encrypt cipher operation */
136         RTE_CRYPTO_CIPHER_OP_DECRYPT
137         /**< Decrypt cipher operation */
138 };
139
140 /** Cipher operation name strings */
141 extern const char *
142 rte_crypto_cipher_operation_strings[];
143
144 /**
145  * Symmetric Cipher Setup Data.
146  *
147  * This structure contains data relating to Cipher (Encryption and Decryption)
148  *  use to create a session.
149  */
150 struct rte_crypto_cipher_xform {
151         enum rte_crypto_cipher_operation op;
152         /**< This parameter determines if the cipher operation is an encrypt or
153          * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
154          * only encrypt operations are valid.
155          */
156         enum rte_crypto_cipher_algorithm algo;
157         /**< Cipher algorithm */
158
159         struct {
160                 uint8_t *data;  /**< pointer to key data */
161                 size_t length;  /**< key length in bytes */
162         } key;
163         /**< Cipher key
164          *
165          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
166          * point to a concatenation of the AES encryption key followed by a
167          * keymask. As per RFC3711, the keymask should be padded with trailing
168          * bytes to match the length of the encryption key used.
169          *
170          * For AES-XTS mode of operation, two keys must be provided and
171          * key.data must point to the two keys concatenated together (Key1 ||
172          * Key2). The cipher key length will contain the total size of both
173          * keys.
174          *
175          * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
176          * 192 bits (24 bytes) or 256 bits (32 bytes).
177          *
178          * For the CCM mode of operation, the only supported key length is 128
179          * bits (16 bytes).
180          *
181          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
182          * should be set to the combined length of the encryption key and the
183          * keymask. Since the keymask and the encryption key are the same size,
184          * key.length should be set to 2 x the AES encryption key length.
185          *
186          * For the AES-XTS mode of operation:
187          *  - Two keys must be provided and key.length refers to total length of
188          *    the two keys.
189          *  - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
190          *  - Both keys must have the same size.
191          **/
192         struct {
193                 uint16_t offset;
194                 /**< Starting point for Initialisation Vector or Counter,
195                  * specified as number of bytes from start of crypto
196                  * operation (rte_crypto_op).
197                  *
198                  * - For block ciphers in CBC or F8 mode, or for KASUMI
199                  * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
200                  * Initialisation Vector (IV) value.
201                  *
202                  * - For block ciphers in CTR mode, this is the counter.
203                  *
204                  * - For GCM mode, this is either the IV (if the length
205                  * is 96 bits) or J0 (for other sizes), where J0 is as
206                  * defined by NIST SP800-38D. Regardless of the IV
207                  * length, a full 16 bytes needs to be allocated.
208                  *
209                  * - For CCM mode, the first byte is reserved, and the
210                  * nonce should be written starting at &iv[1] (to allow
211                  * space for the implementation to write in the flags
212                  * in the first byte). Note that a full 16 bytes should
213                  * be allocated, even though the length field will
214                  * have a value less than this.
215                  *
216                  * - For AES-XTS, this is the 128bit tweak, i, from
217                  * IEEE Std 1619-2007.
218                  *
219                  * For optimum performance, the data pointed to SHOULD
220                  * be 8-byte aligned.
221                  */
222                 uint16_t length;
223                 /**< Length of valid IV data.
224                  *
225                  * - For block ciphers in CBC or F8 mode, or for KASUMI
226                  * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
227                  * length of the IV (which must be the same as the
228                  * block length of the cipher).
229                  *
230                  * - For block ciphers in CTR mode, this is the length
231                  * of the counter (which must be the same as the block
232                  * length of the cipher).
233                  *
234                  * - For GCM mode, this is either 12 (for 96-bit IVs)
235                  * or 16, in which case data points to J0.
236                  *
237                  * - For CCM mode, this is the length of the nonce,
238                  * which can be in the range 7 to 13 inclusive.
239                  */
240         } iv;   /**< Initialisation vector parameters */
241 };
242
243 /** Symmetric Authentication / Hash Algorithms */
244 enum rte_crypto_auth_algorithm {
245         RTE_CRYPTO_AUTH_NULL = 1,
246         /**< NULL hash algorithm. */
247
248         RTE_CRYPTO_AUTH_AES_CBC_MAC,
249         /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
250         RTE_CRYPTO_AUTH_AES_CCM,
251         /**< AES algorithm in CCM mode. This is an authenticated cipher. When
252          * this hash algorithm is used, the *RTE_CRYPTO_CIPHER_AES_CCM*
253          * element of the *rte_crypto_cipher_algorithm* enum MUST be used to
254          * set up the related rte_crypto_cipher_setup_data structure in the
255          * session context or the corresponding parameter in the crypto
256          * operation data structures op_params parameter MUST be set for a
257          * session-less crypto operation.
258          */
259         RTE_CRYPTO_AUTH_AES_CMAC,
260         /**< AES CMAC algorithm. */
261         RTE_CRYPTO_AUTH_AES_GCM,
262         /**< AES algorithm in GCM mode. When this hash algorithm
263          * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
264          * rte_crypto_cipher_algorithm enum MUST be used to set up the related
265          * rte_crypto_cipher_setup_data structure in the session context, or
266          * the corresponding parameter in the crypto operation data structures
267          * op_params parameter MUST be set for a session-less crypto operation.
268          */
269         RTE_CRYPTO_AUTH_AES_GMAC,
270         /**< AES GMAC algorithm. */
271         RTE_CRYPTO_AUTH_AES_XCBC_MAC,
272         /**< AES XCBC algorithm. */
273
274         RTE_CRYPTO_AUTH_KASUMI_F9,
275         /**< KASUMI algorithm in F9 mode. */
276
277         RTE_CRYPTO_AUTH_MD5,
278         /**< MD5 algorithm */
279         RTE_CRYPTO_AUTH_MD5_HMAC,
280         /**< HMAC using MD5 algorithm */
281
282         RTE_CRYPTO_AUTH_SHA1,
283         /**< 128 bit SHA algorithm. */
284         RTE_CRYPTO_AUTH_SHA1_HMAC,
285         /**< HMAC using 128 bit SHA algorithm. */
286         RTE_CRYPTO_AUTH_SHA224,
287         /**< 224 bit SHA algorithm. */
288         RTE_CRYPTO_AUTH_SHA224_HMAC,
289         /**< HMAC using 224 bit SHA algorithm. */
290         RTE_CRYPTO_AUTH_SHA256,
291         /**< 256 bit SHA algorithm. */
292         RTE_CRYPTO_AUTH_SHA256_HMAC,
293         /**< HMAC using 256 bit SHA algorithm. */
294         RTE_CRYPTO_AUTH_SHA384,
295         /**< 384 bit SHA algorithm. */
296         RTE_CRYPTO_AUTH_SHA384_HMAC,
297         /**< HMAC using 384 bit SHA algorithm. */
298         RTE_CRYPTO_AUTH_SHA512,
299         /**< 512 bit SHA algorithm. */
300         RTE_CRYPTO_AUTH_SHA512_HMAC,
301         /**< HMAC using 512 bit SHA algorithm. */
302
303         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
304         /**< SNOW 3G algorithm in UIA2 mode. */
305
306         RTE_CRYPTO_AUTH_ZUC_EIA3,
307         /**< ZUC algorithm in EIA3 mode */
308
309         RTE_CRYPTO_AUTH_LIST_END
310 };
311
312 /** Authentication algorithm name strings */
313 extern const char *
314 rte_crypto_auth_algorithm_strings[];
315
316 /** Symmetric Authentication / Hash Operations */
317 enum rte_crypto_auth_operation {
318         RTE_CRYPTO_AUTH_OP_VERIFY,      /**< Verify authentication digest */
319         RTE_CRYPTO_AUTH_OP_GENERATE     /**< Generate authentication digest */
320 };
321
322 /** Authentication operation name strings */
323 extern const char *
324 rte_crypto_auth_operation_strings[];
325
326 /**
327  * Authentication / Hash transform data.
328  *
329  * This structure contains data relating to an authentication/hash crypto
330  * transforms. The fields op, algo and digest_length are common to all
331  * authentication transforms and MUST be set.
332  */
333 struct rte_crypto_auth_xform {
334         enum rte_crypto_auth_operation op;
335         /**< Authentication operation type */
336         enum rte_crypto_auth_algorithm algo;
337         /**< Authentication algorithm selection */
338
339         struct {
340                 uint8_t *data;  /**< pointer to key data */
341                 size_t length;  /**< key length in bytes */
342         } key;
343         /**< Authentication key data.
344          * The authentication key length MUST be less than or equal to the
345          * block size of the algorithm. It is the callers responsibility to
346          * ensure that the key length is compliant with the standard being used
347          * (for example RFC 2104, FIPS 198a).
348          */
349
350         uint16_t digest_length;
351         /**< Length of the digest to be returned. If the verify option is set,
352          * this specifies the length of the digest to be compared for the
353          * session.
354          *
355          * It is the caller's responsibility to ensure that the
356          * digest length is compliant with the hash algorithm being used.
357          * If the value is less than the maximum length allowed by the hash,
358          * the result shall be truncated.
359          */
360
361         uint16_t add_auth_data_length;
362         /**< The length of the additional authenticated data (AAD) in bytes.
363          * The maximum permitted value is 65535 (2^16 - 1) bytes, unless
364          * otherwise specified below.
365          *
366          * This field must be specified when the hash algorithm is one of the
367          * following:
368          *
369          * - For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM).  In this case, this is
370          *   the length of the Additional Authenticated Data (called A, in NIST
371          *   SP800-38D).
372          *
373          * - For CCM (@ref RTE_CRYPTO_AUTH_AES_CCM).  In this case, this is
374          *   the length of the associated data (called A, in NIST SP800-38C).
375          *   Note that this does NOT include the length of any padding, or the
376          *   18 bytes reserved at the start of the above field to store the
377          *   block B0 and the encoded length.  The maximum permitted value in
378          *   this case is 222 bytes.
379          *
380          */
381
382         struct {
383                 uint16_t offset;
384                 /**< Starting point for Initialisation Vector or Counter,
385                  * specified as number of bytes from start of crypto
386                  * operation (rte_crypto_op).
387                  *
388                  * - For KASUMI in F9 mode, SNOW 3G in UIA2 mode,
389                  *   for ZUC in EIA3 mode and for AES-GMAC, this is the
390                  *   authentication Initialisation Vector (IV) value.
391                  *
392                  *
393                  * For optimum performance, the data pointed to SHOULD
394                  * be 8-byte aligned.
395                  */
396                 uint16_t length;
397                 /**< Length of valid IV data.
398                  *
399                  * - For KASUMI in F9 mode, SNOW3G in UIA2 mode, for
400                  *   ZUC in EIA3 mode and for AES-GMAC, this is the length
401                  *   of the IV.
402                  *
403                  */
404         } iv;   /**< Initialisation vector parameters */
405 };
406
407
408 /** Symmetric AEAD Algorithms */
409 enum rte_crypto_aead_algorithm {
410         RTE_CRYPTO_AEAD_AES_CCM = 1,
411         /**< AES algorithm in CCM mode. */
412         RTE_CRYPTO_AEAD_AES_GCM,
413         /**< AES algorithm in GCM mode. */
414         RTE_CRYPTO_AEAD_LIST_END
415 };
416
417 /** AEAD algorithm name strings */
418 extern const char *
419 rte_crypto_aead_algorithm_strings[];
420
421 /** Symmetric AEAD Operations */
422 enum rte_crypto_aead_operation {
423         RTE_CRYPTO_AEAD_OP_ENCRYPT,
424         /**< Encrypt and generate digest */
425         RTE_CRYPTO_AEAD_OP_DECRYPT
426         /**< Verify digest and decrypt */
427 };
428
429 /** Authentication operation name strings */
430 extern const char *
431 rte_crypto_aead_operation_strings[];
432
433 struct rte_crypto_aead_xform {
434         enum rte_crypto_aead_operation op;
435         /**< AEAD operation type */
436         enum rte_crypto_aead_algorithm algo;
437         /**< AEAD algorithm selection */
438
439         struct {
440                 uint8_t *data;  /**< pointer to key data */
441                 size_t length;   /**< key length in bytes */
442         } key;
443
444         struct {
445                 uint16_t offset;
446                 /**< Starting point for Initialisation Vector or Counter,
447                  * specified as number of bytes from start of crypto
448                  * operation (rte_crypto_op).
449                  *
450                  * - For GCM mode, this is either the IV (if the length
451                  * is 96 bits) or J0 (for other sizes), where J0 is as
452                  * defined by NIST SP800-38D. Regardless of the IV
453                  * length, a full 16 bytes needs to be allocated.
454                  *
455                  * - For CCM mode, the first byte is reserved, and the
456                  * nonce should be written starting at &iv[1] (to allow
457                  * space for the implementation to write in the flags
458                  * in the first byte). Note that a full 16 bytes should
459                  * be allocated, even though the length field will
460                  * have a value less than this.
461                  *
462                  * For optimum performance, the data pointed to SHOULD
463                  * be 8-byte aligned.
464                  */
465                 uint16_t length;
466                 /**< Length of valid IV data.
467                  *
468                  * - For GCM mode, this is either 12 (for 96-bit IVs)
469                  * or 16, in which case data points to J0.
470                  *
471                  * - For CCM mode, this is the length of the nonce,
472                  * which can be in the range 7 to 13 inclusive.
473                  */
474         } iv;   /**< Initialisation vector parameters */
475
476         uint32_t digest_length;
477
478         uint16_t add_auth_data_length;
479         /**< The length of the additional authenticated data (AAD) in bytes. */
480 };
481
482 /** Crypto transformation types */
483 enum rte_crypto_sym_xform_type {
484         RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
485         RTE_CRYPTO_SYM_XFORM_AUTH,              /**< Authentication xform */
486         RTE_CRYPTO_SYM_XFORM_CIPHER,            /**< Cipher xform  */
487         RTE_CRYPTO_SYM_XFORM_AEAD               /**< AEAD xform  */
488 };
489
490 /**
491  * Symmetric crypto transform structure.
492  *
493  * This is used to specify the crypto transforms required, multiple transforms
494  * can be chained together to specify a chain transforms such as authentication
495  * then cipher, or cipher then authentication. Each transform structure can
496  * hold a single transform, the type field is used to specify which transform
497  * is contained within the union
498  */
499 struct rte_crypto_sym_xform {
500         struct rte_crypto_sym_xform *next;
501         /**< next xform in chain */
502         enum rte_crypto_sym_xform_type type
503         ; /**< xform type */
504         RTE_STD_C11
505         union {
506                 struct rte_crypto_auth_xform auth;
507                 /**< Authentication / hash xform */
508                 struct rte_crypto_cipher_xform cipher;
509                 /**< Cipher xform */
510                 struct rte_crypto_aead_xform aead;
511                 /**< AEAD xform */
512         };
513 };
514
515 struct rte_cryptodev_sym_session;
516
517 /**
518  * Symmetric Cryptographic Operation.
519  *
520  * This structure contains data relating to performing symmetric cryptographic
521  * processing on a referenced mbuf data buffer.
522  *
523  * When a symmetric crypto operation is enqueued with the device for processing
524  * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
525  * which contains the source data which the crypto operation is to be performed
526  * on.
527  * While the mbuf is in use by a crypto operation no part of the mbuf should be
528  * changed by the application as the device may read or write to any part of the
529  * mbuf. In the case of hardware crypto devices some or all of the mbuf
530  * may be DMAed in and out of the device, so writing over the original data,
531  * though only the part specified by the rte_crypto_sym_op for transformation
532  * will be changed.
533  * Out-of-place (OOP) operation, where the source mbuf is different to the
534  * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
535  * The part copied includes all the parts of the source mbuf that will be
536  * operated on, based on the cipher.data.offset+cipher.data.length and
537  * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
538  * indicated by the cipher parameters will be transformed, any extra data around
539  * this indicated by the auth parameters will be copied unchanged from source to
540  * destination mbuf.
541  * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
542  * both source and destination mbufs. As these offsets are relative to the
543  * data_off parameter in each mbuf this can result in the data written to the
544  * destination buffer being at a different alignment, relative to buffer start,
545  * to the data in the source buffer.
546  */
547 struct rte_crypto_sym_op {
548         struct rte_mbuf *m_src; /**< source mbuf */
549         struct rte_mbuf *m_dst; /**< destination mbuf */
550
551         RTE_STD_C11
552         union {
553                 struct rte_cryptodev_sym_session *session;
554                 /**< Handle for the initialised session context */
555                 struct rte_crypto_sym_xform *xform;
556                 /**< Session-less API crypto operation parameters */
557         };
558
559         union {
560                 struct {
561                         struct {
562                                 uint32_t offset;
563                                  /**< Starting point for AEAD processing, specified as
564                                   * number of bytes from start of packet in source
565                                   * buffer.
566                                   */
567                                 uint32_t length;
568                                  /**< The message length, in bytes, of the source buffer
569                                   * on which the cryptographic operation will be
570                                   * computed. This must be a multiple of the block size
571                                   */
572                         } data; /**< Data offsets and length for AEAD */
573                         struct {
574                                 uint8_t *data;
575                                 /**< This points to the location where the digest result
576                                  * should be inserted (in the case of digest generation)
577                                  * or where the purported digest exists (in the case of
578                                  * digest verification).
579                                  *
580                                  * At session creation time, the client specified the
581                                  * digest result length with the digest_length member
582                                  * of the @ref rte_crypto_auth_xform structure. For
583                                  * physical crypto devices the caller must allocate at
584                                  * least digest_length of physically contiguous memory
585                                  * at this location.
586                                  *
587                                  * For digest generation, the digest result will
588                                  * overwrite any data at this location.
589                                  *
590                                  * @note
591                                  * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for
592                                  * "digest result" read "authentication tag T".
593                                  */
594                                 phys_addr_t phys_addr;
595                                 /**< Physical address of digest */
596                         } digest; /**< Digest parameters */
597                         struct {
598                                 uint8_t *data;
599                                 /**< Pointer to Additional Authenticated Data (AAD)
600                                  * needed for authenticated cipher mechanisms (CCM and
601                                  * GCM)
602                                  *
603                                  * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM),
604                                  * the caller should setup this field as follows:
605                                  *
606                                  * - the nonce should be written starting at an offset
607                                  * of one byte into the array, leaving room for the
608                                  * implementation to write in the flags to the first
609                                  * byte.
610                                  *
611                                  * - the additional  authentication data itself should
612                                  * be written starting at an offset of 18 bytes into
613                                  * the array, leaving room for the length encoding in
614                                  * the first two bytes of the second block.
615                                  *
616                                  * - the array should be big enough to hold the above
617                                  *  fields, plus any padding to round this up to the
618                                  *  nearest multiple of the block size (16 bytes).
619                                  *  Padding will be added by the implementation.
620                                  *
621                                  * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the
622                                  * caller should setup this field as follows:
623                                  *
624                                  * - the AAD is written in starting at byte 0
625                                  * - the array must be big enough to hold the AAD, plus
626                                  * any space to round this up to the nearest multiple
627                                  * of the block size (16 bytes).
628                                  *
629                                  */
630                                 phys_addr_t phys_addr;  /**< physical address */
631                         } aad;
632                         /**< Additional authentication parameters */
633                 } aead;
634
635                 struct {
636                         struct {
637                                 struct {
638                                         uint32_t offset;
639                                          /**< Starting point for cipher processing,
640                                           * specified as number of bytes from start
641                                           * of data in the source buffer.
642                                           * The result of the cipher operation will be
643                                           * written back into the output buffer
644                                           * starting at this location.
645                                           *
646                                           * @note
647                                           * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
648                                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
649                                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
650                                           * this field should be in bits.
651                                           */
652                                         uint32_t length;
653                                          /**< The message length, in bytes, of the
654                                           * source buffer on which the cryptographic
655                                           * operation will be computed.
656                                           * This must be a multiple of the block size
657                                           * if a block cipher is being used. This is
658                                           * also the same as the result length.
659                                           *
660                                           * @note
661                                           * In the case of CCM
662                                           * @ref RTE_CRYPTO_AUTH_AES_CCM, this value
663                                           * should not include the length of the padding
664                                           * or the length of the MAC; the driver will
665                                           * compute the actual number of bytes over
666                                           * which the encryption will occur, which will
667                                           * include these values.
668                                           *
669                                           * @note
670                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
671                                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
672                                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
673                                           * this field should be in bits.
674                                           */
675                                 } data; /**< Data offsets and length for ciphering */
676                         } cipher;
677
678                         struct {
679                                 struct {
680                                         uint32_t offset;
681                                          /**< Starting point for hash processing,
682                                           * specified as number of bytes from start of
683                                           * packet in source buffer.
684                                           *
685                                           * @note
686                                           * For CCM and GCM modes of operation,
687                                           * this field is ignored.
688                                           * The field @ref aad field should be set
689                                           * instead.
690                                           *
691                                           * @note
692                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
693                                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
694                                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
695                                           * this field should be in bits.
696                                           */
697                                         uint32_t length;
698                                          /**< The message length, in bytes, of the source
699                                           * buffer that the hash will be computed on.
700                                           *
701                                           * @note
702                                           * For CCM and GCM modes of operation,
703                                           * this field is ignored. The field @ref aad
704                                           * field should be set instead.
705                                           *
706                                           * @note
707                                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
708                                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
709                                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
710                                           * this field should be in bits.
711                                           */
712                                 } data;
713                                 /**< Data offsets and length for authentication */
714
715                                 struct {
716                                         uint8_t *data;
717                                         /**< This points to the location where
718                                          * the digest result should be inserted
719                                          * (in the case of digest generation)
720                                          * or where the purported digest exists
721                                          * (in the case of digest verification).
722                                          *
723                                          * At session creation time, the client
724                                          * specified the digest result length with
725                                          * the digest_length member of the
726                                          * @ref rte_crypto_auth_xform structure.
727                                          * For physical crypto devices the caller
728                                          * must allocate at least digest_length of
729                                          * physically contiguous memory at this
730                                          * location.
731                                          *
732                                          * For digest generation, the digest result
733                                          * will overwrite any data at this location.
734                                          *
735                                          * @note
736                                          * For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), for
737                                          * "digest result" read "authentication tag T".
738                                          */
739                                         phys_addr_t phys_addr;
740                                         /**< Physical address of digest */
741                                 } digest; /**< Digest parameters */
742
743                                 struct {
744                                         uint8_t *data;
745                                         /**< Pointer to Additional Authenticated
746                                          * Data (AAD) needed for authenticated cipher
747                                          * mechanisms (CCM and GCM).
748                                          *
749                                          * The length of the data pointed to by this
750                                          * field is set up for the session in the @ref
751                                          * rte_crypto_auth_xform structure as part of
752                                          * the @ref rte_cryptodev_sym_session_create
753                                          * function call.
754                                          * This length must not exceed 65535 (2^16-1)
755                                          * bytes.
756                                          *
757                                          * Specifically for CCM
758                                          * (@ref RTE_CRYPTO_AUTH_AES_CCM),
759                                          * the caller should setup this field as follows:
760                                          *
761                                          * - the nonce should be written starting at
762                                          * an offset of one byte into the array,
763                                          * leaving room for the implementation to
764                                          * write in the flags to the first byte.
765                                          *
766                                          * - the additional authentication data
767                                          * itself should be written starting at
768                                          * an offset of 18 bytes into the array,
769                                          * leaving room for the length encoding in
770                                          * the first two bytes of the second block.
771                                          *
772                                          * - the array should be big enough to hold
773                                          * the above fields, plus any padding to
774                                          * round this up to the nearest multiple of
775                                          * the block size (16 bytes).
776                                          * Padding will be added by the implementation.
777                                          *
778                                          * Finally, for GCM
779                                          * (@ref RTE_CRYPTO_AUTH_AES_GCM), the
780                                          * caller should setup this field as follows:
781                                          *
782                                          * - the AAD is written in starting at byte 0
783                                          * - the array must be big enough to hold
784                                          * the AAD, plus any space to round this up to
785                                          * the nearest multiple of the block size
786                                          * (16 bytes).
787                                          *
788                                          */
789                                         phys_addr_t phys_addr;  /**< physical address */
790                                 } aad;
791                                 /**< Additional authentication parameters */
792                         } auth;
793                 };
794         };
795 };
796
797
798 /**
799  * Reset the fields of a symmetric operation to their default values.
800  *
801  * @param       op      The crypto operation to be reset.
802  */
803 static inline void
804 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
805 {
806         memset(op, 0, sizeof(*op));
807 }
808
809
810 /**
811  * Allocate space for symmetric crypto xforms in the private data space of the
812  * crypto operation. This also defaults the crypto xform type to
813  * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
814  * in the crypto operation
815  *
816  * @return
817  * - On success returns pointer to first crypto xform in crypto operations chain
818  * - On failure returns NULL
819  */
820 static inline struct rte_crypto_sym_xform *
821 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
822                 void *priv_data, uint8_t nb_xforms)
823 {
824         struct rte_crypto_sym_xform *xform;
825
826         sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
827
828         do {
829                 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
830                 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
831         } while (xform);
832
833         return sym_op->xform;
834 }
835
836
837 /**
838  * Attach a session to a symmetric crypto operation
839  *
840  * @param       sym_op  crypto operation
841  * @param       sess    cryptodev session
842  */
843 static inline int
844 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
845                 struct rte_cryptodev_sym_session *sess)
846 {
847         sym_op->session = sess;
848
849         return 0;
850 }
851
852
853 #ifdef __cplusplus
854 }
855 #endif
856
857 #endif /* _RTE_CRYPTO_SYM_H_ */