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

📄 freeotfestats.c

📁 文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2, MD4, MD5, RIPEMD-128, RIPEMD-160, SHA-1, SHA-224, SHA-256,
💻 C
📖 第 1 页 / 共 3 页
字号:
    return allOK;
}

// =========================================================================
// Generate cypher stats
BOOL _DriverStats_Hash(FILE* ReportFile)
{
    // Pointer to a list of strings (pointers to strings)
    WCHAR** driverFilenamesHash;
    WCHAR** driverFilenamesCypher;
    int countDriversHash;
    int countDriversCypher;
    int i;
    int hashDriverIdx;
    unsigned int hashImplIdx;
    WCHAR* currHashDriverFilename;
    // Pointer to a list of algorithms the drivers support (pointers to structs)
    HASH_DRIVER_INFO** driverInfoHash;
    CYPHER_DRIVER_INFO** driverInfoCypher;
    HASH_DRIVER_INFO* currDriverInfoHash;
    HASH* currHashImpl;
    WCHAR* tmpGUIDStr;
    unsigned int criticalDataKeySize;
    BOOL allOK;
    FREEOTFEBYTE* BlockIn;
    FREEOTFEBYTE* BlockOut;
    unsigned int BlockSizeIn;
    unsigned int BlockSizeOut;
    unsigned int tmpBlockSize;
    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;
    
    DEBUGOUTGUI(DEBUGLEV_ENTER, (TEXT("_DriverStats_Hash\n")));
    
    // Stats for...
    BlockSizeIn = STATS_HASH_INPUT_SIZE;
    BlockSizeOut = STATS_HASH_OUTPUT_SIZE;
    Cycles = STATS_HASH_CYCLES;

    // Numbers...
    countDriversCypher = 0;
    criticalDataKeySize = 0;
    hashDriverIdx = 0;
    timeAllStart = 0;
    timeAllEnd = 0;
    failedDrivers = 0;
    failedImpl = 0;

    // Pointers...
    driverInfoHash = NULL;
    driverInfoCypher = NULL;
    driverFilenamesHash = NULL;
    driverFilenamesCypher = NULL;
    

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

    Loop through all hash libs...
      Loop through all hashes supported by current hash lib...
    */

    allOK = TRUE;


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

                                        &countDriversCypher,
                                        &driverFilenamesCypher,
                                        &driverInfoCypher
                                        );
        }

    // Setup the block to hash
    if (allOK)
        {
        BlockIn = malloc((BlockSizeIn / 8));
        BlockOut = malloc((BlockSizeOut / 8));
        if (
            (BlockIn == NULL) ||
            (BlockOut == NULL)
           )
            {
            allOK = FALSE;
            }
        }

    if (allOK)
        {
        fwprintf(ReportFile, TEXT("FreeOTFE Hashes\n"));
        fwprintf(ReportFile, TEXT("---------------\n"));
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("Input block size : %d bits\n"), BlockSizeIn);
        fwprintf(ReportFile, TEXT("Output block size: %d bits\n"), BlockSizeOut);
        fwprintf(ReportFile, TEXT("Cycles           : %d\n"), Cycles);
        fwprintf(ReportFile, TEXT("\n"));
        }

    if (allOK)
        {
        timeAllStart = GetTickCount();

        // Loop through all hash libs...
        while (driverFilenamesHash[hashDriverIdx] != NULL)
            {
            currHashDriverFilename = driverFilenamesHash[hashDriverIdx];
            DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Testing hash driver (%d): %ls\n"), (hashDriverIdx+1), currHashDriverFilename));
            fwprintf(ReportFile, TEXT("------------------------\n"));
            fwprintf(ReportFile, TEXT("Driver         : %s\n"), currHashDriverFilename);
            fwprintf(ReportFile, TEXT("\n"));
            timeDriverStart = GetTickCount();
            currDriverInfoHash = driverInfoHash[hashDriverIdx];
            if (currDriverInfoHash == 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"));
                hashDriverIdx++;
                continue;
                }

            // Loop through all hashes supported by current hash lib...
            failureFoundDriver = FALSE;
            for (hashImplIdx = 0; hashImplIdx < currDriverInfoHash->HashCount; hashImplIdx++)
                {
                failureFoundImpl = FALSE;

                currHashImpl = &(currDriverInfoHash->HashDetails[hashImplIdx]);
                GUIDToWCHAR(&(currHashImpl->HashGUID), &tmpGUIDStr);
                DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Hash implementation: %ls\n"), tmpGUIDStr));
                fwprintf(ReportFile, TEXT("Implementation : %s\n"), tmpGUIDStr);
                driver_HashPrettyprintAlgTitle(currHashImpl, prettyTitle, sizeof(prettyTitle));
                fwprintf(ReportFile, TEXT("Pretty title   : %s\n"), prettyTitle);
                SecZeroAndFreeWCHARMemory(tmpGUIDStr);

                // v2 and later volumes won't work with hash algorithms with <= 0 length, or
                // blocksize, as HMAC/PBKDF2 require these to be fixed
                //  - skip these, and move onto the next hash algorithm (if any)
                if (
                    (currHashImpl->Length <= 0) ||
                    (currHashImpl->BlockSize <= 0)
                   ) 
                    {
                    // Skip - can't use
                    DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Skipping hash; either length or blocksize <= 0.\n")));
                    fwprintf(ReportFile, TEXT("Skipping hash; either length or blocksize <= 0.\n"));
                    fwprintf(ReportFile, TEXT("\n"));
                    failureFoundDriver++;
                    continue;
                    }

                memset(BlockIn, 0, BlockSizeIn);
                memset(BlockOut, 0, BlockSizeOut);                        
                timeCurrStart = GetTickCount();
                for (currCycle = 1; currCycle <= Cycles; currCycle++)
                    {
                    tmpBlockSize = BlockSizeOut;
                    if (!(driver_HashData(
                                 currHashDriverFilename,
                                 currHashImpl->HashGUID,
                                 BlockSizeIn,
                                 BlockIn,
                                 &tmpBlockSize,
                                 BlockOut
                                )))
                        {
                        DEBUGOUTGUI(DEBUGLEV_ERROR, (TEXT("Unable to hash.\n")));
                        fwprintf(ReportFile, TEXT("+++ FAILURE in hashing data block: %d\n"), currCycle);
                        failureFoundImpl = TRUE;
                        break;
                        }
                    }
                timeCurrEnd = GetTickCount();

                fwprintf(ReportFile, TEXT("Hash time      : "));
                _DriverStats_ReportTimeDiff(
                                            ReportFile, 
                                            timeCurrStart, 
                                            timeCurrEnd
                                           );
                fwprintf(ReportFile, TEXT("\n"));
                fwprintf(ReportFile, TEXT("\n"));

                if (failureFoundImpl)
                    {
                    failureFoundDriver = TRUE;
                    failedImpl++;
                    failureFoundImpl = FALSE;
                    }
                }  // for (hashImplIdx = 0; hashImplIdx < currDriverInfoHash->HashCount; hashImplIdx++)

            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;
                }

            hashDriverIdx++;
            }  // while (driverFilenamesHash[hashDriverIdx] != NULL)

        timeAllEnd = GetTickCount();
        }

    // Finish report and close report file...
    if (ReportFile != NULL)
        {
        fwprintf(ReportFile, TEXT("\n"));
        fwprintf(ReportFile, TEXT("\n"));
        _ReportDriverCount(ReportFile, TEXT("hash"), hashDriverIdx);
        fwprintf(ReportFile, TEXT("Time to process             : "));
        _DriverStats_ReportTimeDiff(ReportFile, timeAllStart, timeAllEnd);
        fwprintf(ReportFile, TEXT("\n"));

        _ReportDriverImplFailures(ReportFile, failedDrivers, failedImpl);
        }


    // 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)
        {
        DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Operation completed OK\n")));
        }
    else
        {
        DEBUGOUTGUI(DEBUGLEV_INFO, (TEXT("Operation FAILED.\n")));
        }
    DEBUGOUTGUI(DEBUGLEV_EXIT, (TEXT("_DriverStats_Hash\n")));
    return allOK;
}


// =========================================================================
// =========================================================================

⌨️ 快捷键说明

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