|
|
1.1.1.6 ! 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.6 ! root 10: #include "Tcdefs.h" 1.1 root 11: 12: #ifndef NT4_DRIVER 13: #pragma VxD_LOCKED_CODE_SEG 14: #pragma VxD_LOCKED_DATA_SEG 15: #endif 16: 1.1.1.6 ! root 17: #include "Crypto.h" ! 18: #include "Fat.h" ! 19: #include "Volumes.h" ! 20: #include "Apidrvr.h" ! 21: #include "Common.h" ! 22: #include "Cache.h" ! 23: ! 24: Password CachedPasswords[CACHE_SIZE]; 1.1 root 25: int cacheEmpty = 1; 1.1.1.6 ! root 26: static int nPasswordIdx = 0; 1.1 root 27: 28: int 1.1.1.6 ! root 29: VolumeReadHeaderCache (BOOL bCache, char *header, Password *password, PCRYPTO_INFO *retInfo) 1.1 root 30: { 31: int nReturnCode = ERR_PASSWORD_WRONG; 32: int i; 33: 34: /* Attempt to recognize volume using mount password */ 1.1.1.6 ! root 35: if (password->Length > 0) 1.1 root 36: { 1.1.1.6 ! root 37: nReturnCode = VolumeReadHeader (header, password, retInfo); 1.1 root 38: 39: /* Save mount passwords back into cache if asked to do so */ 1.1.1.6 ! root 40: if (bCache && (nReturnCode == 0 || nReturnCode == ERR_CIPHER_INIT_WEAK_KEY)) 1.1 root 41: { 42: for (i = 0; i < CACHE_SIZE; i++) 43: { 1.1.1.6 ! root 44: if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0) 1.1 root 45: break; 46: } 47: 48: if (i == CACHE_SIZE) 49: { 50: /* Store the password */ 1.1.1.6 ! root 51: CachedPasswords[nPasswordIdx] = *password; 1.1 root 52: 53: /* Try another slot */ 54: nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE; 55: 56: cacheEmpty = 0; 57: } 58: } 59: } 60: else if (!cacheEmpty) 61: { 62: /* Attempt to recognize volume using cached passwords */ 63: for (i = 0; i < CACHE_SIZE; i++) 64: { 1.1.1.6 ! root 65: if (CachedPasswords[i].Length > 0) 1.1 root 66: { 1.1.1.6 ! root 67: nReturnCode = VolumeReadHeader (header, &CachedPasswords[i], retInfo); 1.1 root 68: 69: if (nReturnCode != ERR_PASSWORD_WRONG) 70: break; 71: } 72: } 73: } 74: 75: return nReturnCode; 76: } 77: 78: void 79: WipeCache () 80: { 1.1.1.6 ! root 81: burn (CachedPasswords, sizeof (CachedPasswords)); 1.1 root 82: nPasswordIdx = 0; 83: cacheEmpty = 1; 84: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.