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

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
                      5:    contained in this file are Copyright (c) 2004-2005 TrueCrypt Foundation and
                      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: 
                    108: // Maxium length of scheduled key
                    109: #define AES_KS                         (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
                    110: #define SERPENT_KS                     (140 * 4)
                    111: #define MAX_EXPANDED_KEY       (AES_KS + SERPENT_KS + TWOFISH_KS)
1.1       root      112: 
1.1.1.7   root      113: #define DISK_WIPE_PASSES       36      // (Gutmann)
                    114: 
                    115: #include "Aes.h"
                    116: #include "Blowfish.h"
                    117: #include "Cast.h"
                    118: #include "Des.h"
                    119: #include "Serpent.h"
                    120: #include "Twofish.h"
                    121: 
                    122: #ifndef LINUX_DRIVER
                    123: #include "Rmd160.h"
                    124: #include "Sha1.h"
                    125: #include "Whirlpool.h"
                    126: #endif
1.1       root      127: 
1.1.1.8 ! root      128: #include "GfMul.h"
        !           129: 
1.1       root      130: typedef struct keyInfo_t
                    131: {
                    132:        int noIterations;                                       /* No.of times to iterate setup */
                    133:        int keyLength;                                          /* Length of the key */
1.1.1.8 ! root      134:        __int8 userKey[MAX_PASSWORD];           /* Password (to which keyfiles may have been applied). Max pass, WITHOUT +1 for the NULL */
        !           135:        __int8 key_salt[PKCS5_SALT_SIZE];       /* PKCS-5 salt */
        !           136:        __int8 key[DISKKEY_SIZE];                       /* The actual encryption key */
1.1       root      137: } KEY_INFO, *PKEY_INFO;
                    138: 
                    139: typedef struct CRYPTO_INFO_t
                    140: {
1.1.1.8 ! root      141:        int ea;                                                                 /* Encryption algorithm ID */
        !           142:        int mode;                                                               /* Mode of operation (e.g., LRW) */
        !           143:        unsigned __int8 iv[DISK_IV_SIZE];               /* For LRW mode this contains the secondary key; for CBC it contains the IV (deprecated/legacy) */
        !           144:        unsigned __int8 ks[MAX_EXPANDED_KEY];
        !           145:        GfCtx gf_ctx; 
1.1.1.5   root      146: 
1.1.1.8 ! root      147:        unsigned __int8 master_key[DISKKEY_SIZE];
        !           148:        unsigned __int8 key_salt[PKCS5_SALT_SIZE];
1.1       root      149:        int noIterations;
                    150:        int pkcs5;
                    151: 
                    152:        unsigned __int64 volume_creation_time;
                    153:        unsigned __int64 header_creation_time;
                    154: 
1.1.1.5   root      155:        // Hidden volume status & parameters
1.1.1.7   root      156:        BOOL hiddenVolume;                                      // Indicates whether the volume is mounted/mountable as hidden volume
1.1.1.8 ! root      157:        BOOL bProtectHiddenVolume;                      // Indicates whether the volume contains a hidden volume to be protected against overwriting
1.1.1.7   root      158:        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      159:        unsigned __int64 hiddenVolumeSize;              // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes.
1.1.1.7   root      160:        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      161: 
1.1.1.5   root      162: } CRYPTO_INFO, *PCRYPTO_INFO;
1.1       root      163: 
                    164: PCRYPTO_INFO crypto_open (void);
                    165: void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
                    166: void crypto_close (PCRYPTO_INFO cryptoInfo);
1.1.1.5   root      167: 
                    168: int CipherGetBlockSize (int cipher);
                    169: int CipherGetKeySize (int cipher);
                    170: int CipherGetKeyScheduleSize (int cipher);
                    171: char * CipherGetName (int cipher);
                    172: 
1.1.1.7   root      173: int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
                    174: int EAInit (int ea, unsigned char *key, unsigned char *ks);
1.1.1.8 ! root      175: int EAInitMode (PCRYPTO_INFO ci);
1.1.1.5   root      176: void EncipherBlock(int cipher, void *data, void *ks);
                    177: void DecipherBlock(int cipher, void *data, void *ks);
                    178: 
                    179: int EAGetFirst ();
                    180: int EAGetCount (void);
                    181: int EAGetNext (int previousEA);
                    182: char * EAGetName (char *buf, int ea);
1.1.1.8 ! root      183: int EAGetByName (char *name);
1.1.1.5   root      184: int EAGetKeySize (int ea);
1.1.1.8 ! root      185: int EAGetFirstMode (int ea);
        !           186: int EAGetNextMode (int ea, int previousModeId);
        !           187: char * EAGetModeName (int ea, int mode, BOOL capitalLetters);
1.1.1.5   root      188: int EAGetKeyScheduleSize (int ea);
                    189: int EAGetLargestKey ();
                    190: 
                    191: int EAGetCipherCount (int ea);
                    192: int EAGetFirstCipher (int ea);
                    193: int EAGetLastCipher (int ea);
                    194: int EAGetNextCipher (int ea, int previousCipherId);
                    195: int EAGetPreviousCipher (int ea, int previousCipherId);
                    196: 
1.1.1.8 ! root      197: void EncryptBuffer (unsigned __int32 *buf, unsigned __int64 len, PCRYPTO_INFO cryptoInfo);
        !           198: void DecryptBuffer (unsigned __int32 *buf, unsigned __int64 len, PCRYPTO_INFO cryptoInfo);
        !           199: void EncryptBufferLRW128 (unsigned __int8 *plainText, unsigned int length, unsigned __int64 blockIndex, PCRYPTO_INFO cryptoInfo);
        !           200: void DecryptBufferLRW128 (unsigned __int8 *plainText, int length, unsigned __int64 blockIndex, PCRYPTO_INFO cryptoInfo);
        !           201: void EncryptBufferLRW64 (unsigned __int8 *plainText, unsigned int length, unsigned __int64 blockIndex, PCRYPTO_INFO cryptoInfo);
        !           202: void DecryptBufferLRW64 (unsigned __int8 *plainText, int length, unsigned __int64 blockIndex, PCRYPTO_INFO cryptoInfo);
        !           203: void _cdecl EncryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsigned __int64 noSectors, PCRYPTO_INFO cryptoInfo);
        !           204: void _cdecl DecryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsigned __int64 noSectors, PCRYPTO_INFO cryptoInfo);
        !           205: 
        !           206: unsigned __int64 LRWSector2Index (unsigned __int64 sector, int blockSize, PCRYPTO_INFO ci);
1.1.1.7   root      207: 
                    208: char *get_hash_algo_name (int hash_algo_id);
1.1.1.5   root      209: 
1.1.1.7   root      210: #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.