|
|
1.1.1.9 root 1: /*
1.1.1.11 root 2: Legal Notice: Some portions of the source code contained in this file were
3: derived from the source code of Encryption for the Masses 2.02a, which is
4: Copyright (c) 1998-2000 Paul Le Roux and which is governed by the 'License
5: Agreement for Encryption for the Masses'. Modifications and additions to
1.1.1.17! root 6: the original source code (contained in this file) and all other portions
! 7: of this file are Copyright (c) 2003-2008 TrueCrypt Developers Association
! 8: and are governed by the TrueCrypt License 2.8 the full text of which is
! 9: contained in the file License.txt included in TrueCrypt binary and source
! 10: code distribution packages. */
1.1 root 11:
1.1.1.6 root 12: #include "Tcdefs.h"
1.1 root 13:
14: #ifndef NT4_DRIVER
15: #pragma VxD_LOCKED_CODE_SEG
16: #pragma VxD_LOCKED_DATA_SEG
17: #endif
18:
1.1.1.6 root 19: #include "Crypto.h"
20: #include "Fat.h"
21: #include "Volumes.h"
22: #include "Apidrvr.h"
23: #include "Common.h"
24: #include "Cache.h"
25:
26: Password CachedPasswords[CACHE_SIZE];
1.1 root 27: int cacheEmpty = 1;
1.1.1.6 root 28: static int nPasswordIdx = 0;
1.1 root 29:
1.1.1.14 root 30: int ReadVolumeHeaderWCache (BOOL bBoot, BOOL bCache, char *header, Password *password, PCRYPTO_INFO *retInfo)
1.1 root 31: {
32: int nReturnCode = ERR_PASSWORD_WRONG;
33: int i;
34:
35: /* Attempt to recognize volume using mount password */
1.1.1.6 root 36: if (password->Length > 0)
1.1 root 37: {
1.1.1.14 root 38: nReturnCode = ReadVolumeHeader (bBoot, header, password, retInfo, NULL);
1.1 root 39:
40: /* Save mount passwords back into cache if asked to do so */
1.1.1.6 root 41: if (bCache && (nReturnCode == 0 || nReturnCode == ERR_CIPHER_INIT_WEAK_KEY))
1.1 root 42: {
43: for (i = 0; i < CACHE_SIZE; i++)
44: {
1.1.1.6 root 45: if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
1.1 root 46: break;
47: }
48:
49: if (i == CACHE_SIZE)
50: {
51: /* Store the password */
1.1.1.6 root 52: CachedPasswords[nPasswordIdx] = *password;
1.1 root 53:
54: /* Try another slot */
55: nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
56:
57: cacheEmpty = 0;
58: }
59: }
60: }
61: else if (!cacheEmpty)
62: {
63: /* Attempt to recognize volume using cached passwords */
64: for (i = 0; i < CACHE_SIZE; i++)
65: {
1.1.1.6 root 66: if (CachedPasswords[i].Length > 0)
1.1 root 67: {
1.1.1.14 root 68: nReturnCode = ReadVolumeHeader (bBoot, header, &CachedPasswords[i], retInfo, NULL);
1.1 root 69:
70: if (nReturnCode != ERR_PASSWORD_WRONG)
71: break;
72: }
73: }
74: }
75:
76: return nReturnCode;
77: }
78:
1.1.1.14 root 79:
80: void AddPasswordToCache (Password *password)
81: {
82: int i;
83: for (i = 0; i < CACHE_SIZE; i++)
84: {
85: if (memcmp (&CachedPasswords[i], password, sizeof (Password)) == 0)
86: return;
87: }
88:
89: CachedPasswords[nPasswordIdx] = *password;
90: nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
91: cacheEmpty = 0;
92: }
93:
94:
95: void WipeCache ()
1.1 root 96: {
1.1.1.6 root 97: burn (CachedPasswords, sizeof (CachedPasswords));
1.1 root 98: nPasswordIdx = 0;
99: cacheEmpty = 1;
100: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.