1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2016-2020 Intel Corporation 3 */ 4 5 #ifndef _RTE_CRYPTO_SYM_H_ 6 #define _RTE_CRYPTO_SYM_H_ 7 8 /** 9 * @file rte_crypto_sym.h 10 * 11 * RTE Definitions for Symmetric Cryptography 12 * 13 * Defines symmetric cipher and authentication algorithms and modes, as well 14 * as supported symmetric crypto operation combinations. 15 */ 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 #include <string.h> 22 23 #include <rte_compat.h> 24 #include <rte_mbuf.h> 25 #include <rte_memory.h> 26 #include <rte_mempool.h> 27 #include <rte_common.h> 28 29 /** 30 * Crypto IO Vector (in analogy with struct iovec) 31 * Supposed be used to pass input/output data buffers for crypto data-path 32 * functions. 33 */ 34 struct rte_crypto_vec { 35 /** virtual address of the data buffer */ 36 void *base; 37 /** IOVA of the data buffer */ 38 rte_iova_t iova; 39 /** length of the data buffer */ 40 uint32_t len; 41 /** total buffer length */ 42 uint32_t tot_len; 43 }; 44 45 /** 46 * Crypto scatter-gather list descriptor. Consists of a pointer to an array 47 * of Crypto IO vectors with its size. 48 */ 49 struct rte_crypto_sgl { 50 /** start of an array of vectors */ 51 struct rte_crypto_vec *vec; 52 /** size of an array of vectors */ 53 uint32_t num; 54 }; 55 56 /** 57 * Crypto virtual and IOVA address descriptor, used to describe cryptographic 58 * data buffer without the length information. The length information is 59 * normally predefined during session creation. 60 */ 61 struct rte_crypto_va_iova_ptr { 62 void *va; 63 rte_iova_t iova; 64 }; 65 66 /** 67 * Raw data operation descriptor. 68 * Supposed to be used with synchronous CPU crypto API call or asynchronous 69 * RAW data path API call. 70 */ 71 struct rte_crypto_sym_vec { 72 /** number of operations to perform */ 73 uint32_t num; 74 /** array of SGL vectors */ 75 struct rte_crypto_sgl *src_sgl; 76 /** array of SGL vectors for OOP, keep it NULL for inplace*/ 77 struct rte_crypto_sgl *dest_sgl; 78 /** array of pointers to cipher IV */ 79 struct rte_crypto_va_iova_ptr *iv; 80 /** array of pointers to digest */ 81 struct rte_crypto_va_iova_ptr *digest; 82 83 __extension__ 84 union { 85 /** array of pointers to auth IV, used for chain operation */ 86 struct rte_crypto_va_iova_ptr *auth_iv; 87 /** array of pointers to AAD, used for AEAD operation */ 88 struct rte_crypto_va_iova_ptr *aad; 89 }; 90 91 /** 92 * array of statuses for each operation: 93 * - 0 on success 94 * - errno on error 95 */ 96 int32_t *status; 97 }; 98 99 /** 100 * used for cpu_crypto_process_bulk() to specify head/tail offsets 101 * for auth/cipher processing. 102 */ 103 union rte_crypto_sym_ofs { 104 uint64_t raw; 105 struct { 106 struct { 107 uint16_t head; 108 uint16_t tail; 109 } auth, cipher; 110 } ofs; 111 }; 112 113 /** Symmetric Cipher Algorithms 114 * 115 * Note, to avoid ABI breakage across releases 116 * - LIST_END should not be added to this enum 117 * - the order of enums should not be changed 118 * - new algorithms should only be added to the end 119 */ 120 enum rte_crypto_cipher_algorithm { 121 RTE_CRYPTO_CIPHER_NULL = 1, 122 /**< NULL cipher algorithm. No mode applies to the NULL algorithm. */ 123 124 RTE_CRYPTO_CIPHER_3DES_CBC, 125 /**< Triple DES algorithm in CBC mode */ 126 RTE_CRYPTO_CIPHER_3DES_CTR, 127 /**< Triple DES algorithm in CTR mode */ 128 RTE_CRYPTO_CIPHER_3DES_ECB, 129 /**< Triple DES algorithm in ECB mode */ 130 131 RTE_CRYPTO_CIPHER_AES_CBC, 132 /**< AES algorithm in CBC mode */ 133 RTE_CRYPTO_CIPHER_AES_CTR, 134 /**< AES algorithm in Counter mode */ 135 RTE_CRYPTO_CIPHER_AES_ECB, 136 /**< AES algorithm in ECB mode */ 137 RTE_CRYPTO_CIPHER_AES_F8, 138 /**< AES algorithm in F8 mode */ 139 RTE_CRYPTO_CIPHER_AES_XTS, 140 /**< AES algorithm in XTS mode */ 141 142 RTE_CRYPTO_CIPHER_ARC4, 143 /**< (A)RC4 cipher algorithm */ 144 145 RTE_CRYPTO_CIPHER_KASUMI_F8, 146 /**< KASUMI algorithm in F8 mode */ 147 148 RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 149 /**< SNOW 3G algorithm in UEA2 mode */ 150 151 RTE_CRYPTO_CIPHER_ZUC_EEA3, 152 /**< ZUC algorithm in EEA3 mode */ 153 154 RTE_CRYPTO_CIPHER_DES_CBC, 155 /**< DES algorithm in CBC mode */ 156 157 RTE_CRYPTO_CIPHER_AES_DOCSISBPI, 158 /**< AES algorithm using modes required by 159 * DOCSIS Baseline Privacy Plus Spec. 160 * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next 161 * for m_src and m_dst in the rte_crypto_sym_op must be NULL. 162 */ 163 164 RTE_CRYPTO_CIPHER_DES_DOCSISBPI, 165 /**< DES algorithm using modes required by 166 * DOCSIS Baseline Privacy Plus Spec. 167 * Chained mbufs are not supported in this mode, i.e. rte_mbuf.next 168 * for m_src and m_dst in the rte_crypto_sym_op must be NULL. 169 */ 170 171 RTE_CRYPTO_CIPHER_SM4_ECB, 172 /**< ShangMi 4 (SM4) algorithm in ECB mode */ 173 RTE_CRYPTO_CIPHER_SM4_CBC, 174 /**< ShangMi 4 (SM4) algorithm in CBC mode */ 175 RTE_CRYPTO_CIPHER_SM4_CTR 176 /**< ShangMi 4 (SM4) algorithm in CTR mode */ 177 }; 178 179 /** Cipher algorithm name strings */ 180 __rte_deprecated 181 extern const char * 182 rte_crypto_cipher_algorithm_strings[]; 183 184 /** Symmetric Cipher Direction */ 185 enum rte_crypto_cipher_operation { 186 RTE_CRYPTO_CIPHER_OP_ENCRYPT, 187 /**< Encrypt cipher operation */ 188 RTE_CRYPTO_CIPHER_OP_DECRYPT 189 /**< Decrypt cipher operation */ 190 }; 191 192 /** Cipher operation name strings */ 193 extern const char * 194 rte_crypto_cipher_operation_strings[]; 195 196 /** 197 * Symmetric Cipher Setup Data. 198 * 199 * This structure contains data relating to Cipher (Encryption and Decryption) 200 * use to create a session. 201 */ 202 struct rte_crypto_cipher_xform { 203 enum rte_crypto_cipher_operation op; 204 /**< This parameter determines if the cipher operation is an encrypt or 205 * a decrypt operation. For the RC4 algorithm and the F8/CTR modes, 206 * only encrypt operations are valid. 207 */ 208 enum rte_crypto_cipher_algorithm algo; 209 /**< Cipher algorithm */ 210 211 struct { 212 const uint8_t *data; /**< pointer to key data */ 213 uint16_t length; /**< key length in bytes */ 214 } key; 215 /**< Cipher key 216 * 217 * In case the PMD supports RTE_CRYPTODEV_FF_CIPHER_WRAPPED_KEY, the 218 * original key data provided may be wrapped(encrypted) using key wrap 219 * algorithm such as AES key wrap (rfc3394) and hence length of the key 220 * may increase beyond the PMD advertised supported key size. 221 * PMD shall validate the key length and report EMSGSIZE error while 222 * configuring the session and application can skip checking the 223 * capability key length in such cases. 224 * 225 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.data will 226 * point to a concatenation of the AES encryption key followed by a 227 * keymask. As per RFC3711, the keymask should be padded with trailing 228 * bytes to match the length of the encryption key used. 229 * 230 * Cipher key length is in bytes. For AES it can be 128 bits (16 bytes), 231 * 192 bits (24 bytes) or 256 bits (32 bytes). 232 * 233 * For the RTE_CRYPTO_CIPHER_AES_F8 mode of operation, key.length 234 * should be set to the combined length of the encryption key and the 235 * keymask. Since the keymask and the encryption key are the same size, 236 * key.length should be set to 2 x the AES encryption key length. 237 * 238 * For the AES-XTS mode of operation: 239 * - Two keys must be provided and key.length refers to total length of 240 * the two keys. 241 * - key.data must point to the two keys concatenated together 242 * (key1 || key2). 243 * - Each key can be either 128 bits (16 bytes) or 256 bits (32 bytes). 244 * - Both keys must have the same size. 245 **/ 246 struct { 247 uint16_t offset; 248 /**< Starting point for Initialisation Vector or Counter, 249 * specified as number of bytes from start of crypto 250 * operation (rte_crypto_op). 251 * 252 * - For block ciphers in CBC or F8 mode, or for KASUMI 253 * in F8 mode, or for SNOW 3G in UEA2 mode, this is the 254 * Initialisation Vector (IV) value. 255 * 256 * - For block ciphers in CTR mode, this is the counter. 257 * 258 * - For CCM mode, the first byte is reserved, and the 259 * nonce should be written starting at &iv[1] (to allow 260 * space for the implementation to write in the flags 261 * in the first byte). Note that a full 16 bytes should 262 * be allocated, even though the length field will 263 * have a value less than this. Note that the PMDs may 264 * modify the memory reserved (the first byte and the 265 * final padding) 266 * 267 * - For AES-XTS, this is the 128bit tweak, i, from 268 * IEEE Std 1619-2007. 269 * 270 * For optimum performance, the data pointed to SHOULD 271 * be 8-byte aligned. 272 */ 273 uint16_t length; 274 /**< Length of valid IV data. 275 * 276 * - For block ciphers in CBC or F8 mode, or for KASUMI 277 * in F8 mode, or for SNOW 3G in UEA2 mode, this is the 278 * length of the IV (which must be the same as the 279 * block length of the cipher). 280 * 281 * - For block ciphers in CTR mode, this is the length 282 * of the counter (which must be the same as the block 283 * length of the cipher). 284 * 285 * - For CCM mode, this is the length of the nonce, 286 * which can be in the range 7 to 13 inclusive. 287 */ 288 } iv; /**< Initialisation vector parameters */ 289 290 uint32_t dataunit_len; 291 /**< When RTE_CRYPTODEV_FF_CIPHER_MULTIPLE_DATA_UNITS is enabled, 292 * this is the data-unit length of the algorithm, 293 * otherwise or when the value is 0, use the operation length. 294 * The value should be in the range defined by the dataunit_set field 295 * in the cipher capability. 296 * 297 * - For AES-XTS it is the size of data-unit, from IEEE Std 1619-2007. 298 * For-each data-unit in the operation, the tweak (IV) value is 299 * assigned consecutively starting from the operation assigned IV. 300 */ 301 }; 302 303 /** Symmetric Authentication / Hash Algorithms 304 * 305 * Note, to avoid ABI breakage across releases 306 * - LIST_END should not be added to this enum 307 * - the order of enums should not be changed 308 * - new algorithms should only be added to the end 309 */ 310 enum rte_crypto_auth_algorithm { 311 RTE_CRYPTO_AUTH_NULL = 1, 312 /**< NULL hash algorithm. */ 313 314 RTE_CRYPTO_AUTH_AES_CBC_MAC, 315 /**< AES-CBC-MAC algorithm. Only 128-bit keys are supported. */ 316 RTE_CRYPTO_AUTH_AES_CMAC, 317 /**< AES CMAC algorithm. */ 318 RTE_CRYPTO_AUTH_AES_GMAC, 319 /**< AES GMAC algorithm. */ 320 RTE_CRYPTO_AUTH_AES_XCBC_MAC, 321 /**< AES XCBC algorithm. */ 322 323 RTE_CRYPTO_AUTH_KASUMI_F9, 324 /**< KASUMI algorithm in F9 mode. */ 325 326 RTE_CRYPTO_AUTH_MD5, 327 /**< MD5 algorithm */ 328 RTE_CRYPTO_AUTH_MD5_HMAC, 329 /**< HMAC using MD5 algorithm */ 330 331 RTE_CRYPTO_AUTH_SHA1, 332 /**< 160 bit SHA algorithm. */ 333 RTE_CRYPTO_AUTH_SHA1_HMAC, 334 /**< HMAC using 160 bit SHA algorithm. 335 * HMAC-SHA-1-96 can be generated by setting 336 * digest_length to 12 bytes in auth/aead xforms. 337 */ 338 RTE_CRYPTO_AUTH_SHA224, 339 /**< 224 bit SHA algorithm. */ 340 RTE_CRYPTO_AUTH_SHA224_HMAC, 341 /**< HMAC using 224 bit SHA algorithm. */ 342 RTE_CRYPTO_AUTH_SHA256, 343 /**< 256 bit SHA algorithm. */ 344 RTE_CRYPTO_AUTH_SHA256_HMAC, 345 /**< HMAC using 256 bit SHA algorithm. */ 346 RTE_CRYPTO_AUTH_SHA384, 347 /**< 384 bit SHA algorithm. */ 348 RTE_CRYPTO_AUTH_SHA384_HMAC, 349 /**< HMAC using 384 bit SHA algorithm. */ 350 RTE_CRYPTO_AUTH_SHA512, 351 /**< 512 bit SHA algorithm. */ 352 RTE_CRYPTO_AUTH_SHA512_HMAC, 353 /**< HMAC using 512 bit SHA algorithm. */ 354 355 RTE_CRYPTO_AUTH_SNOW3G_UIA2, 356 /**< SNOW 3G algorithm in UIA2 mode. */ 357 358 RTE_CRYPTO_AUTH_ZUC_EIA3, 359 /**< ZUC algorithm in EIA3 mode */ 360 361 RTE_CRYPTO_AUTH_SHA3_224, 362 /**< 224 bit SHA3 algorithm. */ 363 RTE_CRYPTO_AUTH_SHA3_224_HMAC, 364 /**< HMAC using 224 bit SHA3 algorithm. */ 365 RTE_CRYPTO_AUTH_SHA3_256, 366 /**< 256 bit SHA3 algorithm. */ 367 RTE_CRYPTO_AUTH_SHA3_256_HMAC, 368 /**< HMAC using 256 bit SHA3 algorithm. */ 369 RTE_CRYPTO_AUTH_SHA3_384, 370 /**< 384 bit SHA3 algorithm. */ 371 RTE_CRYPTO_AUTH_SHA3_384_HMAC, 372 /**< HMAC using 384 bit SHA3 algorithm. */ 373 RTE_CRYPTO_AUTH_SHA3_512, 374 /**< 512 bit SHA3 algorithm. */ 375 RTE_CRYPTO_AUTH_SHA3_512_HMAC, 376 /**< HMAC using 512 bit SHA3 algorithm. */ 377 RTE_CRYPTO_AUTH_SM3 378 /**< ShangMi 3 (SM3) algorithm */ 379 }; 380 381 /** Authentication algorithm name strings */ 382 __rte_deprecated 383 extern const char * 384 rte_crypto_auth_algorithm_strings[]; 385 386 /** Symmetric Authentication / Hash Operations */ 387 enum rte_crypto_auth_operation { 388 RTE_CRYPTO_AUTH_OP_VERIFY, /**< Verify authentication digest */ 389 RTE_CRYPTO_AUTH_OP_GENERATE /**< Generate authentication digest */ 390 }; 391 392 /** Authentication operation name strings */ 393 extern const char * 394 rte_crypto_auth_operation_strings[]; 395 396 /** 397 * Authentication / Hash transform data. 398 * 399 * This structure contains data relating to an authentication/hash crypto 400 * transforms. The fields op, algo and digest_length are common to all 401 * authentication transforms and MUST be set. 402 */ 403 struct rte_crypto_auth_xform { 404 enum rte_crypto_auth_operation op; 405 /**< Authentication operation type */ 406 enum rte_crypto_auth_algorithm algo; 407 /**< Authentication algorithm selection */ 408 409 struct { 410 const uint8_t *data; /**< pointer to key data */ 411 uint16_t length; /**< key length in bytes */ 412 } key; 413 /**< Authentication key data. 414 * The authentication key length MUST be less than or equal to the 415 * block size of the algorithm. It is the callers responsibility to 416 * ensure that the key length is compliant with the standard being used 417 * (for example RFC 2104, FIPS 198a). 418 */ 419 420 struct { 421 uint16_t offset; 422 /**< Starting point for Initialisation Vector or Counter, 423 * specified as number of bytes from start of crypto 424 * operation (rte_crypto_op). 425 * 426 * - For SNOW 3G in UIA2 mode, for ZUC in EIA3 mode 427 * this is the authentication Initialisation Vector 428 * (IV) value. For AES-GMAC IV description please refer 429 * to the field `length` in iv struct. 430 * 431 * - For KASUMI in F9 mode and other authentication 432 * algorithms, this field is not used. 433 * 434 * For optimum performance, the data pointed to SHOULD 435 * be 8-byte aligned. 436 */ 437 uint16_t length; 438 /**< Length of valid IV data. 439 * 440 * - For SNOW3G in UIA2 mode, for ZUC in EIA3 mode and 441 * for AES-GMAC, this is the length of the IV. 442 * 443 * - For KASUMI in F9 mode and other authentication 444 * algorithms, this field is not used. 445 * 446 * - For GMAC mode, this is either: 447 * 1) Number greater or equal to one, which means that IV 448 * is used and J0 will be computed internally, a minimum 449 * of 16 bytes must be allocated. 450 * 2) Zero, in which case data points to J0. In this case 451 * 16 bytes of J0 should be passed where J0 is defined 452 * by NIST SP800-38D. 453 * 454 */ 455 } iv; /**< Initialisation vector parameters */ 456 457 uint16_t digest_length; 458 /**< Length of the digest to be returned. If the verify option is set, 459 * this specifies the length of the digest to be compared for the 460 * session. 461 * 462 * It is the caller's responsibility to ensure that the 463 * digest length is compliant with the hash algorithm being used. 464 * If the value is less than the maximum length allowed by the hash, 465 * the result shall be truncated. 466 */ 467 }; 468 469 470 /** Symmetric AEAD Algorithms 471 * 472 * Note, to avoid ABI breakage across releases 473 * - LIST_END should not be added to this enum 474 * - the order of enums should not be changed 475 * - new algorithms should only be added to the end 476 */ 477 enum rte_crypto_aead_algorithm { 478 RTE_CRYPTO_AEAD_AES_CCM = 1, 479 /**< AES algorithm in CCM mode. */ 480 RTE_CRYPTO_AEAD_AES_GCM, 481 /**< AES algorithm in GCM mode. */ 482 RTE_CRYPTO_AEAD_CHACHA20_POLY1305 483 /**< Chacha20 cipher with poly1305 authenticator */ 484 }; 485 486 /** AEAD algorithm name strings */ 487 __rte_deprecated 488 extern const char * 489 rte_crypto_aead_algorithm_strings[]; 490 491 /** Symmetric AEAD Operations */ 492 enum rte_crypto_aead_operation { 493 RTE_CRYPTO_AEAD_OP_ENCRYPT, 494 /**< Encrypt and generate digest */ 495 RTE_CRYPTO_AEAD_OP_DECRYPT 496 /**< Verify digest and decrypt */ 497 }; 498 499 /** Authentication operation name strings */ 500 extern const char * 501 rte_crypto_aead_operation_strings[]; 502 503 struct rte_crypto_aead_xform { 504 enum rte_crypto_aead_operation op; 505 /**< AEAD operation type */ 506 enum rte_crypto_aead_algorithm algo; 507 /**< AEAD algorithm selection */ 508 509 struct { 510 const uint8_t *data; /**< pointer to key data */ 511 uint16_t length; /**< key length in bytes */ 512 } key; 513 514 struct { 515 uint16_t offset; 516 /**< Starting point for Initialisation Vector or Counter, 517 * specified as number of bytes from start of crypto 518 * operation (rte_crypto_op). 519 * 520 * - For CCM mode, the first byte is reserved, and the 521 * nonce should be written starting at &iv[1] (to allow 522 * space for the implementation to write in the flags 523 * in the first byte). Note that a full 16 bytes should 524 * be allocated, even though the length field will 525 * have a value less than this. 526 * 527 * - For Chacha20-Poly1305 it is 96-bit nonce. 528 * PMD sets initial counter for Poly1305 key generation 529 * part to 0 and for Chacha20 encryption to 1 as per 530 * rfc8439 2.8. AEAD construction. 531 * 532 * For optimum performance, the data pointed to SHOULD 533 * be 8-byte aligned. 534 */ 535 uint16_t length; 536 /**< Length of valid IV data. 537 * 538 * - For GCM mode, this is either: 539 * 1) Number greater or equal to one, which means that IV 540 * is used and J0 will be computed internally, a minimum 541 * of 16 bytes must be allocated. 542 * 2) Zero, in which case data points to J0. In this case 543 * 16 bytes of J0 should be passed where J0 is defined 544 * by NIST SP800-38D. 545 * 546 * - For CCM mode, this is the length of the nonce, 547 * which can be in the range 7 to 13 inclusive. 548 * 549 * - For Chacha20-Poly1305 this field is always 12. 550 */ 551 } iv; /**< Initialisation vector parameters */ 552 553 uint16_t digest_length; 554 555 uint16_t aad_length; 556 /**< The length of the additional authenticated data (AAD) in bytes. 557 * For CCM mode, this is the length of the actual AAD, even though 558 * it is required to reserve 18 bytes before the AAD and padding 559 * at the end of it, so a multiple of 16 bytes is allocated. 560 */ 561 }; 562 563 /** Crypto transformation types */ 564 enum rte_crypto_sym_xform_type { 565 RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED = 0, /**< No xform specified */ 566 RTE_CRYPTO_SYM_XFORM_AUTH, /**< Authentication xform */ 567 RTE_CRYPTO_SYM_XFORM_CIPHER, /**< Cipher xform */ 568 RTE_CRYPTO_SYM_XFORM_AEAD /**< AEAD xform */ 569 }; 570 571 /** 572 * Symmetric crypto transform structure. 573 * 574 * This is used to specify the crypto transforms required, multiple transforms 575 * can be chained together to specify a chain transforms such as authentication 576 * then cipher, or cipher then authentication. Each transform structure can 577 * hold a single transform, the type field is used to specify which transform 578 * is contained within the union 579 */ 580 struct rte_crypto_sym_xform { 581 struct rte_crypto_sym_xform *next; 582 /**< next xform in chain */ 583 enum rte_crypto_sym_xform_type type 584 ; /**< xform type */ 585 RTE_STD_C11 586 union { 587 struct rte_crypto_auth_xform auth; 588 /**< Authentication / hash xform */ 589 struct rte_crypto_cipher_xform cipher; 590 /**< Cipher xform */ 591 struct rte_crypto_aead_xform aead; 592 /**< AEAD xform */ 593 }; 594 }; 595 596 /** 597 * Symmetric Cryptographic Operation. 598 * 599 * This structure contains data relating to performing symmetric cryptographic 600 * processing on a referenced mbuf data buffer. 601 * 602 * When a symmetric crypto operation is enqueued with the device for processing 603 * it must have a valid *rte_mbuf* structure attached, via m_src parameter, 604 * which contains the source data which the crypto operation is to be performed 605 * on. 606 * While the mbuf is in use by a crypto operation no part of the mbuf should be 607 * changed by the application as the device may read or write to any part of the 608 * mbuf. In the case of hardware crypto devices some or all of the mbuf 609 * may be DMAed in and out of the device, so writing over the original data, 610 * though only the part specified by the rte_crypto_sym_op for transformation 611 * will be changed. 612 * Out-of-place (OOP) operation, where the source mbuf is different to the 613 * destination mbuf, is a special case. Data will be copied from m_src to m_dst. 614 * The part copied includes all the parts of the source mbuf that will be 615 * operated on, based on the cipher.data.offset+cipher.data.length and 616 * auth.data.offset+auth.data.length values in the rte_crypto_sym_op. The part 617 * indicated by the cipher parameters will be transformed, any extra data around 618 * this indicated by the auth parameters will be copied unchanged from source to 619 * destination mbuf. 620 * Also in OOP operation the cipher.data.offset and auth.data.offset apply to 621 * both source and destination mbufs. As these offsets are relative to the 622 * data_off parameter in each mbuf this can result in the data written to the 623 * destination buffer being at a different alignment, relative to buffer start, 624 * to the data in the source buffer. 625 */ 626 struct rte_crypto_sym_op { 627 struct rte_mbuf *m_src; /**< source mbuf */ 628 struct rte_mbuf *m_dst; /**< destination mbuf */ 629 630 RTE_STD_C11 631 union { 632 void *session; 633 /**< Handle for the initialised crypto/security session context */ 634 struct rte_crypto_sym_xform *xform; 635 /**< Session-less API crypto operation parameters */ 636 }; 637 638 RTE_STD_C11 639 union { 640 struct { 641 struct { 642 uint32_t offset; 643 /**< Starting point for AEAD processing, specified as 644 * number of bytes from start of packet in source 645 * buffer. 646 */ 647 uint32_t length; 648 /**< The message length, in bytes, of the source buffer 649 * on which the cryptographic operation will be 650 * computed. This must be a multiple of the block size 651 */ 652 } data; /**< Data offsets and length for AEAD */ 653 struct { 654 uint8_t *data; 655 /**< This points to the location where the digest result 656 * should be inserted (in the case of digest generation) 657 * or where the purported digest exists (in the case of 658 * digest verification). 659 * 660 * At session creation time, the client specified the 661 * digest result length with the digest_length member 662 * of the @ref rte_crypto_auth_xform structure. For 663 * physical crypto devices the caller must allocate at 664 * least digest_length of physically contiguous memory 665 * at this location. 666 * 667 * For digest generation, the digest result will 668 * overwrite any data at this location. 669 * 670 * @note 671 * For GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), for 672 * "digest result" read "authentication tag T". 673 */ 674 rte_iova_t phys_addr; 675 /**< Physical address of digest */ 676 } digest; /**< Digest parameters */ 677 struct { 678 uint8_t *data; 679 /**< Pointer to Additional Authenticated Data (AAD) 680 * needed for authenticated cipher mechanisms (CCM and 681 * GCM) 682 * 683 * Specifically for CCM (@ref RTE_CRYPTO_AEAD_AES_CCM), 684 * the caller should setup this field as follows: 685 * 686 * - the additional authentication data itself should 687 * be written starting at an offset of 18 bytes into 688 * the array, leaving room for the first block (16 bytes) 689 * and the length encoding in the first two bytes of the 690 * second block. 691 * 692 * - the array should be big enough to hold the above 693 * fields, plus any padding to round this up to the 694 * nearest multiple of the block size (16 bytes). 695 * Padding will be added by the implementation. 696 * 697 * - Note that PMDs may modify the memory reserved 698 * (first 18 bytes and the final padding). 699 * 700 * Finally, for GCM (@ref RTE_CRYPTO_AEAD_AES_GCM), the 701 * caller should setup this field as follows: 702 * 703 * - the AAD is written in starting at byte 0 704 * - the array must be big enough to hold the AAD, plus 705 * any space to round this up to the nearest multiple 706 * of the block size (16 bytes). 707 * 708 */ 709 rte_iova_t phys_addr; /**< physical address */ 710 } aad; 711 /**< Additional authentication parameters */ 712 } aead; 713 714 struct { 715 struct { 716 struct { 717 uint32_t offset; 718 /**< Starting point for cipher processing, 719 * specified as number of bytes from start 720 * of data in the source buffer. 721 * The result of the cipher operation will be 722 * written back into the output buffer 723 * starting at this location. 724 * 725 * @note 726 * For SNOW 3G @ RTE_CRYPTO_CIPHER_SNOW3G_UEA2, 727 * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8 728 * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3, 729 * this field should be in bits. For 730 * digest-encrypted cases this must be 731 * an 8-bit multiple. 732 */ 733 uint32_t length; 734 /**< The message length, in bytes, of the 735 * source buffer on which the cryptographic 736 * operation will be computed. 737 * This is also the same as the result length. 738 * This must be a multiple of the block size 739 * or a multiple of data-unit length 740 * as described in xform. 741 * 742 * @note 743 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UEA2, 744 * KASUMI @ RTE_CRYPTO_CIPHER_KASUMI_F8 745 * and ZUC @ RTE_CRYPTO_CIPHER_ZUC_EEA3, 746 * this field should be in bits. For 747 * digest-encrypted cases this must be 748 * an 8-bit multiple. 749 */ 750 } data; /**< Data offsets and length for ciphering */ 751 } cipher; 752 753 struct { 754 struct { 755 uint32_t offset; 756 /**< Starting point for hash processing, 757 * specified as number of bytes from start of 758 * packet in source buffer. 759 * 760 * @note 761 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2, 762 * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9 763 * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3, 764 * this field should be in bits. For 765 * digest-encrypted cases this must be 766 * an 8-bit multiple. 767 * 768 * @note 769 * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9, 770 * this offset should be such that 771 * data to authenticate starts at COUNT. 772 * 773 * @note 774 * For DOCSIS security protocol, this 775 * offset is the DOCSIS header length 776 * and, therefore, also the CRC offset 777 * i.e. the number of bytes into the 778 * packet at which CRC calculation 779 * should begin. 780 */ 781 uint32_t length; 782 /**< The message length, in bytes, of the source 783 * buffer that the hash will be computed on. 784 * 785 * @note 786 * For SNOW 3G @ RTE_CRYPTO_AUTH_SNOW3G_UIA2, 787 * KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9 788 * and ZUC @ RTE_CRYPTO_AUTH_ZUC_EIA3, 789 * this field should be in bits. For 790 * digest-encrypted cases this must be 791 * an 8-bit multiple. 792 * 793 * @note 794 * For KASUMI @ RTE_CRYPTO_AUTH_KASUMI_F9, 795 * the length should include the COUNT, 796 * FRESH, message, direction bit and padding 797 * (to be multiple of 8 bits). 798 * 799 * @note 800 * For DOCSIS security protocol, this 801 * is the CRC length i.e. the number of 802 * bytes in the packet over which the 803 * CRC should be calculated 804 */ 805 } data; 806 /**< Data offsets and length for authentication */ 807 808 struct { 809 uint8_t *data; 810 /**< This points to the location where 811 * the digest result should be inserted 812 * (in the case of digest generation) 813 * or where the purported digest exists 814 * (in the case of digest verification). 815 * 816 * At session creation time, the client 817 * specified the digest result length with 818 * the digest_length member of the 819 * @ref rte_crypto_auth_xform structure. 820 * For physical crypto devices the caller 821 * must allocate at least digest_length of 822 * physically contiguous memory at this 823 * location. 824 * 825 * For digest generation, the digest result 826 * will overwrite any data at this location. 827 * 828 * @note 829 * Digest-encrypted case. 830 * Digest can be generated, appended to 831 * the end of raw data and encrypted 832 * together using chained digest 833 * generation 834 * (@ref RTE_CRYPTO_AUTH_OP_GENERATE) 835 * and encryption 836 * (@ref RTE_CRYPTO_CIPHER_OP_ENCRYPT) 837 * xforms. Similarly, authentication 838 * of the raw data against appended, 839 * decrypted digest, can be performed 840 * using decryption 841 * (@ref RTE_CRYPTO_CIPHER_OP_DECRYPT) 842 * and digest verification 843 * (@ref RTE_CRYPTO_AUTH_OP_VERIFY) 844 * chained xforms. 845 * To perform those operations, a few 846 * additional conditions must be met: 847 * - caller must allocate at least 848 * digest_length of memory at the end of 849 * source and (in case of out-of-place 850 * operations) destination buffer; those 851 * buffers can be linear or split using 852 * scatter-gather lists, 853 * - digest data pointer must point to 854 * the end of source or (in case of 855 * out-of-place operations) destination 856 * data, which is pointer to the 857 * data buffer + auth.data.offset + 858 * auth.data.length, 859 * - cipher.data.offset + 860 * cipher.data.length must be greater 861 * than auth.data.offset + 862 * auth.data.length and is typically 863 * equal to auth.data.offset + 864 * auth.data.length + digest_length. 865 * - for wireless algorithms, i.e. 866 * SNOW 3G, KASUMI and ZUC, as the 867 * cipher.data.length, 868 * cipher.data.offset, 869 * auth.data.length and 870 * auth.data.offset are in bits, they 871 * must be 8-bit multiples. 872 * 873 * Note, that for security reasons, it 874 * is PMDs' responsibility to not 875 * leave an unencrypted digest in any 876 * buffer after performing auth-cipher 877 * operations. 878 * 879 */ 880 rte_iova_t phys_addr; 881 /**< Physical address of digest */ 882 } digest; /**< Digest parameters */ 883 } auth; 884 }; 885 }; 886 }; 887 888 889 /** 890 * Reset the fields of a symmetric operation to their default values. 891 * 892 * @param op The crypto operation to be reset. 893 */ 894 static inline void 895 __rte_crypto_sym_op_reset(struct rte_crypto_sym_op *op) 896 { 897 memset(op, 0, sizeof(*op)); 898 } 899 900 901 /** 902 * Allocate space for symmetric crypto xforms in the private data space of the 903 * crypto operation. This also defaults the crypto xform type to 904 * RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED and configures the chaining of the xforms 905 * in the crypto operation 906 * 907 * @return 908 * - On success returns pointer to first crypto xform in crypto operations chain 909 * - On failure returns NULL 910 */ 911 static inline struct rte_crypto_sym_xform * 912 __rte_crypto_sym_op_sym_xforms_alloc(struct rte_crypto_sym_op *sym_op, 913 void *priv_data, uint8_t nb_xforms) 914 { 915 struct rte_crypto_sym_xform *xform; 916 917 sym_op->xform = xform = (struct rte_crypto_sym_xform *)priv_data; 918 919 do { 920 xform->type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED; 921 xform = xform->next = --nb_xforms > 0 ? xform + 1 : NULL; 922 } while (xform); 923 924 return sym_op->xform; 925 } 926 927 928 /** 929 * Attach a session to a symmetric crypto operation 930 * 931 * @param sym_op crypto operation 932 * @param sess cryptodev session 933 */ 934 static inline int 935 __rte_crypto_sym_op_attach_sym_session(struct rte_crypto_sym_op *sym_op, void *sess) 936 { 937 sym_op->session = sess; 938 939 return 0; 940 } 941 942 /** 943 * Converts portion of mbuf data into a vector representation. 944 * Each segment will be represented as a separate entry in *vec* array. 945 * Expects that provided *ofs* + *len* not to exceed mbuf's *pkt_len*. 946 * @param mb 947 * Pointer to the *rte_mbuf* object. 948 * @param ofs 949 * Offset within mbuf data to start with. 950 * @param len 951 * Length of data to represent. 952 * @param vec 953 * Pointer to an output array of IO vectors. 954 * @param num 955 * Size of an output array. 956 * @return 957 * - number of successfully filled entries in *vec* array. 958 * - negative number of elements in *vec* array required. 959 */ 960 __rte_experimental 961 static inline int 962 rte_crypto_mbuf_to_vec(const struct rte_mbuf *mb, uint32_t ofs, uint32_t len, 963 struct rte_crypto_vec vec[], uint32_t num) 964 { 965 uint32_t i; 966 struct rte_mbuf *nseg; 967 uint32_t left; 968 uint32_t seglen; 969 970 /* assuming that requested data starts in the first segment */ 971 RTE_ASSERT(mb->data_len > ofs); 972 973 if (mb->nb_segs > num) 974 return -mb->nb_segs; 975 976 vec[0].base = rte_pktmbuf_mtod_offset(mb, void *, ofs); 977 vec[0].iova = rte_pktmbuf_iova_offset(mb, ofs); 978 vec[0].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs; 979 980 /* whole data lies in the first segment */ 981 seglen = mb->data_len - ofs; 982 if (len <= seglen) { 983 vec[0].len = len; 984 return 1; 985 } 986 987 /* data spread across segments */ 988 vec[0].len = seglen; 989 left = len - seglen; 990 for (i = 1, nseg = mb->next; nseg != NULL; nseg = nseg->next, i++) { 991 992 vec[i].base = rte_pktmbuf_mtod(nseg, void *); 993 vec[i].iova = rte_pktmbuf_iova(nseg); 994 vec[i].tot_len = mb->buf_len - rte_pktmbuf_headroom(mb) - ofs; 995 996 seglen = nseg->data_len; 997 if (left <= seglen) { 998 /* whole requested data is completed */ 999 vec[i].len = left; 1000 left = 0; 1001 i++; 1002 break; 1003 } 1004 1005 /* use whole segment */ 1006 vec[i].len = seglen; 1007 left -= seglen; 1008 } 1009 1010 RTE_ASSERT(left == 0); 1011 return i; 1012 } 1013 1014 1015 #ifdef __cplusplus 1016 } 1017 #endif 1018 1019 #endif /* _RTE_CRYPTO_SYM_H_ */ 1020