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