Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_blake2.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE blake2
2#include <boost/test/included/unit_test.hpp>
3
5#include <fc/crypto/hex.hpp>
7#include <fc/utility.hpp>
8
9using namespace fc;
10
11#include "test_utils.hpp"
12
13namespace std {
14std::ostream& operator<<(std::ostream& st, const std::variant<fc::blake2b_error, bytes>& err)
15{
16 if(std::holds_alternative<fc::blake2b_error>(err))
17 st << static_cast<int32_t>(std::get<fc::blake2b_error>(err));
18 else
19 st << fc::to_hex(std::get<bytes>(err));
20 return st;
21}
22}
23
24BOOST_AUTO_TEST_SUITE(blake2)
26
27 using compress_test = std::tuple<std::vector<string>, std::variant<fc::blake2b_error, bytes>>;
28
29 const std::vector<compress_test> tests {
30 //test1
31 {
32 {
33 "00000000",
34 "48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b",
35 "6162630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
36 "0300000000000000",
37 "0000000000000000",
38 "01",
39 },
40 to_bytes("08c9bcf367e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d282e6ad7f520e511f6c3e2b8c68059b9442be0454267ce079217e1319cde05b")
41 },
42
43 //test2
44 {
45 {
46 "0000000c",
47 "48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b",
48 "6162630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
49 "0300000000000000",
50 "0000000000000000",
51 "01",
52 },
53 to_bytes("ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d17d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923")
54 },
55
56 //test3
57 {
58 {
59 "0000000c",
60 "48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b",
61 "6162630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
62 "0300000000000000",
63 "0000000000000000",
64 "00",
65 },
66 to_bytes("75ab69d3190a562c51aef8d88f1c2775876944407270c42c9844252c26d2875298743e7f6d5ea2f2d3e8d226039cd31b4e426ac4f2d3d666a610c2116fde4735")
67 },
68
69 //test4
70 {
71 {
72 "00000001",
73 "48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b",
74 "6162630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
75 "0300000000000000",
76 "0000000000000000",
77 "01",
78 },
79 to_bytes("b63a380cb2897d521994a85234ee2c181b5f844d2c624c002677e9703449d2fba551b3a8333bcdf5f2f7e08993d53923de3d64fcc68c034e717b9293fed7a421")
80 },
81
82 //test5
83 {
84 {
85 "00000000",
86 "c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b",
87 "6162630000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
88 "0300000000000000",
89 "0000000000000000",
90 "01",
91 },
92 blake2b_error::input_len_error
93 },
94 };
95
96 yield_function_t yield = [](){};
97
98 for(const auto& test : tests) {
99
100 const auto& params = std::get<0>(test);
101 const auto& expected_result = std::get<1>(test);
102
103 BOOST_REQUIRE(params.size() == 6);
104
105 uint32_t _rounds = to_uint32(params[0] );
106 bytes _h = to_bytes( params[1] );
107 bytes _m = to_bytes( params[2] );
108 bytes _t0_offset = to_bytes( params[3] );
109 bytes _t1_offset = to_bytes( params[4] );
110 bool _f = params[5] == "00" ? false : true;
111
112 auto res = blake2b(_rounds, _h, _m, _t0_offset, _t1_offset, _f, yield);
113
114 BOOST_CHECK_EQUAL(res, expected_result);
115 }
116
118
119BOOST_AUTO_TEST_SUITE_END()
Defines exception's used by fc.
namespace sysio::chain
Definition authority.cpp:3
std::vector< char > bytes
Definition alt_bn128.hpp:10
std::variant< blake2b_error, bytes > blake2b(uint32_t _rounds, const bytes &_h, const bytes &_m, const bytes &_t0_offset, const bytes &_t1_offset, bool _f, const yield_function_t &yield)
Definition blake2.cpp:105
Definition name.hpp:106
std::ostream & operator<<(std::ostream &st, const std::variant< fc::alt_bn128_error, bytes > &err)
const unsigned char expected_result[]
Definition ssh.c:73
unsigned int uint32_t
Definition stdint.h:126
BOOST_AUTO_TEST_CASE(compress)
FC_LOG_AND_RETHROW()
uint32_t to_uint32(const std::string &s)
Definition test_utils.hpp:1
bytes to_bytes(const std::string &source)
Definition test_utils.hpp:6