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