/src/cryptofuzz/modules/bitcoin/uint256.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | | // Copyright (c) 2009-2020 The Bitcoin Core developers |
3 | | // Distributed under the MIT software license, see the accompanying |
4 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | | |
6 | | #include <uint256.h> |
7 | | |
8 | | #include <util/strencodings.h> |
9 | | |
10 | | #include <string.h> |
11 | | |
12 | | template <unsigned int BITS> |
13 | | base_blob<BITS>::base_blob(const std::vector<unsigned char>& vch) |
14 | 3 | { |
15 | 3 | assert(vch.size() == sizeof(m_data)); |
16 | 3 | memcpy(m_data, vch.data(), sizeof(m_data)); |
17 | 3 | } Unexecuted instantiation: base_blob<160u>::base_blob(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&) base_blob<256u>::base_blob(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&) Line | Count | Source | 14 | 3 | { | 15 | 3 | assert(vch.size() == sizeof(m_data)); | 16 | 3 | memcpy(m_data, vch.data(), sizeof(m_data)); | 17 | 3 | } |
|
18 | | |
19 | | template <unsigned int BITS> |
20 | | std::string base_blob<BITS>::GetHex() const |
21 | 6.23M | { |
22 | 6.23M | uint8_t m_data_rev[WIDTH]; |
23 | 205M | for (int i = 0; i < WIDTH; ++i) { |
24 | 199M | m_data_rev[i] = m_data[WIDTH - 1 - i]; |
25 | 199M | } |
26 | 6.23M | return HexStr(m_data_rev); |
27 | 6.23M | } base_blob<160u>::GetHex() const Line | Count | Source | 21 | 1.79k | { | 22 | 1.79k | uint8_t m_data_rev[WIDTH]; | 23 | 37.7k | for (int i = 0; i < WIDTH; ++i) { | 24 | 35.9k | m_data_rev[i] = m_data[WIDTH - 1 - i]; | 25 | 35.9k | } | 26 | 1.79k | return HexStr(m_data_rev); | 27 | 1.79k | } |
base_blob<256u>::GetHex() const Line | Count | Source | 21 | 6.23M | { | 22 | 6.23M | uint8_t m_data_rev[WIDTH]; | 23 | 205M | for (int i = 0; i < WIDTH; ++i) { | 24 | 199M | m_data_rev[i] = m_data[WIDTH - 1 - i]; | 25 | 199M | } | 26 | 6.23M | return HexStr(m_data_rev); | 27 | 6.23M | } |
|
28 | | |
29 | | template <unsigned int BITS> |
30 | | void base_blob<BITS>::SetHex(const char* psz) |
31 | 6.32k | { |
32 | 6.32k | memset(m_data, 0, sizeof(m_data)); |
33 | | |
34 | | // skip leading spaces |
35 | 6.32k | while (IsSpace(*psz)) |
36 | 0 | psz++; |
37 | | |
38 | | // skip 0x |
39 | 6.32k | if (psz[0] == '0' && ToLower(psz[1]) == 'x') |
40 | 0 | psz += 2; |
41 | | |
42 | | // hex string to uint |
43 | 6.32k | size_t digits = 0; |
44 | 1.96M | while (::HexDigit(psz[digits]) != -1) |
45 | 1.95M | digits++; |
46 | 6.32k | unsigned char* p1 = (unsigned char*)m_data; |
47 | 6.32k | unsigned char* pend = p1 + WIDTH; |
48 | 161k | while (digits > 0 && p1 < pend) { |
49 | 154k | *p1 = ::HexDigit(psz[--digits]); |
50 | 154k | if (digits > 0) { |
51 | 154k | *p1 |= ((unsigned char)::HexDigit(psz[--digits]) << 4); |
52 | 154k | p1++; |
53 | 154k | } |
54 | 154k | } |
55 | 6.32k | } Unexecuted instantiation: base_blob<160u>::SetHex(char const*) base_blob<256u>::SetHex(char const*) Line | Count | Source | 31 | 6.32k | { | 32 | 6.32k | memset(m_data, 0, sizeof(m_data)); | 33 | | | 34 | | // skip leading spaces | 35 | 6.32k | while (IsSpace(*psz)) | 36 | 0 | psz++; | 37 | | | 38 | | // skip 0x | 39 | 6.32k | if (psz[0] == '0' && ToLower(psz[1]) == 'x') | 40 | 0 | psz += 2; | 41 | | | 42 | | // hex string to uint | 43 | 6.32k | size_t digits = 0; | 44 | 1.96M | while (::HexDigit(psz[digits]) != -1) | 45 | 1.95M | digits++; | 46 | 6.32k | unsigned char* p1 = (unsigned char*)m_data; | 47 | 6.32k | unsigned char* pend = p1 + WIDTH; | 48 | 161k | while (digits > 0 && p1 < pend) { | 49 | 154k | *p1 = ::HexDigit(psz[--digits]); | 50 | 154k | if (digits > 0) { | 51 | 154k | *p1 |= ((unsigned char)::HexDigit(psz[--digits]) << 4); | 52 | 154k | p1++; | 53 | 154k | } | 54 | 154k | } | 55 | 6.32k | } |
|
56 | | |
57 | | template <unsigned int BITS> |
58 | | void base_blob<BITS>::SetHex(const std::string& str) |
59 | 0 | { |
60 | 0 | SetHex(str.c_str()); |
61 | 0 | } Unexecuted instantiation: base_blob<160u>::SetHex(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: base_blob<256u>::SetHex(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
62 | | |
63 | | template <unsigned int BITS> |
64 | | std::string base_blob<BITS>::ToString() const |
65 | 6.07M | { |
66 | 6.07M | return (GetHex()); |
67 | 6.07M | } base_blob<160u>::ToString() const Line | Count | Source | 65 | 1.79k | { | 66 | 1.79k | return (GetHex()); | 67 | 1.79k | } |
base_blob<256u>::ToString() const Line | Count | Source | 65 | 6.07M | { | 66 | 6.07M | return (GetHex()); | 67 | 6.07M | } |
|
68 | | |
69 | | // Explicit instantiations for base_blob<160> |
70 | | template base_blob<160>::base_blob(const std::vector<unsigned char>&); |
71 | | template std::string base_blob<160>::GetHex() const; |
72 | | template std::string base_blob<160>::ToString() const; |
73 | | template void base_blob<160>::SetHex(const char*); |
74 | | template void base_blob<160>::SetHex(const std::string&); |
75 | | |
76 | | // Explicit instantiations for base_blob<256> |
77 | | template base_blob<256>::base_blob(const std::vector<unsigned char>&); |
78 | | template std::string base_blob<256>::GetHex() const; |
79 | | template std::string base_blob<256>::ToString() const; |
80 | | template void base_blob<256>::SetHex(const char*); |
81 | | template void base_blob<256>::SetHex(const std::string&); |
82 | | |
83 | | const uint256 uint256::ZERO(0); |
84 | | const uint256 uint256::ONE(1); |