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

1.1       root        1: /*
                      2:  ---------------------------------------------------------------------------
1.1.1.6 ! root        3:  Copyright (c) 1998-2007, Brian Gladman, Worcester, UK. All rights reserved.
1.1       root        4: 
                      5:  LICENSE TERMS
                      6: 
1.1.1.6 ! root        7:  The free distribution and use of this software is allowed (with or without
        !             8:  changes) provided that:
1.1       root        9: 
1.1.1.6 ! root       10:   1. source code distributions include the above copyright notice, this
        !            11:      list of conditions and the following disclaimer;
1.1       root       12: 
1.1.1.6 ! root       13:   2. binary distributions include the above copyright notice, this list
        !            14:      of conditions and the following disclaimer in their documentation;
        !            15: 
        !            16:   3. the name of the copyright holder is not used to endorse products
        !            17:      built using this software without specific written permission.
1.1       root       18: 
                     19:  DISCLAIMER
                     20: 
                     21:  This software is provided 'as is' with no explicit or implied warranties
                     22:  in respect of its properties, including, but not limited to, correctness
                     23:  and/or fitness for purpose.
                     24:  ---------------------------------------------------------------------------
1.1.1.6 ! root       25:  Issue Date: 20/12/2007
1.1       root       26: 
                     27:  This file contains the definitions required to use AES in C. See aesopt.h
                     28:  for optimisation details.
                     29: */
                     30: 
1.1.1.6 ! root       31: /* Adapted by the TrueCrypt Foundation */
1.1.1.3   root       32: 
                     33: #ifndef _AES_H
1.1       root       34: #define _AES_H
                     35: 
1.1.1.5   root       36: #include "Common/Tcdefs.h"
                     37: 
1.1.1.3   root       38: #ifndef EXIT_SUCCESS
                     39: #define EXIT_SUCCESS    0
                     40: #define EXIT_FAILURE    1
1.1.1.2   root       41: #endif
1.1.1.6 ! root       42: #define INT_RETURN   int
1.1.1.3   root       43: 
1.1       root       44: #if defined(__cplusplus)
                     45: extern "C"
                     46: {
                     47: #endif
                     48: 
1.1.1.6 ! root       49: // #define AES_128     /* define if AES with 128 bit keys is needed    */
        !            50: // #define AES_192     /* define if AES with 192 bit keys is needed    */
1.1       root       51: #define AES_256     /* define if AES with 256 bit keys is needed    */
1.1.1.6 ! root       52: // #define AES_VAR     /* define if a variable key size is needed      */
        !            53: // #define AES_MODES   /* define if support is needed for modes        */
1.1       root       54: 
                     55: /* The following must also be set in assembler files if being used  */
                     56: 
                     57: #define AES_ENCRYPT /* if support for encryption is needed          */
                     58: #define AES_DECRYPT /* if support for decryption is needed          */
                     59: #define AES_ERR_CHK /* for parameter checks & error return codes    */
1.1.1.3   root       60: #define AES_REV_DKS /* define to reverse decryption key schedule    */
1.1       root       61: 
                     62: #define AES_BLOCK_SIZE  16  /* the AES block size in bytes          */
                     63: #define N_COLS           4  /* the number of columns in the state   */
                     64: 
                     65: /* The key schedule length is 11, 13 or 15 16-byte blocks for 128,  */
                     66: /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes  */
1.1.1.3   root       67: /* or 44, 52 or 60 32-bit words.                                    */
1.1       root       68: 
                     69: #if defined( AES_VAR ) || defined( AES_256 )
                     70: #define KS_LENGTH       60
                     71: #elif defined( AES_192 )
                     72: #define KS_LENGTH       52
                     73: #else
                     74: #define KS_LENGTH       44
                     75: #endif
                     76: 
                     77: #if defined( AES_ERR_CHK )
1.1.1.4   root       78: #define AES_RETURN     INT_RETURN
1.1       root       79: #else
1.1.1.4   root       80: #define AES_RETURN     VOID_RETURN
1.1       root       81: #endif
                     82: 
1.1.1.3   root       83: /* the character array 'inf' in the following structures is used    */
                     84: /* to hold AES context information. This AES code uses cx->inf.b[0] */
                     85: /* to hold the number of rounds multiplied by 16. The other three   */
                     86: /* elements can be used by code that implements additional modes    */
                     87: 
                     88: typedef union
                     89: {   uint_32t l;
                     90:     uint_8t b[4];
                     91: } aes_inf;
1.1       root       92: 
                     93: typedef struct
1.1.1.3   root       94: {   uint_32t ks[KS_LENGTH];
                     95:     aes_inf inf;
1.1       root       96: } aes_encrypt_ctx;
                     97: 
                     98: typedef struct
1.1.1.3   root       99: {   uint_32t ks[KS_LENGTH];
                    100:     aes_inf inf;
1.1       root      101: } aes_decrypt_ctx;
                    102: 
                    103: /* This routine must be called before first use if non-static       */
                    104: /* tables are being used                                            */
                    105: 
1.1.1.6 ! root      106: AES_RETURN aes_init(void);
1.1       root      107: 
1.1.1.3   root      108: /* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */
                    109: /* those in the range 128 <= key_len <= 256 are given in bits       */
1.1       root      110: 
                    111: #if defined( AES_ENCRYPT )
                    112: 
                    113: #if defined(AES_128) || defined(AES_VAR)
1.1.1.4   root      114: AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]);
1.1       root      115: #endif
                    116: 
                    117: #if defined(AES_192) || defined(AES_VAR)
1.1.1.4   root      118: AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]);
1.1       root      119: #endif
                    120: 
                    121: #if defined(AES_256) || defined(AES_VAR)
1.1.1.4   root      122: AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]);
1.1       root      123: #endif
                    124: 
                    125: #if defined(AES_VAR)
1.1.1.4   root      126: AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]);
1.1       root      127: #endif
                    128: 
1.1.1.4   root      129: AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]);
1.1.1.3   root      130: 
1.1       root      131: #endif
                    132: 
                    133: #if defined( AES_DECRYPT )
                    134: 
                    135: #if defined(AES_128) || defined(AES_VAR)
1.1.1.4   root      136: AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]);
1.1       root      137: #endif
                    138: 
                    139: #if defined(AES_192) || defined(AES_VAR)
1.1.1.4   root      140: AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]);
1.1       root      141: #endif
                    142: 
                    143: #if defined(AES_256) || defined(AES_VAR)
1.1.1.4   root      144: AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]);
1.1       root      145: #endif
                    146: 
                    147: #if defined(AES_VAR)
1.1.1.4   root      148: AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]);
1.1.1.3   root      149: #endif
                    150: 
1.1.1.4   root      151: AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]);
1.1.1.3   root      152: 
1.1       root      153: #endif
                    154: 
1.1.1.3   root      155: #if defined(AES_MODES)
                    156: 
1.1.1.4   root      157: /* Multiple calls to the following subroutines for multiple block   */
                    158: /* ECB, CBC, CFB, OFB and CTR mode encryption can be used to handle */
                    159: /* long messages incremantally provided that the context AND the iv */
                    160: /* are preserved between all such calls.  For the ECB and CBC modes */
                    161: /* each individual call within a series of incremental calls must   */
                    162: /* process only full blocks (i.e. len must be a multiple of 16) but */
                    163: /* the CFB, OFB and CTR mode calls can handle multiple incremental  */
                    164: /* calls of any length. Each mode is reset when a new AES key is    */
                    165: /* set but ECB and CBC operations can be reset without setting a    */
                    166: /* new key by setting a new IV value.  To reset CFB, OFB and CTR    */
                    167: /* without setting the key, aes_mode_reset() must be called and the */
                    168: /* IV must be set.  NOTE: All these calls update the IV on exit so  */
                    169: /* this has to be reset if a new operation with the same IV as the  */
                    170: /* previous one is required (or decryption follows encryption with  */
                    171: /* the same IV array).                                              */
                    172: 
1.1.1.6 ! root      173: AES_RETURN aes_test_alignment_detection(unsigned int n);
        !           174: 
1.1.1.4   root      175: AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
1.1.1.3   root      176:                     int len, const aes_encrypt_ctx cx[1]);
                    177: 
1.1.1.4   root      178: AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
1.1.1.3   root      179:                     int len, const aes_decrypt_ctx cx[1]);
                    180: 
1.1.1.4   root      181: AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf,
1.1.1.3   root      182:                     int len, unsigned char *iv, const aes_encrypt_ctx cx[1]);
                    183: 
1.1.1.4   root      184: AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf,
1.1.1.3   root      185:                     int len, unsigned char *iv, const aes_decrypt_ctx cx[1]);
                    186: 
1.1.1.4   root      187: AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1]);
1.1.1.3   root      188: 
1.1.1.4   root      189: AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf,
1.1.1.3   root      190:                     int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
                    191: 
1.1.1.4   root      192: AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf,
1.1.1.3   root      193:                     int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
                    194: 
                    195: #define aes_ofb_encrypt aes_ofb_crypt
                    196: #define aes_ofb_decrypt aes_ofb_crypt
                    197: 
1.1.1.4   root      198: AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf,
1.1.1.3   root      199:                     int len, unsigned char *iv, aes_encrypt_ctx cx[1]);
                    200: 
                    201: typedef void cbuf_inc(unsigned char *cbuf);
                    202: 
                    203: #define aes_ctr_encrypt aes_ctr_crypt
                    204: #define aes_ctr_decrypt aes_ctr_crypt
                    205: 
1.1.1.4   root      206: AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf,
1.1.1.3   root      207:             int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]);
                    208: 
1.1       root      209: #endif
                    210: 
                    211: #if defined(__cplusplus)
                    212: }
                    213: #endif
                    214: 
                    215: #endif

unix.superglobalmegacorp.com

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