diff --git a/Crypto/Hash/Makefile b/Crypto/Hash/Makefile new file mode 100644 index 0000000..9531acd --- /dev/null +++ b/Crypto/Hash/Makefile @@ -0,0 +1,10 @@ + +pass: unittest + @if ./unittest > pass ; then echo "PASS" ; else echo "FAIL" ; rm pass ; fi + +unittest: main.cpp SHA256.cpp + g++ main.cpp SHA256.cpp -o unittest + +clean: + rm pass unittest + diff --git a/Crypto/Hash/Makefile b/Crypto/Hash/Makefile new file mode 100644 index 0000000..9531acd --- /dev/null +++ b/Crypto/Hash/Makefile @@ -0,0 +1,10 @@ + +pass: unittest + @if ./unittest > pass ; then echo "PASS" ; else echo "FAIL" ; rm pass ; fi + +unittest: main.cpp SHA256.cpp + g++ main.cpp SHA256.cpp -o unittest + +clean: + rm pass unittest + diff --git a/Crypto/Hash/main.cpp b/Crypto/Hash/main.cpp new file mode 100644 index 0000000..bca8e1a --- /dev/null +++ b/Crypto/Hash/main.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include "SHA256.h" + + +void sha256_test(const char* test, const char* msg, const char* cmp) +{ + uint32_t hash[8]; + sha256((uint8_t*)msg, strlen(msg), hash); + char buffer[1024]; + snprintf(buffer, 1024, "0x%08x%08x%08x%08x%08x%08x%08x%08x", hash[0], + hash[1], hash[2], hash[3], hash[4], hash[5], hash[6], hash[7]); + + if ( !strcmp(buffer, cmp) ) { + printf("%s: PASS\n", test); + } else { + printf("%s: FAIL\n", test); + printf("Hash: %s\n", buffer); + printf("Compare: %s\n", cmp); + exit(-1); + } +} + + +int main() +{ + const char* test_str1 = ""; + const char* test_str2 = "The quick brown fox jumps over the lazy dog."; + const char* test_str3 = "The quick brown fox jumps over the lazy dog"; + sha256_test("SHA256 Test 1", test_str1, "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); + sha256_test("SHA256 Test 2", test_str2, "0xef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"); + sha256_test("SHA256 Test 3", test_str3, "0xd7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"); + return 0; +} +