3#include <xrpl/basics/contract.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/protocol/detail/token_errors.h>
7#include <boost/outcome.hpp>
8#include <boost/outcome/result.hpp>
17using Result = boost::outcome_v2::result<T, std::error_code>;
21namespace b58_fast::detail {
27 return {a / b, a % b};
34 unsigned __int128
const x = a;
35 unsigned __int128
const y = b;
36 unsigned __int128
const c = (x * y) + carry;
37 return {c & 0xffff'ffff'ffff'ffff, c >> 64};
43 unsigned __int128
const x = a;
44 unsigned __int128
const y = b;
45 unsigned __int128
const c = x + y;
46 return {c & 0xffff'ffff'ffff'ffff, c >> 64};
63 std::tie(a[0], carry) = carryingAdd(a[0], b);
65 for (
auto& v : a.subspan(1))
71 std::tie(v, carry) = carryingAdd(v, 1);
88 auto const lastIndex = a.size() - 1;
89 if (a[lastIndex] != 0)
95 for (
auto& coeff : a.subspan(0, lastIndex))
97 std::tie(coeff, carry) = carryingMul(coeff, b, carry);
108 if (numerator.
empty())
114 "xrpl::b58_fast::detail::inplaceBigintDivRem : empty "
121 unsigned __int128
const high128 = high;
122 unsigned __int128
const low128 = low;
123 return ((high128 << 64) | low128);
125 auto divRe64 = [](
unsigned __int128 num,
127 unsigned __int128
const denom128 = denom;
128 unsigned __int128
const d = num / denom128;
129 unsigned __int128
const r = num - (denom128 * d);
132 "xrpl::b58_fast::detail::inplaceBigintDivRem::divRe64 : "
133 "valid division result");
136 "xrpl::b58_fast::detail::inplaceBigintDivRem::divRe64 : "
142 int const lastIndex = numerator.
size() - 1;
143 std::tie(numerator[lastIndex], prevRem) = divRem(numerator[lastIndex], divisor);
144 for (
int i = lastIndex - 1; i >= 0; --i)
146 unsigned __int128
const curNum = toU128(prevRem, numerator[i]);
147 std::tie(numerator[i], prevRem) = divRe64(curNum, divisor);
158 [[maybe_unused]]
static constexpr std::uint64_t kB5810 = 430804206899405824;
159 XRPL_ASSERT(input < kB5810,
"xrpl::b58_fast::detail::b5810ToB58Be : valid input");
166 std::tie(input, rem) = divRem(input, 58);
167 result[kResultSize - 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