1 #ifndef __AES_CORE_H__ 2 #define __AES_CORE_H__ 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #include <stdint.h> 9 10 #define AES_ENCRYPT 1 11 #define AES_DECRYPT 0 12 13 /* Because array size can't be a const in C, the following two are macros. 14 Both sizes are in bytes. */ 15 #define AES_MAXNR 14 16 #define AES_BLOCK_SIZE 16 17 18 #ifdef OPENSSL_FIPS 19 #define FIPS_AES_SIZE_T int 20 #endif 21 22 /* zhangzj: make sure u64 is 8 bytes */ 23 #ifndef u32 24 25 #if defined(__arch64__) 26 #define U64(C) C##UL 27 #else 28 #define U64(C) C##ULL 29 #endif 30 31 typedef int64_t i64; 32 typedef uint64_t u64; 33 typedef uint32_t u32; 34 typedef uint16_t u16; 35 typedef uint8_t u8; 36 #endif 37 38 /* This should be a hidden type, but EVP requires that the size be known */ 39 struct rk_aes_key_st { 40 uint32_t rd_key[4 *(AES_MAXNR + 1)]; 41 42 int rounds; 43 }; 44 45 typedef struct rk_aes_key_st RK_AES_KEY; 46 47 enum{ 48 AES_MODE_XTS = 0, 49 AES_MODE_ECB, 50 AES_MODE_CBC, 51 AES_MODE_CTS, 52 AES_MODE_CTR, 53 AES_MODE_OFB, 54 AES_MODE_CFB 55 }; 56 57 enum{ 58 HASH_MODE_MD5 = 0, 59 HASH_MODE_SHA1, 60 HASH_MODE_SHA256, 61 HASH_MODE_SHA224, 62 HASH_MODE_SHA512, 63 HASH_MODE_SHA384 64 }; 65 66 enum{ 67 HMAC_MODE_MD5 = 0, 68 HMAC_MODE_SHA1, 69 HMAC_MODE_SHA256, 70 HMAC_MODE_SHA512 71 }; 72 73 74 struct ctr_state { 75 unsigned char ivec[AES_BLOCK_SIZE]; /* ivec[0..7] as IV, ivec[8..15] as counter */ 76 unsigned char ecount[AES_BLOCK_SIZE]; 77 unsigned int num; 78 }; 79 80 struct aes_ae_in { 81 const void *key; 82 const void *src; 83 const void *iv; 84 const void *aad; 85 int key_len; 86 int src_len; 87 int iv_len; 88 int aad_len; 89 int tag_size; 90 }; 91 92 struct aes_ae_out { 93 void *dest; 94 void *tag; 95 int dest_len; 96 }; 97 98 int rk_aes_set_encrypt_key(const unsigned char *userKey, const int bits, 99 RK_AES_KEY *key); 100 int rk_aes_set_decrypt_key(const unsigned char *userKey, const int bits, 101 RK_AES_KEY *key); 102 103 void rk_aes_encrypt(const unsigned char *in, unsigned char *out, 104 const RK_AES_KEY *key); 105 void rk_aes_decrypt(const unsigned char *in, unsigned char *out, 106 const RK_AES_KEY *key); 107 108 109 110 #ifdef __cplusplus 111 } 112 #endif 113 114 #endif 115