3#include <xrpl/beast/utility/instrumentation.h>
4#include <xrpl/protocol/detail/token_errors.h>
6#include <boost/outcome.hpp>
7#include <boost/outcome/result.hpp>
19using Result = boost::outcome_v2::result<T, std::error_code>;
23namespace b58_fast::detail {
29 return {a / b, a % b};
36 unsigned __int128
const x = a;
37 unsigned __int128
const y = b;
38 unsigned __int128
const c = (x * y) + carry;
39 return {c & 0xffff'ffff'ffff'ffff, c >> 64};
45 unsigned __int128
const x = a;
46 unsigned __int128
const y = b;
47 unsigned __int128
const c = x + y;
48 return {c & 0xffff'ffff'ffff'ffff, c >> 64};
65 std::tie(a[0], carry) = carryingAdd(a[0], b);
67 for (
auto& v : a.subspan(1))
73 std::tie(v, carry) = carryingAdd(v, 1);
90 auto const lastIndex = a.size() - 1;
91 if (a[lastIndex] != 0)
97 for (
auto& coeff : a.subspan(0, lastIndex))
99 std::tie(coeff, carry) = carryingMul(coeff, b, carry);
101 a[lastIndex] = carry;
110 if (numerator.
empty())
116 "xrpl::b58_fast::detail::inplaceBigintDivRem : empty "
123 unsigned __int128
const high128 = high;
124 unsigned __int128
const low128 = low;
125 return ((high128 << 64) | low128);
127 auto divRe64 = [](
unsigned __int128 num,
129 unsigned __int128
const denom128 = denom;
130 unsigned __int128
const d = num / denom128;
131 unsigned __int128
const r = num - (denom128 * d);
134 "xrpl::b58_fast::detail::inplaceBigintDivRem::divRe64 : "
135 "valid division result");
138 "xrpl::b58_fast::detail::inplaceBigintDivRem::divRe64 : "
144 int const lastIndex = numerator.
size() - 1;
145 std::tie(numerator[lastIndex], prevRem) = divRem(numerator[lastIndex], divisor);
146 for (
int i = lastIndex - 1; i >= 0; --i)
148 unsigned __int128
const curNum = toU128(prevRem, numerator[i]);
149 std::tie(numerator[i], prevRem) = divRe64(curNum, divisor);
160 [[maybe_unused]]
static constexpr std::uint64_t kB5810 = 430804206899405824;
161 XRPL_ASSERT(input < kB5810,
"xrpl::b58_fast::detail::b5810ToB58Be : valid input");
168 std::tie(input, rem) = divRem(input, 58);
169 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