aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2014-04-28 03:09:13 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2014-06-21 19:47:39 +0200
commit1cc344ce42d8dddd6356c89ef3ceb58418676816 (patch)
tree36577c13adeaa82a546e3d9b5a6bb37c45c180f1 /src/test
parent85aab2a08824a83a535e6dfee4c150b25ebaf9de (diff)
Add built-in SHA-1 implementation.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/sha1_tests.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/test/sha1_tests.cpp b/src/test/sha1_tests.cpp
new file mode 100644
index 0000000000..bae17c5d4a
--- /dev/null
+++ b/src/test/sha1_tests.cpp
@@ -0,0 +1,27 @@
+// Copyright (c) 2014 The Bitcoin Core developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include "sha1.h"
+#include "util.h"
+
+#include <vector>
+
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_SUITE(sha1_tests)
+
+void SHA1TestVector(const std::string &in, const std::string &out) {
+ std::vector<unsigned char> hash;
+ hash.resize(20);
+ CSHA1().Write((unsigned char*)&in[0], in.size()).Finalize(&hash[0]);
+ BOOST_CHECK_EQUAL(HexStr(hash), out);
+}
+
+BOOST_AUTO_TEST_CASE(sha1_testvectors) {
+ SHA1TestVector("abc", "a9993e364706816aba3e25717850c26c9cd0d89d");
+ SHA1TestVector("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
+ SHA1TestVector(std::string(1000000, 'a'), "34aa973cd4c4daa4f61eeb2bdbad27316534016f");
+}
+
+BOOST_AUTO_TEST_SUITE_END()