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

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.5   root       29: #define MIN_PASSWORD           1                       // Minimum password length
                     30: #define MAX_PASSWORD           64                      // Maximum password length
                     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
        !            35: #define PKCS5_SALT_SIZE                                64
1.1       root       36: 
1.1.1.7 ! root       37: // Disk/master key + IV
1.1       root       38: #define DISKKEY_SIZE           256
                     39: #define DISK_IV_SIZE           32
                     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: {
                     76:        CBC = 1,
                     77:        OUTER_CBC,
                     78:        INNER_CBC
                     79: };
1.1       root       80: 
1.1.1.5   root       81: // Cipher IDs
1.1       root       82: #define NONE                           0
1.1.1.5   root       83: #define AES                                    1
                     84: #define BLOWFISH                       2
1.1.1.2   root       85: #define CAST                           3
1.1.1.5   root       86: #define SERPENT                                4
                     87: #define TRIPLEDES                      5
                     88: #define TWOFISH                                6
                     89: #define DES56                          7                       // Used only by Triple DES
1.1       root       90: 
1.1.1.5   root       91: typedef struct
                     92: {
                     93:        int Id;                                 // Cipher ID
                     94:        char *Name;                             // Name
                     95:        int BlockSize;                  // Block size (bytes)
                     96:        int KeySize;                    // Key size (bytes)
                     97:        int KeyScheduleSize;    // Scheduled key size (bytes)
                     98: } Cipher;
1.1       root       99: 
1.1.1.5   root      100: typedef struct
                    101: {
                    102:        int Ciphers[4];                 // Null terminated array of ciphers used by encryption algorithm
                    103:        int Mode;                               // The mode of operation of the whole EA (cipher cascade)
                    104: } EncryptionAlgorithm;
                    105: 
                    106: // Maxium length of scheduled key
                    107: #define AES_KS                         (sizeof(aes_encrypt_ctx) + sizeof(aes_decrypt_ctx))
                    108: #define SERPENT_KS                     (140 * 4)
                    109: #define MAX_EXPANDED_KEY       (AES_KS + SERPENT_KS + TWOFISH_KS)
1.1       root      110: 
1.1.1.7 ! root      111: #define DISK_WIPE_PASSES       36      // (Gutmann)
        !           112: 
        !           113: #include "Aes.h"
        !           114: #include "Blowfish.h"
        !           115: #include "Cast.h"
        !           116: #include "Des.h"
        !           117: #include "Serpent.h"
        !           118: #include "Twofish.h"
        !           119: 
        !           120: #ifndef LINUX_DRIVER
        !           121: #include "Rmd160.h"
        !           122: #include "Sha1.h"
        !           123: #include "Whirlpool.h"
        !           124: #endif
1.1       root      125: 
                    126: typedef struct keyInfo_t
                    127: {
                    128:        int noIterations;                                       /* No.of times to iterate setup */
                    129:        int keyLength;                                          /* Length of the key */
                    130:        char userKey[MAX_PASSWORD];                     /* Max pass, WITHOUT +1 for the NULL */
1.1.1.7 ! root      131:        char key_salt[PKCS5_SALT_SIZE]; /* Key setup salt */
1.1       root      132:        char key[DISKKEY_SIZE];                         /* The keying material itself */
                    133: } KEY_INFO, *PKEY_INFO;
                    134: 
                    135: typedef struct CRYPTO_INFO_t
                    136: {
1.1.1.5   root      137:        /* Encryption alogrithm information */
                    138:        int ea;
1.1       root      139:        unsigned char iv[DISK_IV_SIZE];
                    140:        unsigned char ks[MAX_EXPANDED_KEY];
                    141: 
1.1.1.5   root      142:        /* Volume information */
                    143: 
1.1.1.7 ! root      144:        unsigned char master_key[DISKKEY_SIZE];
        !           145:        unsigned char key_salt[PKCS5_SALT_SIZE];
1.1       root      146:        int noIterations;
                    147:        int pkcs5;
                    148: 
                    149:        unsigned __int64 volume_creation_time;
                    150:        unsigned __int64 header_creation_time;
                    151: 
1.1.1.5   root      152:        // Hidden volume status & parameters
1.1.1.7 ! root      153:        BOOL hiddenVolume;                                      // Indicates whether the volume is mounted/mountable as hidden volume
        !           154:        BOOL bProtectHiddenVolume;                      // Indicates whether the volume contains a hidden volume to be protected against overwriting (if so, no data must be written at offset hiddenVolumeOffset or beyond).
        !           155:        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      156:        unsigned __int64 hiddenVolumeSize;              // Size of the hidden volume excluding the header (in bytes). Set to 0 for standard volumes.
1.1.1.7 ! root      157:        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      158: 
1.1.1.5   root      159: } CRYPTO_INFO, *PCRYPTO_INFO;
1.1       root      160: 
                    161: PCRYPTO_INFO crypto_open (void);
                    162: void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen);
                    163: void crypto_close (PCRYPTO_INFO cryptoInfo);
1.1.1.5   root      164: 
                    165: int CipherGetBlockSize (int cipher);
                    166: int CipherGetKeySize (int cipher);
                    167: int CipherGetKeyScheduleSize (int cipher);
                    168: char * CipherGetName (int cipher);
                    169: 
1.1.1.7 ! root      170: int CipherInit (int cipher, unsigned char *key, unsigned char *ks);
        !           171: int EAInit (int ea, unsigned char *key, unsigned char *ks);
1.1.1.5   root      172: void EncipherBlock(int cipher, void *data, void *ks);
                    173: void DecipherBlock(int cipher, void *data, void *ks);
                    174: 
                    175: int EAGetFirst ();
                    176: int EAGetCount (void);
                    177: int EAGetNext (int previousEA);
                    178: char * EAGetName (char *buf, int ea);
                    179: int EAGetKeySize (int ea);
                    180: int EAGetMode (int ea);
1.1.1.7 ! root      181: char * EAGetModeName (int ea, BOOL capitalLetters);
1.1.1.5   root      182: int EAGetKeyScheduleSize (int ea);
                    183: int EAGetLargestKey ();
                    184: 
                    185: int EAGetCipherCount (int ea);
                    186: int EAGetFirstCipher (int ea);
                    187: int EAGetLastCipher (int ea);
                    188: int EAGetNextCipher (int ea, int previousCipherId);
                    189: int EAGetPreviousCipher (int ea, int previousCipherId);
                    190: 
1.1.1.7 ! root      191: void EncryptBuffer (unsigned __int32 *buf, unsigned __int64 len, unsigned char *ks, void *iv, void *whitening, int ea);
        !           192: void DecryptBuffer (unsigned __int32 *buf, unsigned __int64 len, unsigned char *ks, void *iv, void *whitening, int ea);
        !           193: void _cdecl EncryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsigned __int64 noSectors, unsigned char *ks, void *iv, int ea);
        !           194: void _cdecl DecryptSectors (unsigned __int32 *buf, unsigned __int64 secNo, unsigned __int64 noSectors, unsigned char *ks, void *iv, int ea);
        !           195: 
        !           196: char *get_hash_algo_name (int hash_algo_id);
1.1.1.5   root      197: 
1.1.1.7 ! root      198: #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.