1*811b558fSMarcel Cornu /********************************************************************** 2*811b558fSMarcel Cornu Copyright(c) 2024 Intel Corporation All rights reserved. 3*811b558fSMarcel Cornu 4*811b558fSMarcel Cornu Redistribution and use in source and binary forms, with or without 5*811b558fSMarcel Cornu modification, are permitted provided that the following conditions 6*811b558fSMarcel Cornu are met: 7*811b558fSMarcel Cornu * Redistributions of source code must retain the above copyright 8*811b558fSMarcel Cornu notice, this list of conditions and the following disclaimer. 9*811b558fSMarcel Cornu * Redistributions in binary form must reproduce the above copyright 10*811b558fSMarcel Cornu notice, this list of conditions and the following disclaimer in 11*811b558fSMarcel Cornu the documentation and/or other materials provided with the 12*811b558fSMarcel Cornu distribution. 13*811b558fSMarcel Cornu * Neither the name of Intel Corporation nor the names of its 14*811b558fSMarcel Cornu contributors may be used to endorse or promote products derived 15*811b558fSMarcel Cornu from this software without specific prior written permission. 16*811b558fSMarcel Cornu 17*811b558fSMarcel Cornu THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*811b558fSMarcel Cornu "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*811b558fSMarcel Cornu LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20*811b558fSMarcel Cornu A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21*811b558fSMarcel Cornu OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22*811b558fSMarcel Cornu SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23*811b558fSMarcel Cornu LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24*811b558fSMarcel Cornu DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25*811b558fSMarcel Cornu THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*811b558fSMarcel Cornu (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27*811b558fSMarcel Cornu OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*811b558fSMarcel Cornu **********************************************************************/ 29*811b558fSMarcel Cornu 30*811b558fSMarcel Cornu /** 31*811b558fSMarcel Cornu * @file aes_xts_internal.h 32*811b558fSMarcel Cornu * @brief AES XTS encryption/decryption internal function prototypes. 33*811b558fSMarcel Cornu * 34*811b558fSMarcel Cornu */ 35*811b558fSMarcel Cornu #ifndef _AES_XTS_INTERNAL_H 36*811b558fSMarcel Cornu #define _AES_XTS_INTERNAL_H 37*811b558fSMarcel Cornu 38*811b558fSMarcel Cornu #include <stdint.h> 39*811b558fSMarcel Cornu 40*811b558fSMarcel Cornu #ifdef __cplusplus 41*811b558fSMarcel Cornu extern "C" { 42*811b558fSMarcel Cornu 43*811b558fSMarcel Cornu #endif 44*811b558fSMarcel Cornu 45*811b558fSMarcel Cornu /** @brief XTS-AES-128 Encryption 46*811b558fSMarcel Cornu * 47*811b558fSMarcel Cornu * @requires AES-NI 48*811b558fSMarcel Cornu */ 49*811b558fSMarcel Cornu 50*811b558fSMarcel Cornu void 51*811b558fSMarcel Cornu _XTS_AES_128_enc(uint8_t *k2, //!< key used for tweaking, 16 bytes 52*811b558fSMarcel Cornu uint8_t *k1, //!< key used for encryption of tweaked plaintext, 16 bytes 53*811b558fSMarcel Cornu uint8_t *TW_initial, //!< initial tweak value, 16 bytes 54*811b558fSMarcel Cornu uint64_t N, //!< sector size, in bytes 55*811b558fSMarcel Cornu const uint8_t *pt, //!< plaintext sector input data 56*811b558fSMarcel Cornu uint8_t *ct //!< ciphertext sector output data 57*811b558fSMarcel Cornu ); 58*811b558fSMarcel Cornu 59*811b558fSMarcel Cornu /** @brief XTS-AES-128 Encryption with pre-expanded keys 60*811b558fSMarcel Cornu * 61*811b558fSMarcel Cornu * @requires AES-NI 62*811b558fSMarcel Cornu */ 63*811b558fSMarcel Cornu 64*811b558fSMarcel Cornu void 65*811b558fSMarcel Cornu _XTS_AES_128_enc_expanded_key( 66*811b558fSMarcel Cornu uint8_t *k2, //!< expanded key used for tweaking, 16*11 bytes 67*811b558fSMarcel Cornu uint8_t *k1, //!< expanded key used for encryption of tweaked plaintext, 16*11 bytes 68*811b558fSMarcel Cornu uint8_t *TW_initial, //!< initial tweak value, 16 bytes 69*811b558fSMarcel Cornu uint64_t N, //!< sector size, in bytes 70*811b558fSMarcel Cornu const uint8_t *pt, //!< plaintext sector input data 71*811b558fSMarcel Cornu uint8_t *ct //!< ciphertext sector output data 72*811b558fSMarcel Cornu ); 73*811b558fSMarcel Cornu 74*811b558fSMarcel Cornu /** @brief XTS-AES-128 Decryption 75*811b558fSMarcel Cornu * 76*811b558fSMarcel Cornu * @requires AES-NI 77*811b558fSMarcel Cornu */ 78*811b558fSMarcel Cornu 79*811b558fSMarcel Cornu void 80*811b558fSMarcel Cornu _XTS_AES_128_dec(uint8_t *k2, //!< key used for tweaking, 16 bytes 81*811b558fSMarcel Cornu uint8_t *k1, //!< key used for decryption of tweaked ciphertext, 16 bytes 82*811b558fSMarcel Cornu uint8_t *TW_initial, //!< initial tweak value, 16 bytes 83*811b558fSMarcel Cornu uint64_t N, //!< sector size, in bytes 84*811b558fSMarcel Cornu const uint8_t *ct, //!< ciphertext sector input data 85*811b558fSMarcel Cornu uint8_t *pt //!< plaintext sector output data 86*811b558fSMarcel Cornu ); 87*811b558fSMarcel Cornu 88*811b558fSMarcel Cornu /** @brief XTS-AES-128 Decryption with pre-expanded keys 89*811b558fSMarcel Cornu * 90*811b558fSMarcel Cornu * @requires AES-NI 91*811b558fSMarcel Cornu */ 92*811b558fSMarcel Cornu 93*811b558fSMarcel Cornu void 94*811b558fSMarcel Cornu _XTS_AES_128_dec_expanded_key( 95*811b558fSMarcel Cornu uint8_t *k2, //!< expanded key used for tweaking, 16*11 bytes - encryption key is used 96*811b558fSMarcel Cornu uint8_t *k1, //!< expanded decryption key used for decryption of tweaked ciphertext, 16*11 97*811b558fSMarcel Cornu //!< bytes 98*811b558fSMarcel Cornu uint8_t *TW_initial, //!< initial tweak value, 16 bytes 99*811b558fSMarcel Cornu uint64_t N, //!< sector size, in bytes 100*811b558fSMarcel Cornu const uint8_t *ct, //!< ciphertext sector input data 101*811b558fSMarcel Cornu uint8_t *pt //!< plaintext sector output data 102*811b558fSMarcel Cornu ); 103*811b558fSMarcel Cornu 104*811b558fSMarcel Cornu /** @brief XTS-AES-256 Encryption 105*811b558fSMarcel Cornu * 106*811b558fSMarcel Cornu * @requires AES-NI 107*811b558fSMarcel Cornu */ 108*811b558fSMarcel Cornu 109*811b558fSMarcel Cornu void 110*811b558fSMarcel Cornu _XTS_AES_256_enc(uint8_t *k2, //!< key used for tweaking, 16*2 bytes 111*811b558fSMarcel Cornu uint8_t *k1, //!< key used for encryption of tweaked plaintext, 16*2 bytes 112*811b558fSMarcel Cornu uint8_t *TW_initial, //!< initial tweak value, 16 bytes 113*811b558fSMarcel Cornu uint64_t N, //!< sector size, in bytes 114*811b558fSMarcel Cornu const uint8_t *pt, //!< plaintext sector input data 115*811b558fSMarcel Cornu uint8_t *ct //!< ciphertext sector output data 116*811b558fSMarcel Cornu ); 117*811b558fSMarcel Cornu 118*811b558fSMarcel Cornu /** @brief XTS-AES-256 Encryption with pre-expanded keys 119*811b558fSMarcel Cornu * 120*811b558fSMarcel Cornu * @requires AES-NI 121*811b558fSMarcel Cornu */ 122*811b558fSMarcel Cornu 123*811b558fSMarcel Cornu void 124*811b558fSMarcel Cornu _XTS_AES_256_enc_expanded_key( 125*811b558fSMarcel Cornu uint8_t *k2, //!< expanded key used for tweaking, 16*15 bytes 126*811b558fSMarcel Cornu uint8_t *k1, //!< expanded key used for encryption of tweaked plaintext, 16*15 bytes 127*811b558fSMarcel Cornu uint8_t *TW_initial, //!< initial tweak value, 16 bytes 128*811b558fSMarcel Cornu uint64_t N, //!< sector size, in bytes 129*811b558fSMarcel Cornu const uint8_t *pt, //!< plaintext sector input data 130*811b558fSMarcel Cornu uint8_t *ct //!< ciphertext sector output data 131*811b558fSMarcel Cornu ); 132*811b558fSMarcel Cornu 133*811b558fSMarcel Cornu /** @brief XTS-AES-256 Decryption 134*811b558fSMarcel Cornu * 135*811b558fSMarcel Cornu * @requires AES-NI 136*811b558fSMarcel Cornu */ 137*811b558fSMarcel Cornu 138*811b558fSMarcel Cornu void 139*811b558fSMarcel Cornu _XTS_AES_256_dec(uint8_t *k2, //!< key used for tweaking, 16*2 bytes 140*811b558fSMarcel Cornu uint8_t *k1, //!< key used for decryption of tweaked ciphertext, 16*2 bytes 141*811b558fSMarcel Cornu uint8_t *TW_initial, //!< initial tweak value, 16 bytes 142*811b558fSMarcel Cornu uint64_t N, //!< sector size, in bytes 143*811b558fSMarcel Cornu const uint8_t *ct, //!< ciphertext sector input data 144*811b558fSMarcel Cornu uint8_t *pt //!< plaintext sector output data 145*811b558fSMarcel Cornu ); 146*811b558fSMarcel Cornu 147*811b558fSMarcel Cornu /** @brief XTS-AES-256 Decryption with pre-expanded keys 148*811b558fSMarcel Cornu * 149*811b558fSMarcel Cornu * @requires AES-NI 150*811b558fSMarcel Cornu */ 151*811b558fSMarcel Cornu 152*811b558fSMarcel Cornu void 153*811b558fSMarcel Cornu _XTS_AES_256_dec_expanded_key( 154*811b558fSMarcel Cornu uint8_t *k2, //!< expanded key used for tweaking, 16*15 bytes - encryption key is used 155*811b558fSMarcel Cornu uint8_t *k1, //!< expanded decryption key used for decryption of tweaked ciphertext, 16*15 156*811b558fSMarcel Cornu //!< bytes 157*811b558fSMarcel Cornu uint8_t *TW_initial, //!< initial tweak value, 16 bytes 158*811b558fSMarcel Cornu uint64_t N, //!< sector size, in bytes 159*811b558fSMarcel Cornu const uint8_t *ct, //!< ciphertext sector input data 160*811b558fSMarcel Cornu uint8_t *pt //!< plaintext sector output data 161*811b558fSMarcel Cornu ); 162*811b558fSMarcel Cornu 163*811b558fSMarcel Cornu #ifdef __cplusplus 164*811b558fSMarcel Cornu } 165*811b558fSMarcel Cornu #endif //__cplusplus 166*811b558fSMarcel Cornu #endif // ifndef _AES_XTS_INTERNAL_H 167