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>
37using Result = boost::outcome_v2::result<T, std::error_code>;
47 return {a / b, a % b};
54 unsigned __int128
const x = a;
55 unsigned __int128
const y = b;
56 unsigned __int128
const c = x * y + carry;
57 return {c & 0xffff'ffff'ffff'ffff, c >> 64};
63 unsigned __int128
const x = a;
64 unsigned __int128
const y = b;
65 unsigned __int128
const c = x + y;
66 return {c & 0xffff'ffff'ffff'ffff, c >> 64};
79 return TokenCodecErrc::inputTooSmall;
83 std::tie(a[0], carry) = carrying_add(a[0], b);
85 for (
auto& v : a.subspan(1))
89 return TokenCodecErrc::success;
91 std::tie(v, carry) = carrying_add(v, 1);
95 return TokenCodecErrc::overflowAdd;
97 return TokenCodecErrc::success;
105 return TokenCodecErrc::inputTooSmall;
108 auto const last_index = a.size() - 1;
109 if (a[last_index] != 0)
111 return TokenCodecErrc::inputTooLarge;
115 for (
auto& coeff : a.subspan(0, last_index))
117 std::tie(coeff, carry) = carrying_mul(coeff, b, carry);
119 a[last_index] = carry;
120 return TokenCodecErrc::success;
128 if (numerator.
size() == 0)
133 "ripple::b58_fast::detail::inplace_bigint_div_rem : empty "
140 unsigned __int128
const high128 = high;
141 unsigned __int128
const low128 = low;
142 return ((high128 << 64) | low128);
145 [](
unsigned __int128 num,
147 unsigned __int128
const denom128 = denom;
148 unsigned __int128
const d = num / denom128;
149 unsigned __int128
const r = num - (denom128 * d);
152 "ripple::b58_fast::detail::inplace_bigint_div_rem::div_rem_64 : "
153 "valid division result");
156 "ripple::b58_fast::detail::inplace_bigint_div_rem::div_rem_64 : "
162 int const last_index = numerator.
size() - 1;
163 std::tie(numerator[last_index], prev_rem) =
164 div_rem(numerator[last_index], divisor);
165 for (
int i = last_index - 1; i >= 0; --i)
167 unsigned __int128
const cur_num = to_u128(prev_rem, numerator[i]);
168 std::tie(numerator[i], prev_rem) = div_rem_64(cur_num, divisor);
183 "ripple::b58_fast::detail::b58_10_to_b58_be : valid input");
190 std::tie(input, rem) = div_rem(input, 58);
191 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