forked from BTCPrivate/BTCP-Rebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sha256compress_tests.cpp
86 lines (69 loc) · 2.69 KB
/
sha256compress_tests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <test/test_bitcoin.h>
#include <crypto/sha256.h>
#include <uint256.h>
#include <stdexcept>
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_SUITE(sha256compress_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(compression222)
{
{
unsigned char preimage[64] = {};
CSHA256 hasher;
hasher.Write(&preimage[0], 64);
uint256 digest;
hasher.FinalizeNoPadding(digest.begin());
BOOST_CHECK_MESSAGE(digest == uint256S("d8a93718eaf9feba4362d2c091d4e58ccabe9f779957336269b4b917be9856da"),
digest.GetHex());
}
{
unsigned char preimage[63] = {};
CSHA256 hasher;
hasher.Write(&preimage[0], 63);
uint256 digest;
BOOST_CHECK_THROW(hasher.FinalizeNoPadding(digest.begin()), std::length_error);
}
{
unsigned char preimage[65] = {};
CSHA256 hasher;
hasher.Write(&preimage[0], 65);
uint256 digest;
BOOST_CHECK_THROW(hasher.FinalizeNoPadding(digest.begin()), std::length_error);
}
{
unsigned char n = 0x00;
CSHA256 hasher;
for (size_t i = 0; i < 64; i++) {
hasher.Write(&n, 1);
}
uint256 digest;
hasher.FinalizeNoPadding(digest.begin());
BOOST_CHECK_MESSAGE(digest == uint256S("d8a93718eaf9feba4362d2c091d4e58ccabe9f779957336269b4b917be9856da"),
digest.GetHex());
}
{
unsigned char preimage[64] = { 'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd',
'a', 'b', 'c', 'd'
};
CSHA256 hasher;
hasher.Write(&preimage[0], 64);
uint256 digest;
hasher.FinalizeNoPadding(digest.begin());
BOOST_CHECK_MESSAGE(digest == uint256S("da70ec41879e36b000281733d4deb27ddf41e8e343a38f2fabbd2d8611987d86"),
digest.GetHex());
}
}
BOOST_AUTO_TEST_SUITE_END()