📄 freeotfestats.c
字号:
(BlockOut == NULL)
)
{
allOK = FALSE;
}
}
if (allOK)
{
fwprintf(ReportFile, TEXT("FreeOTFE Cyphers\n"));
fwprintf(ReportFile, TEXT("----------------\n"));
fwprintf(ReportFile, TEXT("\n"));
fwprintf(ReportFile, TEXT("Data block size: %d bytes\n"), BlockSize);
fwprintf(ReportFile, TEXT("Cycles : %d\n"), Cycles);
fwprintf(ReportFile, TEXT("\n"));
}
if (allOK)
{
// !!! OPTIMISATION !!!
// Determine the longest cypher key and IV size
maxIVSize_bits = 0;
maxCDKSize_bits = 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]);
// Determine size of "critical data key"...
cdkSize_bits = currCypherImpl->KeySize; // In *bits*
if (cdkSize_bits < 0)
{
cdkSize_bits = 512;
}
maxIVSize_bits = max(maxIVSize_bits, currCypherImpl->BlockSize);
maxCDKSize_bits = max(maxCDKSize_bits, cdkSize_bits);
}
cypherDriverIdx++;
}
IV = NULL;
criticalDataKeySize = (maxCDKSize_bits / 8);
criticalDataKey = malloc(criticalDataKeySize);
if (criticalDataKey == NULL)
{
DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to malloc storage for criticalDataKey\n")));
allOK = FALSE;
}
else
{
IV = malloc((maxIVSize_bits / 8));
if (IV == NULL)
{
DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to malloc storage for IV\n")));
allOK = FALSE;
}
}
if (allOK)
{
failedImpl = 0;
timeAllStart = GetTickCount();
// Loop through all cypher libs...
while (driverFilenamesCypher[cypherDriverIdx] != NULL)
{
currCypherDriverFilename = driverFilenamesCypher[cypherDriverIdx];
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Testing cypher driver (%d): %ls\n"), (cypherDriverIdx+1), currCypherDriverFilename));
fwprintf(ReportFile, TEXT("------------------------\n"));
fwprintf(ReportFile, TEXT("Driver : %s\n"), currCypherDriverFilename);
fwprintf(ReportFile, TEXT("\n"));
timeDriverStart = GetTickCount();
currDriverInfoCypher = driverInfoCypher[cypherDriverIdx];
if (currDriverInfoCypher == NULL)
{
// Skip out...
DEBUGOUTGUI(DEBUGLEV_WARN, (TEXT("Skipping; no supported algorithm details obtained.\n")));
fwprintf(ReportFile, (TEXT("+++ FAILURE: Skipping driver; no supported algorithm details obtained.\n")));
fwprintf(ReportFile, TEXT("\n"));
failedDrivers++;
cypherDriverIdx++;
continue;
}
// Loop through all cyphers supported by current cypher lib...
failureFoundDriver = FALSE;
for (cypherImplIdx = 0; cypherImplIdx < currDriverInfoCypher->CypherCount; cypherImplIdx++)
{
failureFoundImpl = FALSE;
currCypherImpl = &(currDriverInfoCypher->CypherDetails[cypherImplIdx]);
GUIDToWCHAR(&(currCypherImpl->CypherGUID), &tmpGUIDStr);
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Cypher implementation: %ls\n"), tmpGUIDStr));
fwprintf(ReportFile, TEXT("Implementation : %s\n"), tmpGUIDStr);
driver_CypherPrettyprintAlgTitle(currCypherImpl, prettyTitle, sizeof(prettyTitle));
fwprintf(ReportFile, TEXT("Pretty title : %s\n"), prettyTitle);
SecZeroAndFreeWCHARMemory(tmpGUIDStr);
// Determine size of "critical data key"...
cdkSize_bits = currCypherImpl->KeySize; // In *bits*
if (cdkSize_bits < 0)
{
cdkSize_bits = 512;
}
// Zero the key for decryption, in case previous was "dirty"
if (currCypherImpl->BlockSize > 0)
{
memset(criticalDataKey, 0, (cdkSize_bits / 8));
}
// Zero the IV for decryption, in case previous was "dirty"
IVSize = 0;
if (currCypherImpl->BlockSize > 0)
{
IVSize = currCypherImpl->BlockSize;
memset(IV, 0, (IVSize / 8));
}
// Encryption...
memset(BlockIn, 0, BlockSize);
memset(BlockOut, 0, BlockSize);
timeCurrStart = GetTickCount();
for (currCycle = 1; currCycle <= Cycles; currCycle++)
{
if (!(driver_CypherEncryptData(
currCypherDriverFilename,
currCypherImpl->CypherGUID,
cdkSize_bits,
criticalDataKey,
IVSize,
IV,
BlockSize,
BlockIn,
BlockOut
)))
{
DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to encrypt.\n")));
fwprintf(ReportFile, TEXT("+++ FAILURE in encrypting data block: %d\n"), currCycle);
failureFoundImpl = TRUE;
break;
}
}
timeCurrEnd = GetTickCount();
fwprintf(ReportFile, TEXT("Encryption time: "));
_DriverStats_ReportTimeDiff(
ReportFile,
timeCurrStart,
timeCurrEnd
);
fwprintf(ReportFile, TEXT("\n"));
// Decryption...
memset(BlockIn, 0, BlockSize);
memset(BlockOut, 0, BlockSize);
timeCurrStart = GetTickCount();
for (currCycle = 1; currCycle <= Cycles; currCycle++)
{
if (!(driver_CypherDecryptData(
currCypherDriverFilename,
currCypherImpl->CypherGUID,
cdkSize_bits,
criticalDataKey,
IVSize,
IV,
BlockSize,
BlockIn,
BlockOut
)))
{
DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to decrypt.\n")));
fwprintf(ReportFile, TEXT("+++ FAILURE in decrypting data block: %d\n"), currCycle);
failureFoundImpl = TRUE;
break;
}
}
timeCurrEnd = GetTickCount();
fwprintf(ReportFile, TEXT("Decryption time: "));
_DriverStats_ReportTimeDiff(
ReportFile,
timeCurrStart,
timeCurrEnd
);
fwprintf(ReportFile, TEXT("\n"));
fwprintf(ReportFile, TEXT("\n"));
if (failureFoundImpl)
{
failureFoundDriver = TRUE;
failedImpl++;
failureFoundImpl = FALSE;
}
} // for (cypherImplIdx = 0; cypherImplIdx < currDriverInfoCypher->CypherCount; cypherImplIdx++)
timeDriverEnd = GetTickCount();
fwprintf(ReportFile, TEXT("Driver time : "));
_DriverStats_ReportTimeDiff(
ReportFile,
timeDriverStart,
timeDriverEnd
);
fwprintf(ReportFile, TEXT("\n"));
fwprintf(ReportFile, TEXT("\n"));
if (failureFoundDriver)
{
failedDrivers++;
failureFoundDriver = FALSE;
}
cypherDriverIdx++;
} // while (driverFilenamesCypher[cypherDriverIdx] != NULL)
}
timeAllEnd = GetTickCount();
}
// Finish report and close report file...
if (ReportFile != NULL)
{
fwprintf(ReportFile, TEXT("\n"));
fwprintf(ReportFile, TEXT("\n"));
_ReportDriverCount(ReportFile, TEXT("cypher"), cypherDriverIdx);
fwprintf(ReportFile, TEXT("Time to process : "));
_DriverStats_ReportTimeDiff(ReportFile, timeAllStart, timeAllEnd);
fwprintf(ReportFile, TEXT("\n"));
_ReportDriverImplFailures(ReportFile, failedDrivers, failedImpl);
}
// Cleanup...
SecZeroAndFreeMemory(BlockIn, BlockSize);
SecZeroAndFreeMemory(BlockOut, BlockSize);
SecZeroAndFreeMemory(criticalDataKey, criticalDataKeySize);
SecZeroAndFreeMemory(IV, (maxIVSize_bits / 8));
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)
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Operation completed OK\n")));
}
else
{
DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Operation FAILED.\n")));
}
DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("_DriverStats_Cypher\n")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -