1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2020 Intel Corporation
5 #ifndef _RTE_CRYPTO_SYM_H_
6 #define _RTE_CRYPTO_SYM_H_
9 * @file rte_crypto_sym.h
11 * RTE Definitions for Symmetric Cryptography
13 * Defines symmetric cipher and authentication algorithms and modes, as well
14 * as supported symmetric crypto operation combinations.
24 #include <rte_memory.h>
25 #include <rte_mempool.h>
26 #include <rte_common.h>
29 * Crypto IO Vector (in analogy with struct iovec)
30 * Supposed be used to pass input/output data buffers for crypto data-path
33 struct rte_crypto_vec {
34 /** virtual address of the data buffer */
36 /** IOVA of the data buffer */
38 /** length of the data buffer */
43 * Crypto scatter-gather list descriptor. Consists of a pointer to an array
44 * of Crypto IO vectors with its size.
46 struct rte_crypto_sgl {
47 /** start of an array of vectors */
48 struct rte_crypto_vec *vec;
49 /** size of an array of vectors */
54 * Crypto virtual and IOVA address descriptor, used to describe cryptographic
55 * data buffer without the length information. The length information is
56 * normally predefined during session creation.
58 struct rte_crypto_va_iova_ptr {
64 * Raw data operation descriptor.
65 * Supposed to be used with synchronous CPU crypto API call or asynchronous
66 * RAW data path API call.
68 struct rte_crypto_sym_vec {
69 /** number of operations to perform */
71 /** array of SGL vectors */
72 struct rte_crypto_sgl *sgl;
73 /** array of pointers to cipher IV */
74 struct rte_crypto_va_iova_ptr *iv;
75 /** array of pointers to digest */
76 struct rte_crypto_va_iova_ptr *digest;
80 /** array of pointers to auth IV, used for chain operation */
81 struct rte_crypto_va_iova_ptr *auth_iv;
82 /** array of pointers to AAD, used for AEAD operation */
83 struct rte_crypto_va_iova_ptr *aad;
87 * array of statuses for each operation:
95 * used for cpu_crypto_process_bulk() to specify head/tail offsets
96 * for auth/cipher processing.
98 union rte_crypto_sym_ofs {
108 /** Symmetric Cipher Algorithms
110 * Note, to avoid ABI breakage across releases
111 * - LIST_END should not be added to this enum
112 * - the order of enums should not be changed
113 * - new algorithms should only be added to the end
115 enum rte_crypto_cipher_algorithm {
116 RTE_CRYPTO_CIPHER_NULL = 1,
117 /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */
119 RTE_CRYPTO_CIPHER_3DES_CBC,
120 /**< Triple DES algorithm in CBC mode */
121 RTE_CRYPTO_CIPHER_3DES_CTR,
122 /**< Triple DES algorithm in CTR mode */
123 RTE_CRYPTO_CIPHER_3DES_ECB,
124 /**< Triple DES algorithm in ECB mode */
126 RTE_CRYPTO_CIPHER_AES_CBC,
127 /**< AES algorithm in CBC mode */
128 RTE_CRYPTO_CIPHER_AES_CTR,
129 /**< AES algorithm in Counter mode */
130 RTE_CRYPTO_CIPHER_AES_ECB,
131 /**< AES algorithm in ECB mode */
132 RTE_CRYPTO_CIPHER_AES_F8,
133 /**< AES algorithm in F8 mode */
134 RTE_CRYPTO_CIPHER_AES_XTS,
135 /**< AES algorithm in XTS mode */
137 RTE_CRYPTO_CIPHER_ARC4,
138 /**< (A)RC4 cipher algorithm */
140 RTE_CRYPTO_CIPHER_KASUMI_F8,
141 /**< KASUMI algorithm in F8 mode */
143 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
144 /**< SNOW 3G algorithm in UEA2 mode */
146 RTE_CRYPTO_CIPHER_ZUC_EEA3,
147 /**< ZUC algorithm in EEA3 mode */
149 RTE_CRYPTO_CIPHER_DES_CBC,
150 /**< DES algorithm in CBC mode */
152 RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
153 /**< AES algorithm using modes required by
154 * DOCSIS Baseline Privacy Plus Spec.
155 * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
156 * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
159 RTE_CRYPTO_CIPHER_DES_DOCSISBPI
160 /**< DES algorithm using modes required by
161 * DOCSIS Baseline Privacy Plus Spec.
162 * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next
163 * for m_src and m_dst in the rte_crypto_sym_op must be NULL.
167 /** Cipher algorithm name strings */
169 rte_crypto_cipher_algorithm_strings[];
171 /** Symmetric Cipher Direction */
172 enum rte_crypto_cipher_operation {
173 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
174 /**< Encrypt cipher operation */
175 RTE_CRYPTO_CIPHER_OP_DECRYPT
176 /**< Decrypt cipher operation */
179 /** Cipher operation name strings */
181 rte_crypto_cipher_operation_strings[];
184 * Symmetric Cipher Setup Data.
186 * This structure contains data relating to Cipher (Encryption and Decryption)
187 * use to create a session.
189 struct rte_crypto_cipher_xform {
190 enum rte_crypto_cipher_operation op;
191 /**< This parameter determines if the cipher operation is an encrypt or
192 * a decrypt operation. For the RC4 algorithm and the F8/CTR modes,
193 * only encrypt operations are valid.
195 enum rte_crypto_cipher_algorithm algo;
196 /**< Cipher algorithm */
199 const uint8_t *data; /**< pointer to key data */
200 uint16_t length; /**< key length in bytes */
204 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
205 * point to a concatenation of the AES encryption key followed by a
206 * keymask. As per RFC3711, the keymask should be padded with trailing
207 * bytes to match the length of the encryption key used.
209 * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
210 * 192 bits (24 bytes) or 256 bits (32 bytes).
212 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
213 * should be set to the combined length of the encryption key and the
214 * keymask. Since the keymask and the encryption key are the same size,
215 * key.length should be set to 2 x the AES encryption key length.
217 * For the AES-XTS mode of operation:
218 * - Two keys must be provided and key.length refers to total length of
220 * - key.data must point to the two keys concatenated together
222 * - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
223 * - Both keys must have the same size.
227 /**< Starting point for Initialisation Vector or Counter,
228 * specified as number of bytes from start of crypto
229 * operation (rte_crypto_op).
231 * - For block ciphers in CBC or F8 mode, or for KASUMI
232 * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
233 * Initialisation Vector (IV) value.
235 * - For block ciphers in CTR mode, this is the counter.
237 * - For CCM mode, the first byte is reserved, and the
238 * nonce should be written starting at &iv[1] (to allow
239 * space for the implementation to write in the flags
240 * in the first byte). Note that a full 16 bytes should
241 * be allocated, even though the length field will
242 * have a value less than this. Note that the PMDs may
243 * modify the memory reserved (the first byte and the
246 * - For AES-XTS, this is the 128bit tweak, i, from
247 * IEEE Std 1619-2007.
249 * For optimum performance, the data pointed to SHOULD
253 /**< Length of valid IV data.
255 * - For block ciphers in CBC or F8 mode, or for KASUMI
256 * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
257 * length of the IV (which must be the same as the
258 * block length of the cipher).
260 * - For block ciphers in CTR mode, this is the length
261 * of the counter (which must be the same as the block
262 * length of the cipher).
264 * - For CCM mode, this is the length of the nonce,
265 * which can be in the range 7 to 13 inclusive.
267 } iv; /**< Initialisation vector parameters */
270 /** Symmetric Authentication / Hash Algorithms
272 * Note, to avoid ABI breakage across releases
273 * - LIST_END should not be added to this enum
274 * - the order of enums should not be changed
275 * - new algorithms should only be added to the end
277 enum rte_crypto_auth_algorithm {
278 RTE_CRYPTO_AUTH_NULL = 1,
279 /**< NULL hash algorithm. */
281 RTE_CRYPTO_AUTH_AES_CBC_MAC,
282 /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
283 RTE_CRYPTO_AUTH_AES_CMAC,
284 /**< AES CMAC algorithm. */
285 RTE_CRYPTO_AUTH_AES_GMAC,
286 /**< AES GMAC algorithm. */
287 RTE_CRYPTO_AUTH_AES_XCBC_MAC,
288 /**< AES XCBC algorithm. */
290 RTE_CRYPTO_AUTH_KASUMI_F9,
291 /**< KASUMI algorithm in F9 mode. */
294 /**< MD5 algorithm */
295 RTE_CRYPTO_AUTH_MD5_HMAC,
296 /**< HMAC using MD5 algorithm */
298 RTE_CRYPTO_AUTH_SHA1,
299 /**< 160 bit SHA algorithm. */
300 RTE_CRYPTO_AUTH_SHA1_HMAC,
301 /**< HMAC using 160 bit SHA algorithm.
302 * HMAC-SHA-1-96 can be generated by setting
303 * digest_length to 12 bytes in auth/aead xforms.
305 RTE_CRYPTO_AUTH_SHA224,
306 /**< 224 bit SHA algorithm. */
307 RTE_CRYPTO_AUTH_SHA224_HMAC,
308 /**< HMAC using 224 bit SHA algorithm. */
309 RTE_CRYPTO_AUTH_SHA256,
310 /**< 256 bit SHA algorithm. */
311 RTE_CRYPTO_AUTH_SHA256_HMAC,
312 /**< HMAC using 256 bit SHA algorithm. */
313 RTE_CRYPTO_AUTH_SHA384,
314 /**< 384 bit SHA algorithm. */
315 RTE_CRYPTO_AUTH_SHA384_HMAC,
316 /**< HMAC using 384 bit SHA algorithm. */
317 RTE_CRYPTO_AUTH_SHA512,
318 /**< 512 bit SHA algorithm. */
319 RTE_CRYPTO_AUTH_SHA512_HMAC,
320 /**< HMAC using 512 bit SHA algorithm. */
322 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
323 /**< SNOW 3G algorithm in UIA2 mode. */
325 RTE_CRYPTO_AUTH_ZUC_EIA3,
326 /**< ZUC algorithm in EIA3 mode */
328 RTE_CRYPTO_AUTH_SHA3_224,
329 /**< 224 bit SHA3 algorithm. */
330 RTE_CRYPTO_AUTH_SHA3_224_HMAC,
331 /**< HMAC using 224 bit SHA3 algorithm. */
332 RTE_CRYPTO_AUTH_SHA3_256,
333 /**< 256 bit SHA3 algorithm. */
334 RTE_CRYPTO_AUTH_SHA3_256_HMAC,
335 /**< HMAC using 256 bit SHA3 algorithm. */
336 RTE_CRYPTO_AUTH_SHA3_384,
337 /**< 384 bit SHA3 algorithm. */
338 RTE_CRYPTO_AUTH_SHA3_384_HMAC,
339 /**< HMAC using 384 bit SHA3 algorithm. */
340 RTE_CRYPTO_AUTH_SHA3_512,
341 /**< 512 bit SHA3 algorithm. */
342 RTE_CRYPTO_AUTH_SHA3_512_HMAC
343 /**< HMAC using 512 bit SHA3 algorithm. */
346 /** Authentication algorithm name strings */
348 rte_crypto_auth_algorithm_strings[];
350 /** Symmetric Authentication / Hash Operations */
351 enum rte_crypto_auth_operation {
352 RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */
353 RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */
356 /** Authentication operation name strings */
358 rte_crypto_auth_operation_strings[];
361 * Authentication / Hash transform data.
363 * This structure contains data relating to an authentication/hash crypto
364 * transforms. The fields op, algo and digest_length are common to all
365 * authentication transforms and MUST be set.
367 struct rte_crypto_auth_xform {
368 enum rte_crypto_auth_operation op;
369 /**< Authentication operation type */
370 enum rte_crypto_auth_algorithm algo;
371 /**< Authentication algorithm selection */
374 const uint8_t *data; /**< pointer to key data */
375 uint16_t length; /**< key length in bytes */
377 /**< Authentication key data.
378 * The authentication key length MUST be less than or equal to the
379 * block size of the algorithm. It is the callers responsibility to
380 * ensure that the key length is compliant with the standard being used
381 * (for example RFC 2104, FIPS 198a).
386 /**< Starting point for Initialisation Vector or Counter,
387 * specified as number of bytes from start of crypto
388 * operation (rte_crypto_op).
390 * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode
391 * this is the authentication Initialisation Vector
392 * (IV) value. For AES-GMAC IV description please refer
393 * to the field `length` in iv struct.
395 * - For KASUMI in F9 mode and other authentication
396 * algorithms, this field is not used.
398 * For optimum performance, the data pointed to SHOULD
402 /**< Length of valid IV data.
404 * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and
405 * for AES-GMAC, this is the length of the IV.
407 * - For KASUMI in F9 mode and other authentication
408 * algorithms, this field is not used.
410 * - For GMAC mode, this is either:
411 * 1) Number greater or equal to one, which means that IV
412 * is used and J0 will be computed internally, a minimum
413 * of 16 bytes must be allocated.
414 * 2) Zero, in which case data points to J0. In this case
415 * 16 bytes of J0 should be passed where J0 is defined
419 } iv; /**< Initialisation vector parameters */
421 uint16_t digest_length;
422 /**< Length of the digest to be returned. If the verify option is set,
423 * this specifies the length of the digest to be compared for the
426 * It is the caller's responsibility to ensure that the
427 * digest length is compliant with the hash algorithm being used.
428 * If the value is less than the maximum length allowed by the hash,
429 * the result shall be truncated.
434 /** Symmetric AEAD Algorithms
436 * Note, to avoid ABI breakage across releases
437 * - LIST_END should not be added to this enum
438 * - the order of enums should not be changed
439 * - new algorithms should only be added to the end
441 enum rte_crypto_aead_algorithm {
442 RTE_CRYPTO_AEAD_AES_CCM = 1,
443 /**< AES algorithm in CCM mode. */
444 RTE_CRYPTO_AEAD_AES_GCM,
445 /**< AES algorithm in GCM mode. */
446 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
447 /**< Chacha20 cipher with poly1305 authenticator */
450 /** AEAD algorithm name strings */
452 rte_crypto_aead_algorithm_strings[];
454 /** Symmetric AEAD Operations */
455 enum rte_crypto_aead_operation {
456 RTE_CRYPTO_AEAD_OP_ENCRYPT,
457 /**< Encrypt and generate digest */
458 RTE_CRYPTO_AEAD_OP_DECRYPT
459 /**< Verify digest and decrypt */
462 /** Authentication operation name strings */
464 rte_crypto_aead_operation_strings[];
466 struct rte_crypto_aead_xform {
467 enum rte_crypto_aead_operation op;
468 /**< AEAD operation type */
469 enum rte_crypto_aead_algorithm algo;
470 /**< AEAD algorithm selection */
473 const uint8_t *data; /**< pointer to key data */
474 uint16_t length; /**< key length in bytes */
479 /**< Starting point for Initialisation Vector or Counter,
480 * specified as number of bytes from start of crypto
481 * operation (rte_crypto_op).
483 * - For CCM mode, the first byte is reserved, and the
484 * nonce should be written starting at &iv[1] (to allow
485 * space for the implementation to write in the flags
486 * in the first byte). Note that a full 16 bytes should
487 * be allocated, even though the length field will
488 * have a value less than this.
490 * - For Chacha20-Poly1305 it is 96-bit nonce.
491 * PMD sets initial counter for Poly1305 key generation
492 * part to 0 and for Chacha20 encryption to 1 as per
493 * rfc8439 2.8. AEAD construction.
495 * For optimum performance, the data pointed to SHOULD
499 /**< Length of valid IV data.
501 * - For GCM mode, this is either:
502 * 1) Number greater or equal to one, which means that IV
503 * is used and J0 will be computed internally, a minimum
504 * of 16 bytes must be allocated.
505 * 2) Zero, in which case data points to J0. In this case
506 * 16 bytes of J0 should be passed where J0 is defined
509 * - For CCM mode, this is the length of the nonce,
510 * which can be in the range 7 to 13 inclusive.
512 * - For Chacha20-Poly1305 this field is always 12.
514 } iv; /**< Initialisation vector parameters */
516 uint16_t digest_length;
519 /**< The length of the additional authenticated data (AAD) in bytes.
520 * For CCM mode, this is the length of the actual AAD, even though
521 * it is required to reserve 18 bytes before the AAD and padding
522 * at the end of it, so a multiple of 16 bytes is allocated.
526 /** Crypto transformation types */
527 enum rte_crypto_sym_xform_type {
528 RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
529 RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */
530 RTE_CRYPTO_SYM_XFORM_CIPHER, /**< Cipher xform */
531 RTE_CRYPTO_SYM_XFORM_AEAD /**< AEAD xform */
535 * Symmetric crypto transform structure.
537 * This is used to specify the crypto transforms required, multiple transforms
538 * can be chained together to specify a chain transforms such as authentication
539 * then cipher, or cipher then authentication. Each transform structure can
540 * hold a single transform, the type field is used to specify which transform
541 * is contained within the union
543 struct rte_crypto_sym_xform {
544 struct rte_crypto_sym_xform *next;
545 /**< next xform in chain */
546 enum rte_crypto_sym_xform_type type
550 struct rte_crypto_auth_xform auth;
551 /**< Authentication / hash xform */
552 struct rte_crypto_cipher_xform cipher;
554 struct rte_crypto_aead_xform aead;
559 struct rte_cryptodev_sym_session;
562 * Symmetric Cryptographic Operation.
564 * This structure contains data relating to performing symmetric cryptographic
565 * processing on a referenced mbuf data buffer.
567 * When a symmetric crypto operation is enqueued with the device for processing
568 * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
569 * which contains the source data which the crypto operation is to be performed
571 * While the mbuf is in use by a crypto operation no part of the mbuf should be
572 * changed by the application as the device may read or write to any part of the
573 * mbuf. In the case of hardware crypto devices some or all of the mbuf
574 * may be DMAed in and out of the device, so writing over the original data,
575 * though only the part specified by the rte_crypto_sym_op for transformation
577 * Out-of-place (OOP) operation, where the source mbuf is different to the
578 * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
579 * The part copied includes all the parts of the source mbuf that will be
580 * operated on, based on the cipher.data.offset+cipher.data.length and
581 * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
582 * indicated by the cipher parameters will be transformed, any extra data around
583 * this indicated by the auth parameters will be copied unchanged from source to
585 * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
586 * both source and destination mbufs. As these offsets are relative to the
587 * data_off parameter in each mbuf this can result in the data written to the
588 * destination buffer being at a different alignment, relative to buffer start,
589 * to the data in the source buffer.
591 struct rte_crypto_sym_op {
592 struct rte_mbuf *m_src; /**< source mbuf */
593 struct rte_mbuf *m_dst; /**< destination mbuf */
597 struct rte_cryptodev_sym_session *session;
598 /**< Handle for the initialised session context */
599 struct rte_crypto_sym_xform *xform;
600 /**< Session-less API crypto operation parameters */
601 struct rte_security_session *sec_session;
602 /**< Handle for the initialised security session context */
610 /**< Starting point for AEAD processing, specified as
611 * number of bytes from start of packet in source
615 /**< The message length, in bytes, of the source buffer
616 * on which the cryptographic operation will be
617 * computed. This must be a multiple of the block size
619 } data; /**< Data offsets and length for AEAD */
622 /**< This points to the location where the digest result
623 * should be inserted (in the case of digest generation)
624 * or where the purported digest exists (in the case of
625 * digest verification).
627 * At session creation time, the client specified the
628 * digest result length with the digest_length member
629 * of the @ref rte_crypto_auth_xform structure. For
630 * physical crypto devices the caller must allocate at
631 * least digest_length of physically contiguous memory
634 * For digest generation, the digest result will
635 * overwrite any data at this location.
638 * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for
639 * "digest result" read "authentication tag T".
641 rte_iova_t phys_addr;
642 /**< Physical address of digest */
643 } digest; /**< Digest parameters */
646 /**< Pointer to Additional Authenticated Data (AAD)
647 * needed for authenticated cipher mechanisms (CCM and
650 * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM),
651 * the caller should setup this field as follows:
653 * - the additional authentication data itself should
654 * be written starting at an offset of 18 bytes into
655 * the array, leaving room for the first block (16 bytes)
656 * and the length encoding in the first two bytes of the
659 * - the array should be big enough to hold the above
660 * fields, plus any padding to round this up to the
661 * nearest multiple of the block size (16 bytes).
662 * Padding will be added by the implementation.
664 * - Note that PMDs may modify the memory reserved
665 * (first 18 bytes and the final padding).
667 * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the
668 * caller should setup this field as follows:
670 * - the AAD is written in starting at byte 0
671 * - the array must be big enough to hold the AAD, plus
672 * any space to round this up to the nearest multiple
673 * of the block size (16 bytes).
676 rte_iova_t phys_addr; /**< physical address */
678 /**< Additional authentication parameters */
685 /**< Starting point for cipher processing,
686 * specified as number of bytes from start
687 * of data in the source buffer.
688 * The result of the cipher operation will be
689 * written back into the output buffer
690 * starting at this location.
693 * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
694 * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
695 * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
696 * this field should be in bits. For
697 * digest-encrypted cases this must be
701 /**< The message length, in bytes, of the
702 * source buffer on which the cryptographic
703 * operation will be computed.
704 * This must be a multiple of the block size
705 * if a block cipher is being used. This is
706 * also the same as the result length.
709 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
710 * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
711 * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
712 * this field should be in bits. For
713 * digest-encrypted cases this must be
716 } data; /**< Data offsets and length for ciphering */
722 /**< Starting point for hash processing,
723 * specified as number of bytes from start of
724 * packet in source buffer.
727 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
728 * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
729 * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
730 * this field should be in bits. For
731 * digest-encrypted cases this must be
735 * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
736 * this offset should be such that
737 * data to authenticate starts at COUNT.
740 * For DOCSIS security protocol, this
741 * offset is the DOCSIS header length
742 * and, therefore, also the CRC offset
743 * i.e. the number of bytes into the
744 * packet at which CRC calculation
748 /**< The message length, in bytes, of the source
749 * buffer that the hash will be computed on.
752 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
753 * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
754 * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
755 * this field should be in bits. For
756 * digest-encrypted cases this must be
760 * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
761 * the length should include the COUNT,
762 * FRESH, message, direction bit and padding
763 * (to be multiple of 8 bits).
766 * For DOCSIS security protocol, this
767 * is the CRC length i.e. the number of
768 * bytes in the packet over which the
769 * CRC should be calculated
772 /**< Data offsets and length for authentication */
776 /**< This points to the location where
777 * the digest result should be inserted
778 * (in the case of digest generation)
779 * or where the purported digest exists
780 * (in the case of digest verification).
782 * At session creation time, the client
783 * specified the digest result length with
784 * the digest_length member of the
785 * @ref rte_crypto_auth_xform structure.
786 * For physical crypto devices the caller
787 * must allocate at least digest_length of
788 * physically contiguous memory at this
791 * For digest generation, the digest result
792 * will overwrite any data at this location.
795 * Digest-encrypted case.
796 * Digest can be generated, appended to
797 * the end of raw data and encrypted
798 * together using chained digest
800 * (@ref RTE_CRYPTO_AUTH_OP_GENERATE)
802 * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT)
803 * xforms. Similarly, authentication
804 * of the raw data against appended,
805 * decrypted digest, can be performed
807 * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT)
808 * and digest verification
809 * (@ref RTE_CRYPTO_AUTH_OP_VERIFY)
811 * To perform those operations, a few
812 * additional conditions must be met:
813 * - caller must allocate at least
814 * digest_length of memory at the end of
815 * source and (in case of out-of-place
816 * operations) destination buffer; those
817 * buffers can be linear or split using
818 * scatter-gather lists,
819 * - digest data pointer must point to
820 * the end of source or (in case of
821 * out-of-place operations) destination
822 * data, which is pointer to the
823 * data buffer + auth.data.offset +
825 * - cipher.data.offset +
826 * cipher.data.length must be greater
827 * than auth.data.offset +
828 * auth.data.length and is typically
829 * equal to auth.data.offset +
830 * auth.data.length + digest_length.
831 * - for wireless algorithms, i.e.
832 * SNOW 3G, KASUMI and ZUC, as the
833 * cipher.data.length,
834 * cipher.data.offset,
835 * auth.data.length and
836 * auth.data.offset are in bits, they
837 * must be 8-bit multiples.
839 * Note, that for security reasons, it
840 * is PMDs' responsibility to not
841 * leave an unencrypted digest in any
842 * buffer after performing auth-cipher
846 rte_iova_t phys_addr;
847 /**< Physical address of digest */
848 } digest; /**< Digest parameters */
856 * Reset the fields of a symmetric operation to their default values.
858 * @param op The crypto operation to be reset.
861 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
863 memset(op, 0, sizeof(*op));
868 * Allocate space for symmetric crypto xforms in the private data space of the
869 * crypto operation. This also defaults the crypto xform type to
870 * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
871 * in the crypto operation
874 * - On success returns pointer to first crypto xform in crypto operations chain
875 * - On failure returns NULL
877 static inline struct rte_crypto_sym_xform *
878 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
879 void *priv_data, uint8_t nb_xforms)
881 struct rte_crypto_sym_xform *xform;
883 sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
886 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
887 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
890 return sym_op->xform;
895 * Attach a session to a symmetric crypto operation
897 * @param sym_op crypto operation
898 * @param sess cryptodev session
901 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
902 struct rte_cryptodev_sym_session *sess)
904 sym_op->session = sess;
910 * Converts portion of mbuf data into a vector representation.
911 * Each segment will be represented as a separate entry in *vec* array.
912 * Expects that provided *ofs* + *len* not to exceed mbuf's *pkt_len*.
914 * Pointer to the *rte_mbuf* object.
916 * Offset within mbuf data to start with.
918 * Length of data to represent.
920 * Pointer to an output array of IO vectors.
922 * Size of an output array.
924 * - number of successfully filled entries in *vec* array.
925 * - negative number of elements in *vec* array required.
929 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
930 struct rte_crypto_vec vec[], uint32_t num)
933 struct rte_mbuf *nseg;
937 /* assuming that requested data starts in the first segment */
938 RTE_ASSERT(mb->data_len > ofs);
940 if (mb->nb_segs > num)
943 vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
944 vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
946 /* whole data lies in the first segment */
947 seglen = mb->data_len - ofs;
953 /* data spread across segments */
956 for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
958 vec[i].base = rte_pktmbuf_mtod(nseg, void *);
959 vec[i].iova = rte_pktmbuf_iova(nseg);
961 seglen = nseg->data_len;
962 if (left <= seglen) {
963 /* whole requested data is completed */
969 /* use whole segment */
974 RTE_ASSERT(left == 0);
983 #endif /* _RTE_CRYPTO_SYM_H_ */