MCPcopy Create free account
hub / github.com/ValveSoftware/GameNetworkingSockets / TestSHA256

Function TestSHA256

tests/test_crypto.cpp:318–340  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Test elliptic-curve primitives (ed25519 signing, curve25519 key exchange) -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

316// Purpose: Test elliptic-curve primitives (ed25519 signing, curve25519 key exchange)
317//-----------------------------------------------------------------------------
318void TestSHA256()
319{
320 // NIST FIPS 180-4 known-answer tests for SHA-256
321 struct { const char *pszData; const char *pszExpected; } rgTests[] =
322 {
323 // SHA-256("")
324 { "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" },
325 // SHA-256("abc")
326 { "abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" },
327 // SHA-256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
328 { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" },
329 };
330 for ( auto &t : rgTests )
331 {
332 SHA256Digest_t digest;
333 CCrypto::GenerateSHA256Digest( t.pszData, strlen(t.pszData), &digest );
334 char hex[sizeof(SHA256Digest_t)*2+1];
335 CCrypto::HexEncode( digest, sizeof(digest), hex, sizeof(hex) );
336 // HexEncode gives uppercase; compare case-insensitively
337 for ( int i = 0; hex[i]; ++i ) hex[i] = tolower(hex[i]);
338 CHECK_EQUAL( 0, strcmp( hex, t.pszExpected ) );
339 }
340}
341
342void TestMD5()
343{

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected