1 /********************************************************************** 2 Copyright(c) 2011-2016 Intel Corporation All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions 6 are met: 7 * Redistributions of source code must retain the above copyright 8 notice, this list of conditions and the following disclaimer. 9 * Redistributions in binary form must reproduce the above copyright 10 notice, this list of conditions and the following disclaimer in 11 the documentation and/or other materials provided with the 12 distribution. 13 * Neither the name of Intel Corporation nor the names of its 14 contributors may be used to endorse or promote products derived 15 from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 **********************************************************************/ 29 30 /** 31 * @file aes_cbc.h 32 * @brief AES CBC encryption/decryption function prototypes. 33 * 34 */ 35 #ifndef _AES_CBC_h 36 #define _AES_CBC_h 37 38 #include <stdint.h> 39 40 #include "types.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 45 #endif 46 47 /* 48 * Define enums from API v2.24, so applications that were using this version 49 * will still be compiled successfully. 50 * This list does not need to be extended for new definitions. 51 */ 52 #ifndef NO_COMPAT_ISAL_CRYPTO_API_2_24 53 /***** Previous hash constants and typedefs *****/ 54 #define CBC_128_BITS ISAL_CBC_128_BITS 55 #define CBC_192_BITS ISAL_CBC_192_BITS 56 #define CBC_256_BITS ISAL_CBC_256_BITS 57 58 #define CBC_ROUND_KEY_LEN ISAL_CBC_ROUND_KEY_LEN 59 #define CBC_128_KEY_ROUNDS ISAL_CBC_128_KEY_ROUNDS 60 #define CBC_192_KEY_ROUNDS ISAL_CBC_192_KEY_ROUNDS 61 #define CBC_256_KEY_ROUNDS ISAL_CBC_256_KEY_ROUNDS 62 #define CBC_MAX_KEYS_SIZE ISAL_CBC_MAX_KEYS_SIZE 63 64 #define CBC_IV_DATA_LEN ISAL_CBC_IV_DATA_LEN 65 66 #define cbc_key_data isal_cbc_key_data 67 #define cbc_key_size isal_cbc_key_size 68 #endif /* !NO_COMPAT_ISAL_CRYPTO_API_2_24 */ 69 70 typedef enum isal_cbc_key_size { 71 ISAL_CBC_128_BITS = 16, 72 ISAL_CBC_192_BITS = 24, 73 ISAL_CBC_256_BITS = 32 74 } isal_cbc_key_size; 75 #define ISAL_CBC_ROUND_KEY_LEN (16) 76 #define ISAL_CBC_128_KEY_ROUNDS (10 + 1) /*expanded key holds 10 key rounds plus original key*/ 77 #define ISAL_CBC_192_KEY_ROUNDS (12 + 1) /*expanded key holds 12 key rounds plus original key*/ 78 #define ISAL_CBC_256_KEY_ROUNDS (14 + 1) /*expanded key holds 14 key rounds plus original key*/ 79 #define ISAL_CBC_MAX_KEYS_SIZE (ISAL_CBC_ROUND_KEY_LEN * ISAL_CBC_256_KEY_ROUNDS) 80 81 #define ISAL_CBC_IV_DATA_LEN (16) 82 83 /** @brief holds intermediate key data used in encryption/decryption 84 * 85 */ 86 struct isal_cbc_key_data { // must be 16 byte aligned 87 uint8_t enc_keys[ISAL_CBC_MAX_KEYS_SIZE]; 88 uint8_t dec_keys[ISAL_CBC_MAX_KEYS_SIZE]; 89 }; 90 91 /** @brief CBC-AES key pre-computation done once for a key 92 * 93 * @deprecated Please use isal_aes_keyexp_128(), isal_aes_keyexp_192() or isal_aes_keyexp_256() 94 * instead. 95 * @requires SSE4.1 and AESNI 96 * 97 * arg 1: in: pointer to key 98 * arg 2: OUT: pointer to a key expanded data 99 */ 100 ISAL_DEPRECATED("Please use isal_aes_keyexp_128/192/256() instead") 101 int 102 aes_cbc_precomp(uint8_t *key, int key_size, struct isal_cbc_key_data *keys_blk); 103 104 /** @brief CBC-AES 128 bit key Decryption 105 * 106 * @deprecated Please use isal_aes_cbc_dec_128() instead. 107 * @requires SSE4.1 and AESNI 108 * 109 * arg 1: in: pointer to input (cipher text) 110 * arg 2: IV: pointer to IV, Must be 16 bytes aligned to a 16 byte boundary 111 * arg 3: keys: pointer to keys, Must be on a 16 byte boundary and length of key size * key rounds 112 * arg 4: OUT: pointer to output (plain text ... in-place allowed) 113 * arg 5: len_bytes: length in bytes (multiple of 16) 114 */ 115 ISAL_DEPRECATED("Please use isal_aes_cbc_dec_128() instead") 116 void 117 aes_cbc_dec_128(void *in, //!< Input cipher text 118 uint8_t *IV, //!< Must be 16 bytes aligned to a 16 byte boundary 119 uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key 120 //!< rounds or dec_keys of isal_cbc_key_data 121 void *out, //!< Output plain text 122 uint64_t len_bytes //!< Must be a multiple of 16 bytes 123 ); 124 125 /** @brief CBC-AES 192 bit key Decryption 126 * 127 * @deprecated Please use isal_aes_cbc_dec_192() instead. 128 * @requires SSE4.1 and AESNI 129 * 130 */ 131 ISAL_DEPRECATED("Please use isal_aes_cbc_dec_192() instead") 132 void 133 aes_cbc_dec_192(void *in, //!< Input cipher text 134 uint8_t *IV, //!< Must be 16 bytes aligned to a 16 byte boundary 135 uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key 136 //!< rounds or dec_keys of isal_cbc_key_data 137 void *out, //!< Output plain text 138 uint64_t len_bytes //!< Must be a multiple of 16 bytes 139 ); 140 141 /** @brief CBC-AES 256 bit key Decryption 142 * 143 * @deprecated Please use isal_aes_cbc_dec_256() instead. 144 * @requires SSE4.1 and AESNI 145 * 146 */ 147 ISAL_DEPRECATED("Please use isal_aes_cbc_dec_256() instead") 148 void 149 aes_cbc_dec_256(void *in, //!< Input cipher text 150 uint8_t *IV, //!< Must be 16 bytes aligned to a 16 byte boundary 151 uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key 152 //!< rounds or dec_keys of isal_cbc_key_data 153 void *out, //!< Output plain text 154 uint64_t len_bytes //!< Must be a multiple of 16 bytes 155 ); 156 157 /** @brief CBC-AES 128 bit key Encryption 158 * 159 * @deprecated Please use isal_aes_cbc_enc_128() instead. 160 * @requires SSE4.1 and AESNI 161 * 162 * arg 1: in: pointer to input (plain text) 163 * arg 2: IV: pointer to IV, Must be 16 bytes aligned to a 16 byte boundary 164 * arg 3: keys: pointer to keys, Must be on a 16 byte boundary and length of key size * key rounds 165 * arg 4: OUT: pointer to output (cipher text ... in-place allowed) 166 * arg 5: len_bytes: length in bytes (multiple of 16) 167 */ 168 ISAL_DEPRECATED("Please use isal_aes_cbc_enc_128() instead") 169 int 170 aes_cbc_enc_128(void *in, //!< Input plain text 171 uint8_t *IV, //!< Must be 16 bytes aligned to a 16 byte boundary 172 uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key 173 //!< rounds or enc_keys of isal_cbc_key_data 174 void *out, //!< Output cipher text 175 uint64_t len_bytes //!< Must be a multiple of 16 bytes 176 ); 177 /** @brief CBC-AES 192 bit key Encryption 178 * 179 * @deprecated Please use isal_aes_cbc_enc_192() instead. 180 * @requires SSE4.1 and AESNI 181 * 182 */ 183 ISAL_DEPRECATED("Please use isal_aes_cbc_enc_192() instead") 184 int 185 aes_cbc_enc_192(void *in, //!< Input plain text 186 uint8_t *IV, //!< Must be 16 bytes aligned to a 16 byte boundary 187 uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key 188 //!< rounds or enc_keys of isal_cbc_key_data 189 void *out, //!< Output cipher text 190 uint64_t len_bytes //!< Must be a multiple of 16 bytes 191 ); 192 193 /** @brief CBC-AES 256 bit key Encryption 194 * 195 * @deprecated Please use isal_aes_cbc_enc_256() instead. 196 * @requires SSE4.1 and AESNI 197 * 198 */ 199 ISAL_DEPRECATED("Please use isal_aes_cbc_enc_256() instead") 200 int 201 aes_cbc_enc_256(void *in, //!< Input plain text 202 uint8_t *IV, //!< Must be 16 bytes aligned to a 16 byte boundary 203 uint8_t *keys, //!< Must be on a 16 byte boundary and length of key size * key 204 //!< rounds or enc_keys of isal_cbc_key_data 205 void *out, //!< Output cipher text 206 uint64_t len_bytes //!< Must be a multiple of 16 bytes 207 ); 208 209 /** @brief CBC-AES 128 bit key Decryption 210 * 211 * @requires AES extensions and SSE4.1 for x86 or ASIMD for ARM 212 * 213 * @return Operation status 214 * @retval 0 on success 215 * @retval Non-zero \a ISAL_CRYPTO_ERR on failure 216 */ 217 int 218 isal_aes_cbc_dec_128(const void *in, //!< Input ciphertext 219 const void *iv, //!< Initialization vector. Must be 16 bytes aligned. 220 const void *keys, //!< Expanded decryption keys. Must be on a 16 byte boundary. 221 void *out, //!< Output plaintext 222 const uint64_t len_bytes //!< Input length. Must be a multiple of 16 bytes 223 ); 224 225 /** @brief CBC-AES 192 bit key Decryption 226 * 227 * @requires AES extensions and SSE4.1 for x86 or ASIMD for ARM 228 * @return Operation status 229 * @retval 0 on success 230 * @retval Non-zero \a ISAL_CRYPTO_ERR on failure 231 */ 232 int 233 isal_aes_cbc_dec_192(const void *in, //!< Input ciphertext 234 const void *iv, //!< Initialization vector. Must be 16 bytes aligned. 235 const void *keys, //!< Expanded decryption keys. Must be on a 16 byte boundary. 236 void *out, //!< Output plaintext 237 const uint64_t len_bytes //!< Input length. Must be a multiple of 16 bytes 238 ); 239 240 /** @brief CBC-AES 256 bit key Decryption 241 * 242 * @requires AES extensions and SSE4.1 for x86 or ASIMD for ARM 243 * @return Operation status 244 * @retval 0 on success 245 * @retval Non-zero \a ISAL_CRYPTO_ERR on failure 246 */ 247 int 248 isal_aes_cbc_dec_256(const void *in, //!< Input ciphertext 249 const void *iv, //!< Initialization vector. Must be 16 bytes aligned. 250 const void *keys, //!< Expanded decryption keys. Must be on a 16 byte boundary. 251 void *out, //!< Output plaintext 252 const uint64_t len_bytes //!< Input length. Must be a multiple of 16 bytes 253 ); 254 255 /** @brief CBC-AES 128 bit key Encryption 256 * 257 * @requires AES extensions and SSE4.1 for x86 or ASIMD for ARM 258 * 259 * @return Operation status 260 * @retval 0 on success 261 * @retval Non-zero \a ISAL_CRYPTO_ERR on failure 262 */ 263 int 264 isal_aes_cbc_enc_128(const void *in, //!< Input plaintext 265 const void *iv, //!< Initialization vector. Must be 16 bytes aligned. 266 const void *keys, //!< Expanded decryption keys. Must be on a 16 byte boundary. 267 void *out, //!< Output ciphertext 268 const uint64_t len_bytes //!< Input length. Must be a multiple of 16 bytes 269 ); 270 /** @brief CBC-AES 192 bit key Encryption 271 * 272 * @requires AES extensions and SSE4.1 for x86 or ASIMD for ARM 273 * @return Operation status 274 * @retval 0 on success 275 * @retval Non-zero \a ISAL_CRYPTO_ERR on failure 276 */ 277 int 278 isal_aes_cbc_enc_192(const void *in, //!< Input plaintext 279 const void *iv, //!< Initialization vector. Must be 16 bytes aligned. 280 const void *keys, //!< Expanded decryption keys. Must be on a 16 byte boundary. 281 void *out, //!< Output ciphertext 282 const uint64_t len_bytes //!< Input length. Must be a multiple of 16 bytes 283 ); 284 285 /** @brief CBC-AES 256 bit key Encryption 286 * 287 * @requires AES extensions and SSE4.1 for x86 or ASIMD for ARM 288 * @return Operation status 289 * @retval 0 on success 290 * @retval Non-zero \a ISAL_CRYPTO_ERR on failure 291 */ 292 int 293 isal_aes_cbc_enc_256(const void *in, //!< Input plaintext 294 const void *iv, //!< Initialization vector. Must be 16 bytes aligned. 295 const void *keys, //!< Expanded decryption keys. Must be on a 16 byte boundary. 296 void *out, //!< Output ciphertext 297 const uint64_t len_bytes //!< Input length. Must be a multiple of 16 bytes 298 ); 299 300 #ifdef __cplusplus 301 } 302 #endif //__cplusplus 303 #endif // ifndef _AES_CBC_h 304