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