Annotation of truecrypt/common/cache.c, revision 1.1.1.4

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
1.1.1.4 ! root        4:    TrueCrypt Foundation and Copyright (c) 2004 TrueCrypt Team. Unmodified
1.1.1.3   root        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: #include "tcdefs.h"
                      9: 
                     10: #ifndef NT4_DRIVER
                     11: #pragma VxD_LOCKED_CODE_SEG
                     12: #pragma VxD_LOCKED_DATA_SEG
                     13: #endif
                     14: 
                     15: #include "crypto.h"
                     16: #include "fat.h"
                     17: #include "volumes.h"
                     18: #include "apidrvr.h"
                     19: 
                     20: #include "cache.h"
                     21: 
                     22: #define CACHE_SIZE 4
                     23: 
                     24: char szDriverPassword[CACHE_SIZE][MAX_PASSWORD + 1];
                     25: int nDriverPasswordLen[CACHE_SIZE];
                     26: int nPasswordIdx = 0;
                     27: int cacheEmpty = 1;
                     28: 
                     29: int
1.1.1.4 ! root       30: VolumeReadHeaderCache (BOOL bCache, char *header, char *headerHiddenVol, char *lpszPassword, int nPasswordLen,
1.1       root       31:                       PCRYPTO_INFO * retInfo)
                     32: {
                     33:        int nReturnCode = ERR_PASSWORD_WRONG;
                     34:        int i;
                     35: 
                     36:        /* Attempt to recognize volume using mount password */
                     37:        if (nPasswordLen > 0)
                     38:        {
1.1.1.4 ! root       39:                nReturnCode = VolumeReadHeader (header, headerHiddenVol, lpszPassword, retInfo);
1.1       root       40: 
                     41:                /* Save mount passwords back into cache if asked to do so */
                     42:                if (bCache == TRUE && nReturnCode == 0)
                     43:                {
                     44:                        for (i = 0; i < CACHE_SIZE; i++)
                     45:                        {
                     46:                                if (nDriverPasswordLen[i] > 0 && nDriverPasswordLen[i] == nPasswordLen &&
                     47:                                        memcmp (szDriverPassword[i], lpszPassword, nPasswordLen) == 0)
                     48:                                        break;
                     49:                        }
                     50: 
                     51:                        if (i == CACHE_SIZE)
                     52:                        {
                     53:                                /* Store the password */
                     54:                                memcpy (szDriverPassword[nPasswordIdx], lpszPassword, nPasswordLen);
                     55: 
                     56:                                /* Add in the null as we made room for this */
                     57:                                szDriverPassword[nPasswordIdx][nPasswordLen] = 0;
                     58: 
                     59:                                /* Save the length for later */
                     60:                                nDriverPasswordLen[nPasswordIdx] = nPasswordLen;
                     61: 
                     62:                                /* Try another slot */
                     63:                                nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;
                     64: 
                     65:                                cacheEmpty = 0;
                     66:                        }
                     67:                }
                     68:        }
                     69:        else if (!cacheEmpty)
                     70:        {
                     71:                /* Attempt to recognize volume using cached passwords */
                     72:                for (i = 0; i < CACHE_SIZE; i++)
                     73:                {
                     74:                        if (nDriverPasswordLen[i] > 0)
                     75:                        {
1.1.1.4 ! root       76:                                nReturnCode = VolumeReadHeader (header, headerHiddenVol, szDriverPassword[i], retInfo);
1.1       root       77: 
                     78:                                if (nReturnCode != ERR_PASSWORD_WRONG)
                     79:                                        break;
                     80:                        }
                     81: 
                     82:                }
                     83:        }
                     84: 
                     85:        return nReturnCode;
                     86: }
                     87: 
                     88: void
                     89: WipeCache ()
                     90: {
                     91:        burn (szDriverPassword, sizeof (szDriverPassword));
                     92:        burn (nDriverPasswordLen, sizeof (nDriverPasswordLen));
                     93:        nPasswordIdx = 0;
                     94:        cacheEmpty = 1;
                     95: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.