|
|
1.1.1.3 ! root 1: /* The source code contained in this file has been derived from the source code ! 2: of Encryption for the Masses 2.02a by Paul Le Roux. Modifications and ! 3: additions to that source code contained in this file are Copyright (c) 2004 ! 4: TrueCrypt Team and Copyright (c) 2004 TrueCrypt Foundation. Unmodified ! 5: parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation ! 6: release. Please see the file license.txt for full license details. */ 1.1 root 7: 8: 9: // User text input limits 10: #ifndef _DEBUG 11: #define MIN_PASSWORD 12 12: #else 13: #define MIN_PASSWORD 0 14: #endif 15: #define MAX_PASSWORD 64 16: 17: // User key 18: #define USERKEY_ITERATIONS 2000 19: #define USERKEY_SALT_SIZE 64 20: 21: // Disk key + IV 22: #define DISKKEY_SIZE 256 23: #define DISK_IV_SIZE 32 24: 25: // Volume header byte offsets 26: #define HEADER_USERKEY_SALT 0 27: #define HEADER_ENCRYPTEDDATA USERKEY_SALT_SIZE 28: #define HEADER_DISKKEY 256 29: 30: // Volume header sizes 31: #define HEADER_SIZE 512 32: #define HEADER_ENCRYPTEDDATASIZE (HEADER_SIZE - HEADER_ENCRYPTEDDATA) 33: 34: // PKCS5 PRF hash algorithm ID 35: #define SHA1 1 36: #define RIPEMD160 2 1.1.1.3 ! root 37: #define LAST_PRF_ID 2 // Last PRF used for volume encryption 1.1 root 38: 39: /* The encryption algorithm ID */ 40: #define NONE 0 41: #define BLOWFISH 1 1.1.1.2 root 42: #define AES 2 43: #define CAST 3 44: #define IDEA 4 45: #define TRIPLEDES 5 1.1 root 46: #define DES56 100 // Used only for DES test vectors 47: 1.1.1.2 root 48: #define LAST_CIPHER_ID 5 // Last cipher used for volume encryption 1.1 root 49: 50: // Length in bytes of the longest key used by encryption algorithms 51: #define MAX_CIPHER_KEY 56 // Blowfish 448 bits 52: 53: /* Length of scheduled keys */ 54: #define IDEA_KS 104 55: #define DES_KS 128 56: #define TRIPLEDES_KS (DES_KS*3) 57: #define BLOWFISH_KS 4168 1.1.1.2 root 58: #define AES_KS 240 1.1 root 59: #define CAST_KS 128 60: 61: #define MAX_EXPANDED_KEY 4168 62: 63: #include "des.h" 64: #include "blowfish.h" 1.1.1.2 root 65: #include "aes.h" 1.1 root 66: #include "idea.h" 67: #include "cast.h" 1.1.1.3 ! root 68: #include "sha1.h" ! 69: #include "rmd160.h" 1.1 root 70: 71: /* _cdecl is needed here because the device driver defaults to stdcall */ 72: typedef void (_cdecl * sector_func) (unsigned long *, unsigned __int64, unsigned long, 73: unsigned char *, unsigned char *, int); 74: 75: typedef struct keyInfo_t 76: { 77: int noIterations; /* No.of times to iterate setup */ 78: int keyLength; /* Length of the key */ 79: char userKey[MAX_PASSWORD]; /* Max pass, WITHOUT +1 for the NULL */ 80: char key_salt[USERKEY_SALT_SIZE]; /* Key setup salt */ 81: char key[DISKKEY_SIZE]; /* The keying material itself */ 82: } KEY_INFO, *PKEY_INFO; 83: 84: typedef struct CRYPTO_INFO_t 85: { 86: /* cipher information */ 87: int cipher; 88: sector_func encrypt_sector; 89: sector_func decrypt_sector; 90: unsigned char iv[DISK_IV_SIZE]; 91: unsigned char ks[MAX_EXPANDED_KEY]; 92: 93: /* volume information */ 94: unsigned char master_decrypted_key[DISKKEY_SIZE]; 95: unsigned char key_salt[USERKEY_SALT_SIZE]; 96: int noIterations; 97: int pkcs5; 98: 99: unsigned __int64 volume_creation_time; 100: unsigned __int64 header_creation_time; 101: } CRYPTO_INFO, *PCRYPTO_INFO; 102: 103: #define decipher_block(cipher, data, ks) \ 104: {\ 105: if (cipher == BLOWFISH) BF_decrypt ((void *) data, (void *) ks); \ 1.1.1.2 root 106: else if (cipher == AES) aes_decrypt ((void *) data, (void *) data, (void *)((char *)(ks)+sizeof(aes_encrypt_ctx))); \ 1.1 root 107: else if (cipher == IDEA) ideaCrypt ((void *) data,(void *) data, (void *) ((char *) ks + IDEA_KS)); \ 108: else if (cipher == DES56) des_encrypt ((void *) data, (void *) ks, 0); \ 109: else if (cipher == CAST) CAST_ecb_encrypt((void *) data,(void *) data,(void*)ks,0); \ 110: else if (cipher == TRIPLEDES) des_ecb3_encrypt ((void *) data,(void *) data, (void *) ks, \ 111: (void*)((char*)ks+DES_KS),(void*)((char*)ks+DES_KS*2),0); \ 112: } 113: 114: #define encipher_block(cipher, data, ks) \ 115: {\ 116: if (cipher == BLOWFISH) BF_encrypt ((void *) data, (void *) ks); \ 1.1.1.2 root 117: else if (cipher == AES) aes_encrypt ((void *) data, (void *) data, (void *) ks); \ 1.1 root 118: else if (cipher == IDEA) ideaCrypt ((void *) data, (void *) data, (void *) ks); \ 119: else if (cipher == DES56) des_encrypt ((void *) data, (void *) ks, 1); \ 120: else if (cipher == CAST) CAST_ecb_encrypt((void *) data,(void *) data,(void*)ks,1); \ 121: else if (cipher == TRIPLEDES) des_ecb3_encrypt ((void *) data,(void *) data, (void *) ks, \ 122: (void*)((char*)ks+DES_KS),(void*)((char*)ks+DES_KS*2),1); \ 123: } 124: 125: #define init_cipher(cipher, key, ks) \ 126: {\ 127: if (cipher == BLOWFISH) BF_set_key ((void*)ks, 56, (void*) (key)); \ 1.1.1.2 root 128: else if (cipher == AES) {aes_encrypt_key((void*)(key), 32, (void*)ks); aes_decrypt_key((void*)(key), 32, (void*)((char *)(ks)+sizeof(aes_encrypt_ctx)));} \ 1.1 root 129: else if (cipher == IDEA) ideaExpandKey ((void*) (key), (void*)ks, (void *) ((char *) ks + IDEA_KS)); \ 130: else if (cipher == DES56) des_key_sched ((void*) (key), (void*)ks); \ 131: else if (cipher == CAST) CAST_set_key((void*)ks, 16, (void*)(key)); \ 132: else if (cipher == TRIPLEDES) { \ 133: des_key_sched ((void*) (key), (void*)ks); \ 134: des_key_sched ((void*) ((char*)(key)+8), (void*)((char*)ks+DES_KS)); \ 135: des_key_sched ((void*) ((char*)(key)+16), (void*)((char*)ks+DES_KS*2)); \ 136: } \ 137: } 138: 139: 140: PCRYPTO_INFO crypto_open (void); 141: void crypto_loadkey (PKEY_INFO keyInfo, char *lpszUserKey, int nUserKeyLen); 142: void crypto_close (PCRYPTO_INFO cryptoInfo); 143: int get_block_size (int cipher); 144: int get_key_size (int cipher); 145: char * get_cipher_name (int cipher); 146: char * get_hash_name (int pkcs5);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.