Annotation of truecrypt/crypto/aes.h, revision 1.1.1.2

1.1       root        1: /*
                      2:  ---------------------------------------------------------------------------
                      3:  Copyright (c) 2003, Dr Brian Gladman, Worcester, UK.   All rights reserved.
                      4: 
                      5:  LICENSE TERMS
                      6: 
                      7:  The free distribution and use of this software in both source and binary
                      8:  form is allowed (with or without changes) provided that:
                      9: 
                     10:    1. distributions of this source code include the above copyright
                     11:       notice, this list of conditions and the following disclaimer;
                     12: 
                     13:    2. distributions in binary form include the above copyright
                     14:       notice, this list of conditions and the following disclaimer
                     15:       in the documentation and/or other associated materials;
                     16: 
                     17:    3. the copyright holder's name is not used to endorse products
                     18:       built using this software without specific written permission.
                     19: 
                     20:  ALTERNATIVELY, provided that this notice is retained in full, this product
                     21:  may be distributed under the terms of the GNU General Public License (GPL),
                     22:  in which case the provisions of the GPL apply INSTEAD OF those given above.
                     23: 
                     24:  DISCLAIMER
                     25: 
                     26:  This software is provided 'as is' with no explicit or implied warranties
                     27:  in respect of its properties, including, but not limited to, correctness
                     28:  and/or fitness for purpose.
                     29:  ---------------------------------------------------------------------------
                     30:  Issue 28/01/2004
                     31: 
                     32:  This file contains the definitions required to use AES in C. See aesopt.h
                     33:  for optimisation details.
                     34: */
                     35: 
                     36: #if !defined( _AES_H )
                     37: #define _AES_H
                     38: 
                     39: /*  This include is used to find 8 & 32 bit unsigned integer types  */
1.1.1.2 ! root       40: #ifndef LINUX_DRIVER
        !            41: #include <limits.h>
        !            42: #else
        !            43: #undef UCHAR_MAX
        !            44: #define UCHAR_MAX 0xff 
        !            45: #undef UINT_MAX
        !            46: #define UINT_MAX 4294967295
        !            47: #endif
1.1       root       48: 
                     49: #if defined(__cplusplus)
                     50: extern "C"
                     51: {
                     52: #endif
                     53: 
                     54: #define AES_128     /* define if AES with 128 bit keys is needed    */
                     55: #define AES_192     /* define if AES with 192 bit keys is needed    */
                     56: #define AES_256     /* define if AES with 256 bit keys is needed    */
                     57: #define AES_VAR     /* define if a variable key size is needed      */
                     58: 
                     59: /* The following must also be set in assembler files if being used  */
                     60: 
                     61: #define AES_ENCRYPT /* if support for encryption is needed          */
                     62: #define AES_DECRYPT /* if support for decryption is needed          */
                     63: #define AES_ERR_CHK /* for parameter checks & error return codes    */
                     64: 
                     65: #if UCHAR_MAX == 0xff                   /* an unsigned 8 bit type   */
                     66:   typedef unsigned char      aes_08t;
                     67: #else
                     68: #  error Please define aes_08t as an 8-bit unsigned integer type in aes.h
                     69: #endif
                     70: 
                     71: #if UINT_MAX == 4294967295              /* an unsigned 32 bit type  */
                     72:   typedef   unsigned int     aes_32t;
                     73: #elif ULONG_MAX == 4294967295ul
1.1.1.2 ! root       74:   typedef   unsigned __int32    aes_32t;
1.1       root       75: #else
                     76: #  error Please define aes_32t as a 32-bit unsigned integer type in aes.h
                     77: #endif
                     78: 
                     79: #define AES_BLOCK_SIZE  16  /* the AES block size in bytes          */
                     80: #define N_COLS           4  /* the number of columns in the state   */
                     81: 
                     82: /* The key schedule length is 11, 13 or 15 16-byte blocks for 128,  */
                     83: /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes  */
                     84: /* or 44, 52 or 60 32-bit words. For simplicity this code allocates */
                     85: /* the maximum 60 word array for the key schedule for all key sizes */
                     86: 
                     87: #if defined( AES_VAR ) || defined( AES_256 )
                     88: #define KS_LENGTH       60
                     89: #elif defined( AES_192 )
                     90: #define KS_LENGTH       52
                     91: #else
                     92: #define KS_LENGTH       44
                     93: #endif
                     94: 
                     95: #if defined( AES_ERR_CHK )
                     96: #define aes_ret     int
                     97: #define aes_good    0
                     98: #define aes_error  -1
                     99: #else
                    100: #define aes_ret     void
                    101: #endif
                    102: 
                    103: #if !defined( AES_DLL )                 /* implement normal/DLL functions   */
                    104: #define aes_rval    aes_ret
                    105: #else
                    106: #define aes_rval    aes_ret __declspec(dllexport) _stdcall
                    107: #endif
                    108: 
                    109: typedef struct
                    110: {   aes_32t ks[KS_LENGTH];
                    111:     aes_32t rn;
                    112: } aes_encrypt_ctx;
                    113: 
                    114: typedef struct
                    115: {   aes_32t ks[KS_LENGTH];
                    116:     aes_32t rn;
                    117: } aes_decrypt_ctx;
                    118: 
                    119: /* This routine must be called before first use if non-static       */
                    120: /* tables are being used                                            */
                    121: 
                    122: void gen_tabs(void);
                    123: 
                    124: /* The key length (klen) is input in bytes when it is in the range  */
                    125: /* 16 <= klen <= 32 or in bits when in the range 128 <= klen <= 256 */
                    126: 
                    127: #if defined( AES_ENCRYPT )
                    128: 
                    129: #if defined(AES_128) || defined(AES_VAR)
                    130: aes_rval aes_encrypt_key128(const unsigned char *in_key, aes_encrypt_ctx cx[1]);
                    131: #endif
                    132: 
                    133: #if defined(AES_192) || defined(AES_VAR)
                    134: aes_rval aes_encrypt_key192(const unsigned char *in_key, aes_encrypt_ctx cx[1]);
                    135: #endif
                    136: 
                    137: #if defined(AES_256) || defined(AES_VAR)
                    138: aes_rval aes_encrypt_key256(const unsigned char *in_key, aes_encrypt_ctx cx[1]);
                    139: #endif
                    140: 
                    141: #if defined(AES_VAR)
                    142: aes_rval _cdecl aes_encrypt_key(const unsigned char *in_key, int key_len, aes_encrypt_ctx cx[1]);
                    143: #endif
                    144: 
                    145: aes_rval _cdecl aes_encrypt(const unsigned char *in_blk, unsigned char *out_blk, const aes_encrypt_ctx cx[1]);
                    146: #endif
                    147: 
                    148: #if defined( AES_DECRYPT )
                    149: 
                    150: #if defined(AES_128) || defined(AES_VAR)
                    151: aes_rval aes_decrypt_key128(const unsigned char *in_key, aes_decrypt_ctx cx[1]);
                    152: #endif
                    153: 
                    154: #if defined(AES_192) || defined(AES_VAR)
                    155: aes_rval aes_decrypt_key192(const unsigned char *in_key, aes_decrypt_ctx cx[1]);
                    156: #endif
                    157: 
                    158: #if defined(AES_256) || defined(AES_VAR)
                    159: aes_rval aes_decrypt_key256(const unsigned char *in_key, aes_decrypt_ctx cx[1]);
                    160: #endif
                    161: 
                    162: #if defined(AES_VAR)
                    163: aes_rval _cdecl aes_decrypt_key(const unsigned char *in_key, int key_len, aes_decrypt_ctx cx[1]);
                    164: #endif
                    165: 
                    166: aes_rval _cdecl aes_decrypt(const unsigned char *in_blk,  unsigned char *out_blk, const aes_decrypt_ctx cx[1]);
                    167: #endif
                    168: 
                    169: #if defined(__cplusplus)
                    170: }
                    171: #endif
                    172: 
                    173: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.