|
|
1.1 ! root 1: /* Copyright (C) 2004 TrueCrypt Team, truecrypt.org ! 2: This product uses components written by Paul Le Roux <[email protected]> */ ! 3: ! 4: #include "tcdefs.h" ! 5: ! 6: #ifndef NT4_DRIVER ! 7: #pragma VxD_LOCKED_CODE_SEG ! 8: #pragma VxD_LOCKED_DATA_SEG ! 9: #endif ! 10: ! 11: #include "crypto.h" ! 12: #include "fat.h" ! 13: #include "volumes.h" ! 14: #include "apidrvr.h" ! 15: ! 16: #include "cache.h" ! 17: ! 18: #define CACHE_SIZE 4 ! 19: ! 20: char szDriverPassword[CACHE_SIZE][MAX_PASSWORD + 1]; ! 21: int nDriverPasswordLen[CACHE_SIZE]; ! 22: int nPasswordIdx = 0; ! 23: int cacheEmpty = 1; ! 24: ! 25: int ! 26: VolumeReadHeaderCache (BOOL bCache, char *dev, char *lpszPassword, int nPasswordLen, ! 27: PCRYPTO_INFO * retInfo) ! 28: { ! 29: int nReturnCode = ERR_PASSWORD_WRONG; ! 30: int i; ! 31: ! 32: /* Attempt to recognize volume using mount password */ ! 33: if (nPasswordLen > 0) ! 34: { ! 35: nReturnCode = VolumeReadHeader (dev, lpszPassword, retInfo); ! 36: ! 37: /* Save mount passwords back into cache if asked to do so */ ! 38: if (bCache == TRUE && nReturnCode == 0) ! 39: { ! 40: for (i = 0; i < CACHE_SIZE; i++) ! 41: { ! 42: if (nDriverPasswordLen[i] > 0 && nDriverPasswordLen[i] == nPasswordLen && ! 43: memcmp (szDriverPassword[i], lpszPassword, nPasswordLen) == 0) ! 44: break; ! 45: } ! 46: ! 47: if (i == CACHE_SIZE) ! 48: { ! 49: /* Store the password */ ! 50: memcpy (szDriverPassword[nPasswordIdx], lpszPassword, nPasswordLen); ! 51: ! 52: /* Add in the null as we made room for this */ ! 53: szDriverPassword[nPasswordIdx][nPasswordLen] = 0; ! 54: ! 55: /* Save the length for later */ ! 56: nDriverPasswordLen[nPasswordIdx] = nPasswordLen; ! 57: ! 58: /* Try another slot */ ! 59: nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE; ! 60: ! 61: cacheEmpty = 0; ! 62: } ! 63: } ! 64: } ! 65: else if (!cacheEmpty) ! 66: { ! 67: /* Attempt to recognize volume using cached passwords */ ! 68: for (i = 0; i < CACHE_SIZE; i++) ! 69: { ! 70: if (nDriverPasswordLen[i] > 0) ! 71: { ! 72: nReturnCode = VolumeReadHeader (dev, szDriverPassword[i], retInfo); ! 73: ! 74: if (nReturnCode != ERR_PASSWORD_WRONG) ! 75: break; ! 76: } ! 77: ! 78: } ! 79: } ! 80: ! 81: return nReturnCode; ! 82: } ! 83: ! 84: void ! 85: WipeCache () ! 86: { ! 87: burn (szDriverPassword, sizeof (szDriverPassword)); ! 88: burn (nDriverPasswordLen, sizeof (nDriverPasswordLen)); ! 89: nPasswordIdx = 0; ! 90: cacheEmpty = 1; ! 91: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.