@eosrio/node-abieos 2.1.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/abieos.node +0 -0
- package/lib/abieos.d.ts +19 -0
- package/lib/abieos.d.ts.map +1 -0
- package/lib/abieos.js +100 -0
- package/lib/abieos.ts +107 -0
- package/package.json +13 -8
- package/.idea/modules.xml +0 -8
- package/.idea/node-abieos.iml +0 -12
- package/.idea/vcs.xml +0 -9
- package/.idea/workspace.xml +0 -66
- package/CMakeLists.txt +0 -35
- package/abieos.d.ts +0 -21
- package/abieos.js +0 -59
- package/eosio.json +0 -1596
- package/include/.clang-format +0 -76
- package/include/eosio/abi.hpp +0 -393
- package/include/eosio/asset.hpp +0 -458
- package/include/eosio/bytes.hpp +0 -27
- package/include/eosio/chain_conversions.hpp +0 -450
- package/include/eosio/chain_types.hpp +0 -14
- package/include/eosio/check.hpp +0 -178
- package/include/eosio/convert.hpp +0 -95
- package/include/eosio/crypto.hpp +0 -148
- package/include/eosio/eosio_outcome.hpp +0 -41
- package/include/eosio/fixed_bytes.hpp +0 -250
- package/include/eosio/float.hpp +0 -35
- package/include/eosio/for_each_field.hpp +0 -48
- package/include/eosio/fpconv.c +0 -336
- package/include/eosio/fpconv.h +0 -41
- package/include/eosio/fpconv.license +0 -23
- package/include/eosio/from_bin.hpp +0 -272
- package/include/eosio/from_json.hpp +0 -749
- package/include/eosio/from_string.hpp +0 -28
- package/include/eosio/map_macro.h +0 -64
- package/include/eosio/murmur.hpp +0 -55
- package/include/eosio/name.hpp +0 -178
- package/include/eosio/opaque.hpp +0 -184
- package/include/eosio/operators.hpp +0 -71
- package/include/eosio/powers.h +0 -76
- package/include/eosio/reflection.hpp +0 -61
- package/include/eosio/ship_protocol.hpp +0 -971
- package/include/eosio/stream.hpp +0 -235
- package/include/eosio/symbol.hpp +0 -300
- package/include/eosio/time.hpp +0 -264
- package/include/eosio/to_bin.hpp +0 -189
- package/include/eosio/to_json.hpp +0 -334
- package/include/eosio/to_key.hpp +0 -305
- package/include/eosio/types.hpp +0 -103
- package/include/eosio/varint.hpp +0 -452
- package/include/outcome-basic.hpp +0 -6836
- package/include/rapidjson/allocators.h +0 -284
- package/include/rapidjson/cursorstreamwrapper.h +0 -78
- package/include/rapidjson/document.h +0 -2646
- package/include/rapidjson/encodedstream.h +0 -299
- package/include/rapidjson/encodings.h +0 -716
- package/include/rapidjson/error/en.h +0 -74
- package/include/rapidjson/error/error.h +0 -161
- package/include/rapidjson/filereadstream.h +0 -99
- package/include/rapidjson/filewritestream.h +0 -104
- package/include/rapidjson/fwd.h +0 -151
- package/include/rapidjson/internal/biginteger.h +0 -290
- package/include/rapidjson/internal/diyfp.h +0 -271
- package/include/rapidjson/internal/dtoa.h +0 -245
- package/include/rapidjson/internal/ieee754.h +0 -78
- package/include/rapidjson/internal/itoa.h +0 -308
- package/include/rapidjson/internal/meta.h +0 -186
- package/include/rapidjson/internal/pow10.h +0 -55
- package/include/rapidjson/internal/regex.h +0 -732
- package/include/rapidjson/internal/stack.h +0 -231
- package/include/rapidjson/internal/strfunc.h +0 -69
- package/include/rapidjson/internal/strtod.h +0 -290
- package/include/rapidjson/internal/swap.h +0 -46
- package/include/rapidjson/istreamwrapper.h +0 -113
- package/include/rapidjson/memorybuffer.h +0 -70
- package/include/rapidjson/memorystream.h +0 -71
- package/include/rapidjson/msinttypes/inttypes.h +0 -316
- package/include/rapidjson/msinttypes/stdint.h +0 -300
- package/include/rapidjson/ostreamwrapper.h +0 -81
- package/include/rapidjson/pointer.h +0 -1357
- package/include/rapidjson/prettywriter.h +0 -277
- package/include/rapidjson/rapidjson.h +0 -654
- package/include/rapidjson/reader.h +0 -2230
- package/include/rapidjson/schema.h +0 -2494
- package/include/rapidjson/stream.h +0 -223
- package/include/rapidjson/stringbuffer.h +0 -121
- package/include/rapidjson/writer.h +0 -710
- package/src/abi.cpp +0 -274
- package/src/abieos.cpp +0 -334
- package/src/abieos.h +0 -91
- package/src/abieos.hpp +0 -1011
- package/src/abieos_exception.hpp +0 -89
- package/src/abieos_numeric.hpp +0 -94
- package/src/abieos_ripemd160.hpp +0 -417
- package/src/crypto.cpp +0 -215
- package/src/main.cpp +0 -242
- package/src/ship.abi.cpp +0 -695
- package/tools/CMakeLists.txt +0 -9
- package/tools/name.cpp +0 -86
package/src/abieos_exception.hpp
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
// copyright defined in abieos/LICENSE.txt
|
|
2
|
-
|
|
3
|
-
#pragma once
|
|
4
|
-
|
|
5
|
-
#include "abieos.hpp"
|
|
6
|
-
|
|
7
|
-
#include <exception>
|
|
8
|
-
|
|
9
|
-
namespace abieos {
|
|
10
|
-
|
|
11
|
-
struct error : std::exception {
|
|
12
|
-
std::string message;
|
|
13
|
-
|
|
14
|
-
error(std::string message) : message(std::move(message)) {}
|
|
15
|
-
virtual const char* what() const noexcept { return message.c_str(); }
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
inline std::string public_key_to_string(const public_key& key) {
|
|
19
|
-
std::string dest, error;
|
|
20
|
-
if (!public_key_to_string(dest, error, key))
|
|
21
|
-
throw abieos::error(error);
|
|
22
|
-
return dest;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
inline std::string signature_to_string(const signature& key) {
|
|
26
|
-
std::string dest, error;
|
|
27
|
-
if (!signature_to_string(dest, error, key))
|
|
28
|
-
throw abieos::error(error);
|
|
29
|
-
return dest;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
inline time_point_sec string_to_time_point_sec(const char* s) {
|
|
33
|
-
time_point_sec result;
|
|
34
|
-
std::string error;
|
|
35
|
-
if (!string_to_time_point_sec(result, error, s, s + strlen(s)))
|
|
36
|
-
throw abieos::error(error);
|
|
37
|
-
return result;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
inline time_point string_to_time_point(const std::string& s) {
|
|
41
|
-
time_point result;
|
|
42
|
-
std::string error;
|
|
43
|
-
if (!string_to_time_point(result, error, s))
|
|
44
|
-
throw abieos::error(error);
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
inline uint64_t string_to_symbol_code(const char* s) {
|
|
49
|
-
uint64_t result;
|
|
50
|
-
if (!eosio::string_to_symbol_code(result, s, s + strlen(s)))
|
|
51
|
-
throw abieos::error("invalid symbol_code");
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
inline uint64_t string_to_symbol(const char* s) {
|
|
56
|
-
uint64_t result;
|
|
57
|
-
if (!eosio::string_to_symbol(result, s, s + strlen(s)))
|
|
58
|
-
throw abieos::error("invalid symbol");
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
inline asset string_to_asset(const char* s) {
|
|
63
|
-
asset result;
|
|
64
|
-
if (!eosio::string_to_asset(result.amount, result.sym.value, s, s + strlen(s)))
|
|
65
|
-
throw abieos::error("invalid asset");
|
|
66
|
-
return result;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
inline void check_abi_version(const std::string& s) {
|
|
70
|
-
std::string error;
|
|
71
|
-
if (!check_abi_version(s, error))
|
|
72
|
-
throw abieos::error(error);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
inline contract create_contract(const abi_def& abi) {
|
|
76
|
-
std::string error;
|
|
77
|
-
contract c;
|
|
78
|
-
if (!fill_contract(c, error, abi))
|
|
79
|
-
throw abieos::error(error);
|
|
80
|
-
return c;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
inline void json_to_bin(std::vector<char>& bin, const abi_type* type, const jvalue& value) {
|
|
84
|
-
std::string error;
|
|
85
|
-
if (!json_to_bin(bin, error, type, value))
|
|
86
|
-
throw abieos::error(error);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
} // namespace abieos
|
package/src/abieos_numeric.hpp
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
// copyright defined in abieos/LICENSE.txt
|
|
2
|
-
|
|
3
|
-
#pragma once
|
|
4
|
-
|
|
5
|
-
#include <algorithm>
|
|
6
|
-
#include <array>
|
|
7
|
-
#include <stdint.h>
|
|
8
|
-
#include <string>
|
|
9
|
-
#include <string_view>
|
|
10
|
-
#include <eosio/from_json.hpp>
|
|
11
|
-
|
|
12
|
-
#include "abieos_ripemd160.hpp"
|
|
13
|
-
|
|
14
|
-
#define ABIEOS_NODISCARD [[nodiscard]]
|
|
15
|
-
|
|
16
|
-
namespace abieos {
|
|
17
|
-
|
|
18
|
-
template <typename State>
|
|
19
|
-
ABIEOS_NODISCARD bool set_error(State& state, std::string error) {
|
|
20
|
-
state.error = std::move(error);
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
ABIEOS_NODISCARD inline bool set_error(std::string& state, std::string error) {
|
|
25
|
-
state = std::move(error);
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
inline constexpr char base58_chars[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
30
|
-
|
|
31
|
-
inline constexpr auto create_base58_map() {
|
|
32
|
-
std::array<int8_t, 256> base58_map{{0}};
|
|
33
|
-
for (unsigned i = 0; i < base58_map.size(); ++i)
|
|
34
|
-
base58_map[i] = -1;
|
|
35
|
-
for (unsigned i = 0; i < sizeof(base58_chars); ++i)
|
|
36
|
-
base58_map[base58_chars[i]] = i;
|
|
37
|
-
return base58_map;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
inline constexpr auto base58_map = create_base58_map();
|
|
41
|
-
|
|
42
|
-
template <auto size>
|
|
43
|
-
bool is_negative(const std::array<uint8_t, size>& a) {
|
|
44
|
-
return a[size - 1] & 0x80;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
template <auto size>
|
|
48
|
-
void negate(std::array<uint8_t, size>& a) {
|
|
49
|
-
uint8_t carry = 1;
|
|
50
|
-
for (auto& byte : a) {
|
|
51
|
-
int x = uint8_t(~byte) + carry;
|
|
52
|
-
byte = x;
|
|
53
|
-
carry = x >> 8;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
template <auto size>
|
|
58
|
-
inline void decimal_to_binary(std::array<uint8_t, size>& result,
|
|
59
|
-
std::string_view s) {
|
|
60
|
-
memset(result.begin(), 0, result.size());
|
|
61
|
-
for (auto& src_digit : s) {
|
|
62
|
-
eosio::check(!(src_digit < '0' || src_digit > '9'),
|
|
63
|
-
eosio::convert_json_error(eosio::from_json_error::expected_int));
|
|
64
|
-
uint8_t carry = src_digit - '0';
|
|
65
|
-
for (auto& result_byte : result) {
|
|
66
|
-
int x = result_byte * 10 + carry;
|
|
67
|
-
result_byte = x;
|
|
68
|
-
carry = x >> 8;
|
|
69
|
-
}
|
|
70
|
-
eosio::check(!carry,
|
|
71
|
-
eosio::convert_json_error(eosio::from_json_error::number_out_of_range));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
template <auto size>
|
|
76
|
-
std::string binary_to_decimal(const std::array<uint8_t, size>& bin) {
|
|
77
|
-
std::string result("0");
|
|
78
|
-
for (auto byte_it = bin.rbegin(); byte_it != bin.rend(); ++byte_it) {
|
|
79
|
-
int carry = *byte_it;
|
|
80
|
-
for (auto& result_digit : result) {
|
|
81
|
-
int x = ((result_digit - '0') << 8) + carry;
|
|
82
|
-
result_digit = '0' + x % 10;
|
|
83
|
-
carry = x / 10;
|
|
84
|
-
}
|
|
85
|
-
while (carry) {
|
|
86
|
-
result.push_back('0' + carry % 10);
|
|
87
|
-
carry = carry / 10;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
std::reverse(result.begin(), result.end());
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
} // namespace abieos
|
package/src/abieos_ripemd160.hpp
DELETED
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* RIPEMD160.c : RIPEMD-160 implementation
|
|
4
|
-
*
|
|
5
|
-
* Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
|
|
6
|
-
*
|
|
7
|
-
* ===================================================================
|
|
8
|
-
* The contents of this file are dedicated to the public domain. To
|
|
9
|
-
* the extent that dedication to the public domain is not available,
|
|
10
|
-
* everyone is granted a worldwide, perpetual, royalty-free,
|
|
11
|
-
* non-exclusive license to exercise all rights associated with the
|
|
12
|
-
* contents of this file for any purpose whatsoever.
|
|
13
|
-
* No rights are reserved.
|
|
14
|
-
*
|
|
15
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
17
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
19
|
-
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
20
|
-
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
21
|
-
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
* ===================================================================
|
|
24
|
-
*
|
|
25
|
-
* Country of origin: Canada
|
|
26
|
-
*
|
|
27
|
-
* This implementation (written in C) is based on an implementation the author
|
|
28
|
-
* wrote in Python.
|
|
29
|
-
*
|
|
30
|
-
* This implementation was written with reference to the RIPEMD-160
|
|
31
|
-
* specification, which is available at:
|
|
32
|
-
* http://homes.esat.kuleuven.be/~cosicart/pdf/AB-9601/
|
|
33
|
-
*
|
|
34
|
-
* It is also documented in the _Handbook of Applied Cryptography_, as
|
|
35
|
-
* Algorithm 9.55. It's on page 30 of the following PDF file:
|
|
36
|
-
* http://www.cacr.math.uwaterloo.ca/hac/about/chap9.pdf
|
|
37
|
-
*
|
|
38
|
-
* The RIPEMD-160 specification doesn't really tell us how to do padding, but
|
|
39
|
-
* since RIPEMD-160 is inspired by MD4, you can use the padding algorithm from
|
|
40
|
-
* RFC 1320.
|
|
41
|
-
*
|
|
42
|
-
* According to http://www.users.zetnet.co.uk/hopwood/crypto/scan/md.html:
|
|
43
|
-
* "RIPEMD-160 is big-bit-endian, little-byte-endian, and left-justified."
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
#pragma once
|
|
47
|
-
|
|
48
|
-
#include <assert.h>
|
|
49
|
-
#include <string.h>
|
|
50
|
-
|
|
51
|
-
namespace abieos_ripemd160 {
|
|
52
|
-
|
|
53
|
-
inline constexpr auto ripemd160_digest_size = 20;
|
|
54
|
-
inline constexpr auto ripemd160_magic = 0x9f19dd68u;
|
|
55
|
-
|
|
56
|
-
typedef struct {
|
|
57
|
-
uint32_t magic;
|
|
58
|
-
uint32_t h[5]; /* The current hash state */
|
|
59
|
-
uint64_t length; /* Total number of _bits_ (not bytes) added to the
|
|
60
|
-
hash. This includes bits that have been buffered
|
|
61
|
-
but not fed through the compression function yet. */
|
|
62
|
-
union {
|
|
63
|
-
uint32_t w[16];
|
|
64
|
-
uint8_t b[64];
|
|
65
|
-
} buf;
|
|
66
|
-
uint8_t bufpos; /* number of bytes currently in the buffer */
|
|
67
|
-
} ripemd160_state;
|
|
68
|
-
|
|
69
|
-
/* cyclic left-shift the 32-bit word n left by s bits */
|
|
70
|
-
#define ROL(s, n) (((n) << (s)) | ((n) >> (32 - (s))))
|
|
71
|
-
|
|
72
|
-
/* Initial values for the chaining variables.
|
|
73
|
-
* This is just 0123456789ABCDEFFEDCBA9876543210F0E1D2C3 in little-endian. */
|
|
74
|
-
inline const uint32_t initial_h[5] = {0x67452301u, 0xEFCDAB89u, 0x98BADCFEu, 0x10325476u, 0xC3D2E1F0u};
|
|
75
|
-
|
|
76
|
-
/* Ordering of message words. Based on the permutations rho(i) and pi(i), defined as follows:
|
|
77
|
-
*
|
|
78
|
-
* rho(i) := { 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8 }[i] 0 <= i <= 15
|
|
79
|
-
*
|
|
80
|
-
* pi(i) := 9*i + 5 (mod 16)
|
|
81
|
-
*
|
|
82
|
-
* Line | Round 1 | Round 2 | Round 3 | Round 4 | Round 5
|
|
83
|
-
* -------+-----------+-----------+-----------+-----------+-----------
|
|
84
|
-
* left | id | rho | rho^2 | rho^3 | rho^4
|
|
85
|
-
* right | pi | rho pi | rho^2 pi | rho^3 pi | rho^4 pi
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
|
-
/* Left line */
|
|
89
|
-
inline const uint8_t RL[5][16] = {
|
|
90
|
-
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, /* Round 1: id */
|
|
91
|
-
{7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8}, /* Round 2: rho */
|
|
92
|
-
{3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12}, /* Round 3: rho^2 */
|
|
93
|
-
{1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2}, /* Round 4: rho^3 */
|
|
94
|
-
{4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13} /* Round 5: rho^4 */
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
/* Right line */
|
|
98
|
-
inline const uint8_t RR[5][16] = {
|
|
99
|
-
{5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12}, /* Round 1: pi */
|
|
100
|
-
{6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2}, /* Round 2: rho pi */
|
|
101
|
-
{15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13}, /* Round 3: rho^2 pi */
|
|
102
|
-
{8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14}, /* Round 4: rho^3 pi */
|
|
103
|
-
{12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11} /* Round 5: rho^4 pi */
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/*
|
|
107
|
-
* Shifts - Since we don't actually re-order the message words according to
|
|
108
|
-
* the permutations above (we could, but it would be slower), these tables
|
|
109
|
-
* come with the permutations pre-applied.
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
/* Shifts, left line */
|
|
113
|
-
inline const uint8_t SL[5][16] = {
|
|
114
|
-
{11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8}, /* Round 1 */
|
|
115
|
-
{7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12}, /* Round 2 */
|
|
116
|
-
{11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5}, /* Round 3 */
|
|
117
|
-
{11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12}, /* Round 4 */
|
|
118
|
-
{9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6} /* Round 5 */
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/* Shifts, right line */
|
|
122
|
-
inline const uint8_t SR[5][16] = {
|
|
123
|
-
{8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6}, /* Round 1 */
|
|
124
|
-
{9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11}, /* Round 2 */
|
|
125
|
-
{9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5}, /* Round 3 */
|
|
126
|
-
{15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8}, /* Round 4 */
|
|
127
|
-
{8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11} /* Round 5 */
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/* Boolean functions */
|
|
131
|
-
|
|
132
|
-
#define F1(x, y, z) ((x) ^ (y) ^ (z))
|
|
133
|
-
#define F2(x, y, z) (((x) & (y)) | (~(x) & (z)))
|
|
134
|
-
#define F3(x, y, z) (((x) | ~(y)) ^ (z))
|
|
135
|
-
#define F4(x, y, z) (((x) & (z)) | ((y) & ~(z)))
|
|
136
|
-
#define F5(x, y, z) ((x) ^ ((y) | ~(z)))
|
|
137
|
-
|
|
138
|
-
/* Round constants, left line */
|
|
139
|
-
inline const uint32_t KL[5] = {
|
|
140
|
-
0x00000000u, /* Round 1: 0 */
|
|
141
|
-
0x5A827999u, /* Round 2: floor(2**30 * sqrt(2)) */
|
|
142
|
-
0x6ED9EBA1u, /* Round 3: floor(2**30 * sqrt(3)) */
|
|
143
|
-
0x8F1BBCDCu, /* Round 4: floor(2**30 * sqrt(5)) */
|
|
144
|
-
0xA953FD4Eu /* Round 5: floor(2**30 * sqrt(7)) */
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
/* Round constants, right line */
|
|
148
|
-
inline const uint32_t KR[5] = {
|
|
149
|
-
0x50A28BE6u, /* Round 1: floor(2**30 * cubert(2)) */
|
|
150
|
-
0x5C4DD124u, /* Round 2: floor(2**30 * cubert(3)) */
|
|
151
|
-
0x6D703EF3u, /* Round 3: floor(2**30 * cubert(5)) */
|
|
152
|
-
0x7A6D76E9u, /* Round 4: floor(2**30 * cubert(7)) */
|
|
153
|
-
0x00000000u /* Round 5: 0 */
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
inline void ripemd160_init(ripemd160_state* self) {
|
|
157
|
-
|
|
158
|
-
memcpy(self->h, initial_h, ripemd160_digest_size);
|
|
159
|
-
memset(&self->buf, 0, sizeof(self->buf));
|
|
160
|
-
self->length = 0;
|
|
161
|
-
self->bufpos = 0;
|
|
162
|
-
self->magic = ripemd160_magic;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/* NB: This is not currently called in the hash object's destructor. */
|
|
166
|
-
inline void ripemd160_wipe(ripemd160_state* self) {
|
|
167
|
-
memset(self, 0, sizeof(ripemd160_state));
|
|
168
|
-
self->magic = 0;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
inline void byteswap32(uint32_t* v) {
|
|
172
|
-
union {
|
|
173
|
-
uint32_t w;
|
|
174
|
-
uint8_t b[4];
|
|
175
|
-
} x, y;
|
|
176
|
-
|
|
177
|
-
x.w = *v;
|
|
178
|
-
y.b[0] = x.b[3];
|
|
179
|
-
y.b[1] = x.b[2];
|
|
180
|
-
y.b[2] = x.b[1];
|
|
181
|
-
y.b[3] = x.b[0];
|
|
182
|
-
*v = y.w;
|
|
183
|
-
|
|
184
|
-
/* Wipe temporary variables */
|
|
185
|
-
x.w = y.w = 0;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
inline void byteswap_digest(uint32_t* p) {
|
|
189
|
-
unsigned int i;
|
|
190
|
-
|
|
191
|
-
for (i = 0; i < 4; i++) {
|
|
192
|
-
byteswap32(p++);
|
|
193
|
-
byteswap32(p++);
|
|
194
|
-
byteswap32(p++);
|
|
195
|
-
byteswap32(p++);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/* The RIPEMD160 compression function. Operates on self->buf */
|
|
200
|
-
inline void ripemd160_compress(ripemd160_state* self) {
|
|
201
|
-
uint8_t w, round;
|
|
202
|
-
uint32_t T;
|
|
203
|
-
uint32_t AL, BL, CL, DL, EL; /* left line */
|
|
204
|
-
uint32_t AR, BR, CR, DR, ER; /* right line */
|
|
205
|
-
|
|
206
|
-
/* Sanity check */
|
|
207
|
-
assert(self->magic == ripemd160_magic);
|
|
208
|
-
assert(self->bufpos == 64);
|
|
209
|
-
if (self->magic != ripemd160_magic || self->bufpos != 64) {
|
|
210
|
-
ripemd160_wipe(self);
|
|
211
|
-
return; /* error */
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/* Load the left and right lines with the initial state */
|
|
215
|
-
AL = AR = self->h[0];
|
|
216
|
-
BL = BR = self->h[1];
|
|
217
|
-
CL = CR = self->h[2];
|
|
218
|
-
DL = DR = self->h[3];
|
|
219
|
-
EL = ER = self->h[4];
|
|
220
|
-
|
|
221
|
-
/* Round 1 */
|
|
222
|
-
round = 0;
|
|
223
|
-
for (w = 0; w < 16; w++) { /* left line */
|
|
224
|
-
T = ROL(SL[round][w], AL + F1(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;
|
|
225
|
-
AL = EL;
|
|
226
|
-
EL = DL;
|
|
227
|
-
DL = ROL(10, CL);
|
|
228
|
-
CL = BL;
|
|
229
|
-
BL = T;
|
|
230
|
-
}
|
|
231
|
-
for (w = 0; w < 16; w++) { /* right line */
|
|
232
|
-
T = ROL(SR[round][w], AR + F5(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;
|
|
233
|
-
AR = ER;
|
|
234
|
-
ER = DR;
|
|
235
|
-
DR = ROL(10, CR);
|
|
236
|
-
CR = BR;
|
|
237
|
-
BR = T;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/* Round 2 */
|
|
241
|
-
round++;
|
|
242
|
-
for (w = 0; w < 16; w++) { /* left line */
|
|
243
|
-
T = ROL(SL[round][w], AL + F2(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;
|
|
244
|
-
AL = EL;
|
|
245
|
-
EL = DL;
|
|
246
|
-
DL = ROL(10, CL);
|
|
247
|
-
CL = BL;
|
|
248
|
-
BL = T;
|
|
249
|
-
}
|
|
250
|
-
for (w = 0; w < 16; w++) { /* right line */
|
|
251
|
-
T = ROL(SR[round][w], AR + F4(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;
|
|
252
|
-
AR = ER;
|
|
253
|
-
ER = DR;
|
|
254
|
-
DR = ROL(10, CR);
|
|
255
|
-
CR = BR;
|
|
256
|
-
BR = T;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/* Round 3 */
|
|
260
|
-
round++;
|
|
261
|
-
for (w = 0; w < 16; w++) { /* left line */
|
|
262
|
-
T = ROL(SL[round][w], AL + F3(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;
|
|
263
|
-
AL = EL;
|
|
264
|
-
EL = DL;
|
|
265
|
-
DL = ROL(10, CL);
|
|
266
|
-
CL = BL;
|
|
267
|
-
BL = T;
|
|
268
|
-
}
|
|
269
|
-
for (w = 0; w < 16; w++) { /* right line */
|
|
270
|
-
T = ROL(SR[round][w], AR + F3(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;
|
|
271
|
-
AR = ER;
|
|
272
|
-
ER = DR;
|
|
273
|
-
DR = ROL(10, CR);
|
|
274
|
-
CR = BR;
|
|
275
|
-
BR = T;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/* Round 4 */
|
|
279
|
-
round++;
|
|
280
|
-
for (w = 0; w < 16; w++) { /* left line */
|
|
281
|
-
T = ROL(SL[round][w], AL + F4(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;
|
|
282
|
-
AL = EL;
|
|
283
|
-
EL = DL;
|
|
284
|
-
DL = ROL(10, CL);
|
|
285
|
-
CL = BL;
|
|
286
|
-
BL = T;
|
|
287
|
-
}
|
|
288
|
-
for (w = 0; w < 16; w++) { /* right line */
|
|
289
|
-
T = ROL(SR[round][w], AR + F2(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;
|
|
290
|
-
AR = ER;
|
|
291
|
-
ER = DR;
|
|
292
|
-
DR = ROL(10, CR);
|
|
293
|
-
CR = BR;
|
|
294
|
-
BR = T;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/* Round 5 */
|
|
298
|
-
round++;
|
|
299
|
-
for (w = 0; w < 16; w++) { /* left line */
|
|
300
|
-
T = ROL(SL[round][w], AL + F5(BL, CL, DL) + self->buf.w[RL[round][w]] + KL[round]) + EL;
|
|
301
|
-
AL = EL;
|
|
302
|
-
EL = DL;
|
|
303
|
-
DL = ROL(10, CL);
|
|
304
|
-
CL = BL;
|
|
305
|
-
BL = T;
|
|
306
|
-
}
|
|
307
|
-
for (w = 0; w < 16; w++) { /* right line */
|
|
308
|
-
T = ROL(SR[round][w], AR + F1(BR, CR, DR) + self->buf.w[RR[round][w]] + KR[round]) + ER;
|
|
309
|
-
AR = ER;
|
|
310
|
-
ER = DR;
|
|
311
|
-
DR = ROL(10, CR);
|
|
312
|
-
CR = BR;
|
|
313
|
-
BR = T;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/* Final mixing stage */
|
|
317
|
-
T = self->h[1] + CL + DR;
|
|
318
|
-
self->h[1] = self->h[2] + DL + ER;
|
|
319
|
-
self->h[2] = self->h[3] + EL + AR;
|
|
320
|
-
self->h[3] = self->h[4] + AL + BR;
|
|
321
|
-
self->h[4] = self->h[0] + BL + CR;
|
|
322
|
-
self->h[0] = T;
|
|
323
|
-
|
|
324
|
-
/* Clear the buffer and wipe the temporary variables */
|
|
325
|
-
T = AL = BL = CL = DL = EL = AR = BR = CR = DR = ER = 0;
|
|
326
|
-
memset(&self->buf, 0, sizeof(self->buf));
|
|
327
|
-
self->bufpos = 0;
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
template<typename T, typename std::enable_if<sizeof(T) == 1>::type* = nullptr>
|
|
331
|
-
inline void ripemd160_update(ripemd160_state* self, T* p, int length) {
|
|
332
|
-
unsigned int bytes_needed;
|
|
333
|
-
|
|
334
|
-
/* Some assertions */
|
|
335
|
-
assert(self->magic == ripemd160_magic);
|
|
336
|
-
assert(p != NULL && length >= 0);
|
|
337
|
-
|
|
338
|
-
/* NDEBUG is probably defined, so check for invalid inputs explicitly. */
|
|
339
|
-
if (self->magic != ripemd160_magic || p == NULL || length < 0) {
|
|
340
|
-
/* error */
|
|
341
|
-
ripemd160_wipe(self);
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/* We never leave a full buffer */
|
|
346
|
-
assert(self->bufpos < 64);
|
|
347
|
-
|
|
348
|
-
while (length > 0) {
|
|
349
|
-
/* Figure out how many bytes we need to fill the internal buffer. */
|
|
350
|
-
bytes_needed = 64 - self->bufpos;
|
|
351
|
-
|
|
352
|
-
if ((unsigned int)length >= bytes_needed) {
|
|
353
|
-
/* We have enough bytes, so copy them into the internal buffer and run
|
|
354
|
-
* the compression function. */
|
|
355
|
-
memcpy(&self->buf.b[self->bufpos], p, bytes_needed);
|
|
356
|
-
self->bufpos += bytes_needed;
|
|
357
|
-
self->length += bytes_needed << 3; /* length is in bits */
|
|
358
|
-
p += bytes_needed;
|
|
359
|
-
ripemd160_compress(self);
|
|
360
|
-
length -= bytes_needed;
|
|
361
|
-
continue;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/* We do not have enough bytes to fill the internal buffer.
|
|
365
|
-
* Copy what's there and return. */
|
|
366
|
-
memcpy(&self->buf.b[self->bufpos], p, length);
|
|
367
|
-
self->bufpos += length;
|
|
368
|
-
self->length += length << 3; /* length is in bits */
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
inline void ripemd160_copy(const ripemd160_state* source, ripemd160_state* dest) {
|
|
374
|
-
memcpy(dest, source, sizeof(ripemd160_state));
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
inline int ripemd160_digest(const ripemd160_state* self, unsigned char* out) {
|
|
378
|
-
ripemd160_state tmp;
|
|
379
|
-
|
|
380
|
-
assert(self->magic == ripemd160_magic);
|
|
381
|
-
assert(out != NULL);
|
|
382
|
-
if (self->magic != ripemd160_magic || out == NULL) {
|
|
383
|
-
return 0;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
ripemd160_copy(self, &tmp);
|
|
387
|
-
|
|
388
|
-
/* Append the padding */
|
|
389
|
-
tmp.buf.b[tmp.bufpos++] = 0x80;
|
|
390
|
-
|
|
391
|
-
if (tmp.bufpos > 56) {
|
|
392
|
-
tmp.bufpos = 64;
|
|
393
|
-
ripemd160_compress(&tmp);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/* Append the length */
|
|
397
|
-
tmp.buf.w[14] = (uint32_t)(tmp.length & 0xFFFFffffu);
|
|
398
|
-
tmp.buf.w[15] = (uint32_t)((tmp.length >> 32) & 0xFFFFffffu);
|
|
399
|
-
tmp.bufpos = 64;
|
|
400
|
-
ripemd160_compress(&tmp);
|
|
401
|
-
|
|
402
|
-
/* Copy the final state into the output buffer */
|
|
403
|
-
memcpy(out, &tmp.h, ripemd160_digest_size);
|
|
404
|
-
|
|
405
|
-
if (tmp.magic == ripemd160_magic) {
|
|
406
|
-
/* success */
|
|
407
|
-
ripemd160_wipe(&tmp);
|
|
408
|
-
return 1;
|
|
409
|
-
} else {
|
|
410
|
-
/* error */
|
|
411
|
-
ripemd160_wipe(&tmp);
|
|
412
|
-
memset(out, 0, ripemd160_digest_size);
|
|
413
|
-
return 0;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
} // namespace ripemd160
|