⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cache.c

📁 一个提供档案及Partition作加解密的程式支援以下的加密演算法AESBlowfishCAST5SerpentTriple DESTwofishAES-BlowfishAES-TwofishAES-
💻 C
字号:
/* The source code contained in this file has been derived from the source code
   of Encryption for the Masses 2.02a by Paul Le Roux. Modifications and
   additions to that source code contained in this file are Copyright (c) 2004-2005
   TrueCrypt Foundation and Copyright (c) 2004 TrueCrypt Team. Unmodified
   parts are Copyright (c) 1998-99 Paul Le Roux. This is a TrueCrypt Foundation
   release. Please see the file license.txt for full license details. */

#include "tcdefs.h"

#ifndef NT4_DRIVER
#pragma VxD_LOCKED_CODE_SEG
#pragma VxD_LOCKED_DATA_SEG
#endif

#include "crypto.h"
#include "fat.h"
#include "volumes.h"
#include "apidrvr.h"

#include "cache.h"

#define CACHE_SIZE 4

char szDriverPassword[CACHE_SIZE][MAX_PASSWORD + 1];
int nDriverPasswordLen[CACHE_SIZE];
int nPasswordIdx = 0;
int cacheEmpty = 1;

int
VolumeReadHeaderCache (BOOL bCache, char *header, char *headerHiddenVol, char *lpszPassword, int nPasswordLen,
		       PCRYPTO_INFO * retInfo)
{
	int nReturnCode = ERR_PASSWORD_WRONG;
	int i;

	/* Attempt to recognize volume using mount password */
	if (nPasswordLen > 0)
	{
		nReturnCode = VolumeReadHeader (header, headerHiddenVol, lpszPassword, retInfo);

		/* Save mount passwords back into cache if asked to do so */
		if (bCache == TRUE && nReturnCode == 0)
		{
			for (i = 0; i < CACHE_SIZE; i++)
			{
				if (nDriverPasswordLen[i] > 0 && nDriverPasswordLen[i] == nPasswordLen &&
					memcmp (szDriverPassword[i], lpszPassword, nPasswordLen) == 0)
					break;
			}

			if (i == CACHE_SIZE)
			{
				/* Store the password */
				memcpy (szDriverPassword[nPasswordIdx], lpszPassword, nPasswordLen);

				/* Add in the null as we made room for this */
				szDriverPassword[nPasswordIdx][nPasswordLen] = 0;

				/* Save the length for later */
				nDriverPasswordLen[nPasswordIdx] = nPasswordLen;

				/* Try another slot */
				nPasswordIdx = (nPasswordIdx + 1) % CACHE_SIZE;

				cacheEmpty = 0;
			}
		}
	}
	else if (!cacheEmpty)
	{
		/* Attempt to recognize volume using cached passwords */
		for (i = 0; i < CACHE_SIZE; i++)
		{
			if (nDriverPasswordLen[i] > 0)
			{
				nReturnCode = VolumeReadHeader (header, headerHiddenVol, szDriverPassword[i], retInfo);

				if (nReturnCode != ERR_PASSWORD_WRONG)
					break;
			}

		}
	}

	return nReturnCode;
}

void
WipeCache ()
{
	burn (szDriverPassword, sizeof (szDriverPassword));
	burn (nDriverPasswordLen, sizeof (nDriverPasswordLen));
	nPasswordIdx = 0;
	cacheEmpty = 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -