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

Function TestVector

src/test/crypto_tests.cpp:26–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

InsecureRandRangeFunction · 0.85
sizeMethod · 0.45
resizeMethod · 0.45
FinalizeMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected