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