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 *src_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 * In case the PMD supports RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY, the
205 * original key data provided may be wrapped(encrypted) using key wrap
206 * algorithm such as AES key wrap (rfc3394) and hence length of the key
207 * may increase beyond the PMD advertised supported key size.
208 * PMD shall validate the key length and report EMSGSIZE error while
209 * configuring the session and application can skip checking the
210 * capability key length in such cases.
212 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will
213 * point to a concatenation of the AES encryption key followed by a
214 * keymask. As per RFC3711, the keymask should be padded with trailing
215 * bytes to match the length of the encryption key used.
217 * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes),
218 * 192 bits (24 bytes) or 256 bits (32 bytes).
220 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length
221 * should be set to the combined length of the encryption key and the
222 * keymask. Since the keymask and the encryption key are the same size,
223 * key.length should be set to 2 x the AES encryption key length.
225 * For the AES-XTS mode of operation:
226 * - Two keys must be provided and key.length refers to total length of
228 * - key.data must point to the two keys concatenated together
230 * - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes).
231 * - Both keys must have the same size.
235 /**< Starting point for Initialisation Vector or Counter,
236 * specified as number of bytes from start of crypto
237 * operation (rte_crypto_op).
239 * - For block ciphers in CBC or F8 mode, or for KASUMI
240 * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
241 * Initialisation Vector (IV) value.
243 * - For block ciphers in CTR mode, this is the counter.
245 * - For CCM mode, the first byte is reserved, and the
246 * nonce should be written starting at &iv[1] (to allow
247 * space for the implementation to write in the flags
248 * in the first byte). Note that a full 16 bytes should
249 * be allocated, even though the length field will
250 * have a value less than this. Note that the PMDs may
251 * modify the memory reserved (the first byte and the
254 * - For AES-XTS, this is the 128bit tweak, i, from
255 * IEEE Std 1619-2007.
257 * For optimum performance, the data pointed to SHOULD
261 /**< Length of valid IV data.
263 * - For block ciphers in CBC or F8 mode, or for KASUMI
264 * in F8 mode, or for SNOW 3G in UEA2 mode, this is the
265 * length of the IV (which must be the same as the
266 * block length of the cipher).
268 * - For block ciphers in CTR mode, this is the length
269 * of the counter (which must be the same as the block
270 * length of the cipher).
272 * - For CCM mode, this is the length of the nonce,
273 * which can be in the range 7 to 13 inclusive.
275 } iv; /**< Initialisation vector parameters */
277 uint32_t dataunit_len;
278 /**< When RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS is enabled,
279 * this is the data-unit length of the algorithm,
280 * otherwise or when the value is 0, use the operation length.
281 * The value should be in the range defined by the dataunit_set field
282 * in the cipher capability.
284 * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007.
285 * For-each data-unit in the operation, the tweak (IV) value is
286 * assigned consecutively starting from the operation assigned IV.
290 /** Symmetric Authentication / Hash Algorithms
292 * Note, to avoid ABI breakage across releases
293 * - LIST_END should not be added to this enum
294 * - the order of enums should not be changed
295 * - new algorithms should only be added to the end
297 enum rte_crypto_auth_algorithm {
298 RTE_CRYPTO_AUTH_NULL = 1,
299 /**< NULL hash algorithm. */
301 RTE_CRYPTO_AUTH_AES_CBC_MAC,
302 /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */
303 RTE_CRYPTO_AUTH_AES_CMAC,
304 /**< AES CMAC algorithm. */
305 RTE_CRYPTO_AUTH_AES_GMAC,
306 /**< AES GMAC algorithm. */
307 RTE_CRYPTO_AUTH_AES_XCBC_MAC,
308 /**< AES XCBC algorithm. */
310 RTE_CRYPTO_AUTH_KASUMI_F9,
311 /**< KASUMI algorithm in F9 mode. */
314 /**< MD5 algorithm */
315 RTE_CRYPTO_AUTH_MD5_HMAC,
316 /**< HMAC using MD5 algorithm */
318 RTE_CRYPTO_AUTH_SHA1,
319 /**< 160 bit SHA algorithm. */
320 RTE_CRYPTO_AUTH_SHA1_HMAC,
321 /**< HMAC using 160 bit SHA algorithm.
322 * HMAC-SHA-1-96 can be generated by setting
323 * digest_length to 12 bytes in auth/aead xforms.
325 RTE_CRYPTO_AUTH_SHA224,
326 /**< 224 bit SHA algorithm. */
327 RTE_CRYPTO_AUTH_SHA224_HMAC,
328 /**< HMAC using 224 bit SHA algorithm. */
329 RTE_CRYPTO_AUTH_SHA256,
330 /**< 256 bit SHA algorithm. */
331 RTE_CRYPTO_AUTH_SHA256_HMAC,
332 /**< HMAC using 256 bit SHA algorithm. */
333 RTE_CRYPTO_AUTH_SHA384,
334 /**< 384 bit SHA algorithm. */
335 RTE_CRYPTO_AUTH_SHA384_HMAC,
336 /**< HMAC using 384 bit SHA algorithm. */
337 RTE_CRYPTO_AUTH_SHA512,
338 /**< 512 bit SHA algorithm. */
339 RTE_CRYPTO_AUTH_SHA512_HMAC,
340 /**< HMAC using 512 bit SHA algorithm. */
342 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
343 /**< SNOW 3G algorithm in UIA2 mode. */
345 RTE_CRYPTO_AUTH_ZUC_EIA3,
346 /**< ZUC algorithm in EIA3 mode */
348 RTE_CRYPTO_AUTH_SHA3_224,
349 /**< 224 bit SHA3 algorithm. */
350 RTE_CRYPTO_AUTH_SHA3_224_HMAC,
351 /**< HMAC using 224 bit SHA3 algorithm. */
352 RTE_CRYPTO_AUTH_SHA3_256,
353 /**< 256 bit SHA3 algorithm. */
354 RTE_CRYPTO_AUTH_SHA3_256_HMAC,
355 /**< HMAC using 256 bit SHA3 algorithm. */
356 RTE_CRYPTO_AUTH_SHA3_384,
357 /**< 384 bit SHA3 algorithm. */
358 RTE_CRYPTO_AUTH_SHA3_384_HMAC,
359 /**< HMAC using 384 bit SHA3 algorithm. */
360 RTE_CRYPTO_AUTH_SHA3_512,
361 /**< 512 bit SHA3 algorithm. */
362 RTE_CRYPTO_AUTH_SHA3_512_HMAC
363 /**< HMAC using 512 bit SHA3 algorithm. */
366 /** Authentication algorithm name strings */
368 rte_crypto_auth_algorithm_strings[];
370 /** Symmetric Authentication / Hash Operations */
371 enum rte_crypto_auth_operation {
372 RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */
373 RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */
376 /** Authentication operation name strings */
378 rte_crypto_auth_operation_strings[];
381 * Authentication / Hash transform data.
383 * This structure contains data relating to an authentication/hash crypto
384 * transforms. The fields op, algo and digest_length are common to all
385 * authentication transforms and MUST be set.
387 struct rte_crypto_auth_xform {
388 enum rte_crypto_auth_operation op;
389 /**< Authentication operation type */
390 enum rte_crypto_auth_algorithm algo;
391 /**< Authentication algorithm selection */
394 const uint8_t *data; /**< pointer to key data */
395 uint16_t length; /**< key length in bytes */
397 /**< Authentication key data.
398 * The authentication key length MUST be less than or equal to the
399 * block size of the algorithm. It is the callers responsibility to
400 * ensure that the key length is compliant with the standard being used
401 * (for example RFC 2104, FIPS 198a).
406 /**< Starting point for Initialisation Vector or Counter,
407 * specified as number of bytes from start of crypto
408 * operation (rte_crypto_op).
410 * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode
411 * this is the authentication Initialisation Vector
412 * (IV) value. For AES-GMAC IV description please refer
413 * to the field `length` in iv struct.
415 * - For KASUMI in F9 mode and other authentication
416 * algorithms, this field is not used.
418 * For optimum performance, the data pointed to SHOULD
422 /**< Length of valid IV data.
424 * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and
425 * for AES-GMAC, this is the length of the IV.
427 * - For KASUMI in F9 mode and other authentication
428 * algorithms, this field is not used.
430 * - For GMAC mode, this is either:
431 * 1) Number greater or equal to one, which means that IV
432 * is used and J0 will be computed internally, a minimum
433 * of 16 bytes must be allocated.
434 * 2) Zero, in which case data points to J0. In this case
435 * 16 bytes of J0 should be passed where J0 is defined
439 } iv; /**< Initialisation vector parameters */
441 uint16_t digest_length;
442 /**< Length of the digest to be returned. If the verify option is set,
443 * this specifies the length of the digest to be compared for the
446 * It is the caller's responsibility to ensure that the
447 * digest length is compliant with the hash algorithm being used.
448 * If the value is less than the maximum length allowed by the hash,
449 * the result shall be truncated.
454 /** Symmetric AEAD Algorithms
456 * Note, to avoid ABI breakage across releases
457 * - LIST_END should not be added to this enum
458 * - the order of enums should not be changed
459 * - new algorithms should only be added to the end
461 enum rte_crypto_aead_algorithm {
462 RTE_CRYPTO_AEAD_AES_CCM = 1,
463 /**< AES algorithm in CCM mode. */
464 RTE_CRYPTO_AEAD_AES_GCM,
465 /**< AES algorithm in GCM mode. */
466 RTE_CRYPTO_AEAD_CHACHA20_POLY1305
467 /**< Chacha20 cipher with poly1305 authenticator */
470 /** AEAD algorithm name strings */
472 rte_crypto_aead_algorithm_strings[];
474 /** Symmetric AEAD Operations */
475 enum rte_crypto_aead_operation {
476 RTE_CRYPTO_AEAD_OP_ENCRYPT,
477 /**< Encrypt and generate digest */
478 RTE_CRYPTO_AEAD_OP_DECRYPT
479 /**< Verify digest and decrypt */
482 /** Authentication operation name strings */
484 rte_crypto_aead_operation_strings[];
486 struct rte_crypto_aead_xform {
487 enum rte_crypto_aead_operation op;
488 /**< AEAD operation type */
489 enum rte_crypto_aead_algorithm algo;
490 /**< AEAD algorithm selection */
493 const uint8_t *data; /**< pointer to key data */
494 uint16_t length; /**< key length in bytes */
499 /**< Starting point for Initialisation Vector or Counter,
500 * specified as number of bytes from start of crypto
501 * operation (rte_crypto_op).
503 * - For CCM mode, the first byte is reserved, and the
504 * nonce should be written starting at &iv[1] (to allow
505 * space for the implementation to write in the flags
506 * in the first byte). Note that a full 16 bytes should
507 * be allocated, even though the length field will
508 * have a value less than this.
510 * - For Chacha20-Poly1305 it is 96-bit nonce.
511 * PMD sets initial counter for Poly1305 key generation
512 * part to 0 and for Chacha20 encryption to 1 as per
513 * rfc8439 2.8. AEAD construction.
515 * For optimum performance, the data pointed to SHOULD
519 /**< Length of valid IV data.
521 * - For GCM mode, this is either:
522 * 1) Number greater or equal to one, which means that IV
523 * is used and J0 will be computed internally, a minimum
524 * of 16 bytes must be allocated.
525 * 2) Zero, in which case data points to J0. In this case
526 * 16 bytes of J0 should be passed where J0 is defined
529 * - For CCM mode, this is the length of the nonce,
530 * which can be in the range 7 to 13 inclusive.
532 * - For Chacha20-Poly1305 this field is always 12.
534 } iv; /**< Initialisation vector parameters */
536 uint16_t digest_length;
539 /**< The length of the additional authenticated data (AAD) in bytes.
540 * For CCM mode, this is the length of the actual AAD, even though
541 * it is required to reserve 18 bytes before the AAD and padding
542 * at the end of it, so a multiple of 16 bytes is allocated.
546 /** Crypto transformation types */
547 enum rte_crypto_sym_xform_type {
548 RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */
549 RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */
550 RTE_CRYPTO_SYM_XFORM_CIPHER, /**< Cipher xform */
551 RTE_CRYPTO_SYM_XFORM_AEAD /**< AEAD xform */
555 * Symmetric crypto transform structure.
557 * This is used to specify the crypto transforms required, multiple transforms
558 * can be chained together to specify a chain transforms such as authentication
559 * then cipher, or cipher then authentication. Each transform structure can
560 * hold a single transform, the type field is used to specify which transform
561 * is contained within the union
563 struct rte_crypto_sym_xform {
564 struct rte_crypto_sym_xform *next;
565 /**< next xform in chain */
566 enum rte_crypto_sym_xform_type type
570 struct rte_crypto_auth_xform auth;
571 /**< Authentication / hash xform */
572 struct rte_crypto_cipher_xform cipher;
574 struct rte_crypto_aead_xform aead;
579 struct rte_cryptodev_sym_session;
582 * Symmetric Cryptographic Operation.
584 * This structure contains data relating to performing symmetric cryptographic
585 * processing on a referenced mbuf data buffer.
587 * When a symmetric crypto operation is enqueued with the device for processing
588 * it must have a valid *rte_mbuf* structure attached, via m_src parameter,
589 * which contains the source data which the crypto operation is to be performed
591 * While the mbuf is in use by a crypto operation no part of the mbuf should be
592 * changed by the application as the device may read or write to any part of the
593 * mbuf. In the case of hardware crypto devices some or all of the mbuf
594 * may be DMAed in and out of the device, so writing over the original data,
595 * though only the part specified by the rte_crypto_sym_op for transformation
597 * Out-of-place (OOP) operation, where the source mbuf is different to the
598 * destination mbuf, is a special case. Data will be copied from m_src to m_dst.
599 * The part copied includes all the parts of the source mbuf that will be
600 * operated on, based on the cipher.data.offset+cipher.data.length and
601 * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part
602 * indicated by the cipher parameters will be transformed, any extra data around
603 * this indicated by the auth parameters will be copied unchanged from source to
605 * Also in OOP operation the cipher.data.offset and auth.data.offset apply to
606 * both source and destination mbufs. As these offsets are relative to the
607 * data_off parameter in each mbuf this can result in the data written to the
608 * destination buffer being at a different alignment, relative to buffer start,
609 * to the data in the source buffer.
611 struct rte_crypto_sym_op {
612 struct rte_mbuf *m_src; /**< source mbuf */
613 struct rte_mbuf *m_dst; /**< destination mbuf */
617 struct rte_cryptodev_sym_session *session;
618 /**< Handle for the initialised session context */
619 struct rte_crypto_sym_xform *xform;
620 /**< Session-less API crypto operation parameters */
621 struct rte_security_session *sec_session;
622 /**< Handle for the initialised security session context */
630 /**< Starting point for AEAD processing, specified as
631 * number of bytes from start of packet in source
635 /**< The message length, in bytes, of the source buffer
636 * on which the cryptographic operation will be
637 * computed. This must be a multiple of the block size
639 } data; /**< Data offsets and length for AEAD */
642 /**< This points to the location where the digest result
643 * should be inserted (in the case of digest generation)
644 * or where the purported digest exists (in the case of
645 * digest verification).
647 * At session creation time, the client specified the
648 * digest result length with the digest_length member
649 * of the @ref rte_crypto_auth_xform structure. For
650 * physical crypto devices the caller must allocate at
651 * least digest_length of physically contiguous memory
654 * For digest generation, the digest result will
655 * overwrite any data at this location.
658 * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for
659 * "digest result" read "authentication tag T".
661 rte_iova_t phys_addr;
662 /**< Physical address of digest */
663 } digest; /**< Digest parameters */
666 /**< Pointer to Additional Authenticated Data (AAD)
667 * needed for authenticated cipher mechanisms (CCM and
670 * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM),
671 * the caller should setup this field as follows:
673 * - the additional authentication data itself should
674 * be written starting at an offset of 18 bytes into
675 * the array, leaving room for the first block (16 bytes)
676 * and the length encoding in the first two bytes of the
679 * - the array should be big enough to hold the above
680 * fields, plus any padding to round this up to the
681 * nearest multiple of the block size (16 bytes).
682 * Padding will be added by the implementation.
684 * - Note that PMDs may modify the memory reserved
685 * (first 18 bytes and the final padding).
687 * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the
688 * caller should setup this field as follows:
690 * - the AAD is written in starting at byte 0
691 * - the array must be big enough to hold the AAD, plus
692 * any space to round this up to the nearest multiple
693 * of the block size (16 bytes).
696 rte_iova_t phys_addr; /**< physical address */
698 /**< Additional authentication parameters */
705 /**< Starting point for cipher processing,
706 * specified as number of bytes from start
707 * of data in the source buffer.
708 * The result of the cipher operation will be
709 * written back into the output buffer
710 * starting at this location.
713 * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
714 * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
715 * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
716 * this field should be in bits. For
717 * digest-encrypted cases this must be
721 /**< The message length, in bytes, of the
722 * source buffer on which the cryptographic
723 * operation will be computed.
724 * This is also the same as the result length.
725 * This must be a multiple of the block size
726 * or a multiple of data-unit length
727 * as described in xform.
730 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2,
731 * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8
732 * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3,
733 * this field should be in bits. For
734 * digest-encrypted cases this must be
737 } data; /**< Data offsets and length for ciphering */
743 /**< Starting point for hash processing,
744 * specified as number of bytes from start of
745 * packet in source buffer.
748 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
749 * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
750 * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
751 * this field should be in bits. For
752 * digest-encrypted cases this must be
756 * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
757 * this offset should be such that
758 * data to authenticate starts at COUNT.
761 * For DOCSIS security protocol, this
762 * offset is the DOCSIS header length
763 * and, therefore, also the CRC offset
764 * i.e. the number of bytes into the
765 * packet at which CRC calculation
769 /**< The message length, in bytes, of the source
770 * buffer that the hash will be computed on.
773 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2,
774 * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9
775 * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3,
776 * this field should be in bits. For
777 * digest-encrypted cases this must be
781 * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9,
782 * the length should include the COUNT,
783 * FRESH, message, direction bit and padding
784 * (to be multiple of 8 bits).
787 * For DOCSIS security protocol, this
788 * is the CRC length i.e. the number of
789 * bytes in the packet over which the
790 * CRC should be calculated
793 /**< Data offsets and length for authentication */
797 /**< This points to the location where
798 * the digest result should be inserted
799 * (in the case of digest generation)
800 * or where the purported digest exists
801 * (in the case of digest verification).
803 * At session creation time, the client
804 * specified the digest result length with
805 * the digest_length member of the
806 * @ref rte_crypto_auth_xform structure.
807 * For physical crypto devices the caller
808 * must allocate at least digest_length of
809 * physically contiguous memory at this
812 * For digest generation, the digest result
813 * will overwrite any data at this location.
816 * Digest-encrypted case.
817 * Digest can be generated, appended to
818 * the end of raw data and encrypted
819 * together using chained digest
821 * (@ref RTE_CRYPTO_AUTH_OP_GENERATE)
823 * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT)
824 * xforms. Similarly, authentication
825 * of the raw data against appended,
826 * decrypted digest, can be performed
828 * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT)
829 * and digest verification
830 * (@ref RTE_CRYPTO_AUTH_OP_VERIFY)
832 * To perform those operations, a few
833 * additional conditions must be met:
834 * - caller must allocate at least
835 * digest_length of memory at the end of
836 * source and (in case of out-of-place
837 * operations) destination buffer; those
838 * buffers can be linear or split using
839 * scatter-gather lists,
840 * - digest data pointer must point to
841 * the end of source or (in case of
842 * out-of-place operations) destination
843 * data, which is pointer to the
844 * data buffer + auth.data.offset +
846 * - cipher.data.offset +
847 * cipher.data.length must be greater
848 * than auth.data.offset +
849 * auth.data.length and is typically
850 * equal to auth.data.offset +
851 * auth.data.length + digest_length.
852 * - for wireless algorithms, i.e.
853 * SNOW 3G, KASUMI and ZUC, as the
854 * cipher.data.length,
855 * cipher.data.offset,
856 * auth.data.length and
857 * auth.data.offset are in bits, they
858 * must be 8-bit multiples.
860 * Note, that for security reasons, it
861 * is PMDs' responsibility to not
862 * leave an unencrypted digest in any
863 * buffer after performing auth-cipher
867 rte_iova_t phys_addr;
868 /**< Physical address of digest */
869 } digest; /**< Digest parameters */
877 * Reset the fields of a symmetric operation to their default values.
879 * @param op The crypto operation to be reset.
882 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op)
884 memset(op, 0, sizeof(*op));
889 * Allocate space for symmetric crypto xforms in the private data space of the
890 * crypto operation. This also defaults the crypto xform type to
891 * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms
892 * in the crypto operation
895 * - On success returns pointer to first crypto xform in crypto operations chain
896 * - On failure returns NULL
898 static inline struct rte_crypto_sym_xform *
899 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op,
900 void *priv_data, uint8_t nb_xforms)
902 struct rte_crypto_sym_xform *xform;
904 sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data;
907 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED;
908 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL;
911 return sym_op->xform;
916 * Attach a session to a symmetric crypto operation
918 * @param sym_op crypto operation
919 * @param sess cryptodev session
922 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op,
923 struct rte_cryptodev_sym_session *sess)
925 sym_op->session = sess;
931 * Converts portion of mbuf data into a vector representation.
932 * Each segment will be represented as a separate entry in *vec* array.
933 * Expects that provided *ofs* + *len* not to exceed mbuf's *pkt_len*.
935 * Pointer to the *rte_mbuf* object.
937 * Offset within mbuf data to start with.
939 * Length of data to represent.
941 * Pointer to an output array of IO vectors.
943 * Size of an output array.
945 * - number of successfully filled entries in *vec* array.
946 * - negative number of elements in *vec* array required.
950 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len,
951 struct rte_crypto_vec vec[], uint32_t num)
954 struct rte_mbuf *nseg;
958 /* assuming that requested data starts in the first segment */
959 RTE_ASSERT(mb->data_len > ofs);
961 if (mb->nb_segs > num)
964 vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs);
965 vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs);
967 /* whole data lies in the first segment */
968 seglen = mb->data_len - ofs;
974 /* data spread across segments */
977 for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) {
979 vec[i].base = rte_pktmbuf_mtod(nseg, void *);
980 vec[i].iova = rte_pktmbuf_iova(nseg);
982 seglen = nseg->data_len;
983 if (left <= seglen) {
984 /* whole requested data is completed */
990 /* use whole segment */
995 RTE_ASSERT(left == 0);
1004 #endif /* _RTE_CRYPTO_SYM_H_ */