aes.h (2317B)
1 /* 2 This is free and unencumbered software released into the public domain. 3 4 Anyone is free to copy, modify, publish, use, compile, sell, or 5 distribute this software, either in source code form or as a compiled 6 binary, for any purpose, commercial or non-commercial, and by any 7 means. 8 9 In jurisdictions that recognize copyright laws, the author or authors 10 of this software dedicate any and all copyright interest in the 11 software to the public domain. We make this dedication for the benefit 12 of the public at large and to the detriment of our heirs and 13 successors. We intend this dedication to be an overt act of 14 relinquishment in perpetuity of all present and future rights to this 15 software under copyright law. 16 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 OTHER DEALINGS IN THE SOFTWARE. 24 25 For more information, please refer to <http://unlicense.org/> 26 */ 27 #ifndef _AES_H_ 28 #define _AES_H_ 29 30 #ifdef _MSC_VER 31 typedef unsigned char uint8_t; 32 typedef unsigned int uint32_t; 33 #else 34 #include <stdint.h> 35 #endif 36 37 38 // #define the macros below to 1/0 to enable/disable the mode of operation. 39 // 40 // CBC enables AES128 encryption in CBC-mode of operation and handles 0-padding. 41 // ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously. 42 43 // The #ifndef-guard allows it to be configured before #include'ing or at compile time. 44 #ifndef CBC 45 #define CBC 1 46 #endif 47 48 #ifndef ECB 49 #define ECB 1 50 #endif 51 52 53 54 #if defined(ECB) && ECB 55 56 void AES128_ECB_encrypt(uint8_t* input, const uint8_t* key, uint8_t *output); 57 void AES128_ECB_decrypt(uint8_t* input, const uint8_t* key, uint8_t *output); 58 59 #endif // #if defined(ECB) && ECB 60 61 62 #if defined(CBC) && CBC 63 64 void AES128_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 65 void AES128_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 66 67 #endif // #if defined(CBC) && CBC 68 69 70 71 #endif //_AES_H_