MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / TestVector

Function TestVector

src/test/crypto_tests.cpp:23–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22template<typename Hasher, typename In, typename Out>
23void TestVector(const Hasher &h, const In &in, const Out &out) {
24 Out hash;
25 BOOST_CHECK(out.size() == h.OUTPUT_SIZE);
26 hash.resize(out.size());
27 {
28 // Test that writing the whole input string at once works.
29 Hasher(h).Write((unsigned char*)&in[0], in.size()).Finalize(&hash[0]);
30 BOOST_CHECK(hash == out);
31 }
32 for (int i=0; i<32; i++) {
33 // Test that writing the string broken up in random pieces works.
34 Hasher hasher(h);
35 size_t pos = 0;
36 while (pos < in.size()) {
37 size_t len = insecure_rand() % ((in.size() - pos + 1) / 2 + 1);
38 hasher.Write((unsigned char*)&in[pos], len);
39 pos += len;
40 if (pos > 0 && pos + 2 * out.size() > in.size() && pos < in.size()) {
41 // Test that writing the rest at once to a copy of a hasher works.
42 Hasher(hasher).Write((unsigned char*)&in[pos], in.size() - pos).Finalize(&hash[0]);
43 BOOST_CHECK(hash == out);
44 }
45 }
46 hasher.Finalize(&hash[0]);
47 BOOST_CHECK(hash == out);
48 }
49}
50
51void TestSHA1(const std::string &in, const std::string &hexout) { TestVector(CSHA1(), in, ParseHex(hexout));}
52void TestSHA256(const std::string &in, const std::string &hexout) { TestVector(CSHA256(), in, ParseHex(hexout));}

Callers 6

TestSHA1Function · 0.70
TestSHA256Function · 0.70
TestSHA512Function · 0.70
TestRIPEMD160Function · 0.70
TestHMACSHA256Function · 0.70
TestHMACSHA512Function · 0.70

Calls 5

insecure_randFunction · 0.85
resizeMethod · 0.80
sizeMethod · 0.45
FinalizeMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected