Imported Upstream version 16.11.2
[deb_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* or *RTE_CRYPTO_AUTH_AES_GMAC* element
88          * of the *rte_crypto_auth_algorithm* enum MUST be used to set up
89          * the related *rte_crypto_auth_setup_data* structure in the session
90          * context or in the op_params of the crypto operation structure
91          * in the case of a 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         /**< SNOW 3G 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         /**< SNOW 3G 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          * It is the caller's responsibility to ensure that the
280          * digest length is compliant with the hash algorithm being used.
281          * If the value is less than the maximum length allowed by the hash,
282          * the result shall be truncated.
283          */
284
285         uint32_t add_auth_data_length;
286         /**< The length of the additional authenticated data (AAD) in bytes.
287          * The maximum permitted value is 240 bytes, unless otherwise specified
288          * below.
289          *
290          * This field must be specified when the hash algorithm is one of the
291          * following:
292          *
293          * - For SNOW 3G (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2), this is the
294          *   length of the IV (which should be 16).
295          *
296          * - For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM).  In this case, this is
297          *   the length of the Additional Authenticated Data (called A, in NIST
298          *   SP800-38D).
299          *
300          * - For CCM (@ref RTE_CRYPTO_AUTH_AES_CCM).  In this case, this is
301          *   the length of the associated data (called A, in NIST SP800-38C).
302          *   Note that this does NOT include the length of any padding, or the
303          *   18 bytes reserved at the start of the above field to store the
304          *   block B0 and the encoded length.  The maximum permitted value in
305          *   this case is 222 bytes.
306          *
307          * @note
308          *  For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of operation
309          *  this field is not used and should be set to 0. Instead the length
310          *  of the AAD data is specified in additional authentication data
311          *  length field of the rte_crypto_sym_op_data structure
312          */
313 };
314
315 /** Crypto transformation types */
316 enum rte_crypto_sym_xform_type {
317         RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
318         RTE_CRYPTO_SYM_XFORM_AUTH,              /**< Authentication xform */
319         RTE_CRYPTO_SYM_XFORM_CIPHER             /**< Cipher xform  */
320 };
321
322 /**
323  * Symmetric crypto transform structure.
324  *
325  * This is used to specify the crypto transforms required, multiple transforms
326  * can be chained together to specify a chain transforms such as authentication
327  * then cipher, or cipher then authentication. Each transform structure can
328  * hold a single transform, the type field is used to specify which transform
329  * is contained within the union
330  */
331 struct rte_crypto_sym_xform {
332         struct rte_crypto_sym_xform *next;
333         /**< next xform in chain */
334         enum rte_crypto_sym_xform_type type
335         ; /**< xform type */
336         RTE_STD_C11
337         union {
338                 struct rte_crypto_auth_xform auth;
339                 /**< Authentication / hash xform */
340                 struct rte_crypto_cipher_xform cipher;
341                 /**< Cipher xform */
342         };
343 };
344
345 /**
346  * Crypto operation session type. This is used to specify whether a crypto
347  * operation has session structure attached for immutable parameters or if all
348  * operation information is included in the operation data structure.
349  */
350 enum rte_crypto_sym_op_sess_type {
351         RTE_CRYPTO_SYM_OP_WITH_SESSION, /**< Session based crypto operation */
352         RTE_CRYPTO_SYM_OP_SESSIONLESS   /**< Session-less crypto operation */
353 };
354
355
356 struct rte_cryptodev_sym_session;
357
358 /**
359  * Symmetric Cryptographic Operation.
360  *
361  * This structure contains data relating to performing symmetric cryptographic
362  * processing on a referenced mbuf data buffer.
363  *
364  * When a symmetric crypto operation is enqueued with the device for processing
365  * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
366  * which contains the source data which the crypto operation is to be performed
367  * on.
368  * While the mbuf is in use by a crypto operation no part of the mbuf should be
369  * changed by the application as the device may read or write to any part of the
370  * mbuf. In the case of hardware crypto devices some or all of the mbuf
371  * may be DMAed in and out of the device, so writing over the original data,
372  * though only the part specified by the rte_crypto_sym_op for transformation
373  * will be changed.
374  * Out-of-place (OOP) operation, where the source mbuf is different to the
375  * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
376  * The part copied includes all the parts of the source mbuf that will be
377  * operated on, based on the cipher.data.offset+cipher.data.length and
378  * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
379  * indicated by the cipher parameters will be transformed, any extra data around
380  * this indicated by the auth parameters will be copied unchanged from source to
381  * destination mbuf.
382  * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
383  * both source and destination mbufs. As these offsets are relative to the
384  * data_off parameter in each mbuf this can result in the data written to the
385  * destination buffer being at a different alignment, relative to buffer start,
386  * to the data in the source buffer.
387  */
388 struct rte_crypto_sym_op {
389         struct rte_mbuf *m_src; /**< source mbuf */
390         struct rte_mbuf *m_dst; /**< destination mbuf */
391
392         enum rte_crypto_sym_op_sess_type sess_type;
393
394         RTE_STD_C11
395         union {
396                 struct rte_cryptodev_sym_session *session;
397                 /**< Handle for the initialised session context */
398                 struct rte_crypto_sym_xform *xform;
399                 /**< Session-less API crypto operation parameters */
400         };
401
402         struct {
403                 struct {
404                         uint32_t offset;
405                          /**< Starting point for cipher processing, specified
406                           * as number of bytes from start of data in the source
407                           * buffer. The result of the cipher operation will be
408                           * written back into the output buffer starting at
409                           * this location.
410                           *
411                           * @note
412                           * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
413                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
414                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
415                           * this field should be in bits.
416                           */
417
418                         uint32_t length;
419                          /**< The message length, in bytes, of the source buffer
420                           * on which the cryptographic operation will be
421                           * computed. This must be a multiple of the block size
422                           * if a block cipher is being used. This is also the
423                           * same as the result length.
424                           *
425                           * @note
426                           * In the case of CCM @ref RTE_CRYPTO_AUTH_AES_CCM,
427                           * this value should not include the length of the
428                           * padding or the length of the MAC; the driver will
429                           * compute the actual number of bytes over which the
430                           * encryption will occur, which will include these
431                           * values.
432                           *
433                           * @note
434                           * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC, this
435                           * field should be set to 0.
436                           *
437                           * @note
438                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
439                           * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
440                           * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
441                           * this field should be in bits.
442                           */
443                 } data; /**< Data offsets and length for ciphering */
444
445                 struct {
446                         uint8_t *data;
447                         /**< Initialisation Vector or Counter.
448                          *
449                          * - For block ciphers in CBC or F8 mode, or for KASUMI
450                          * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
451                          * Initialisation Vector (IV) value.
452                          *
453                          * - For block ciphers in CTR mode, this is the counter.
454                          *
455                          * - For GCM mode, this is either the IV (if the length
456                          * is 96 bits) or J0 (for other sizes), where J0 is as
457                          * defined by NIST SP800-38D. Regardless of the IV
458                          * length, a full 16 bytes needs to be allocated.
459                          *
460                          * - For CCM mode, the first byte is reserved, and the
461                          * nonce should be written starting at &iv[1] (to allow
462                          * space for the implementation to write in the flags
463                          * in the first byte). Note that a full 16 bytes should
464                          * be allocated, even though the length field will
465                          * have a value less than this.
466                          *
467                          * - For AES-XTS, this is the 128bit tweak, i, from
468                          * IEEE Std 1619-2007.
469                          *
470                          * For optimum performance, the data pointed to SHOULD
471                          * be 8-byte aligned.
472                          */
473                         phys_addr_t phys_addr;
474                         uint16_t length;
475                         /**< Length of valid IV data.
476                          *
477                          * - For block ciphers in CBC or F8 mode, or for KASUMI
478                          * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
479                          * length of the IV (which must be the same as the
480                          * block length of the cipher).
481                          *
482                          * - For block ciphers in CTR mode, this is the length
483                          * of the counter (which must be the same as the block
484                          * length of the cipher).
485                          *
486                          * - For GCM mode, this is either 12 (for 96-bit IVs)
487                          * or 16, in which case data points to J0.
488                          *
489                          * - For CCM mode, this is the length of the nonce,
490                          * which can be in the range 7 to 13 inclusive.
491                          */
492                 } iv;   /**< Initialisation vector parameters */
493         } cipher;
494
495         struct {
496                 struct {
497                         uint32_t offset;
498                          /**< Starting point for hash processing, specified as
499                           * number of bytes from start of packet in source
500                           * buffer.
501                           *
502                           * @note
503                           * For CCM and GCM modes of operation, this field is
504                           * ignored. The field @ref aad field
505                           * should be set instead.
506                           *
507                           * @note For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC)
508                           * mode of operation, this field is set to 0. aad data
509                           * pointer of rte_crypto_sym_op_data structure is
510                           * used instead
511                           *
512                           * @note
513                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
514                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
515                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
516                           * this field should be in bits.
517                           */
518
519                         uint32_t length;
520                          /**< The message length, in bytes, of the source
521                           * buffer that the hash will be computed on.
522                           *
523                           * @note
524                           * For CCM and GCM modes of operation, this field is
525                           * ignored. The field @ref aad field should be set
526                           * instead.
527                           *
528                           * @note
529                           * For AES-GMAC @ref RTE_CRYPTO_AUTH_AES_GMAC mode
530                           * of operation, this field is set to 0.
531                           * Auth.aad.length is used instead.
532                           *
533                           * @note
534                           * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
535                           * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
536                           * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
537                           * this field should be in bits.
538                           */
539                 } data; /**< Data offsets and length for authentication */
540
541                 struct {
542                         uint8_t *data;
543                         /**< If this member of this structure is set this is a
544                          * pointer to the location where the digest result
545                          * should be inserted (in the case of digest generation)
546                          * or where the purported digest exists (in the case of
547                          * digest verification).
548                          *
549                          * At session creation time, the client specified the
550                          * digest result length with the digest_length member
551                          * of the @ref rte_crypto_auth_xform structure. For
552                          * physical crypto devices the caller must allocate at
553                          * least digest_length of physically contiguous memory
554                          * at this location.
555                          *
556                          * For digest generation, the digest result will
557                          * overwrite any data at this location.
558                          *
559                          * @note
560                          * For GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), for
561                          * "digest result" read "authentication tag T".
562                          *
563                          * If this member is not set the digest result is
564                          * understood to be in the destination buffer for
565                          * digest generation, and in the source buffer for
566                          * digest verification. The location of the digest
567                          * result in this case is immediately following the
568                          * region over which the digest is computed.
569                          */
570                         phys_addr_t phys_addr;
571                         /**< Physical address of digest */
572                         uint16_t length;
573                         /**< Length of digest. This must be the same value as
574                          * @ref rte_crypto_auth_xform.digest_length.
575                          */
576                 } digest; /**< Digest parameters */
577
578                 struct {
579                         uint8_t *data;
580                         /**< Pointer to Additional Authenticated Data (AAD)
581                          * needed for authenticated cipher mechanisms (CCM and
582                          * GCM), and to the IV for SNOW 3G authentication
583                          * (@ref RTE_CRYPTO_AUTH_SNOW3G_UIA2). For other
584                          * authentication mechanisms this pointer is ignored.
585                          *
586                          * The length of the data pointed to by this field is
587                          * set up for the session in the @ref
588                          * rte_crypto_auth_xform structure as part of the @ref
589                          * rte_cryptodev_sym_session_create function call.
590                          * This length must not exceed 240 bytes.
591                          *
592                          * Specifically for CCM (@ref RTE_CRYPTO_AUTH_AES_CCM),
593                          * the caller should setup this field as follows:
594                          *
595                          * - the nonce should be written starting at an offset
596                          * of one byte into the array, leaving room for the
597                          * implementation to write in the flags to the first
598                          *  byte.
599                          *
600                          * - the additional  authentication data itself should
601                          * be written starting at an offset of 18 bytes into
602                          * the array, leaving room for the length encoding in
603                          * the first two bytes of the second block.
604                          *
605                          * - the array should be big enough to hold the above
606                          *  fields, plus any padding to round this up to the
607                          *  nearest multiple of the block size (16 bytes).
608                          *  Padding will be added by the implementation.
609                          *
610                          * Finally, for GCM (@ref RTE_CRYPTO_AUTH_AES_GCM), the
611                          * caller should setup this field as follows:
612                          *
613                          * - the AAD is written in starting at byte 0
614                          * - the array must be big enough to hold the AAD, plus
615                          * any space to round this up to the nearest multiple
616                          * of the block size (16 bytes).
617                          *
618                          * @note
619                          * For AES-GMAC (@ref RTE_CRYPTO_AUTH_AES_GMAC) mode of
620                          * operation, this field is used to pass plaintext.
621                          */
622                         phys_addr_t phys_addr;  /**< physical address */
623                         uint16_t length;        /**< Length of digest */
624                 } aad;
625                 /**< Additional authentication parameters */
626         } auth;
627 } __rte_cache_aligned;
628
629
630 /**
631  * Reset the fields of a symmetric operation to their default values.
632  *
633  * @param       op      The crypto operation to be reset.
634  */
635 static inline void
636 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
637 {
638         memset(op, 0, sizeof(*op));
639
640         op->sess_type = RTE_CRYPTO_SYM_OP_SESSIONLESS;
641 }
642
643
644 /**
645  * Allocate space for symmetric crypto xforms in the private data space of the
646  * crypto operation. This also defaults the crypto xform type to
647  * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
648  * in the crypto operation
649  *
650  * @return
651  * - On success returns pointer to first crypto xform in crypto operations chain
652  * - On failure returns NULL
653  */
654 static inline struct rte_crypto_sym_xform *
655 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
656                 void *priv_data, uint8_t nb_xforms)
657 {
658         struct rte_crypto_sym_xform *xform;
659
660         sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
661
662         do {
663                 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
664                 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
665         } while (xform);
666
667         return sym_op->xform;
668 }
669
670
671 /**
672  * Attach a session to a symmetric crypto operation
673  *
674  * @param       sym_op  crypto operation
675  * @param       sess    cryptodev session
676  */
677 static inline int
678 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
679                 struct rte_cryptodev_sym_session *sess)
680 {
681         sym_op->session = sess;
682         sym_op->sess_type = RTE_CRYPTO_SYM_OP_WITH_SESSION;
683
684         return 0;
685 }
686
687
688 #ifdef __cplusplus
689 }
690 #endif
691
692 #endif /* _RTE_CRYPTO_SYM_H_ */