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