Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages

# 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: 1/06/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 /* if support for encryption is needed          */
    00053 #define AES_DECRYPT /* if support for decryption is needed          */
    00054 #define AES_ERR_CHK /* for parameter checks & error return codes    */
    00055
    00056 /*  This include is used to find 8 & 32 bit unsigned integer types  */
    00057 #include "limits.h"
    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 aes_32t aes_encrypt_ctx[KS_LENGTH];
    00107
    00108 #if defined(AES_128) || defined(AES_VAR)
    00109 aes_rval aes_encrypt_key128(const void *in_key, aes_encrypt_ctx cx);
    00110 #endif
    00111
    00112 #if defined(AES_192) || defined(AES_VAR)
    00113 aes_rval aes_encrypt_key192(const void *in_key, aes_encrypt_ctx cx);
    00114 #endif
    00115
    00116 #if defined(AES_256) || defined(AES_VAR)
    00117 aes_rval aes_encrypt_key256(const void *in_key, aes_encrypt_ctx cx);
    00118 #endif
    00119
    00120 #if defined(AES_VAR)
    00121 aes_rval aes_encrypt_key(const void *in_key, int key_len, aes_encrypt_ctx cx);
    00122 #endif
    00123
    00124 aes_rval aes_encrypt(const void *in_blk, void *out_blk, const aes_encrypt_ctx cx);
    00125 #endif
    00126
    00127 #ifdef AES_DECRYPT
    00128
    00129 typedef aes_32t aes_decrypt_ctx[KS_LENGTH];
    00130
    00131 #if defined(AES_128) || defined(AES_VAR)
    00132 aes_rval aes_decrypt_key128(const void *in_key, aes_decrypt_ctx cx);
    00133 #endif
    00134
    00135 #if defined(AES_192) || defined(AES_VAR)
    00136 aes_rval aes_decrypt_key192(const void *in_key, aes_decrypt_ctx cx);
    00137 #endif
    00138
    00139 #if defined(AES_256) || defined(AES_VAR)
    00140 aes_rval aes_decrypt_key256(const void *in_key, aes_decrypt_ctx cx);
    00141 #endif
    00142
    00143 #if defined(AES_VAR)
    00144 aes_rval aes_decrypt_key(const void *in_key, int key_len, aes_decrypt_ctx cx);
    00145 #endif
    00146
    00147 aes_rval aes_decrypt(const void *in_blk, void *out_blk, const aes_decrypt_ctx cx);
    00148 #endif
    00149
    00150 #if defined(__cplusplus)
    00151 }
    00152 #endif
    00153
    00154 #endif