/home/aherms/Code/git/awds-routing/src/crypto/gladman/aes.h

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: 1/05/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 #if defined(__cplusplus)
00041 extern "C"
00042 {
00043 #endif
00044 
00045 #define AES_128     /* define if AES with 128 bit keys is needed    */
00046 #define AES_192     /* define if AES with 192 bit keys is needed    */
00047 #define AES_256     /* define if AES with 256 bit keys is needed    */
00048 #define AES_VAR     /* define if a variable key size is needed      */
00049 
00050 /* The following must also be set in assembler files if being used  */
00051 
00052 #define AES_ENCRYPT /* define if support for encryption is needed   */
00053   /* #define AES_DECRYPT */ /* define if support for decryption is needed   */
00054   
00055   /*  This include is used to find 8 & 32 bit unsigned integer types  */
00056 #include "limits.h"
00057   
00058 #if UCHAR_MAX == 0xff                   /* an unsigned 8 bit type   */
00059   typedef unsigned char      aes_08t;
00060 #else
00061 #error Please define aes_08t as an 8-bit unsigned integer type in aes.h
00062 #endif
00063 
00064 #if UINT_MAX == 0xffffffff              /* an unsigned 32 bit type  */
00065   typedef   unsigned int     aes_32t;
00066 #elif ULONG_MAX == 0xffffffff
00067   typedef   unsigned long    aes_32t;
00068 #else
00069 #error Please define aes_32t as a 32-bit unsigned integer type in aes.h
00070 #endif
00071 
00072 /* AES_BLOCK_SIZE is the size in BYTES of the AES block             */
00073 
00074 #define AES_BLOCK_SIZE  16                  /* the AES block size   */
00075 #define KS_LENGTH  (4 * AES_BLOCK_SIZE)     /* key schedule length  */
00076 #define N_COLS     (AES_BLOCK_SIZE >> 2)    /* columns in the state */
00077 
00078 #ifndef AES_DLL                 /* implement normal/DLL functions   */
00079 #define aes_rval    void
00080 #else
00081 #define aes_rval    void __declspec(dllexport) _stdcall
00082 #endif
00083 
00084 /* This routine must be called before first use if non-static       */
00085 /* tables are being used                                            */
00086 
00087 void gen_tabs(void);
00088 
00089 /* The key length (klen) is input in bytes when it is in the range  */
00090 /* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */
00091 
00092 #ifdef  AES_ENCRYPT
00093 
00094 typedef struct                     /* AES context for encryption    */
00095 {   aes_32t    k_sch[KS_LENGTH];   /* the encryption key schedule   */
00096     aes_32t    n_rnd;              /* the number of cipher rounds   */
00097 } aes_encrypt_ctx;
00098 
00099 #if defined(AES_128) || defined(AES_VAR)
00100 aes_rval aes_encrypt_key128(const void *in_key, aes_encrypt_ctx cx[1]);
00101 #endif
00102 
00103 #if defined(AES_192) || defined(AES_VAR)
00104 aes_rval aes_encrypt_key192(const void *in_key, aes_encrypt_ctx cx[1]);
00105 #endif
00106 
00107 #if defined(AES_256) || defined(AES_VAR)
00108 aes_rval aes_encrypt_key256(const void *in_key, aes_encrypt_ctx cx[1]);
00109 #endif
00110 
00111 #if defined(AES_VAR)
00112 aes_rval aes_encrypt_key(const void *in_key, int key_len, aes_encrypt_ctx cx[1]);
00113 #endif
00114 
00115 aes_rval aes_encrypt(const void *in_blk, void *out_blk, const aes_encrypt_ctx cx[1]);
00116 #endif
00117 
00118 #ifdef AES_DECRYPT
00119 
00120 typedef struct                     /* AES context for decryption    */
00121 {   aes_32t    k_sch[KS_LENGTH];   /* the decryption key schedule   */
00122     aes_32t    n_rnd;              /* the number of cipher rounds   */
00123 } aes_decrypt_ctx;
00124 
00125 #if defined(AES_128) || defined(AES_VAR)
00126 aes_rval aes_decrypt_key128(const void *in_key, aes_decrypt_ctx cx[1]);
00127 #endif
00128 
00129 #if defined(AES_192) || defined(AES_VAR)
00130 aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx[1]);
00131 #endif
00132 
00133 #if defined(AES_256) || defined(AES_VAR)
00134 aes_rval aes_decrypt_key256(const void *in_key, aes_decrypt_ctx cx[1]);
00135 #endif
00136 
00137 #if defined(AES_VAR)
00138 aes_rval aes_decrypt_key(const void *in_key, int key_len, aes_decrypt_ctx cx[1]);
00139 #endif
00140 
00141 aes_rval aes_decrypt(const void *in_blk, void *out_blk, const aes_decrypt_ctx cx[1]);
00142 #endif
00143 
00144 #if defined(__cplusplus)
00145 }
00146 #endif
00147 
00148 #endif

Generated on Tue Dec 11 17:58:48 2007 for AWDS by  doxygen 1.5.3-20071008