VirtualBox

Changeset 51838 in vbox for trunk/src/VBox/Runtime/testcase


Ignore:
Timestamp:
Jul 3, 2014 11:05:50 AM (10 years ago)
Author:
vboxsync
Message:

Alternative SHA-256 implementation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstRTDigest-2.cpp

    r51821 r51838  
    102102 * @param   paTests         The test table.
    103103 * @param   cTests          The number of tests in the table.
     104 * @param   pszDigestName   The name of the digest.
    104105 */
    105 static void testGeneric(const char *pszDigestObjId, TESTRTDIGEST const *paTests, size_t cTests)
     106static void testGeneric(const char *pszDigestObjId, TESTRTDIGEST const *paTests, size_t cTests, const char *pszDigestName)
    106107{
     108    /*
     109     * Execute the tests.
     110     */
     111    RTCRDIGEST hDigest;
    107112    for (uint32_t iTest = 0; iTest < cTests; iTest++)
    108113    {
     
    110115         * The whole thing in one go.
    111116         */
    112         RTCRDIGEST hDigest;
    113117        RTTESTI_CHECK_RC_RETV(RTCrDigestCreateByObjIdString(&hDigest, pszDigestObjId), VINF_SUCCESS);
    114118        uint32_t const cbHash = RTCrDigestGetHashSize(hDigest);
     
    142146                break; /* No need to test the other permutations if this fails. */
    143147        }
     148
     149        RTTESTI_CHECK_RC(RTCrDigestRelease(hDigest), 0);
    144150    }
     151
     152    /*
     153     * Do a quick benchmark.
     154     */
     155    RTTESTI_CHECK_RC_RETV(RTCrDigestCreateByObjIdString(&hDigest, pszDigestObjId), VINF_SUCCESS);
     156    uint32_t const cChunks  = 64;
     157    uint32_t       cLeft    = cChunks;
     158    int            rc       = VINF_SUCCESS;
     159
     160    uint64_t       uStartTS = RTTimeNanoTS();
     161    while (cLeft-- > 0)
     162        rc |= RTCrDigestUpdate(hDigest, g_abRandom72KB, sizeof(g_abRandom72KB));
     163    rc |= RTCrDigestFinal(hDigest, NULL, 0);
     164    uint64_t cNsElapsed = RTTimeNanoTS() - uStartTS;
     165
     166    RTTESTI_CHECK(rc == VINF_SUCCESS);
     167
     168    RTTestIValueF((uint64_t)cChunks * sizeof(g_abRandom72KB) / _1K / (0.000000001 * cNsElapsed), RTTESTUNIT_KILOBYTES_PER_SEC,
     169                  "%s throughput", pszDigestName);
    145170}
    146171
     
    341366        { &g_abRandom72KB[0x20c9],  9991, "bbba194efa81238e5b613e20e937144e", "MD2 8393 bytes @9991" },
    342367    };
    343     testGeneric("1.2.840.113549.2.2", s_abTests, RT_ELEMENTS(s_abTests));
     368    testGeneric("1.2.840.113549.2.2", s_abTests, RT_ELEMENTS(s_abTests), "MD2");
    344369}
    345370
     
    540565        { &g_abRandom72KB[0x20c9], 9991, "6461339c6615d23c704298a313e07cf5", "MD5 8393 bytes @9991" },
    541566    };
    542     testGeneric("1.2.840.113549.2.5", s_abTests, RT_ELEMENTS(s_abTests));
     567    testGeneric("1.2.840.113549.2.5", s_abTests, RT_ELEMENTS(s_abTests), "MD5");
    543568}
    544569
     
    719744        { &g_abRandom72KB[0x20c9],  9991, "62001184bacacce3774566d916055d425a85eba5", "SHA-1 8393 bytes @9991" },
    720745    };
    721     testGeneric("1.3.14.3.2.26", s_abTests, RT_ELEMENTS(s_abTests));
     746    testGeneric("1.3.14.3.2.26", s_abTests, RT_ELEMENTS(s_abTests), "SHA-1");
    722747}
    723748
     
    887912        { &g_abRandom72KB[0x20c9],  9991, "8bd4c6142e36f15385769ebdeb855dcdf542f72d067315472a52ff626946310e", "SHA-256 8393 bytes @9991" },
    888913    };
    889     testGeneric("2.16.840.1.101.3.4.2.1", s_abTests, RT_ELEMENTS(s_abTests));
     914    testGeneric("2.16.840.1.101.3.4.2.1", s_abTests, RT_ELEMENTS(s_abTests), "SHA-256");
    890915}
    891916
     
    10551080        { &g_abRandom72KB[0x20c9],  9991, "d6ac7c68664df2e34dc6be233b33f8dad196348350b70a4c2c5a78eb54d6e297c819771313d798de7552b7a3cb85370aab25087e189f3be8560d49406ebb6280", "SHA-512 8393 bytes @9991" },
    10561081    };
    1057     testGeneric("2.16.840.1.101.3.4.2.3", s_abTests, RT_ELEMENTS(s_abTests));
     1082    testGeneric("2.16.840.1.101.3.4.2.3", s_abTests, RT_ELEMENTS(s_abTests), "SHA-512");
    10581083}
    10591084
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette