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

📄 freeotfestats.c

📁 文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-1, SHA-224, SHA-256,
💻 C
📖 第 1 页 / 共 3 页
字号:
// Description: 
// By Sarah Dean
// Email: sdean12@sdean12.org
// WWW:   http://www.FreeOTFE.org/
//
// -----------------------------------------------------------------------------
//


#include <stdlib.h>

#include "SDUGeneral.h"

#include "DriverInterface.h"
#include "DriverInterfaceTwo.h"
#include "FreeOTFEDebug.h"
#include "FreeOTFEAPIConstsCommon.h"
#include "FreeOTFEPlatform.h"
#include "FreeOTFElib.h"
#include "FreeOTFE4PDAlib.h"
#include "DriverInterface.h"
#include "DriverInterfaceHash.h"
#include "DriverInterfaceCypher.h"
#include "DriverInterfaceCommon.h"
#include "FreeOTFEStats.h"
#include "FreeOTFEDriverConstsCommon.h"

#define STATS_CYPHER_CYCLES         1000
//#define STATS_CYPHER_CYCLES         1
// Data block size in bytes
#define STATS_CYPHER_DATABLOCKSIZE  ENCRYPTION_BLOCK_SIZE

#define STATS_HASH_CYCLES        1000
//#define STATS_HASH_CYCLES          0
// Hash input size in *bits*
#define STATS_HASH_INPUT_SIZE    256
// Max hash output buffer size in *bits*
#define STATS_HASH_OUTPUT_SIZE  1024

// =========================================================================
// Forward declarations...
BOOL _DriverStats_Cypher(FILE* ReportFile);
BOOL _DriverStats_Hash(FILE* ReportFile);
void _DriverStats_ReportTimeDiff(
    FILE* ReportFile, 
    DWORD timeStart, 
    DWORD timeEnd
);


// =========================================================================
BOOL GenerateDriverStatsReport(WCHAR* ReportFilename)
{
    BOOL allOK;
    FILE* ReportFile;
    DWORD timeReportStart;
    DWORD timeReportEnd;

    allOK = TRUE;

    ReportFile = _wfopen(ReportFilename, TEXT("w"));
    if (ReportFile == NULL)
        {
        allOK = FALSE;
        }
    else
        {
        fwprintf(ReportFile, TEXT("FreeOTFE Statistics Report\n"));
        fwprintf(ReportFile, TEXT("==========================\n"));
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("\n"));

        fwprintf(ReportFile, TEXT("!!!!!!!!!!!!!!!!!!!!!!!!!!\n"));
        fwprintf(ReportFile, TEXT("!!!  IMPORTANT NOTICE  !!!\n"));
        fwprintf(ReportFile, TEXT("!!!!!!!!!!!!!!!!!!!!!!!!!!\n"));
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("The statistics produced by this software are MEANINGLESS OUTSIDE FREEOTFE, and should NOT be used for comparison purposes with other software products.\n"));
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("The cypher/hash routines are called in a manner intended to generate comparative statistics that are only valid when compared BETWEEN FREEOTFE DRIVERS ONLY.\n"));
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("In short, don't use the information shown in this report for benchmarking anything other than FreeOTFE drivers against other *FreeOTFE* *drivers* - the figures generated have no value beyond this, and you'll only end up comparing apples with oranges!\n"));
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("\n"));

        timeReportStart = GetTickCount();
        _DriverStats_Cypher(ReportFile);
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("\n"));
        _DriverStats_Hash(ReportFile);
        timeReportEnd = GetTickCount();
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("Report Summary\n"));
        fwprintf(ReportFile, TEXT("--------------\n"));
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("Time to generate report: "));
        _DriverStats_ReportTimeDiff(
                                    ReportFile, 
                                    timeReportStart, 
                                    timeReportEnd
                                   );
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("\n"));

        fwprintf(ReportFile, TEXT("End of Report.\n"));
        fwprintf(ReportFile, TEXT("\n"));

        fclose(ReportFile);
        }

    return allOK;
}


// =========================================================================
void _DriverStats_ReportTimeDiff(
    FILE* ReportFile, 
    DWORD timeStart, 
    DWORD timeEnd
)
{
    DWORD timeDiff;
    DWORD timeDiffMins, timeDiffSecs, timeDiffMSecs;

    timeDiff = (timeEnd - timeStart);

    timeDiffSecs = (timeDiff / 1000);
    timeDiffMSecs = (timeDiff % 1000);
    timeDiffMins = (timeDiffSecs / 60);
    timeDiffSecs = (timeDiffSecs % 60);

    fwprintf(
             ReportFile,
             TEXT("%d:%02d.%03d"),
             timeDiffMins,
             timeDiffSecs,
             timeDiffMSecs
            );
}


// =========================================================================
void _ReportWarningBanner(FILE* ReportFile)
{
    fwprintf(ReportFile, TEXT("\n"));
    fwprintf(ReportFile, TEXT("+++++++++++++\n"));
    fwprintf(ReportFile, TEXT("++ WARNING ++\n"));
    fwprintf(ReportFile, TEXT("+++++++++++++\n"));
    fwprintf(ReportFile, TEXT("\n"));
}


// =========================================================================
void _ReportDriverImplFailures(
    FILE* ReportFile, 
    int failedDrivers, 
    int failedImpl
)
{
    if (failedDrivers > 0) 
        {
        _ReportWarningBanner(ReportFile);
        fwprintf(ReportFile, TEXT("%d of the drivers tested has one or more FAILURES.\n"), failedDrivers);
        fwprintf(ReportFile, TEXT("(Implementation failures for all drivers: %d)\n"), failedImpl);
        fwprintf(ReportFile, TEXT("\n"));
        }
}


// =========================================================================
void _ReportDriverCount(
    FILE* ReportFile, 
    WCHAR* driverTypeText,
    int driverCount 
)
{
    if (driverCount <= 0) 
        {
        _ReportWarningBanner(ReportFile);
        fwprintf(ReportFile, TEXT("No %s drivers could be found.\n"), driverTypeText);
        fwprintf(ReportFile, TEXT("\n"));
        }
    else
        {
        fwprintf(
                 ReportFile, 
                 TEXT("Total %s drivers processed: %d\n"), 
                 driverTypeText, 
                 driverCount
                );
        }
}


// =========================================================================
// Generate cypher stats
BOOL _DriverStats_Cypher(FILE* ReportFile)
{
    // Pointer to a list of strings (pointers to strings)
    WCHAR** driverFilenamesHash;
    WCHAR** driverFilenamesCypher;
    int countDriversHash;
    int countDriversCypher;
    int i;
    int cypherDriverIdx;
    unsigned int cypherImplIdx;
    WCHAR* currCypherDriverFilename;
    // Pointer to a list of algorithms the drivers support (pointers to structs)
    HASH_DRIVER_INFO** driverInfoHash;
    CYPHER_DRIVER_INFO** driverInfoCypher;
    CYPHER_DRIVER_INFO* currDriverInfoCypher;
    CYPHER* currCypherImpl;
    WCHAR* tmpGUIDStr;
    int maxCDKSize_bits;
    int maxIVSize_bits;
    int cdkSize_bits;
    unsigned int criticalDataKeySize;
    FREEOTFEBYTE* criticalDataKey;
    FREEOTFEBYTE* IV;
    BOOL allOK;
    int BlockSize;  // In bytes
    FREEOTFEBYTE* BlockIn;
    FREEOTFEBYTE* BlockOut;
    int Cycles;
    int currCycle;
    DWORD timeAllStart;
    DWORD timeAllEnd;
    DWORD timeDriverStart;
    DWORD timeDriverEnd;
    DWORD timeCurrStart;
    DWORD timeCurrEnd;
    WCHAR prettyTitle[MAX_PRETTYPRINTED_TITLE];
    BOOL failureFoundDriver;
    BOOL failureFoundImpl;
    int failedDrivers;
    int failedImpl;
    unsigned int IVSize;

    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("_DriverStats_Cypher\n")));
    
    // Stats for...
    BlockSize = STATS_CYPHER_DATABLOCKSIZE;
    Cycles = STATS_CYPHER_CYCLES;

    // Numbers...
    maxCDKSize_bits = 0;
    maxIVSize_bits = 0;
    countDriversCypher = 0;
    criticalDataKeySize = 0;
    cypherDriverIdx = 0;
    failedDrivers = 0;
    failedImpl = 0;
    timeAllStart = 0;
    timeAllEnd = 0;

    // Pointers...
    criticalDataKey = NULL;
    IV = NULL;
    driverInfoHash = NULL;
    driverInfoCypher = NULL;
    driverFilenamesHash = NULL;
    driverFilenamesCypher = NULL;
    BlockIn = NULL;
    BlockOut = NULL;
    

    /*
    Identify all cypher drivers
    Identify all cypher algorithms supported by each of the cypher drivers

    Loop through all cypher libs...
      Loop through all cyphers supported by current cypher lib...
    */

    allOK = TRUE;

    if (allOK)
        {
        allOK = driver_GetAllAlgorithmDriverDetails(
                                        &countDriversHash,
                                        &driverFilenamesHash,
                                        &driverInfoHash,

                                        &countDriversCypher,
                                        &driverFilenamesCypher,
                                        &driverInfoCypher
                                        );
        }

    // Setup the block to encrypt/decrypt
    if (allOK)
        {
        BlockIn = malloc(BlockSize);
        BlockOut = malloc(BlockSize);
        if (
            (BlockIn == NULL) ||

⌨️ 快捷键说明

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