| 398 | |
| 399 | |
| 400 | int sha256_test() |
| 401 | { |
| 402 | SHA256 sha; |
| 403 | byte hash[SHA256::DIGEST_SIZE]; |
| 404 | |
| 405 | testVector test_sha[] = |
| 406 | { |
| 407 | testVector("abc", |
| 408 | "\xBA\x78\x16\xBF\x8F\x01\xCF\xEA\x41\x41\x40\xDE\x5D\xAE\x22" |
| 409 | "\x23\xB0\x03\x61\xA3\x96\x17\x7A\x9C\xB4\x10\xFF\x61\xF2\x00" |
| 410 | "\x15\xAD"), |
| 411 | testVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", |
| 412 | "\x24\x8D\x6A\x61\xD2\x06\x38\xB8\xE5\xC0\x26\x93\x0C\x3E\x60" |
| 413 | "\x39\xA3\x3C\xE4\x59\x64\xFF\x21\x67\xF6\xEC\xED\xD4\x19\xDB" |
| 414 | "\x06\xC1") |
| 415 | }; |
| 416 | |
| 417 | int times( sizeof(test_sha) / sizeof(testVector) ); |
| 418 | for (int i = 0; i < times; ++i) { |
| 419 | sha.Update(test_sha[i].input_, test_sha[i].inLen_); |
| 420 | sha.Final(hash); |
| 421 | |
| 422 | if (memcmp(hash, test_sha[i].output_, SHA256::DIGEST_SIZE) != 0) |
| 423 | return -1 - i; |
| 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | |
| 430 | #ifdef WORD64_AVAILABLE |
no test coverage detected