20#ifndef RIPPLE_PROTOCOL_B58_UTILS_H_INCLUDED
21#define RIPPLE_PROTOCOL_B58_UTILS_H_INCLUDED
23#include <xrpl/basics/contract.h>
24#include <xrpl/beast/utility/instrumentation.h>
25#include <xrpl/protocol/detail/token_errors.h>
27#include <boost/outcome.hpp>
28#include <boost/outcome/result.hpp>
38using Result = boost::outcome_v2::result<T, std::error_code>;
48 return {a / b, a % b};
55 unsigned __int128
const x = a;
56 unsigned __int128
const y = b;
57 unsigned __int128
const c = x * y + carry;
58 return {c & 0xffff'ffff'ffff'ffff, c >> 64};
64 unsigned __int128
const x = a;
65 unsigned __int128
const y = b;
66 unsigned __int128
const c = x + y;
67 return {c & 0xffff'ffff'ffff'ffff, c >> 64};
80 return TokenCodecErrc::inputTooSmall;
84 std::tie(a[0], carry) = carrying_add(a[0], b);
86 for (
auto& v : a.subspan(1))
90 return TokenCodecErrc::success;
92 std::tie(v, carry) = carrying_add(v, 1);
96 return TokenCodecErrc::overflowAdd;
98 return TokenCodecErrc::success;
106 return TokenCodecErrc::inputTooSmall;
109 auto const last_index = a.size() - 1;
110 if (a[last_index] != 0)
112 return TokenCodecErrc::inputTooLarge;
116 for (
auto& coeff : a.subspan(0, last_index))
118 std::tie(coeff, carry) = carrying_mul(coeff, b, carry);
120 a[last_index] = carry;
121 return TokenCodecErrc::success;
129 if (numerator.
size() == 0)
134 "ripple::b58_fast::detail::inplace_bigint_div_rem : empty "
141 unsigned __int128
const high128 = high;
142 unsigned __int128
const low128 = low;
143 return ((high128 << 64) | low128);
146 [](
unsigned __int128 num,
148 unsigned __int128
const denom128 = denom;
149 unsigned __int128
const d = num / denom128;
150 unsigned __int128
const r = num - (denom128 * d);
153 "ripple::b58_fast::detail::inplace_bigint_div_rem::div_rem_64 : "
154 "valid division result");
157 "ripple::b58_fast::detail::inplace_bigint_div_rem::div_rem_64 : "
163 int const last_index = numerator.
size() - 1;
164 std::tie(numerator[last_index], prev_rem) =
165 div_rem(numerator[last_index], divisor);
166 for (
int i = last_index - 1; i >= 0; --i)
168 unsigned __int128
const cur_num = to_u128(prev_rem, numerator[i]);
169 std::tie(numerator[i], prev_rem) = div_rem_64(cur_num, divisor);
184 "ripple::b58_fast::detail::b58_10_to_b58_be : valid input");
191 std::tie(input, rem) = div_rem(input, 58);
192 result[resultSize - 1 - i] = rem;
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
boost::outcome_v2::result< T, std::error_code > Result