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

1.1.1.9   root        1: /*
                      2:  Legal Notice: The source code contained in this file has been derived from
                      3:  the source code of Encryption for the Masses 2.02a, which is Copyright (c)
                      4:  Paul Le Roux and which is covered by the 'License Agreement for Encryption
                      5:  for the Masses'. Modifications and additions to that source code contained
                      6:  in this file are Copyright (c) TrueCrypt Foundation and are covered by the
1.1.1.10! root        7:  TrueCrypt License 2.3 the full text of which is contained in the file
1.1.1.9   root        8:  License.txt included in TrueCrypt binary and source code distribution
                      9:  packages. */
1.1       root       10: 
1.1.1.6   root       11: #include "Tcdefs.h"
1.1       root       12: 
                     13: #ifndef NT4_DRIVER
                     14: #pragma VxD_LOCKED_CODE_SEG
                     15: #pragma VxD_LOCKED_DATA_SEG
                     16: #endif
                     17: 
1.1.1.6   root       18: #include "Crypto.h"
                     19: #include "Fat.h"
                     20: #include "Volumes.h"
                     21: #include "Apidrvr.h"
                     22: #include "Common.h"
                     23: #include "Cache.h"
                     24: 
                     25: Password CachedPasswords[CACHE_SIZE];
1.1       root       26: int cacheEmpty = 1;
1.1.1.6   root       27: static int nPasswordIdx = 0;
1.1       root       28: 
                     29: int
1.1.1.6   root       30: VolumeReadHeaderCache (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.6   root       38:                nReturnCode = VolumeReadHeader (header, password, retInfo);
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.6   root       68:                                nReturnCode = VolumeReadHeader (header, &CachedPasswords[i], retInfo);
1.1       root       69: 
                     70:                                if (nReturnCode != ERR_PASSWORD_WRONG)
                     71:                                        break;
                     72:                        }
                     73:                }
                     74:        }
                     75: 
                     76:        return nReturnCode;
                     77: }
                     78: 
                     79: void
                     80: WipeCache ()
                     81: {
1.1.1.6   root       82:        burn (CachedPasswords, sizeof (CachedPasswords));
1.1       root       83:        nPasswordIdx = 0;
                     84:        cacheEmpty = 1;
                     85: }

unix.superglobalmegacorp.com

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