Annotation of truecrypt/common/crypto.h, revision 1.1.1.9

1.1.1.7   root        1: /* Legal Notice: The source code contained in this file has been derived from
                      2:    the source code of Encryption for the Masses 2.02a, which is Copyright (c)
                      3:    1998-99 Paul Le Roux and which is covered by the 'License Agreement for
                      4:    Encryption for the Masses'. Modifications and additions to that source code
1.1.1.9 ! root        5:    contained in this file are Copyright (c) 2004-2006 TrueCrypt Foundation and
1.1.1.7   root        6:    Copyright (c) 2004 TrueCrypt Team, and are covered by TrueCrypt License 2.0
                      7:    the full text of which is contained in the file License.txt included in
                      8:    TrueCrypt binary and source code distribution archives.  */
1.1       root        9: 
1.1.1.5   root       10: /* Update the following when adding a new cipher or EA:
                     11: 
                     12:    Crypto.h:
                     13:      ID #define
                     14:      MAX_EXPANDED_KEY #define
                     15: 
                     16:    Crypto.c:
                     17:      Ciphers[]
                     18:      EncryptionAlgorithms[]
                     19:      CipherInit()
                     20:      EncipherBlock()
                     21:      DecipherBlock()
1.1.1.7   root       22: 
1.1.1.5   root       23: */
1.1       root       24: 
1.1.1.7   root       25: #ifndef CRYPTO_H
                     26: #define CRYPTO_H
                     27: 
1.1       root       28: // User text input limits
1.1.1.8   root       29: #define MIN_PASSWORD                   1               // Minimum password length
                     30: #define MAX_PASSWORD                   64              // Maximum password length
1.1.1.5   root       31: 
                     32: #define PASSWORD_LEN_WARNING   12              // Display a warning when a password is shorter than this
1.1       root       33: 
1.1.1.7   root       34: // Header key derivation
1.1.1.8   root       35: #define PKCS5_SALT_SIZE                        64
1.1       root       36: 
1.1.1.8   root       37: // Master key + secondary key (LRW mode)
                     38: #define DISKKEY_SIZE                   256
                     39: #define DISK_IV_SIZE                   32
1.1       root       40: 
                     41: // Volume header byte offsets
                     42: #define        HEADER_USERKEY_SALT             0
1.1.1.7   root       43: #define HEADER_ENCRYPTEDDATA   PKCS5_SALT_SIZE
1.1       root       44: #define        HEADER_DISKKEY                  256
                     45: 
                     46: // Volume header sizes
                     47: #define HEADER_SIZE                                    512
                     48: #define HEADER_ENCRYPTEDDATASIZE       (HEADER_SIZE - HEADER_ENCRYPTEDDATA)
                     49: 
1.1.1.5   root       50: /* The offset, in bytes, of the hidden volume header position from the end of the file (a positive value).
                     51:    The extra offset (SECTOR_SIZE * 2) was added because FAT file system fills the last sector with zeroes
                     52:    (marked as free; observed when quick format was performed using the OS format tool). One extra sector was
                     53:    added to the offset for future expandability (should the header size increase, or should header backup be
                     54:    introduced). */
                     55: #define HIDDEN_VOL_HEADER_OFFSET       (HEADER_SIZE + SECTOR_SIZE * 2)         
                     56: 
1.1.1.7   root       57: // Hash algorithms
                     58: #define        RIPEMD160                       1
                     59: #define        SHA1                            2
                     60: #define        WHIRLPOOL                       3
                     61: #define LAST_PRF_ID                    3                       // The number of implemented/available pseudo-random functions (PKCS #5 v2.0)
                     62: 
                     63: #define SHA1_BLOCKSIZE                 64
                     64: #define SHA1_DIGESTSIZE                        20
                     65: #define RIPEMD160_BLOCKSIZE            64
                     66: #define RIPEMD160_DIGESTSIZE   20
                     67: #define WHIRLPOOL_BLOCKSIZE            64
                     68: #define WHIRLPOOL_DIGESTSIZE   64
                     69: #define MAX_DIGESTSIZE                 WHIRLPOOL_DIGESTSIZE
                     70: 
                     71: #define DEFAULT_HASH_ALGORITHM         RIPEMD160
1.1.1.5   root       72: 
                     73: // Modes of operation
                     74: enum
                     75: {
1.1.1.8   root       76:        LRW = 1,
                     77:        CBC,            // Deprecated/legacy
                     78:        OUTER_CBC,      // Deprecated/legacy
                     79:        INNER_CBC,      // Deprecated/legacy
                     80:        INVALID_MODE
1.1.1.5   root       81: };
1.1       root       82: 
1.1.1.5   root       83: // Cipher IDs
1.1       root       84: #define NONE                           0
1.1.1.5   root       85: #define AES                                    1
                     86: #define BLOWFISH                       2
1.1.1.2   root       87: #define CAST                           3
1.1.1.5   root       88: #define SERPENT                                4
                     89: #define TRIPLEDES                      5
                     90: #define TWOFISH                                6
                     91: #define DES56                          7                       // Used only by Triple DES
1.1       root       92: 
1.1.1.5   root       93: typedef struct
                     94: {
                     95:        int Id;                                 // Cipher ID
                     96:        char *Name;                             // Name
                     97:        int BlockSize;                  // Block size (bytes)
                     98:        int KeySize;                    // Key size (bytes)
                     99:        int KeyScheduleSize;    // Scheduled key size (bytes)
                    100: } Cipher;
1.1       root      101: 
1.1.1.5   root      102: typedef struct
                    103: {
                    104:        int Ciphers[4];                 // Null terminated array of ciphers used by encryption algorithm
1.1.1.8   root      105:        int Modes[3];                   // Null terminated array of modes of operation
1.1.1.5   root      106: } EncryptionAlgorithm;
                    107: 
1.1.1.9 ! root      108: typedef struct
        !           109: {
        !           110:        int Id;                                 // Hash ID
        !           111:        char *Name;                             // Name
        !           112: } Hash;
        !           113: 
1.1.1.5   root      114: // Maxium length of scheduled key
                    115: #define AES_KS                         (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
                    116: #define SERPENT_KS                     (140 * 4)
                    117: #define MAX_EXPANDED_KEY       (AES_KS + SERPENT_KS + TWOFISH_KS)
1.1       root      118: 
1.1.1.7   root      119: #define DISK_WIPE_PASSES       36      // (Gutmann)
                    120: 
1.1.1.9 ! root      121: /* If a 64-bit block cipher is selected and the volume size is greater than WARN_VOL_SIZE_BLOCK64,
        !           122: warn and require a confirmation from the user. For n-bit blocks, this constant shall be << 8*2^(n/2);
        !           123: i.e. for 64-bit ciphers this constant shall be much less than the number of bytes in 2^32 blocks
        !           124: (birthday bound for 64-bit PRP). */
        !           125: #define WARN_VOL_SIZE_BLOCK64  1 * BYTES_PER_GB
        !           126: 
1.1.1.7   root      127: #include "Aes.h"
                    128: #include "Blowfish.h"
                    129: #include "Cast.h"
                    130: #include "Des.h"
                    131: #include "Serpent.h"
                    132: #include "Twofish.h"
                    133: 
                    134: #ifndef LINUX_DRIVER
                    135: #include "Rmd160.h"
                    136: #include "Sha1.h"
                    137: #include "Whirlpool.h"
                    138: #endif
1.1       root      139: 
1.1.1.8   root      140: #include "GfMul.h"
                    141: 
1.1       root      142: typedef struct keyInfo_t
                    143: {
                    144:        int noIterations;                                       /* No.of times to iterate setup */
                    145:        int keyLength;                                          /* Length of the key */
1.1.1.8   root      146:        __int8 userKey[MAX_PASSWORD];           /* Password (to which keyfiles may have been applied). Max pass, WITHOUT +1 for the NULL */
                    147:        __int8 key_salt[PKCS5_SALT_SIZE];       /* PKCS-5 salt */
                    148:        __int8 key[DISKKEY_SIZE];                       /* The actual encryption key */
1.1       root      149: } KEY_INFO, *PKEY_INFO;
                    150: 
                    151: typedef struct CRYPTO_INFO_t
                    152: {
1.1.1.8   root      153:        int ea;                                                                 /* Encryption algorithm ID */
                    154:        int mode;                                                               /* Mode of operation (e.g., LRW) */
                    155:        unsigned __int8 iv[DISK_IV_SIZE];               /* For LRW mode this contains the secondary key; for CBC it contains the IV (deprecated/legacy) */
                    156:        unsigned __int8 ks[MAX_EXPANDED_KEY];
                    157:        GfCtx gf_ctx; 
1.1.1.5   root      158: 
1.1.1.8   root      159:        unsigned __int8 master_key[DISKKEY_SIZE];
                    160:        unsigned __int8 key_salt[PKCS5_SALT_SIZE];
1.1       root      161:        int noIterations;
                    162:        int pkcs5;
                    163: 
                    164:        unsigned __int64 volume_creation_time;
                    165:        unsigned __int64 header_creation_time;
                    166: 
1.1.1.5   root      167:        // Hidden volume status & parameters
1.1.1.7   root      168:        BOOL hiddenVolume;                                      // Indicates whether the volume is mounted/mountable as hidden volume
1.1.1.8   root      169:        BOOL bProtectHiddenVolume;                      // Indicates whether the volume contains a hidden volume to be protected against overwriting
1.1.1.7   root      170:        BOOL bHiddenVolProtectionAction;                // TRUE if a write operation has been denied by the driver in order to prevent the hidden volume from being overwritten (set to FALSE upon volume mount).
1.1.1.5   root      171:        unsigned __int64 hiddenVolumeSize;              // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes.
1.1.1.7   root      172:        unsigned __int64 hiddenVolumeOffset;    // Absolute position, in bytes, of the first hidden volume data sector within the host volume (provided that there is a hidden volume within). This must be set for all hidden volumes; in case of a normal volume, this variable is only used when protecting a hidden volume within it.
1.1       root      173: 
1.1.1.5   root      174: } CRYPTO_INFO, *PCRYPTO_INFO;
1.1       root      175: 
                    176: PCRYPTO_INFO crypto_open (void);
                    177: void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
                    178: void crypto_close (PCRYPTO_INFO cryptoInfo);
1.1.1.5   root      179: 
                    180: int CipherGetBlockSize (int cipher);
                    181: int CipherGetKeySize (int cipher);
                    182: int CipherGetKeyScheduleSize (int cipher);
                    183: char * CipherGetName (int cipher);
                    184: 
1.1.1.7   root      185: int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
                    186: int EAInit (int ea, unsigned char *key, unsigned char *ks);
1.1.1.8   root      187: int EAInitMode (PCRYPTO_INFO ci);
1.1.1.5   root      188: void EncipherBlock(int cipher, void *data, void *ks);
                    189: void DecipherBlock(int cipher, void *data, void *ks);
                    190: 
                    191: int EAGetFirst ();
                    192: int EAGetCount (void);
                    193: int EAGetNext (int previousEA);
                    194: char * EAGetName (char *buf, int ea);
1.1.1.8   root      195: int EAGetByName (char *name);
1.1.1.5   root      196: int EAGetKeySize (int ea);
1.1.1.8   root      197: int EAGetFirstMode (int ea);
                    198: int EAGetNextMode (int ea, int previousModeId);
                    199: char * EAGetModeName (int ea, int mode, BOOL capitalLetters);
1.1.1.5   root      200: int EAGetKeyScheduleSize (int ea);
                    201: int EAGetLargestKey ();
                    202: 
                    203: int EAGetCipherCount (int ea);
                    204: int EAGetFirstCipher (int ea);
                    205: int EAGetLastCipher (int ea);
                    206: int EAGetNextCipher (int ea, int previousCipherId);
                    207: int EAGetPreviousCipher (int ea, int previousCipherId);
                    208: 
1.1.1.8   root      209: void EncryptBuffer (unsigned __int32 *buf, unsigned __int64 len, PCRYPTO_INFO cryptoInfo);
                    210: void DecryptBuffer (unsigned __int32 *buf, unsigned __int64 len, PCRYPTO_INFO cryptoInfo);
                    211: void EncryptBufferLRW128 (unsigned __int8 *plainText, unsigned int length, unsigned __int64 blockIndex, PCRYPTO_INFO cryptoInfo);
                    212: void DecryptBufferLRW128 (unsigned __int8 *plainText, int length, unsigned __int64 blockIndex, PCRYPTO_INFO cryptoInfo);
                    213: void EncryptBufferLRW64 (unsigned __int8 *plainText, unsigned int length, unsigned __int64 blockIndex, PCRYPTO_INFO cryptoInfo);
                    214: void DecryptBufferLRW64 (unsigned __int8 *plainText, int length, unsigned __int64 blockIndex, PCRYPTO_INFO cryptoInfo);
                    215: void _cdecl EncryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsigned __int64 noSectors, PCRYPTO_INFO cryptoInfo);
                    216: void _cdecl DecryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsigned __int64 noSectors, PCRYPTO_INFO cryptoInfo);
                    217: 
                    218: unsigned __int64 LRWSector2Index (unsigned __int64 sector, int blockSize, PCRYPTO_INFO ci);
1.1.1.7   root      219: 
1.1.1.9 ! root      220: char *HashGetName (int hash_algo_id);
        !           221: 
        !           222: BOOL DetectWeakSecondaryKey (unsigned char *key, int len);
1.1.1.5   root      223: 
1.1.1.7   root      224: #endif         /* CRYPTO_H */

unix.superglobalmegacorp.com

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