SASC
DVBSoftCAM

aes.h

Go to the documentation of this file.
00001 #ifndef HEADER_AES_H
00002 #define HEADER_AES_H
00003 
00004 /*
00005 #ifdef OPENSSL_NO_AES
00006 #error AES is disabled.
00007 #endif
00008 */
00009 
00010 #define AES_ENCRYPT     1
00011 #define AES_DECRYPT     0
00012 
00013 /* Because array size can't be a const in C, the following two are macros.
00014    Both sizes are in bytes. */
00015 #define AES_MAXNR 14
00016 #define AES_BLOCK_SIZE 16
00017 
00018 #ifdef  __cplusplus
00019 extern "C" {
00020 #endif
00021 
00022 #if defined(_MSC_VER) && !defined(OPENSSL_SYS_WINCE)
00023 # define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
00024 # define GETU32(p) SWAP(*((u32 *)(p)))
00025 # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
00026 #else
00027 # define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] <<  8) ^ ((u32)(pt)[3]))
00028 # define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >>  8); (ct)[3] = (u8)(st); }
00029 #endif
00030 
00031 typedef unsigned long u32;
00032 typedef unsigned short u16;
00033 typedef unsigned char u8;
00034 
00035 #define MAXKC   (256/32)
00036 #define MAXKB   (256/8)
00037 #define MAXNR   14
00038 
00039 /* This controls loop-unrolling in aes_core.c */
00040 #undef FULL_UNROLL
00041 
00042 /* This should be a hidden type, but EVP requires that the size be known */
00043 struct aes_key_st {
00044     unsigned long rd_key[4 *(AES_MAXNR + 1)];
00045     int rounds;
00046 };
00047 typedef struct aes_key_st AES_KEY;
00048 
00049 const char *AES_options(void);
00050 
00051 int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
00052         AES_KEY *key);
00053 int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
00054         AES_KEY *key);
00055 
00056 void AES_encrypt(const unsigned char *in, unsigned char *out,
00057         const AES_KEY *key);
00058 void AES_decrypt(const unsigned char *in, unsigned char *out,
00059         const AES_KEY *key);
00060 
00061 void AES_ecb_encrypt(const unsigned char *in, unsigned char *out,
00062         const AES_KEY *key, const int enc);
00063 void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
00064         const unsigned long length, const AES_KEY *key,
00065         unsigned char *ivec, const int enc);
00066 void AES_cfb128_encrypt(const unsigned char *in, unsigned char *out,
00067         const unsigned long length, const AES_KEY *key,
00068         unsigned char *ivec, int *num, const int enc);
00069 void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out,
00070         const unsigned long length, const AES_KEY *key,
00071         unsigned char *ivec, int *num);
00072 void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
00073         const unsigned long length, const AES_KEY *key,
00074         unsigned char ivec[AES_BLOCK_SIZE],
00075         unsigned char ecount_buf[AES_BLOCK_SIZE],
00076         unsigned int *num);
00077 
00078 
00079 #ifdef  __cplusplus
00080 }
00081 #endif
00082 
00083 #endif /* !HEADER_AES_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines