Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

aes.h

Go to the documentation of this file.
00001 /* 00002 --------------------------------------------------------------------------- 00003 Copyright (c) 2003, Dr Brian Gladman <brg@gladman.me.uk>, Worcester, UK. 00004 All rights reserved. 00005 00006 LICENSE TERMS 00007 00008 The free distribution and use of this software in both source and binary 00009 form is allowed (with or without changes) provided that: 00010 00011 1. distributions of this source code include the above copyright 00012 notice, this list of conditions and the following disclaimer; 00013 00014 2. distributions in binary form include the above copyright 00015 notice, this list of conditions and the following disclaimer 00016 in the documentation and/or other associated materials; 00017 00018 3. the copyright holder's name is not used to endorse products 00019 built using this software without specific written permission. 00020 00021 ALTERNATIVELY, provided that this notice is retained in full, this product 00022 may be distributed under the terms of the GNU General Public License (GPL), 00023 in which case the provisions of the GPL apply INSTEAD OF those given above. 00024 00025 DISCLAIMER 00026 00027 This software is provided 'as is' with no explicit or implied warranties 00028 in respect of its properties, including, but not limited to, correctness 00029 and/or fitness for purpose. 00030 --------------------------------------------------------------------------- 00031 Issue Date: 26/08/2003 00032 00033 This file contains the definitions required to use AES in C. See aesopt.h 00034 for optimisation details. 00035 */ 00036 00037 #ifndef _AES_H 00038 #define _AES_H 00039 00040 /* This include is used to find 8 & 32 bit unsigned integer types */ 00041 #include "limits.h" 00042 00043 #if defined(__cplusplus) 00044 extern "C" 00045 { 00046 #endif 00047 00048 #define AES_128 /* define if AES with 128 bit keys is needed */ 00049 #undef AES_192 /* define if AES with 192 bit keys is needed */ 00050 #undef AES_256 /* define if AES with 256 bit keys is needed */ 00051 #undef AES_VAR /* define if a variable key size is needed */ 00052 00053 /* The following must also be set in assembler files if being used */ 00054 00055 #define AES_ENCRYPT /* if support for encryption is needed */ 00056 #define AES_DECRYPT /* if support for decryption is needed */ 00057 #define AES_ERR_CHK /* for parameter checks & error return codes */ 00058 00059 #if UCHAR_MAX == 0xff /* an unsigned 8 bit type */ 00060 typedef unsigned char aes_08t; 00061 #else 00062 #error Please define aes_08t as an 8-bit unsigned integer type in aes.h 00063 #endif 00064 00065 #if UINT_MAX == 0xffffffff /* an unsigned 32 bit type */ 00066 typedef unsigned int aes_32t; 00067 #elif ULONG_MAX == 0xffffffff 00068 typedef unsigned long aes_32t; 00069 #else 00070 #error Please define aes_32t as a 32-bit unsigned integer type in aes.h 00071 #endif 00072 00073 #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */ 00074 #define N_COLS 4 /* the number of columns in the state */ 00075 00076 /* a maximum of 60 32-bit words are needed for the key schedule but */ 00077 /* 64 are claimed to allow space at the top for a CBC xor buffer. */ 00078 /* If this is not needed, this value can be reduced to 60. A value */ 00079 /* of 64 may also help in maintaining alignment in some situations */ 00080 #define KS_LENGTH 64 00081 00082 #ifdef AES_ERR_CHK 00083 #define aes_ret int 00084 #define aes_good 0 00085 #define aes_error -1 00086 #else 00087 #define aes_ret void 00088 #endif 00089 00090 #ifndef AES_DLL /* implement normal/DLL functions */ 00091 #define aes_rval aes_ret 00092 #else 00093 #define aes_rval aes_ret __declspec(dllexport) _stdcall 00094 #endif 00095 00096 /* This routine must be called before first use if non-static */ 00097 /* tables are being used */ 00098 00099 void gen_tabs(void); 00100 00101 /* The key length (klen) is input in bytes when it is in the range */ 00102 /* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */ 00103 00104 #ifdef AES_ENCRYPT 00105 00106 typedef struct 00107 { aes_32t ks[KS_LENGTH]; 00108 } aes_encrypt_ctx; 00109 00110 #if defined(AES_128) || defined(AES_VAR) 00111 aes_rval aes_encrypt_key128(const void *in_key, aes_encrypt_ctx cx[1]); 00112 #endif 00113 00114 #if defined(AES_192) || defined(AES_VAR) 00115 aes_rval aes_encrypt_key192(const void *in_key, aes_encrypt_ctx cx[1]); 00116 #endif 00117 00118 #if defined(AES_256) || defined(AES_VAR) 00119 aes_rval aes_encrypt_key256(const void *in_key, aes_encrypt_ctx cx[1]); 00120 #endif 00121 00122 #if defined(AES_VAR) 00123 aes_rval aes_encrypt_key(const void *in_key, int key_len, aes_encrypt_ctx cx[1]); 00124 #endif 00125 00126 aes_rval aes_encrypt(const void *in_blk, void *out_blk, const aes_encrypt_ctx cx[1]); 00127 #endif 00128 00129 #ifdef AES_DECRYPT 00130 00131 typedef struct 00132 { aes_32t ks[KS_LENGTH]; 00133 } aes_decrypt_ctx; 00134 00135 #if defined(AES_128) || defined(AES_VAR) 00136 aes_rval aes_decrypt_key128(const void *in_key, aes_decrypt_ctx cx[1]); 00137 #endif 00138 00139 #if defined(AES_192) || defined(AES_VAR) 00140 aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx[1]); 00141 #endif 00142 00143 #if defined(AES_256) || defined(AES_VAR) 00144 aes_rval aes_decrypt_key256(const void *in_key, aes_decrypt_ctx cx[1]); 00145 #endif 00146 00147 #if defined(AES_VAR) 00148 aes_rval aes_decrypt_key(const void *in_key, int key_len, aes_decrypt_ctx cx[1]); 00149 #endif 00150 00151 aes_rval aes_decrypt(const void *in_blk, void *out_blk, const aes_decrypt_ctx cx[1]); 00152 #endif 00153 00154 #if defined(__cplusplus) 00155 } 00156 #endif 00157 00158 #endif

Generated on Sat Jun 12 16:40:57 2004 for Asterisk by doxygen 1.3.7