199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2016-2020 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #ifndef _RTE_CRYPTO_SYM_H_ 699a2dd95SBruce Richardson #define _RTE_CRYPTO_SYM_H_ 799a2dd95SBruce Richardson 899a2dd95SBruce Richardson /** 999a2dd95SBruce Richardson * @file rte_crypto_sym.h 1099a2dd95SBruce Richardson * 1199a2dd95SBruce Richardson * RTE Definitions for Symmetric Cryptography 1299a2dd95SBruce Richardson * 1399a2dd95SBruce Richardson * Defines symmetric cipher and authentication algorithms and modes, as well 1499a2dd95SBruce Richardson * as supported symmetric crypto operation combinations. 1599a2dd95SBruce Richardson */ 1699a2dd95SBruce Richardson 1799a2dd95SBruce Richardson #include <string.h> 1899a2dd95SBruce Richardson 191094dd94SDavid Marchand #include <rte_compat.h> 2099a2dd95SBruce Richardson #include <rte_mbuf.h> 2199a2dd95SBruce Richardson #include <rte_memory.h> 2299a2dd95SBruce Richardson #include <rte_mempool.h> 2399a2dd95SBruce Richardson #include <rte_common.h> 2499a2dd95SBruce Richardson 25719834a6SMattias Rönnblom #ifdef __cplusplus 26719834a6SMattias Rönnblom extern "C" { 27719834a6SMattias Rönnblom #endif 28719834a6SMattias Rönnblom 2999a2dd95SBruce Richardson /** 3099a2dd95SBruce Richardson * Crypto IO Vector (in analogy with struct iovec) 3199a2dd95SBruce Richardson * Supposed be used to pass input/output data buffers for crypto data-path 3299a2dd95SBruce Richardson * functions. 3399a2dd95SBruce Richardson */ 3499a2dd95SBruce Richardson struct rte_crypto_vec { 3599a2dd95SBruce Richardson /** virtual address of the data buffer */ 3699a2dd95SBruce Richardson void *base; 3799a2dd95SBruce Richardson /** IOVA of the data buffer */ 3899a2dd95SBruce Richardson rte_iova_t iova; 3999a2dd95SBruce Richardson /** length of the data buffer */ 4099a2dd95SBruce Richardson uint32_t len; 416afd461fSGagandeep Singh /** total buffer length */ 426afd461fSGagandeep Singh uint32_t tot_len; 4399a2dd95SBruce Richardson }; 4499a2dd95SBruce Richardson 4599a2dd95SBruce Richardson /** 4699a2dd95SBruce Richardson * Crypto scatter-gather list descriptor. Consists of a pointer to an array 4799a2dd95SBruce Richardson * of Crypto IO vectors with its size. 4899a2dd95SBruce Richardson */ 4999a2dd95SBruce Richardson struct rte_crypto_sgl { 5099a2dd95SBruce Richardson /** start of an array of vectors */ 5199a2dd95SBruce Richardson struct rte_crypto_vec *vec; 5299a2dd95SBruce Richardson /** size of an array of vectors */ 5399a2dd95SBruce Richardson uint32_t num; 5499a2dd95SBruce Richardson }; 5599a2dd95SBruce Richardson 5699a2dd95SBruce Richardson /** 5799a2dd95SBruce Richardson * Crypto virtual and IOVA address descriptor, used to describe cryptographic 5899a2dd95SBruce Richardson * data buffer without the length information. The length information is 5999a2dd95SBruce Richardson * normally predefined during session creation. 6099a2dd95SBruce Richardson */ 6199a2dd95SBruce Richardson struct rte_crypto_va_iova_ptr { 6299a2dd95SBruce Richardson void *va; 6399a2dd95SBruce Richardson rte_iova_t iova; 6499a2dd95SBruce Richardson }; 6599a2dd95SBruce Richardson 6699a2dd95SBruce Richardson /** 6799a2dd95SBruce Richardson * Raw data operation descriptor. 6899a2dd95SBruce Richardson * Supposed to be used with synchronous CPU crypto API call or asynchronous 6999a2dd95SBruce Richardson * RAW data path API call. 7099a2dd95SBruce Richardson */ 7199a2dd95SBruce Richardson struct rte_crypto_sym_vec { 7299a2dd95SBruce Richardson /** number of operations to perform */ 7399a2dd95SBruce Richardson uint32_t num; 7499a2dd95SBruce Richardson /** array of SGL vectors */ 7510488d59SHemant Agrawal struct rte_crypto_sgl *src_sgl; 7668f5d3d3SHemant Agrawal /** array of SGL vectors for OOP, keep it NULL for inplace*/ 7768f5d3d3SHemant Agrawal struct rte_crypto_sgl *dest_sgl; 7899a2dd95SBruce Richardson /** array of pointers to cipher IV */ 7999a2dd95SBruce Richardson struct rte_crypto_va_iova_ptr *iv; 8099a2dd95SBruce Richardson /** array of pointers to digest */ 8199a2dd95SBruce Richardson struct rte_crypto_va_iova_ptr *digest; 8299a2dd95SBruce Richardson 8399a2dd95SBruce Richardson __extension__ 8499a2dd95SBruce Richardson union { 8599a2dd95SBruce Richardson /** array of pointers to auth IV, used for chain operation */ 8699a2dd95SBruce Richardson struct rte_crypto_va_iova_ptr *auth_iv; 8799a2dd95SBruce Richardson /** array of pointers to AAD, used for AEAD operation */ 8899a2dd95SBruce Richardson struct rte_crypto_va_iova_ptr *aad; 8999a2dd95SBruce Richardson }; 9099a2dd95SBruce Richardson 9199a2dd95SBruce Richardson /** 9299a2dd95SBruce Richardson * array of statuses for each operation: 9399a2dd95SBruce Richardson * - 0 on success 9499a2dd95SBruce Richardson * - errno on error 9599a2dd95SBruce Richardson */ 9699a2dd95SBruce Richardson int32_t *status; 9799a2dd95SBruce Richardson }; 9899a2dd95SBruce Richardson 9999a2dd95SBruce Richardson /** 10099a2dd95SBruce Richardson * used for cpu_crypto_process_bulk() to specify head/tail offsets 10199a2dd95SBruce Richardson * for auth/cipher processing. 10299a2dd95SBruce Richardson */ 10399a2dd95SBruce Richardson union rte_crypto_sym_ofs { 10499a2dd95SBruce Richardson uint64_t raw; 10599a2dd95SBruce Richardson struct { 10699a2dd95SBruce Richardson struct { 10799a2dd95SBruce Richardson uint16_t head; 10899a2dd95SBruce Richardson uint16_t tail; 10999a2dd95SBruce Richardson } auth, cipher; 11099a2dd95SBruce Richardson } ofs; 11199a2dd95SBruce Richardson }; 11299a2dd95SBruce Richardson 11399a2dd95SBruce Richardson /** Symmetric Cipher Algorithms 11499a2dd95SBruce Richardson * 11599a2dd95SBruce Richardson * Note, to avoid ABI breakage across releases 11699a2dd95SBruce Richardson * - LIST_END should not be added to this enum 11799a2dd95SBruce Richardson * - the order of enums should not be changed 11899a2dd95SBruce Richardson * - new algorithms should only be added to the end 11999a2dd95SBruce Richardson */ 12099a2dd95SBruce Richardson enum rte_crypto_cipher_algorithm { 12199a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_NULL = 1, 12299a2dd95SBruce Richardson /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */ 12399a2dd95SBruce Richardson 12499a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_3DES_CBC, 12599a2dd95SBruce Richardson /**< Triple DES algorithm in CBC mode */ 12699a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_3DES_CTR, 12799a2dd95SBruce Richardson /**< Triple DES algorithm in CTR mode */ 12899a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_3DES_ECB, 12999a2dd95SBruce Richardson /**< Triple DES algorithm in ECB mode */ 13099a2dd95SBruce Richardson 13199a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_AES_CBC, 13299a2dd95SBruce Richardson /**< AES algorithm in CBC mode */ 13399a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_AES_CTR, 13499a2dd95SBruce Richardson /**< AES algorithm in Counter mode */ 13599a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_AES_ECB, 13699a2dd95SBruce Richardson /**< AES algorithm in ECB mode */ 13799a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_AES_F8, 13899a2dd95SBruce Richardson /**< AES algorithm in F8 mode */ 13999a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_AES_XTS, 14099a2dd95SBruce Richardson /**< AES algorithm in XTS mode */ 14199a2dd95SBruce Richardson 14299a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_ARC4, 14399a2dd95SBruce Richardson /**< (A)RC4 cipher algorithm */ 14499a2dd95SBruce Richardson 14599a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_KASUMI_F8, 14699a2dd95SBruce Richardson /**< KASUMI algorithm in F8 mode */ 14799a2dd95SBruce Richardson 14899a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 14999a2dd95SBruce Richardson /**< SNOW 3G algorithm in UEA2 mode */ 15099a2dd95SBruce Richardson 15199a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_ZUC_EEA3, 15299a2dd95SBruce Richardson /**< ZUC algorithm in EEA3 mode */ 15399a2dd95SBruce Richardson 15499a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_DES_CBC, 15599a2dd95SBruce Richardson /**< DES algorithm in CBC mode */ 15699a2dd95SBruce Richardson 15799a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_AES_DOCSISBPI, 15899a2dd95SBruce Richardson /**< AES algorithm using modes required by 15999a2dd95SBruce Richardson * DOCSIS Baseline Privacy Plus Spec. 16099a2dd95SBruce Richardson * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next 16199a2dd95SBruce Richardson * for m_src and m_dst in the rte_crypto_sym_op must be NULL. 16299a2dd95SBruce Richardson */ 16399a2dd95SBruce Richardson 164515cd4a4SArek Kusztal RTE_CRYPTO_CIPHER_DES_DOCSISBPI, 16599a2dd95SBruce Richardson /**< DES algorithm using modes required by 16699a2dd95SBruce Richardson * DOCSIS Baseline Privacy Plus Spec. 16799a2dd95SBruce Richardson * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next 16899a2dd95SBruce Richardson * for m_src and m_dst in the rte_crypto_sym_op must be NULL. 16999a2dd95SBruce Richardson */ 170515cd4a4SArek Kusztal 171515cd4a4SArek Kusztal RTE_CRYPTO_CIPHER_SM4_ECB, 172515cd4a4SArek Kusztal /**< ShangMi 4 (SM4) algorithm in ECB mode */ 173515cd4a4SArek Kusztal RTE_CRYPTO_CIPHER_SM4_CBC, 174515cd4a4SArek Kusztal /**< ShangMi 4 (SM4) algorithm in CBC mode */ 1751daecf63SSunyang Wu RTE_CRYPTO_CIPHER_SM4_CTR, 176515cd4a4SArek Kusztal /**< ShangMi 4 (SM4) algorithm in CTR mode */ 1771daecf63SSunyang Wu RTE_CRYPTO_CIPHER_SM4_OFB, 1781daecf63SSunyang Wu /**< ShangMi 4 (SM4) algorithm in OFB mode */ 179*4acc862bSHanxiao Li RTE_CRYPTO_CIPHER_SM4_CFB, 1801daecf63SSunyang Wu /**< ShangMi 4 (SM4) algorithm in CFB mode */ 181*4acc862bSHanxiao Li RTE_CRYPTO_CIPHER_SM4_XTS 182*4acc862bSHanxiao Li /**< ShangMi 4 (SM4) algorithm in XTS mode */ 18399a2dd95SBruce Richardson }; 18499a2dd95SBruce Richardson 18599a2dd95SBruce Richardson /** Symmetric Cipher Direction */ 18699a2dd95SBruce Richardson enum rte_crypto_cipher_operation { 18799a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_OP_ENCRYPT, 18899a2dd95SBruce Richardson /**< Encrypt cipher operation */ 18999a2dd95SBruce Richardson RTE_CRYPTO_CIPHER_OP_DECRYPT 19099a2dd95SBruce Richardson /**< Decrypt cipher operation */ 19199a2dd95SBruce Richardson }; 19299a2dd95SBruce Richardson 19399a2dd95SBruce Richardson /** Cipher operation name strings */ 19499a2dd95SBruce Richardson extern const char * 19599a2dd95SBruce Richardson rte_crypto_cipher_operation_strings[]; 19699a2dd95SBruce Richardson 19799a2dd95SBruce Richardson /** 19899a2dd95SBruce Richardson * Symmetric Cipher Setup Data. 19999a2dd95SBruce Richardson * 20099a2dd95SBruce Richardson * This structure contains data relating to Cipher (Encryption and Decryption) 20199a2dd95SBruce Richardson * use to create a session. 20299a2dd95SBruce Richardson */ 20399a2dd95SBruce Richardson struct rte_crypto_cipher_xform { 20499a2dd95SBruce Richardson enum rte_crypto_cipher_operation op; 20599a2dd95SBruce Richardson /**< This parameter determines if the cipher operation is an encrypt or 20699a2dd95SBruce Richardson * a decrypt operation. For the RC4 algorithm and the F8/CTR modes, 20799a2dd95SBruce Richardson * only encrypt operations are valid. 20899a2dd95SBruce Richardson */ 20999a2dd95SBruce Richardson enum rte_crypto_cipher_algorithm algo; 21099a2dd95SBruce Richardson /**< Cipher algorithm */ 21199a2dd95SBruce Richardson 21299a2dd95SBruce Richardson struct { 21399a2dd95SBruce Richardson const uint8_t *data; /**< pointer to key data */ 21499a2dd95SBruce Richardson uint16_t length; /**< key length in bytes */ 21599a2dd95SBruce Richardson } key; 21699a2dd95SBruce Richardson /**< Cipher key 21799a2dd95SBruce Richardson * 21899a2dd95SBruce Richardson * In case the PMD supports RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY, the 21999a2dd95SBruce Richardson * original key data provided may be wrapped(encrypted) using key wrap 22099a2dd95SBruce Richardson * algorithm such as AES key wrap (rfc3394) and hence length of the key 22199a2dd95SBruce Richardson * may increase beyond the PMD advertised supported key size. 22299a2dd95SBruce Richardson * PMD shall validate the key length and report EMSGSIZE error while 22399a2dd95SBruce Richardson * configuring the session and application can skip checking the 22499a2dd95SBruce Richardson * capability key length in such cases. 22599a2dd95SBruce Richardson * 22699a2dd95SBruce Richardson * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will 22799a2dd95SBruce Richardson * point to a concatenation of the AES encryption key followed by a 22899a2dd95SBruce Richardson * keymask. As per RFC3711, the keymask should be padded with trailing 22999a2dd95SBruce Richardson * bytes to match the length of the encryption key used. 23099a2dd95SBruce Richardson * 23199a2dd95SBruce Richardson * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes), 23299a2dd95SBruce Richardson * 192 bits (24 bytes) or 256 bits (32 bytes). 23399a2dd95SBruce Richardson * 23499a2dd95SBruce Richardson * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length 23599a2dd95SBruce Richardson * should be set to the combined length of the encryption key and the 23699a2dd95SBruce Richardson * keymask. Since the keymask and the encryption key are the same size, 23799a2dd95SBruce Richardson * key.length should be set to 2 x the AES encryption key length. 23899a2dd95SBruce Richardson * 23999a2dd95SBruce Richardson * For the AES-XTS mode of operation: 24099a2dd95SBruce Richardson * - Two keys must be provided and key.length refers to total length of 24199a2dd95SBruce Richardson * the two keys. 24299a2dd95SBruce Richardson * - key.data must point to the two keys concatenated together 24399a2dd95SBruce Richardson * (key1 || key2). 24499a2dd95SBruce Richardson * - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes). 24599a2dd95SBruce Richardson * - Both keys must have the same size. 2463e4c5be9SThomas Monjalon */ 24799a2dd95SBruce Richardson struct { 24899a2dd95SBruce Richardson uint16_t offset; 24999a2dd95SBruce Richardson /**< Starting point for Initialisation Vector or Counter, 25099a2dd95SBruce Richardson * specified as number of bytes from start of crypto 25199a2dd95SBruce Richardson * operation (rte_crypto_op). 25299a2dd95SBruce Richardson * 25399a2dd95SBruce Richardson * - For block ciphers in CBC or F8 mode, or for KASUMI 25499a2dd95SBruce Richardson * in F8 mode, or for SNOW 3G in UEA2 mode, this is the 25599a2dd95SBruce Richardson * Initialisation Vector (IV) value. 25699a2dd95SBruce Richardson * 25799a2dd95SBruce Richardson * - For block ciphers in CTR mode, this is the counter. 25899a2dd95SBruce Richardson * 25999a2dd95SBruce Richardson * - For CCM mode, the first byte is reserved, and the 26099a2dd95SBruce Richardson * nonce should be written starting at &iv[1] (to allow 26199a2dd95SBruce Richardson * space for the implementation to write in the flags 26299a2dd95SBruce Richardson * in the first byte). Note that a full 16 bytes should 26399a2dd95SBruce Richardson * be allocated, even though the length field will 26499a2dd95SBruce Richardson * have a value less than this. Note that the PMDs may 26599a2dd95SBruce Richardson * modify the memory reserved (the first byte and the 26699a2dd95SBruce Richardson * final padding) 26799a2dd95SBruce Richardson * 26899a2dd95SBruce Richardson * - For AES-XTS, this is the 128bit tweak, i, from 26999a2dd95SBruce Richardson * IEEE Std 1619-2007. 27099a2dd95SBruce Richardson * 27199a2dd95SBruce Richardson * For optimum performance, the data pointed to SHOULD 27299a2dd95SBruce Richardson * be 8-byte aligned. 27399a2dd95SBruce Richardson */ 27499a2dd95SBruce Richardson uint16_t length; 27599a2dd95SBruce Richardson /**< Length of valid IV data. 27699a2dd95SBruce Richardson * 27799a2dd95SBruce Richardson * - For block ciphers in CBC or F8 mode, or for KASUMI 27899a2dd95SBruce Richardson * in F8 mode, or for SNOW 3G in UEA2 mode, this is the 27999a2dd95SBruce Richardson * length of the IV (which must be the same as the 28099a2dd95SBruce Richardson * block length of the cipher). 28199a2dd95SBruce Richardson * 28299a2dd95SBruce Richardson * - For block ciphers in CTR mode, this is the length 28399a2dd95SBruce Richardson * of the counter (which must be the same as the block 284e0e729b4SArkadiusz Kusztal * length of the cipher) or a 12-byte nonce (AES only) 28599a2dd95SBruce Richardson * 28699a2dd95SBruce Richardson * - For CCM mode, this is the length of the nonce, 28799a2dd95SBruce Richardson * which can be in the range 7 to 13 inclusive. 28899a2dd95SBruce Richardson */ 28999a2dd95SBruce Richardson } iv; /**< Initialisation vector parameters */ 290cab0c8f3SMatan Azrad 291cab0c8f3SMatan Azrad uint32_t dataunit_len; 292cab0c8f3SMatan Azrad /**< When RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS is enabled, 293cab0c8f3SMatan Azrad * this is the data-unit length of the algorithm, 294cab0c8f3SMatan Azrad * otherwise or when the value is 0, use the operation length. 295cab0c8f3SMatan Azrad * The value should be in the range defined by the dataunit_set field 296cab0c8f3SMatan Azrad * in the cipher capability. 297cab0c8f3SMatan Azrad * 298cab0c8f3SMatan Azrad * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007. 299cab0c8f3SMatan Azrad * For-each data-unit in the operation, the tweak (IV) value is 300cab0c8f3SMatan Azrad * assigned consecutively starting from the operation assigned IV. 301cab0c8f3SMatan Azrad */ 30299a2dd95SBruce Richardson }; 30399a2dd95SBruce Richardson 30499a2dd95SBruce Richardson /** Symmetric Authentication / Hash Algorithms 30599a2dd95SBruce Richardson * 30699a2dd95SBruce Richardson * Note, to avoid ABI breakage across releases 30799a2dd95SBruce Richardson * - LIST_END should not be added to this enum 30899a2dd95SBruce Richardson * - the order of enums should not be changed 30999a2dd95SBruce Richardson * - new algorithms should only be added to the end 31099a2dd95SBruce Richardson */ 31199a2dd95SBruce Richardson enum rte_crypto_auth_algorithm { 31299a2dd95SBruce Richardson RTE_CRYPTO_AUTH_NULL = 1, 31399a2dd95SBruce Richardson /**< NULL hash algorithm. */ 31499a2dd95SBruce Richardson 31599a2dd95SBruce Richardson RTE_CRYPTO_AUTH_AES_CBC_MAC, 31699a2dd95SBruce Richardson /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */ 31799a2dd95SBruce Richardson RTE_CRYPTO_AUTH_AES_CMAC, 31899a2dd95SBruce Richardson /**< AES CMAC algorithm. */ 31999a2dd95SBruce Richardson RTE_CRYPTO_AUTH_AES_GMAC, 32099a2dd95SBruce Richardson /**< AES GMAC algorithm. */ 32199a2dd95SBruce Richardson RTE_CRYPTO_AUTH_AES_XCBC_MAC, 32299a2dd95SBruce Richardson /**< AES XCBC algorithm. */ 32399a2dd95SBruce Richardson 32499a2dd95SBruce Richardson RTE_CRYPTO_AUTH_KASUMI_F9, 32599a2dd95SBruce Richardson /**< KASUMI algorithm in F9 mode. */ 32699a2dd95SBruce Richardson 32799a2dd95SBruce Richardson RTE_CRYPTO_AUTH_MD5, 32899a2dd95SBruce Richardson /**< MD5 algorithm */ 32999a2dd95SBruce Richardson RTE_CRYPTO_AUTH_MD5_HMAC, 33099a2dd95SBruce Richardson /**< HMAC using MD5 algorithm */ 33199a2dd95SBruce Richardson 33299a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA1, 33399a2dd95SBruce Richardson /**< 160 bit SHA algorithm. */ 33499a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA1_HMAC, 33599a2dd95SBruce Richardson /**< HMAC using 160 bit SHA algorithm. 33699a2dd95SBruce Richardson * HMAC-SHA-1-96 can be generated by setting 33799a2dd95SBruce Richardson * digest_length to 12 bytes in auth/aead xforms. 33899a2dd95SBruce Richardson */ 33999a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA224, 34099a2dd95SBruce Richardson /**< 224 bit SHA algorithm. */ 34199a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA224_HMAC, 34299a2dd95SBruce Richardson /**< HMAC using 224 bit SHA algorithm. */ 34399a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA256, 34499a2dd95SBruce Richardson /**< 256 bit SHA algorithm. */ 34599a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA256_HMAC, 34699a2dd95SBruce Richardson /**< HMAC using 256 bit SHA algorithm. */ 34799a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA384, 34899a2dd95SBruce Richardson /**< 384 bit SHA algorithm. */ 34999a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA384_HMAC, 35099a2dd95SBruce Richardson /**< HMAC using 384 bit SHA algorithm. */ 35199a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA512, 35299a2dd95SBruce Richardson /**< 512 bit SHA algorithm. */ 35399a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA512_HMAC, 35499a2dd95SBruce Richardson /**< HMAC using 512 bit SHA algorithm. */ 35599a2dd95SBruce Richardson 35699a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SNOW3G_UIA2, 35799a2dd95SBruce Richardson /**< SNOW 3G algorithm in UIA2 mode. */ 35899a2dd95SBruce Richardson 35999a2dd95SBruce Richardson RTE_CRYPTO_AUTH_ZUC_EIA3, 36099a2dd95SBruce Richardson /**< ZUC algorithm in EIA3 mode */ 36199a2dd95SBruce Richardson 36299a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA3_224, 36399a2dd95SBruce Richardson /**< 224 bit SHA3 algorithm. */ 36499a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA3_224_HMAC, 36599a2dd95SBruce Richardson /**< HMAC using 224 bit SHA3 algorithm. */ 36699a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA3_256, 36799a2dd95SBruce Richardson /**< 256 bit SHA3 algorithm. */ 36899a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA3_256_HMAC, 36999a2dd95SBruce Richardson /**< HMAC using 256 bit SHA3 algorithm. */ 37099a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA3_384, 37199a2dd95SBruce Richardson /**< 384 bit SHA3 algorithm. */ 37299a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA3_384_HMAC, 37399a2dd95SBruce Richardson /**< HMAC using 384 bit SHA3 algorithm. */ 37499a2dd95SBruce Richardson RTE_CRYPTO_AUTH_SHA3_512, 37599a2dd95SBruce Richardson /**< 512 bit SHA3 algorithm. */ 37635ffc5b0SArek Kusztal RTE_CRYPTO_AUTH_SHA3_512_HMAC, 37799a2dd95SBruce Richardson /**< HMAC using 512 bit SHA3 algorithm. */ 37856ee8af9SVolodymyr Fialko RTE_CRYPTO_AUTH_SM3, 37935ffc5b0SArek Kusztal /**< ShangMi 3 (SM3) algorithm */ 38056ee8af9SVolodymyr Fialko 38156ee8af9SVolodymyr Fialko RTE_CRYPTO_AUTH_SHAKE_128, 38256ee8af9SVolodymyr Fialko /**< 128 bit SHAKE algorithm. */ 38356ee8af9SVolodymyr Fialko RTE_CRYPTO_AUTH_SHAKE_256, 38456ee8af9SVolodymyr Fialko /**< 256 bit SHAKE algorithm. */ 3851daecf63SSunyang Wu RTE_CRYPTO_AUTH_SM3_HMAC, 3861daecf63SSunyang Wu /** < HMAC using ShangMi 3 (SM3) algorithm */ 38799a2dd95SBruce Richardson }; 38899a2dd95SBruce Richardson 38999a2dd95SBruce Richardson /** Symmetric Authentication / Hash Operations */ 39099a2dd95SBruce Richardson enum rte_crypto_auth_operation { 39199a2dd95SBruce Richardson RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */ 39299a2dd95SBruce Richardson RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */ 39399a2dd95SBruce Richardson }; 39499a2dd95SBruce Richardson 39599a2dd95SBruce Richardson /** Authentication operation name strings */ 39699a2dd95SBruce Richardson extern const char * 39799a2dd95SBruce Richardson rte_crypto_auth_operation_strings[]; 39899a2dd95SBruce Richardson 39999a2dd95SBruce Richardson /** 40099a2dd95SBruce Richardson * Authentication / Hash transform data. 40199a2dd95SBruce Richardson * 40299a2dd95SBruce Richardson * This structure contains data relating to an authentication/hash crypto 40399a2dd95SBruce Richardson * transforms. The fields op, algo and digest_length are common to all 40499a2dd95SBruce Richardson * authentication transforms and MUST be set. 40599a2dd95SBruce Richardson */ 40699a2dd95SBruce Richardson struct rte_crypto_auth_xform { 40799a2dd95SBruce Richardson enum rte_crypto_auth_operation op; 40899a2dd95SBruce Richardson /**< Authentication operation type */ 40999a2dd95SBruce Richardson enum rte_crypto_auth_algorithm algo; 41099a2dd95SBruce Richardson /**< Authentication algorithm selection */ 41199a2dd95SBruce Richardson 41299a2dd95SBruce Richardson struct { 41399a2dd95SBruce Richardson const uint8_t *data; /**< pointer to key data */ 41499a2dd95SBruce Richardson uint16_t length; /**< key length in bytes */ 41599a2dd95SBruce Richardson } key; 41699a2dd95SBruce Richardson /**< Authentication key data. 41799a2dd95SBruce Richardson * The authentication key length MUST be less than or equal to the 41899a2dd95SBruce Richardson * block size of the algorithm. It is the callers responsibility to 41999a2dd95SBruce Richardson * ensure that the key length is compliant with the standard being used 42099a2dd95SBruce Richardson * (for example RFC 2104, FIPS 198a). 42199a2dd95SBruce Richardson */ 42299a2dd95SBruce Richardson 42399a2dd95SBruce Richardson struct { 42499a2dd95SBruce Richardson uint16_t offset; 42599a2dd95SBruce Richardson /**< Starting point for Initialisation Vector or Counter, 42699a2dd95SBruce Richardson * specified as number of bytes from start of crypto 42799a2dd95SBruce Richardson * operation (rte_crypto_op). 42899a2dd95SBruce Richardson * 42999a2dd95SBruce Richardson * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode 43099a2dd95SBruce Richardson * this is the authentication Initialisation Vector 43199a2dd95SBruce Richardson * (IV) value. For AES-GMAC IV description please refer 43299a2dd95SBruce Richardson * to the field `length` in iv struct. 43399a2dd95SBruce Richardson * 43499a2dd95SBruce Richardson * - For KASUMI in F9 mode and other authentication 43599a2dd95SBruce Richardson * algorithms, this field is not used. 43699a2dd95SBruce Richardson * 43799a2dd95SBruce Richardson * For optimum performance, the data pointed to SHOULD 43899a2dd95SBruce Richardson * be 8-byte aligned. 43999a2dd95SBruce Richardson */ 44099a2dd95SBruce Richardson uint16_t length; 44199a2dd95SBruce Richardson /**< Length of valid IV data. 44299a2dd95SBruce Richardson * 44399a2dd95SBruce Richardson * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and 44499a2dd95SBruce Richardson * for AES-GMAC, this is the length of the IV. 44599a2dd95SBruce Richardson * 44699a2dd95SBruce Richardson * - For KASUMI in F9 mode and other authentication 44799a2dd95SBruce Richardson * algorithms, this field is not used. 44899a2dd95SBruce Richardson * 44999a2dd95SBruce Richardson * - For GMAC mode, this is either: 45099a2dd95SBruce Richardson * 1) Number greater or equal to one, which means that IV 45199a2dd95SBruce Richardson * is used and J0 will be computed internally, a minimum 45299a2dd95SBruce Richardson * of 16 bytes must be allocated. 45399a2dd95SBruce Richardson * 2) Zero, in which case data points to J0. In this case 45499a2dd95SBruce Richardson * 16 bytes of J0 should be passed where J0 is defined 45599a2dd95SBruce Richardson * by NIST SP800-38D. 45699a2dd95SBruce Richardson * 45799a2dd95SBruce Richardson */ 45899a2dd95SBruce Richardson } iv; /**< Initialisation vector parameters */ 45999a2dd95SBruce Richardson 46099a2dd95SBruce Richardson uint16_t digest_length; 46199a2dd95SBruce Richardson /**< Length of the digest to be returned. If the verify option is set, 46299a2dd95SBruce Richardson * this specifies the length of the digest to be compared for the 46399a2dd95SBruce Richardson * session. 46499a2dd95SBruce Richardson * 46599a2dd95SBruce Richardson * It is the caller's responsibility to ensure that the 46699a2dd95SBruce Richardson * digest length is compliant with the hash algorithm being used. 46799a2dd95SBruce Richardson * If the value is less than the maximum length allowed by the hash, 46899a2dd95SBruce Richardson * the result shall be truncated. 46999a2dd95SBruce Richardson */ 47099a2dd95SBruce Richardson }; 47199a2dd95SBruce Richardson 47299a2dd95SBruce Richardson 47399a2dd95SBruce Richardson /** Symmetric AEAD Algorithms 47499a2dd95SBruce Richardson * 47599a2dd95SBruce Richardson * Note, to avoid ABI breakage across releases 47699a2dd95SBruce Richardson * - LIST_END should not be added to this enum 47799a2dd95SBruce Richardson * - the order of enums should not be changed 47899a2dd95SBruce Richardson * - new algorithms should only be added to the end 47999a2dd95SBruce Richardson */ 48099a2dd95SBruce Richardson enum rte_crypto_aead_algorithm { 48199a2dd95SBruce Richardson RTE_CRYPTO_AEAD_AES_CCM = 1, 48299a2dd95SBruce Richardson /**< AES algorithm in CCM mode. */ 48399a2dd95SBruce Richardson RTE_CRYPTO_AEAD_AES_GCM, 48499a2dd95SBruce Richardson /**< AES algorithm in GCM mode. */ 48599a2dd95SBruce Richardson RTE_CRYPTO_AEAD_CHACHA20_POLY1305 48699a2dd95SBruce Richardson /**< Chacha20 cipher with poly1305 authenticator */ 48799a2dd95SBruce Richardson }; 48899a2dd95SBruce Richardson 48999a2dd95SBruce Richardson /** Symmetric AEAD Operations */ 49099a2dd95SBruce Richardson enum rte_crypto_aead_operation { 49199a2dd95SBruce Richardson RTE_CRYPTO_AEAD_OP_ENCRYPT, 49299a2dd95SBruce Richardson /**< Encrypt and generate digest */ 49399a2dd95SBruce Richardson RTE_CRYPTO_AEAD_OP_DECRYPT 49499a2dd95SBruce Richardson /**< Verify digest and decrypt */ 49599a2dd95SBruce Richardson }; 49699a2dd95SBruce Richardson 49799a2dd95SBruce Richardson /** Authentication operation name strings */ 49899a2dd95SBruce Richardson extern const char * 49999a2dd95SBruce Richardson rte_crypto_aead_operation_strings[]; 50099a2dd95SBruce Richardson 50199a2dd95SBruce Richardson struct rte_crypto_aead_xform { 50299a2dd95SBruce Richardson enum rte_crypto_aead_operation op; 50399a2dd95SBruce Richardson /**< AEAD operation type */ 50499a2dd95SBruce Richardson enum rte_crypto_aead_algorithm algo; 50599a2dd95SBruce Richardson /**< AEAD algorithm selection */ 50699a2dd95SBruce Richardson 50799a2dd95SBruce Richardson struct { 50899a2dd95SBruce Richardson const uint8_t *data; /**< pointer to key data */ 50999a2dd95SBruce Richardson uint16_t length; /**< key length in bytes */ 51099a2dd95SBruce Richardson } key; 51199a2dd95SBruce Richardson 51299a2dd95SBruce Richardson struct { 51399a2dd95SBruce Richardson uint16_t offset; 51499a2dd95SBruce Richardson /**< Starting point for Initialisation Vector or Counter, 51599a2dd95SBruce Richardson * specified as number of bytes from start of crypto 51699a2dd95SBruce Richardson * operation (rte_crypto_op). 51799a2dd95SBruce Richardson * 51899a2dd95SBruce Richardson * - For CCM mode, the first byte is reserved, and the 51999a2dd95SBruce Richardson * nonce should be written starting at &iv[1] (to allow 52099a2dd95SBruce Richardson * space for the implementation to write in the flags 52199a2dd95SBruce Richardson * in the first byte). Note that a full 16 bytes should 52299a2dd95SBruce Richardson * be allocated, even though the length field will 52399a2dd95SBruce Richardson * have a value less than this. 52499a2dd95SBruce Richardson * 52599a2dd95SBruce Richardson * - For Chacha20-Poly1305 it is 96-bit nonce. 52699a2dd95SBruce Richardson * PMD sets initial counter for Poly1305 key generation 52799a2dd95SBruce Richardson * part to 0 and for Chacha20 encryption to 1 as per 52899a2dd95SBruce Richardson * rfc8439 2.8. AEAD construction. 52999a2dd95SBruce Richardson * 53099a2dd95SBruce Richardson * For optimum performance, the data pointed to SHOULD 53199a2dd95SBruce Richardson * be 8-byte aligned. 53299a2dd95SBruce Richardson */ 53399a2dd95SBruce Richardson uint16_t length; 53499a2dd95SBruce Richardson /**< Length of valid IV data. 53599a2dd95SBruce Richardson * 53699a2dd95SBruce Richardson * - For GCM mode, this is either: 53799a2dd95SBruce Richardson * 1) Number greater or equal to one, which means that IV 53899a2dd95SBruce Richardson * is used and J0 will be computed internally, a minimum 53999a2dd95SBruce Richardson * of 16 bytes must be allocated. 54099a2dd95SBruce Richardson * 2) Zero, in which case data points to J0. In this case 54199a2dd95SBruce Richardson * 16 bytes of J0 should be passed where J0 is defined 54299a2dd95SBruce Richardson * by NIST SP800-38D. 54399a2dd95SBruce Richardson * 54499a2dd95SBruce Richardson * - For CCM mode, this is the length of the nonce, 54599a2dd95SBruce Richardson * which can be in the range 7 to 13 inclusive. 54699a2dd95SBruce Richardson * 54799a2dd95SBruce Richardson * - For Chacha20-Poly1305 this field is always 12. 54899a2dd95SBruce Richardson */ 54999a2dd95SBruce Richardson } iv; /**< Initialisation vector parameters */ 55099a2dd95SBruce Richardson 55199a2dd95SBruce Richardson uint16_t digest_length; 55299a2dd95SBruce Richardson 55399a2dd95SBruce Richardson uint16_t aad_length; 55499a2dd95SBruce Richardson /**< The length of the additional authenticated data (AAD) in bytes. 55599a2dd95SBruce Richardson * For CCM mode, this is the length of the actual AAD, even though 55699a2dd95SBruce Richardson * it is required to reserve 18 bytes before the AAD and padding 55799a2dd95SBruce Richardson * at the end of it, so a multiple of 16 bytes is allocated. 55899a2dd95SBruce Richardson */ 55999a2dd95SBruce Richardson }; 56099a2dd95SBruce Richardson 56199a2dd95SBruce Richardson /** Crypto transformation types */ 56299a2dd95SBruce Richardson enum rte_crypto_sym_xform_type { 56399a2dd95SBruce Richardson RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */ 56499a2dd95SBruce Richardson RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */ 56599a2dd95SBruce Richardson RTE_CRYPTO_SYM_XFORM_CIPHER, /**< Cipher xform */ 56699a2dd95SBruce Richardson RTE_CRYPTO_SYM_XFORM_AEAD /**< AEAD xform */ 56799a2dd95SBruce Richardson }; 56899a2dd95SBruce Richardson 56999a2dd95SBruce Richardson /** 57099a2dd95SBruce Richardson * Symmetric crypto transform structure. 57199a2dd95SBruce Richardson * 57299a2dd95SBruce Richardson * This is used to specify the crypto transforms required, multiple transforms 57399a2dd95SBruce Richardson * can be chained together to specify a chain transforms such as authentication 57499a2dd95SBruce Richardson * then cipher, or cipher then authentication. Each transform structure can 57599a2dd95SBruce Richardson * hold a single transform, the type field is used to specify which transform 57699a2dd95SBruce Richardson * is contained within the union 57799a2dd95SBruce Richardson */ 578d2d7f019SAkhil Goyal /* Structure rte_crypto_sym_xform 8< */ 57999a2dd95SBruce Richardson struct rte_crypto_sym_xform { 58099a2dd95SBruce Richardson struct rte_crypto_sym_xform *next; 58199a2dd95SBruce Richardson /**< next xform in chain */ 58299a2dd95SBruce Richardson enum rte_crypto_sym_xform_type type 58399a2dd95SBruce Richardson ; /**< xform type */ 58499a2dd95SBruce Richardson union { 58599a2dd95SBruce Richardson struct rte_crypto_auth_xform auth; 58699a2dd95SBruce Richardson /**< Authentication / hash xform */ 58799a2dd95SBruce Richardson struct rte_crypto_cipher_xform cipher; 58899a2dd95SBruce Richardson /**< Cipher xform */ 58999a2dd95SBruce Richardson struct rte_crypto_aead_xform aead; 59099a2dd95SBruce Richardson /**< AEAD xform */ 59199a2dd95SBruce Richardson }; 59299a2dd95SBruce Richardson }; 593d2d7f019SAkhil Goyal /* >8 End of structure rte_crypto_sym_xform. */ 59499a2dd95SBruce Richardson 59599a2dd95SBruce Richardson /** 59699a2dd95SBruce Richardson * Symmetric Cryptographic Operation. 59799a2dd95SBruce Richardson * 59899a2dd95SBruce Richardson * This structure contains data relating to performing symmetric cryptographic 59999a2dd95SBruce Richardson * processing on a referenced mbuf data buffer. 60099a2dd95SBruce Richardson * 60199a2dd95SBruce Richardson * When a symmetric crypto operation is enqueued with the device for processing 60299a2dd95SBruce Richardson * it must have a valid *rte_mbuf* structure attached, via m_src parameter, 60399a2dd95SBruce Richardson * which contains the source data which the crypto operation is to be performed 60499a2dd95SBruce Richardson * on. 60599a2dd95SBruce Richardson * While the mbuf is in use by a crypto operation no part of the mbuf should be 60699a2dd95SBruce Richardson * changed by the application as the device may read or write to any part of the 60799a2dd95SBruce Richardson * mbuf. In the case of hardware crypto devices some or all of the mbuf 60899a2dd95SBruce Richardson * may be DMAed in and out of the device, so writing over the original data, 60999a2dd95SBruce Richardson * though only the part specified by the rte_crypto_sym_op for transformation 61099a2dd95SBruce Richardson * will be changed. 61199a2dd95SBruce Richardson * Out-of-place (OOP) operation, where the source mbuf is different to the 61299a2dd95SBruce Richardson * destination mbuf, is a special case. Data will be copied from m_src to m_dst. 61399a2dd95SBruce Richardson * The part copied includes all the parts of the source mbuf that will be 61499a2dd95SBruce Richardson * operated on, based on the cipher.data.offset+cipher.data.length and 61599a2dd95SBruce Richardson * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part 61699a2dd95SBruce Richardson * indicated by the cipher parameters will be transformed, any extra data around 61799a2dd95SBruce Richardson * this indicated by the auth parameters will be copied unchanged from source to 61899a2dd95SBruce Richardson * destination mbuf. 61999a2dd95SBruce Richardson * Also in OOP operation the cipher.data.offset and auth.data.offset apply to 62099a2dd95SBruce Richardson * both source and destination mbufs. As these offsets are relative to the 62199a2dd95SBruce Richardson * data_off parameter in each mbuf this can result in the data written to the 62299a2dd95SBruce Richardson * destination buffer being at a different alignment, relative to buffer start, 62399a2dd95SBruce Richardson * to the data in the source buffer. 62499a2dd95SBruce Richardson */ 625d2d7f019SAkhil Goyal /* Structure rte_crypto_sym_op 8< */ 62699a2dd95SBruce Richardson struct rte_crypto_sym_op { 62799a2dd95SBruce Richardson struct rte_mbuf *m_src; /**< source mbuf */ 62899a2dd95SBruce Richardson struct rte_mbuf *m_dst; /**< destination mbuf */ 62999a2dd95SBruce Richardson 63099a2dd95SBruce Richardson union { 6312a440d6aSAkhil Goyal void *session; 6322973dbf9SAkhil Goyal /**< Handle for the initialised crypto/security session context */ 63399a2dd95SBruce Richardson struct rte_crypto_sym_xform *xform; 63499a2dd95SBruce Richardson /**< Session-less API crypto operation parameters */ 63599a2dd95SBruce Richardson }; 63699a2dd95SBruce Richardson 63799a2dd95SBruce Richardson union { 63899a2dd95SBruce Richardson struct { 63999a2dd95SBruce Richardson struct { 64099a2dd95SBruce Richardson uint32_t offset; 64199a2dd95SBruce Richardson /**< Starting point for AEAD processing, specified as 64299a2dd95SBruce Richardson * number of bytes from start of packet in source 64399a2dd95SBruce Richardson * buffer. 64499a2dd95SBruce Richardson */ 64599a2dd95SBruce Richardson uint32_t length; 64699a2dd95SBruce Richardson /**< The message length, in bytes, of the source buffer 64799a2dd95SBruce Richardson * on which the cryptographic operation will be 648e0e729b4SArkadiusz Kusztal * computed. 64999a2dd95SBruce Richardson */ 65099a2dd95SBruce Richardson } data; /**< Data offsets and length for AEAD */ 65199a2dd95SBruce Richardson struct { 65299a2dd95SBruce Richardson uint8_t *data; 65399a2dd95SBruce Richardson /**< This points to the location where the digest result 65499a2dd95SBruce Richardson * should be inserted (in the case of digest generation) 65599a2dd95SBruce Richardson * or where the purported digest exists (in the case of 65699a2dd95SBruce Richardson * digest verification). 65799a2dd95SBruce Richardson * 65899a2dd95SBruce Richardson * At session creation time, the client specified the 65999a2dd95SBruce Richardson * digest result length with the digest_length member 66099a2dd95SBruce Richardson * of the @ref rte_crypto_auth_xform structure. For 66199a2dd95SBruce Richardson * physical crypto devices the caller must allocate at 66299a2dd95SBruce Richardson * least digest_length of physically contiguous memory 66399a2dd95SBruce Richardson * at this location. 66499a2dd95SBruce Richardson * 66599a2dd95SBruce Richardson * For digest generation, the digest result will 66699a2dd95SBruce Richardson * overwrite any data at this location. 66799a2dd95SBruce Richardson * 66899a2dd95SBruce Richardson * @note 66999a2dd95SBruce Richardson * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for 67099a2dd95SBruce Richardson * "digest result" read "authentication tag T". 67199a2dd95SBruce Richardson */ 67299a2dd95SBruce Richardson rte_iova_t phys_addr; 67399a2dd95SBruce Richardson /**< Physical address of digest */ 67499a2dd95SBruce Richardson } digest; /**< Digest parameters */ 67599a2dd95SBruce Richardson struct { 67699a2dd95SBruce Richardson uint8_t *data; 67799a2dd95SBruce Richardson /**< Pointer to Additional Authenticated Data (AAD) 67899a2dd95SBruce Richardson * needed for authenticated cipher mechanisms (CCM and 67999a2dd95SBruce Richardson * GCM) 68099a2dd95SBruce Richardson * 68199a2dd95SBruce Richardson * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM), 68299a2dd95SBruce Richardson * the caller should setup this field as follows: 68399a2dd95SBruce Richardson * 68499a2dd95SBruce Richardson * - the additional authentication data itself should 68599a2dd95SBruce Richardson * be written starting at an offset of 18 bytes into 68699a2dd95SBruce Richardson * the array, leaving room for the first block (16 bytes) 68799a2dd95SBruce Richardson * and the length encoding in the first two bytes of the 68899a2dd95SBruce Richardson * second block. 68999a2dd95SBruce Richardson * 69099a2dd95SBruce Richardson * - Note that PMDs may modify the memory reserved 69199a2dd95SBruce Richardson * (first 18 bytes and the final padding). 69299a2dd95SBruce Richardson * 69399a2dd95SBruce Richardson * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the 69499a2dd95SBruce Richardson * caller should setup this field as follows: 69599a2dd95SBruce Richardson * 69699a2dd95SBruce Richardson */ 69799a2dd95SBruce Richardson rte_iova_t phys_addr; /**< physical address */ 69899a2dd95SBruce Richardson } aad; 69999a2dd95SBruce Richardson /**< Additional authentication parameters */ 70099a2dd95SBruce Richardson } aead; 70199a2dd95SBruce Richardson 70299a2dd95SBruce Richardson struct { 70399a2dd95SBruce Richardson struct { 70499a2dd95SBruce Richardson struct { 70599a2dd95SBruce Richardson uint32_t offset; 70699a2dd95SBruce Richardson /**< Starting point for cipher processing, 70799a2dd95SBruce Richardson * specified as number of bytes from start 70899a2dd95SBruce Richardson * of data in the source buffer. 70999a2dd95SBruce Richardson * The result of the cipher operation will be 71099a2dd95SBruce Richardson * written back into the output buffer 71199a2dd95SBruce Richardson * starting at this location. 71299a2dd95SBruce Richardson * 71399a2dd95SBruce Richardson * @note 71499a2dd95SBruce Richardson * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 71599a2dd95SBruce Richardson * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8 71699a2dd95SBruce Richardson * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3, 71799a2dd95SBruce Richardson * this field should be in bits. For 71899a2dd95SBruce Richardson * digest-encrypted cases this must be 71999a2dd95SBruce Richardson * an 8-bit multiple. 72099a2dd95SBruce Richardson */ 72199a2dd95SBruce Richardson uint32_t length; 72299a2dd95SBruce Richardson /**< The message length, in bytes, of the 72399a2dd95SBruce Richardson * source buffer on which the cryptographic 72499a2dd95SBruce Richardson * operation will be computed. 72599a2dd95SBruce Richardson * This is also the same as the result length. 726e0e729b4SArkadiusz Kusztal * For block ciphers, this must be a 727e0e729b4SArkadiusz Kusztal * multiple of the block size, 728e0e729b4SArkadiusz Kusztal * or for the AES-XTS a multiple of the data-unit length 72999a2dd95SBruce Richardson * as described in xform. 73099a2dd95SBruce Richardson * 73199a2dd95SBruce Richardson * @note 73299a2dd95SBruce Richardson * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2, 73399a2dd95SBruce Richardson * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8 73499a2dd95SBruce Richardson * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3, 73599a2dd95SBruce Richardson * this field should be in bits. For 73699a2dd95SBruce Richardson * digest-encrypted cases this must be 73799a2dd95SBruce Richardson * an 8-bit multiple. 73899a2dd95SBruce Richardson */ 73999a2dd95SBruce Richardson } data; /**< Data offsets and length for ciphering */ 74099a2dd95SBruce Richardson } cipher; 74199a2dd95SBruce Richardson 74299a2dd95SBruce Richardson struct { 74399a2dd95SBruce Richardson struct { 74499a2dd95SBruce Richardson uint32_t offset; 74599a2dd95SBruce Richardson /**< Starting point for hash processing, 74699a2dd95SBruce Richardson * specified as number of bytes from start of 74799a2dd95SBruce Richardson * packet in source buffer. 74899a2dd95SBruce Richardson * 74999a2dd95SBruce Richardson * @note 75099a2dd95SBruce Richardson * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2, 75199a2dd95SBruce Richardson * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9 75299a2dd95SBruce Richardson * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3, 75399a2dd95SBruce Richardson * this field should be in bits. For 75499a2dd95SBruce Richardson * digest-encrypted cases this must be 75599a2dd95SBruce Richardson * an 8-bit multiple. 75699a2dd95SBruce Richardson * 75799a2dd95SBruce Richardson * @note 75899a2dd95SBruce Richardson * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9, 75999a2dd95SBruce Richardson * this offset should be such that 76099a2dd95SBruce Richardson * data to authenticate starts at COUNT. 76199a2dd95SBruce Richardson * 76299a2dd95SBruce Richardson * @note 76399a2dd95SBruce Richardson * For DOCSIS security protocol, this 76499a2dd95SBruce Richardson * offset is the DOCSIS header length 76599a2dd95SBruce Richardson * and, therefore, also the CRC offset 76699a2dd95SBruce Richardson * i.e. the number of bytes into the 76799a2dd95SBruce Richardson * packet at which CRC calculation 76899a2dd95SBruce Richardson * should begin. 76999a2dd95SBruce Richardson */ 77099a2dd95SBruce Richardson uint32_t length; 77199a2dd95SBruce Richardson /**< The message length, in bytes, of the source 77299a2dd95SBruce Richardson * buffer that the hash will be computed on. 77399a2dd95SBruce Richardson * 77499a2dd95SBruce Richardson * @note 77599a2dd95SBruce Richardson * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2, 77699a2dd95SBruce Richardson * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9 77799a2dd95SBruce Richardson * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3, 77899a2dd95SBruce Richardson * this field should be in bits. For 77999a2dd95SBruce Richardson * digest-encrypted cases this must be 78099a2dd95SBruce Richardson * an 8-bit multiple. 78199a2dd95SBruce Richardson * 78299a2dd95SBruce Richardson * @note 78399a2dd95SBruce Richardson * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9, 78499a2dd95SBruce Richardson * the length should include the COUNT, 78599a2dd95SBruce Richardson * FRESH, message, direction bit and padding 78699a2dd95SBruce Richardson * (to be multiple of 8 bits). 78799a2dd95SBruce Richardson * 78899a2dd95SBruce Richardson * @note 78999a2dd95SBruce Richardson * For DOCSIS security protocol, this 79099a2dd95SBruce Richardson * is the CRC length i.e. the number of 79199a2dd95SBruce Richardson * bytes in the packet over which the 79299a2dd95SBruce Richardson * CRC should be calculated 79399a2dd95SBruce Richardson */ 79499a2dd95SBruce Richardson } data; 79599a2dd95SBruce Richardson /**< Data offsets and length for authentication */ 79699a2dd95SBruce Richardson 79799a2dd95SBruce Richardson struct { 79899a2dd95SBruce Richardson uint8_t *data; 79999a2dd95SBruce Richardson /**< This points to the location where 80099a2dd95SBruce Richardson * the digest result should be inserted 80199a2dd95SBruce Richardson * (in the case of digest generation) 80299a2dd95SBruce Richardson * or where the purported digest exists 80399a2dd95SBruce Richardson * (in the case of digest verification). 80499a2dd95SBruce Richardson * 80599a2dd95SBruce Richardson * At session creation time, the client 80699a2dd95SBruce Richardson * specified the digest result length with 80799a2dd95SBruce Richardson * the digest_length member of the 80899a2dd95SBruce Richardson * @ref rte_crypto_auth_xform structure. 80999a2dd95SBruce Richardson * For physical crypto devices the caller 81099a2dd95SBruce Richardson * must allocate at least digest_length of 81199a2dd95SBruce Richardson * physically contiguous memory at this 81299a2dd95SBruce Richardson * location. 81399a2dd95SBruce Richardson * 81499a2dd95SBruce Richardson * For digest generation, the digest result 81599a2dd95SBruce Richardson * will overwrite any data at this location. 81699a2dd95SBruce Richardson * 81799a2dd95SBruce Richardson * @note 81899a2dd95SBruce Richardson * Digest-encrypted case. 81999a2dd95SBruce Richardson * Digest can be generated, appended to 82099a2dd95SBruce Richardson * the end of raw data and encrypted 82199a2dd95SBruce Richardson * together using chained digest 82299a2dd95SBruce Richardson * generation 82399a2dd95SBruce Richardson * (@ref RTE_CRYPTO_AUTH_OP_GENERATE) 82499a2dd95SBruce Richardson * and encryption 82599a2dd95SBruce Richardson * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT) 82699a2dd95SBruce Richardson * xforms. Similarly, authentication 82799a2dd95SBruce Richardson * of the raw data against appended, 82899a2dd95SBruce Richardson * decrypted digest, can be performed 82999a2dd95SBruce Richardson * using decryption 83099a2dd95SBruce Richardson * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT) 83199a2dd95SBruce Richardson * and digest verification 83299a2dd95SBruce Richardson * (@ref RTE_CRYPTO_AUTH_OP_VERIFY) 83399a2dd95SBruce Richardson * chained xforms. 83499a2dd95SBruce Richardson * To perform those operations, a few 83599a2dd95SBruce Richardson * additional conditions must be met: 83699a2dd95SBruce Richardson * - caller must allocate at least 83799a2dd95SBruce Richardson * digest_length of memory at the end of 83899a2dd95SBruce Richardson * source and (in case of out-of-place 83999a2dd95SBruce Richardson * operations) destination buffer; those 84099a2dd95SBruce Richardson * buffers can be linear or split using 84199a2dd95SBruce Richardson * scatter-gather lists, 84299a2dd95SBruce Richardson * - digest data pointer must point to 84399a2dd95SBruce Richardson * the end of source or (in case of 84499a2dd95SBruce Richardson * out-of-place operations) destination 84599a2dd95SBruce Richardson * data, which is pointer to the 84699a2dd95SBruce Richardson * data buffer + auth.data.offset + 84799a2dd95SBruce Richardson * auth.data.length, 84899a2dd95SBruce Richardson * - cipher.data.offset + 84999a2dd95SBruce Richardson * cipher.data.length must be greater 85099a2dd95SBruce Richardson * than auth.data.offset + 85199a2dd95SBruce Richardson * auth.data.length and is typically 85299a2dd95SBruce Richardson * equal to auth.data.offset + 85399a2dd95SBruce Richardson * auth.data.length + digest_length. 85499a2dd95SBruce Richardson * - for wireless algorithms, i.e. 85599a2dd95SBruce Richardson * SNOW 3G, KASUMI and ZUC, as the 85699a2dd95SBruce Richardson * cipher.data.length, 85799a2dd95SBruce Richardson * cipher.data.offset, 85899a2dd95SBruce Richardson * auth.data.length and 85999a2dd95SBruce Richardson * auth.data.offset are in bits, they 86099a2dd95SBruce Richardson * must be 8-bit multiples. 86199a2dd95SBruce Richardson * 86299a2dd95SBruce Richardson * Note, that for security reasons, it 86399a2dd95SBruce Richardson * is PMDs' responsibility to not 86499a2dd95SBruce Richardson * leave an unencrypted digest in any 86599a2dd95SBruce Richardson * buffer after performing auth-cipher 86699a2dd95SBruce Richardson * operations. 86799a2dd95SBruce Richardson * 86899a2dd95SBruce Richardson */ 86999a2dd95SBruce Richardson rte_iova_t phys_addr; 87099a2dd95SBruce Richardson /**< Physical address of digest */ 87199a2dd95SBruce Richardson } digest; /**< Digest parameters */ 87299a2dd95SBruce Richardson } auth; 87399a2dd95SBruce Richardson }; 87499a2dd95SBruce Richardson }; 87599a2dd95SBruce Richardson }; 876d2d7f019SAkhil Goyal /* >8 End of structure rte_crypto_sym_op. */ 87799a2dd95SBruce Richardson 87899a2dd95SBruce Richardson 87999a2dd95SBruce Richardson /** 88099a2dd95SBruce Richardson * Reset the fields of a symmetric operation to their default values. 88199a2dd95SBruce Richardson * 88299a2dd95SBruce Richardson * @param op The crypto operation to be reset. 88399a2dd95SBruce Richardson */ 88499a2dd95SBruce Richardson static inline void 88599a2dd95SBruce Richardson __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op) 88699a2dd95SBruce Richardson { 88799a2dd95SBruce Richardson memset(op, 0, sizeof(*op)); 88899a2dd95SBruce Richardson } 88999a2dd95SBruce Richardson 89099a2dd95SBruce Richardson 89199a2dd95SBruce Richardson /** 89299a2dd95SBruce Richardson * Allocate space for symmetric crypto xforms in the private data space of the 89399a2dd95SBruce Richardson * crypto operation. This also defaults the crypto xform type to 89499a2dd95SBruce Richardson * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms 89599a2dd95SBruce Richardson * in the crypto operation 89699a2dd95SBruce Richardson * 89799a2dd95SBruce Richardson * @return 89899a2dd95SBruce Richardson * - On success returns pointer to first crypto xform in crypto operations chain 89999a2dd95SBruce Richardson * - On failure returns NULL 90099a2dd95SBruce Richardson */ 90199a2dd95SBruce Richardson static inline struct rte_crypto_sym_xform * 90299a2dd95SBruce Richardson __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op, 90399a2dd95SBruce Richardson void *priv_data, uint8_t nb_xforms) 90499a2dd95SBruce Richardson { 90599a2dd95SBruce Richardson struct rte_crypto_sym_xform *xform; 90699a2dd95SBruce Richardson 90799a2dd95SBruce Richardson sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data; 90899a2dd95SBruce Richardson 90999a2dd95SBruce Richardson do { 91099a2dd95SBruce Richardson xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED; 91199a2dd95SBruce Richardson xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL; 91299a2dd95SBruce Richardson } while (xform); 91399a2dd95SBruce Richardson 91499a2dd95SBruce Richardson return sym_op->xform; 91599a2dd95SBruce Richardson } 91699a2dd95SBruce Richardson 91799a2dd95SBruce Richardson 91899a2dd95SBruce Richardson /** 91999a2dd95SBruce Richardson * Attach a session to a symmetric crypto operation 92099a2dd95SBruce Richardson * 92199a2dd95SBruce Richardson * @param sym_op crypto operation 92299a2dd95SBruce Richardson * @param sess cryptodev session 92399a2dd95SBruce Richardson */ 92499a2dd95SBruce Richardson static inline int 9252a440d6aSAkhil Goyal __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, void *sess) 92699a2dd95SBruce Richardson { 92799a2dd95SBruce Richardson sym_op->session = sess; 92899a2dd95SBruce Richardson 92999a2dd95SBruce Richardson return 0; 93099a2dd95SBruce Richardson } 93199a2dd95SBruce Richardson 93299a2dd95SBruce Richardson /** 93399a2dd95SBruce Richardson * Converts portion of mbuf data into a vector representation. 93499a2dd95SBruce Richardson * Each segment will be represented as a separate entry in *vec* array. 93599a2dd95SBruce Richardson * Expects that provided *ofs* + *len* not to exceed mbuf's *pkt_len*. 93699a2dd95SBruce Richardson * @param mb 93799a2dd95SBruce Richardson * Pointer to the *rte_mbuf* object. 93899a2dd95SBruce Richardson * @param ofs 93999a2dd95SBruce Richardson * Offset within mbuf data to start with. 94099a2dd95SBruce Richardson * @param len 94199a2dd95SBruce Richardson * Length of data to represent. 94299a2dd95SBruce Richardson * @param vec 94399a2dd95SBruce Richardson * Pointer to an output array of IO vectors. 94499a2dd95SBruce Richardson * @param num 94599a2dd95SBruce Richardson * Size of an output array. 94699a2dd95SBruce Richardson * @return 94799a2dd95SBruce Richardson * - number of successfully filled entries in *vec* array. 94899a2dd95SBruce Richardson * - negative number of elements in *vec* array required. 94999a2dd95SBruce Richardson */ 95099a2dd95SBruce Richardson __rte_experimental 95199a2dd95SBruce Richardson static inline int 95299a2dd95SBruce Richardson rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len, 95399a2dd95SBruce Richardson struct rte_crypto_vec vec[], uint32_t num) 95499a2dd95SBruce Richardson { 95599a2dd95SBruce Richardson uint32_t i; 95699a2dd95SBruce Richardson struct rte_mbuf *nseg; 95799a2dd95SBruce Richardson uint32_t left; 95899a2dd95SBruce Richardson uint32_t seglen; 95999a2dd95SBruce Richardson 96099a2dd95SBruce Richardson /* assuming that requested data starts in the first segment */ 96199a2dd95SBruce Richardson RTE_ASSERT(mb->data_len > ofs); 96299a2dd95SBruce Richardson 96399a2dd95SBruce Richardson if (mb->nb_segs > num) 96499a2dd95SBruce Richardson return -mb->nb_segs; 96599a2dd95SBruce Richardson 96699a2dd95SBruce Richardson vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs); 96799a2dd95SBruce Richardson vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs); 9686afd461fSGagandeep Singh vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs; 96999a2dd95SBruce Richardson 97099a2dd95SBruce Richardson /* whole data lies in the first segment */ 97199a2dd95SBruce Richardson seglen = mb->data_len - ofs; 97299a2dd95SBruce Richardson if (len <= seglen) { 97399a2dd95SBruce Richardson vec[0].len = len; 97499a2dd95SBruce Richardson return 1; 97599a2dd95SBruce Richardson } 97699a2dd95SBruce Richardson 97799a2dd95SBruce Richardson /* data spread across segments */ 97899a2dd95SBruce Richardson vec[0].len = seglen; 97999a2dd95SBruce Richardson left = len - seglen; 98099a2dd95SBruce Richardson for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) { 98199a2dd95SBruce Richardson 98299a2dd95SBruce Richardson vec[i].base = rte_pktmbuf_mtod(nseg, void *); 98399a2dd95SBruce Richardson vec[i].iova = rte_pktmbuf_iova(nseg); 9846afd461fSGagandeep Singh vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs; 98599a2dd95SBruce Richardson 98699a2dd95SBruce Richardson seglen = nseg->data_len; 98799a2dd95SBruce Richardson if (left <= seglen) { 98899a2dd95SBruce Richardson /* whole requested data is completed */ 98999a2dd95SBruce Richardson vec[i].len = left; 99099a2dd95SBruce Richardson left = 0; 9918edcb68fSGagandeep Singh i++; 99299a2dd95SBruce Richardson break; 99399a2dd95SBruce Richardson } 99499a2dd95SBruce Richardson 99599a2dd95SBruce Richardson /* use whole segment */ 99699a2dd95SBruce Richardson vec[i].len = seglen; 99799a2dd95SBruce Richardson left -= seglen; 99899a2dd95SBruce Richardson } 99999a2dd95SBruce Richardson 100099a2dd95SBruce Richardson RTE_ASSERT(left == 0); 10018edcb68fSGagandeep Singh return i; 100299a2dd95SBruce Richardson } 100399a2dd95SBruce Richardson 100499a2dd95SBruce Richardson 100599a2dd95SBruce Richardson #ifdef __cplusplus 100699a2dd95SBruce Richardson } 100799a2dd95SBruce Richardson #endif 100899a2dd95SBruce Richardson 100999a2dd95SBruce Richardson #endif /* _RTE_CRYPTO_SYM_H_ */ 1010