lib: work around unnamed structs/unions
[dpdk.git] / lib / librte_cryptodev / rte_crypto_sym.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2016 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
88          * *rte_crypto_auth_algorithm* enum MUST be used to set up the related
89          * *rte_crypto_auth_setup_data* structure in the session context or in
90          * the op_params of the crypto operation structure in the case of a
91          * session-less crypto operation.
92          */
93         RTE_CRYPTO_CIPHER_AES_XTS,
94         /**< AES algorithm in XTS mode */
95
96         RTE_CRYPTO_CIPHER_ARC4,
97         /**< (A)RC4 cipher algorithm */
98
99         RTE_CRYPTO_CIPHER_KASUMI_F8,
100         /**< Kasumi algorithm in F8 mode */
101
102         RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
103         /**< SNOW3G algorithm in UEA2 mode */
104
105         RTE_CRYPTO_CIPHER_ZUC_EEA3,
106         /**< ZUC algorithm in EEA3 mode */
107
108         RTE_CRYPTO_CIPHER_LIST_END
109 };
110
111 /** Symmetric Cipher Direction */
112 enum rte_crypto_cipher_operation {
113         RTE_CRYPTO_CIPHER_OP_ENCRYPT,
114         /**< Encrypt cipher operation */
115         RTE_CRYPTO_CIPHER_OP_DECRYPT
116         /**< Decrypt cipher operation */
117 };
118
119 /**
120  * Symmetric Cipher Setup Data.
121  *
122  * This structure contains data relating to Cipher (Encryption and Decryption)
123  *  use to create a session.
124  */
125 struct rte_crypto_cipher_xform {
126         enum rte_crypto_cipher_operation op;
127         /**< This parameter determines if the cipher operation is an encrypt or
128          * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
129          * only encrypt operations are valid.
130          */
131         enum rte_crypto_cipher_algorithm algo;
132         /**< Cipher algorithm */
133
134         struct {
135                 uint8_t *data;  /**< pointer to key data */
136                 size_t length;  /**< key length in bytes */
137         } key;
138         /**< Cipher key
139          *
140          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
141          * point to a concatenation of the AES encryption key followed by a
142          * keymask. As per RFC3711, the keymask should be padded with trailing
143          * bytes to match the length of the encryption key used.
144          *
145          * For AES-XTS mode of operation, two keys must be provided and
146          * key.data must point to the two keys concatenated together (Key1 ||
147          * Key2). The cipher key length will contain the total size of both
148          * keys.
149          *
150          * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
151          * 192 bits (24 bytes) or 256 bits (32 bytes).
152          *
153          * For the CCM mode of operation, the only supported key length is 128
154          * bits (16 bytes).
155          *
156          * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
157          * should be set to the combined length of the encryption key and the
158          * keymask. Since the keymask and the encryption key are the same size,
159          * key.length should be set to 2 x the AES encryption key length.
160          *
161          * For the AES-XTS mode of operation:
162          *  - Two keys must be provided and key.length refers to total length of
163          *    the two keys.
164          *  - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
165          *  - Both keys must have the same size.
166          **/
167 };
168
169 /** Symmetric Authentication / Hash Algorithms */
170 enum rte_crypto_auth_algorithm {
171         RTE_CRYPTO_AUTH_NULL = 1,
172         /**< NULL hash algorithm. */
173
174         RTE_CRYPTO_AUTH_AES_CBC_MAC,
175         /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
176         RTE_CRYPTO_AUTH_AES_CCM,
177         /**< AES algorithm in CCM mode. This is an authenticated cipher. When
178          * this hash algorithm is used, the *RTE_CRYPTO_CIPHER_AES_CCM*
179          * element of the *rte_crypto_cipher_algorithm* enum MUST be used to
180          * set up the related rte_crypto_cipher_setup_data structure in the
181          * session context or the corresponding parameter in the crypto
182          * operation data structures op_params parameter MUST be set for a
183          * session-less crypto operation.
184          */
185         RTE_CRYPTO_AUTH_AES_CMAC,
186         /**< AES CMAC algorithm. */
187         RTE_CRYPTO_AUTH_AES_GCM,
188         /**< AES algorithm in GCM mode. When this hash algorithm
189          * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
190          * rte_crypto_cipher_algorithm enum MUST be used to set up the related
191          * rte_crypto_cipher_setup_data structure in the session context, or
192          * the corresponding parameter in the crypto operation data structures
193          * op_params parameter MUST be set for a session-less crypto operation.
194          */
195         RTE_CRYPTO_AUTH_AES_GMAC,
196         /**< AES GMAC algorithm. When this hash algorithm
197         * is used, the RTE_CRYPTO_CIPHER_AES_GCM element of the
198         * rte_crypto_cipher_algorithm enum MUST be used to set up the related
199         * rte_crypto_cipher_setup_data structure in the session context,  or
200         * the corresponding parameter in the crypto operation data structures
201         * op_params parameter MUST be set for a session-less crypto operation.
202         */
203         RTE_CRYPTO_AUTH_AES_XCBC_MAC,
204         /**< AES XCBC algorithm. */
205
206         RTE_CRYPTO_AUTH_KASUMI_F9,
207         /**< Kasumi algorithm in F9 mode. */
208
209         RTE_CRYPTO_AUTH_MD5,
210         /**< MD5 algorithm */
211         RTE_CRYPTO_AUTH_MD5_HMAC,
212         /**< HMAC using MD5 algorithm */
213
214         RTE_CRYPTO_AUTH_SHA1,
215         /**< 128 bit SHA algorithm. */
216         RTE_CRYPTO_AUTH_SHA1_HMAC,
217         /**< HMAC using 128 bit SHA algorithm. */
218         RTE_CRYPTO_AUTH_SHA224,
219         /**< 224 bit SHA algorithm. */
220         RTE_CRYPTO_AUTH_SHA224_HMAC,
221         /**< HMAC using 224 bit SHA algorithm. */
222         RTE_CRYPTO_AUTH_SHA256,
223         /**< 256 bit SHA algorithm. */
224         RTE_CRYPTO_AUTH_SHA256_HMAC,
225         /**< HMAC using 256 bit SHA algorithm. */
226         RTE_CRYPTO_AUTH_SHA384,
227         /**< 384 bit SHA algorithm. */
228         RTE_CRYPTO_AUTH_SHA384_HMAC,
229         /**< HMAC using 384 bit SHA algorithm. */
230         RTE_CRYPTO_AUTH_SHA512,
231         /**< 512 bit SHA algorithm. */
232         RTE_CRYPTO_AUTH_SHA512_HMAC,
233         /**< HMAC using 512 bit SHA algorithm. */
234
235         RTE_CRYPTO_AUTH_SNOW3G_UIA2,
236         /**< SNOW3G algorithm in UIA2 mode. */
237
238         RTE_CRYPTO_AUTH_ZUC_EIA3,
239         /**< ZUC algorithm in EIA3 mode */
240
241         RTE_CRYPTO_AUTH_LIST_END
242 };
243
244 /** Symmetric Authentication / Hash Operations */
245 enum rte_crypto_auth_operation {
246         RTE_CRYPTO_AUTH_OP_VERIFY,      /**< Verify authentication digest */
247         RTE_CRYPTO_AUTH_OP_GENERATE     /**< Generate authentication digest */
248 };
249
250 /**
251  * Authentication / Hash transform data.
252  *
253  * This structure contains data relating to an authentication/hash crypto
254  * transforms. The fields op, algo and digest_length are common to all
255  * authentication transforms and MUST be set.
256  */
257 struct rte_crypto_auth_xform {
258         enum rte_crypto_auth_operation op;
259         /**< Authentication operation type */
260         enum rte_crypto_auth_algorithm algo;
261         /**< Authentication algorithm selection */
262
263         struct {
264                 uint8_t *data;  /**< pointer to key data */
265                 size_t length;  /**< key length in bytes */
266         } key;
267         /**< Authentication key data.
268          * The authentication key length MUST be less than or equal to the
269          * block size of the algorithm. It is the callers responsibility to
270          * ensure that the key length is compliant with the standard being used
271          * (for example RFC 2104, FIPS 198a).
272          */
273
274         uint32_t digest_length;
275         /**< Length of the digest to be returned. If the verify option is set,
276          * this specifies the length of the digest to be compared for the
277          * session.
278          *
279          * If the value is less than the maximum length allowed by the hash,
280          * the result shall be truncated.  If the value is greater than the
281          * maximum length allowed by the hash then an error will be generated
282          * by *rte_cryptodev_sym_session_create* or by the
283          * *rte_cryptodev_sym_enqueue_burst* if using session-less APIs.
284          */
285
286         uint32_t add_auth_data_length;
287         /**< The length of the additional authenticated data (AAD) in bytes.
288          * The maximum permitted value is 240 bytes, unless otherwise specified
289          * below.
290          *
291          * This field must be specified when the hash algorithm is one of the
292          * following:
293          *
294          * - For SNOW3G (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2), this is the
295          *   length of the IV (which should be 16).
296          *
297          * - For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM).  In this case, this is
298          *   the length of the Additional Authenticated Data (called A, in NIST
299          *   SP800-38D).
300          *
301          * - For CCM (@ref RTE_CRYPTO_AUTH_AES_CCM).  In this case, this is
302          *   the length of the associated data (called A, in NIST SP800-38C).
303          *   Note that this does NOT include the length of any padding, or the
304          *   18 bytes reserved at the start of the above field to store the
305          *   block B0 and the encoded length.  The maximum permitted value in
306          *   this case is 222 bytes.
307          *
308          * @note
309          *  For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of operation
310          *  this field is not used and should be set to 0. Instead the length
311          *  of the AAD data is specified in the message length to hash field of
312          *  the rte_crypto_sym_op_data structure.
313          */
314 };
315
316 /** Crypto transformation types */
317 enum rte_crypto_sym_xform_type {
318         RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
319         RTE_CRYPTO_SYM_XFORM_AUTH,              /**< Authentication xform */
320         RTE_CRYPTO_SYM_XFORM_CIPHER             /**< Cipher xform  */
321 };
322
323 /**
324  * Symmetric crypto transform structure.
325  *
326  * This is used to specify the crypto transforms required, multiple transforms
327  * can be chained together to specify a chain transforms such as authentication
328  * then cipher, or cipher then authentication. Each transform structure can
329  * hold a single transform, the type field is used to specify which transform
330  * is contained within the union
331  */
332 struct rte_crypto_sym_xform {
333         struct rte_crypto_sym_xform *next;
334         /**< next xform in chain */
335         enum rte_crypto_sym_xform_type type
336         ; /**< xform type */
337         RTE_STD_C11
338         union {
339                 struct rte_crypto_auth_xform auth;
340                 /**< Authentication / hash xform */
341                 struct rte_crypto_cipher_xform cipher;
342                 /**< Cipher xform */
343         };
344 };
345
346 /**
347  * Crypto operation session type. This is used to specify whether a crypto
348  * operation has session structure attached for immutable parameters or if all
349  * operation information is included in the operation data structure.
350  */
351 enum rte_crypto_sym_op_sess_type {
352         RTE_CRYPTO_SYM_OP_WITH_SESSION, /**< Session based crypto operation */
353         RTE_CRYPTO_SYM_OP_SESSIONLESS   /**< Session-less crypto operation */
354 };
355
356
357 struct rte_cryptodev_sym_session;
358
359 /**
360  * Symmetric Cryptographic Operation.
361  *
362  * This structure contains data relating to performing symmetric cryptographic
363  * processing on a referenced mbuf data buffer.
364  *
365  * When a symmetric crypto operation is enqueued with the device for processing
366  * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
367  * which contains the source data which the crypto operation is to be performed
368  * on.
369  */
370 struct rte_crypto_sym_op {
371         struct rte_mbuf *m_src; /**< source mbuf */
372         struct rte_mbuf *m_dst; /**< destination mbuf */
373
374         enum rte_crypto_sym_op_sess_type sess_type;
375
376         RTE_STD_C11
377         union {
378                 struct rte_cryptodev_sym_session *session;
379                 /**< Handle for the initialised session context */
380                 struct rte_crypto_sym_xform *xform;
381                 /**< Session-less API crypto operation parameters */
382         };
383
384         struct {
385                 struct {
386                         uint32_t offset;
387                          /**< Starting point for cipher processing, specified
388                           * as number of bytes from start of data in the source
389                           * buffer. The result of the cipher operation will be
390                           * written back into the output buffer starting at
391                           * this location.
392                           *
393                           * @note
394                           * For Snow3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2
395                           * and KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8,
396                           * this field should be in bits.
397                           */
398
399                         uint32_t length;
400                          /**< The message length, in bytes, of the source buffer
401                           * on which the cryptographic operation will be
402                           * computed. This must be a multiple of the block size
403                           * if a block cipher is being used. This is also the
404                           * same as the result length.
405                           *
406                           * @note
407                           * In the case of CCM @ref RTE_CRYPTO_AUTH_AES_CCM,
408                           * this value should not include the length of the
409                           * padding or the length of the MAC; the driver will
410                           * compute the actual number of bytes over which the
411                           * encryption will occur, which will include these
412                           * values.
413                           *
414                           * @note
415                           * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC, this
416                           * field should be set to 0.
417                           *
418                           * @note
419                           * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2
420                           * and KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8,
421                           * this field should be in bits.
422                           */
423                 } data; /**< Data offsets and length for ciphering */
424
425                 struct {
426                         uint8_t *data;
427                         /**< Initialisation Vector or Counter.
428                          *
429                          * - For block ciphers in CBC or F8 mode, or for Kasumi
430                          * in F8 mode, or for SNOW3G in UEA2 mode, this is the
431                          * Initialisation Vector (IV) value.
432                          *
433                          * - For block ciphers in CTR mode, this is the counter.
434                          *
435                          * - For GCM mode, this is either the IV (if the length
436                          * is 96 bits) or J0 (for other sizes), where J0 is as
437                          * defined by NIST SP800-38D. Regardless of the IV
438                          * length, a full 16 bytes needs to be allocated.
439                          *
440                          * - For CCM mode, the first byte is reserved, and the
441                          * nonce should be written starting at &iv[1] (to allow
442                          * space for the implementation to write in the flags
443                          * in the first byte). Note that a full 16 bytes should
444                          * be allocated, even though the length field will
445                          * have a value less than this.
446                          *
447                          * - For AES-XTS, this is the 128bit tweak, i, from
448                          * IEEE Std 1619-2007.
449                          *
450                          * For optimum performance, the data pointed to SHOULD
451                          * be 8-byte aligned.
452                          */
453                         phys_addr_t phys_addr;
454                         uint16_t length;
455                         /**< Length of valid IV data.
456                          *
457                          * - For block ciphers in CBC or F8 mode, or for Kasumi
458                          * in F8 mode, or for SNOW3G in UEA2 mode, this is the
459                          * length of the IV (which must be the same as the
460                          * block length of the cipher).
461                          *
462                          * - For block ciphers in CTR mode, this is the length
463                          * of the counter (which must be the same as the block
464                          * length of the cipher).
465                          *
466                          * - For GCM mode, this is either 12 (for 96-bit IVs)
467                          * or 16, in which case data points to J0.
468                          *
469                          * - For CCM mode, this is the length of the nonce,
470                          * which can be in the range 7 to 13 inclusive.
471                          */
472                 } iv;   /**< Initialisation vector parameters */
473         } cipher;
474
475         struct {
476                 struct {
477                         uint32_t offset;
478                          /**< Starting point for hash processing, specified as
479                           * number of bytes from start of packet in source
480                           * buffer.
481                           *
482                           * @note
483                           * For CCM and GCM modes of operation, this field is
484                           * ignored. The field @ref aad field
485                           * should be set instead.
486                           *
487                           * @note For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC)
488                           * mode of operation, this field specifies the start
489                           * of the AAD data in the source buffer.
490                           *
491                           * @note
492                           * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2
493                           * and KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
494                           * this field should be in bits.
495                           */
496
497                         uint32_t length;
498                          /**< The message length, in bytes, of the source
499                           * buffer that the hash will be computed on.
500                           *
501                           * @note
502                           * For CCM and GCM modes of operation, this field is
503                           * ignored. The field @ref aad field should be set
504                           * instead.
505                           *
506                           * @note
507                           * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC mode
508                           * of operation, this field specifies the length of
509                           * the AAD data in the source buffer.
510                           *
511                           * @note
512                           * For Snow3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2
513                           * and KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
514                           * this field should be in bits.
515                           */
516                 } data; /**< Data offsets and length for authentication */
517
518                 struct {
519                         uint8_t *data;
520                         /**< If this member of this structure is set this is a
521                          * pointer to the location where the digest result
522                          * should be inserted (in the case of digest generation)
523                          * or where the purported digest exists (in the case of
524                          * digest verification).
525                          *
526                          * At session creation time, the client specified the
527                          * digest result length with the digest_length member
528                          * of the @ref rte_crypto_auth_xform structure. For
529                          * physical crypto devices the caller must allocate at
530                          * least digest_length of physically contiguous memory
531                          * at this location.
532                          *
533                          * For digest generation, the digest result will
534                          * overwrite any data at this location.
535                          *
536                          * @note
537                          * For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), for
538                          * "digest result" read "authentication tag T".
539                          *
540                          * If this member is not set the digest result is
541                          * understood to be in the destination buffer for
542                          * digest generation, and in the source buffer for
543                          * digest verification. The location of the digest
544                          * result in this case is immediately following the
545                          * region over which the digest is computed.
546                          */
547                         phys_addr_t phys_addr;
548                         /**< Physical address of digest */
549                         uint16_t length;
550                         /**< Length of digest */
551                 } digest; /**< Digest parameters */
552
553                 struct {
554                         uint8_t *data;
555                         /**< Pointer to Additional Authenticated Data (AAD)
556                          * needed for authenticated cipher mechanisms (CCM and
557                          * GCM), and to the IV for SNOW3G authentication
558                          * (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2). For other
559                          * authentication mechanisms this pointer is ignored.
560                          *
561                          * The length of the data pointed to by this field is
562                          * set up for the session in the @ref
563                          * rte_crypto_auth_xform structure as part of the @ref
564                          * rte_cryptodev_sym_session_create function call.
565                          * This length must not exceed 240 bytes.
566                          *
567                          * Specifically for CCM (@ref RTE_CRYPTO_AUTH_AES_CCM),
568                          * the caller should setup this field as follows:
569                          *
570                          * - the nonce should be written starting at an offset
571                          * of one byte into the array, leaving room for the
572                          * implementation to write in the flags to the first
573                          *  byte.
574                          *
575                          * - the additional  authentication data itself should
576                          * be written starting at an offset of 18 bytes into
577                          * the array, leaving room for the length encoding in
578                          * the first two bytes of the second block.
579                          *
580                          * - the array should be big enough to hold the above
581                          *  fields, plus any padding to round this up to the
582                          *  nearest multiple of the block size (16 bytes).
583                          *  Padding will be added by the implementation.
584                          *
585                          * Finally, for GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), the
586                          * caller should setup this field as follows:
587                          *
588                          * - the AAD is written in starting at byte 0
589                          * - the array must be big enough to hold the AAD, plus
590                          * any space to round this up to the nearest multiple
591                          * of the block size (16 bytes).
592                          *
593                          * @note
594                          * For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of
595                          * operation, this field is not used and should be set
596                          * to 0. Instead the AAD data should be placed in the
597                          * source buffer.
598                          */
599                         phys_addr_t phys_addr;  /**< physical address */
600                         uint16_t length;        /**< Length of digest */
601                 } aad;
602                 /**< Additional authentication parameters */
603         } auth;
604 } __rte_cache_aligned;
605
606
607 /**
608  * Reset the fields of a symmetric operation to their default values.
609  *
610  * @param       op      The crypto operation to be reset.
611  */
612 static inline void
613 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
614 {
615         memset(op, 0, sizeof(*op));
616
617         op->sess_type = RTE_CRYPTO_SYM_OP_SESSIONLESS;
618 }
619
620
621 /**
622  * Allocate space for symmetric crypto xforms in the private data space of the
623  * crypto operation. This also defaults the crypto xform type to
624  * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
625  * in the crypto operation
626  *
627  * @return
628  * - On success returns pointer to first crypto xform in crypto operations chain
629  * - On failure returns NULL
630  */
631 static inline struct rte_crypto_sym_xform *
632 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
633                 void *priv_data, uint8_t nb_xforms)
634 {
635         struct rte_crypto_sym_xform *xform;
636
637         sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
638
639         do {
640                 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
641                 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
642         } while (xform);
643
644         return sym_op->xform;
645 }
646
647
648 /**
649  * Attach a session to a symmetric crypto operation
650  *
651  * @param       sym_op  crypto operation
652  * @param       sess    cryptodev session
653  */
654 static inline int
655 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
656                 struct rte_cryptodev_sym_session *sess)
657 {
658         sym_op->session = sess;
659         sym_op->sess_type = RTE_CRYPTO_SYM_OP_WITH_SESSION;
660
661         return 0;
662 }
663
664
665 #ifdef __cplusplus
666 }
667 #endif
668
669 #endif /* _RTE_CRYPTO_SYM_H_ */