30inline void extract3(limb_t &
c0, limb_t &
c1, limb_t &
c2, limb_t &n) {
38inline void mul(limb_t &
c0, limb_t &
c1,
const limb_t &
a,
const limb_t &
b) {
39 double_limb_t
t = (double_limb_t)
a *
b;
46 limb_t &
d2,
const limb_t &n) {
47 double_limb_t
t = (double_limb_t)
d0 * n +
c0;
50 t += (double_limb_t)
d1 * n +
c1;
57inline void muln2(limb_t &
c0, limb_t &
c1,
const limb_t &n) {
58 double_limb_t
t = (double_limb_t)
c0 * n;
61 t += (double_limb_t)
c1 * n;
66inline void muladd3(limb_t &
c0, limb_t &
c1, limb_t &
c2,
const limb_t &
a,
68 double_limb_t
t = (double_limb_t)
a *
b;
69 limb_t
th =
t >> LIMB_SIZE;
81 double_limb_t
t = (double_limb_t)
a *
b;
82 limb_t
th =
t >> LIMB_SIZE;
86 limb_t
tt =
th + ((
c0 <
tl) ? 1 : 0);
121 for (
int j = 0;
j <
sq; ++
j) {
134 for (
int i = 1; i <
LIMBS; ++i) {
135 if (this->
limbs[i] != std::numeric_limits<limb_t>::max()) {
145 for (
int i = 0; i <
LIMBS; ++i) {
160 for (
int i = 0; i < 11; ++i) {
162 for (
int j = 0;
j < (1 << i); ++
j) {
165 p[i + 1].Multiply(
p[i]);
195 for (
int j = 0;
j <
LIMBS - 1; ++
j) {
198 for (
int i = 2 +
j; i <
LIMBS; ++i) {
202 for (
int i = 0; i <
j + 1; ++i) {
210 for (
int i = 0; i <
LIMBS; ++i) {
242 for (
int j = 0;
j <
LIMBS - 1; ++
j) {
244 for (
int i = 0; i < (
LIMBS - 1 -
j) / 2; ++i) {
246 this->
limbs[LIMBS - 1 - i]);
253 for (
int i = 0; i < (
j + 1) / 2; ++i) {
264 for (
int i = 0; i <
LIMBS / 2; ++i) {
293 for (
int i = 1; i <
LIMBS; ++i) {
304 if (
a.IsOverflow()) {
307 inv =
b.GetInverse();
309 inv =
a.GetInverse();
319 for (
int i = 0; i <
LIMBS; ++i) {
320 if (
sizeof(
limb_t) == 4) {
322 }
else if (
sizeof(
limb_t) == 8) {
329 for (
int i = 0; i <
LIMBS; ++i) {
330 if (
sizeof(
limb_t) == 4) {
332 }
else if (
sizeof(
limb_t) == 8) {
350 m_numerator = ToNum3072(
in);
354 m_numerator.Divide(m_denominator);
356 m_denominator.SetToOne();
359 m_numerator.ToBytes(data);
365 m_numerator.Multiply(
mul.m_numerator);
366 m_denominator.Multiply(
mul.m_denominator);
371 m_numerator.Multiply(
div.m_denominator);
372 m_denominator.Multiply(
div.m_numerator);
377 m_numerator.Multiply(ToNum3072(
in));
382 m_denominator.Multiply(ToNum3072(
in));
A class for ChaCha20 256-bit stream cipher developed by Daniel J.
void Keystream(uint8_t *c, size_t bytes)
outputs the keystream of size <bytes> into
A writer stream (for serialization) that computes a 256-bit hash.
A class representing MuHash sets.
Num3072 ToNum3072(Span< const uint8_t > in)
MuHash3072 & Remove(Span< const uint8_t > in) noexcept
void Finalize(uint256 &out) noexcept
MuHash3072 & operator/=(const MuHash3072 &div) noexcept
MuHash3072 & Insert(Span< const uint8_t > in) noexcept
MuHash3072 & operator*=(const MuHash3072 &mul) noexcept
Num3072 GetInverse() const
static constexpr int LIMBS
static constexpr size_t BYTE_SIZE
bool IsOverflow() const
Indicates whether d is larger than the modulus.
void ToBytes(uint8_t(&out)[BYTE_SIZE])
static constexpr int LIMB_SIZE
void Divide(const Num3072 &a)
void Multiply(const Num3072 &a)
A Span is an object that can refer to a contiguous sequence of objects.
static void WriteLE32(uint8_t *ptr, uint32_t x)
static uint64_t ReadLE64(const uint8_t *ptr)
static uint32_t ReadLE32(const uint8_t *ptr)
static void WriteLE64(uint8_t *ptr, uint64_t x)
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...