📄 driverinterfacetwo.c
字号:
int* CountImplHash,
int* CountImplCypher
)
{
int hashDriverIdx;
int cypherDriverIdx;
HASH_DRIVER_INFO* currDriverInfoHash;
CYPHER_DRIVER_INFO* currDriverInfoCypher;
*CountImplHash = 0;
hashDriverIdx = 0;
while (driverFilenamesHash[hashDriverIdx] != NULL)
{
currDriverInfoHash = driverInfoHash[hashDriverIdx];
// If we got the DLL filename, but no hash details, skip this DLL file
if (currDriverInfoHash != NULL)
{
*CountImplHash += currDriverInfoHash->HashCount;
}
hashDriverIdx++;
}
*CountImplCypher = 0;
cypherDriverIdx = 0;
while (driverFilenamesCypher[cypherDriverIdx] != NULL)
{
currDriverInfoCypher = driverInfoCypher[cypherDriverIdx];
// If we got the DLL filename, but no cypher details, skip this DLL file
if (currDriverInfoCypher != NULL)
{
*CountImplCypher += currDriverInfoCypher->CypherCount;
}
cypherDriverIdx++;
}
}
// =========================================================================
// Note: It is up the *caller* to free off the returned values
// e.g. By driver_FreeAllAlgorithmDriverOptions(...)
BOOL driver_GetAllAlgorithmDriverOptions(
int* CountImplHash,
DRIVER_AND_ALG** HashImpl,
int* CountImplCypher,
DRIVER_AND_ALG** CypherImpl
)
{
BOOL allOK = FALSE;
int countDriversHash;
int countDriversCypher;
WCHAR** driverFilenamesHash;
WCHAR** driverFilenamesCypher;
HASH_DRIVER_INFO** driverInfoHash;
CYPHER_DRIVER_INFO** driverInfoCypher;
int hashDriverIdx;
int cypherDriverIdx;
unsigned int hashImplIdx;
unsigned int cypherImplIdx;
WCHAR* currHashDriverFilename;
WCHAR* currCypherDriverFilename;
HASH_DRIVER_INFO* currDriverInfoHash;
CYPHER_DRIVER_INFO* currDriverInfoCypher;
HASH* currHashImpl;
CYPHER* currCypherImpl;
int implIdx;
int i;
if (driver_GetAllAlgorithmDriverDetails(
&countDriversHash,
&driverFilenamesHash,
&driverInfoHash,
&countDriversCypher,
&driverFilenamesCypher,
&driverInfoCypher
))
{
_driver_GetAllAlgorithmDriverOptions_Count(
driverFilenamesHash,
driverInfoHash,
driverFilenamesCypher,
driverInfoCypher,
CountImplHash,
CountImplCypher
);
// At this point, we know exactly how many cypher/hash algorithms
// there are.
// Malloc storage to hold their details, and populate.
*HashImpl = calloc(*CountImplHash, sizeof(DRIVER_AND_ALG));
*CypherImpl = calloc(*CountImplCypher, sizeof(DRIVER_AND_ALG));
if (
(*HashImpl == NULL) ||
(*CypherImpl == NULL)
)
{
DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to malloc memory for implementation summary\n")));
}
else
{
implIdx = 0;
cypherDriverIdx = 0;
while (driverFilenamesCypher[cypherDriverIdx] != NULL)
{
currCypherDriverFilename = driverFilenamesCypher[cypherDriverIdx];
currDriverInfoCypher = driverInfoCypher[cypherDriverIdx];
// If we got the DLL filename, but no cypher details, skip this DLL file
if (currDriverInfoCypher == NULL)
{
DEBUGOUTGUI(DEBUGLEV_WARN, (TEXT("Optimisation skipping cypher DLL filename due to lack of driver details\n")));
cypherDriverIdx++;
continue;
}
for (cypherImplIdx = 0; cypherImplIdx < currDriverInfoCypher->CypherCount; cypherImplIdx++)
{
currCypherImpl = &(currDriverInfoCypher->CypherDetails[cypherImplIdx]);
driver_CypherPrettyprintAlgTitle(
currCypherImpl,
(*CypherImpl)[implIdx].PrettyName,
sizeof((*CypherImpl)[implIdx].PrettyName)
);
wcscpy(
(*CypherImpl)[implIdx].DriverFilename,
currCypherDriverFilename
);
(*CypherImpl)[implIdx].DriverImplAlgGUID = currCypherImpl->CypherGUID;
(*CypherImpl)[implIdx].CypherKeySize = currCypherImpl->KeySize;
(*CypherImpl)[implIdx].CypherBlockSize = currCypherImpl->BlockSize;
implIdx++;
}
cypherDriverIdx++;
}
implIdx = 0;
hashDriverIdx = 0;
while (driverFilenamesHash[hashDriverIdx] != NULL)
{
currHashDriverFilename = driverFilenamesHash[hashDriverIdx];
currDriverInfoHash = driverInfoHash[hashDriverIdx];
// If we got the DLL filename, but no hash details, skip this DLL file
if (currDriverInfoHash == NULL)
{
DEBUGOUTGUI(DEBUGLEV_WARN, (TEXT("Optimisation skipping hash DLL filename due to lack of driver details\n")));
hashDriverIdx++;
continue;
}
for (hashImplIdx = 0; hashImplIdx < currDriverInfoHash->HashCount; hashImplIdx++)
{
currHashImpl = &(currDriverInfoHash->HashDetails[hashImplIdx]);
driver_HashPrettyprintAlgTitle(
currHashImpl,
(*HashImpl)[implIdx].PrettyName,
sizeof((*HashImpl)[implIdx].PrettyName)
);
wcscpy(
(*HashImpl)[implIdx].DriverFilename,
currHashDriverFilename
);
(*HashImpl)[implIdx].DriverImplAlgGUID = currHashImpl->HashGUID;
(*HashImpl)[implIdx].HashLength = currHashImpl->Length;
(*HashImpl)[implIdx].HashBlockSize = currHashImpl->BlockSize;
implIdx++;
}
hashDriverIdx++;
}
allOK = TRUE;
}
}
// Cleanup...
for(i = 0; i < countDriversHash; i++)
{
driver_HashFreeDriverDetails(driverInfoHash[i]);
SecZeroAndFreeMemory(
driverInfoHash[i],
sizeof(*(driverInfoHash[0]))
);
}
SecZeroAndFreeMemory(
driverInfoHash,
(countDriversHash * sizeof(*driverInfoHash))
);
for(i = 0; i < countDriversCypher; i++)
{
driver_CypherFreeDriverDetails(driverInfoCypher[i]);
SecZeroAndFreeMemory(
driverInfoCypher[i],
sizeof(*(driverInfoCypher[0]))
);
}
SecZeroAndFreeMemory(
driverInfoCypher,
(countDriversCypher * sizeof(*driverInfoCypher))
);
driver_FreeDriverFilenames(&driverFilenamesHash);
driver_FreeDriverFilenames(&driverFilenamesCypher);
if (!(allOK))
{
driver_FreeAllAlgorithmDriverOptions(
CountImplHash,
HashImpl,
CountImplCypher,
CypherImpl
);
}
return allOK;
}
// =========================================================================
void driver_FreeAllAlgorithmDriverOptions(
int* CountImplHash,
DRIVER_AND_ALG** HashImpl,
int* CountImplCypher,
DRIVER_AND_ALG** CypherImpl
)
{
SecZeroAndFreeMemory(
*HashImpl,
((*CountImplHash) * sizeof(DRIVER_AND_ALG))
);
SecZeroAndFreeMemory(
*CypherImpl,
((*CountImplCypher) * sizeof(DRIVER_AND_ALG))
);
*HashImpl = NULL;
*CypherImpl = NULL;
*CountImplHash = 0;
*CountImplCypher = 0;
}
// =========================================================================
// Cleardown any dump data
void driver_FreeCriticalDump()
{
SecZeroAndFreeMemory(
_driver_DumpCriticalDataKey,
(_driver_DumpCriticalDataKeyBits / 8)
);
SecZeroAndFreeMemory(
_driver_DumpCheckMAC,
(_driver_DumpCheckMACBits / 8)
);
SecZeroAndFreeMemory(
_driver_DumpPlaintextEncryptedBlock,
(_driver_DumpPlaintextEncryptedBlockBits / 8)
);
SecZeroAndFreeMemory(
_driver_DumpVolumeDetailsBlock,
(_driver_DumpVolumeDetailsBlockBits / 8)
);
_driver_DumpCriticalDataKeyBits = 0;
_driver_DumpCriticalDataKey = NULL;
_driver_DumpCheckMACBits = 0;
_driver_DumpCheckMAC = NULL;
_driver_DumpPlaintextEncryptedBlockBits = 0;
_driver_DumpPlaintextEncryptedBlock = NULL;
_driver_DumpVolumeDetailsBlockBits = 0;
_driver_DumpVolumeDetailsBlock = NULL;
_driver_DumpFlag = FALSE;
}
// =========================================================================
// Store any dump data
_driver_StoreCriticalDump(
int CriticalDataKeyBits,
FREEOTFEBYTE* CriticalDataKey,
int CheckMACBits,
FREEOTFEBYTE* CheckMAC,
int PlaintextEncryptedBlockBits,
FREEOTFEBYTE* PlaintextEncryptedBlock,
int VolumeDetailsBlockBits,
FREEOTFEBYTE* VolumeDetailsBlock
)
{
// Additional: Store internal information, if dumping
if (_driver_DumpFlag)
{
// Store sizes and allocate storage...
// Critical data key...
_driver_DumpCriticalDataKeyBits = CriticalDataKeyBits;
_driver_DumpCriticalDataKey = malloc(_driver_DumpCriticalDataKeyBits / 8);
// Check MAC...
_driver_DumpCheckMACBits = CheckMACBits;
_driver_DumpCheckMAC = malloc(_driver_DumpCheckMACBits / 8);
// Encrypted block...
_driver_DumpPlaintextEncryptedBlockBits = PlaintextEncryptedBlockBits;
_driver_DumpPlaintextEncryptedBlock = malloc(_driver_DumpPlaintextEncryptedBlockBits / 8);
// Volume details block...
_driver_DumpVolumeDetailsBlockBits = VolumeDetailsBlockBits;
_driver_DumpVolumeDetailsBlock = malloc(_driver_DumpVolumeDetailsBlockBits / 8);
// Check OK
if (
(_driver_DumpCriticalDataKey == NULL) ||
(_driver_DumpCheckMAC == NULL) ||
(_driver_DumpPlaintextEncryptedBlock == NULL) ||
(_driver_DumpVolumeDetailsBlock == NULL)
)
{
driver_FreeCriticalDump();
}
else
{
// Store dump...
// Critical data key...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -