8#include <botan/bigint.h>
9#include <botan/internal/mp_core.h>
10#include <botan/internal/bit_ops.h>
19 grow_to(std::max(x_sw, y_words) + 1);
27 const int32_t relative_size =
bigint_cmp(
data(), x_sw, y, y_words);
29 if(relative_size >= 0)
43 else if(relative_size == 0)
53 throw Invalid_Argument(
"BigInt::mod_add expects all arguments are positive");
69 BOTAN_ARG_CHECK(mod_sw > 0,
"BigInt::mod_add modulus must be positive");
75 if(ws.size() < 3*mod_sw)
83 borrow =
bigint_sub3(&ws[mod_sw], this->
data(), mod_sw, &ws[0], mod_sw);
97 throw Invalid_Argument(
"BigInt::mod_sub expects all arguments are positive");
108 if(ws.size() < mod_sw)
128 *
this *=
static_cast<word
>(y);
136 throw Invalid_State(
"BigInt::sub_rev requires this is positive");
140 ws.resize(std::max(x_sw, y_sw));
157 return this->
mul(y, ws);
166 if(x_sw == 0 || y_sw == 0)
171 else if(x_sw == 1 && y_sw)
176 else if(y_sw == 1 && x_sw)
183 const size_t new_size = x_sw + y_sw + 1;
190 ws.data(), ws.size());
207 ws.data(), ws.size());
235 (*this) >>= (y.
bits() - 1);
237 (*
this) = (*this) / y;
246 return (*
this = (*
this) % mod);
261 remainder = (
word_at(0) & (mod - 1));
266 for(
size_t i = sw; i > 0; --i)
271 remainder = mod - remainder;
273 m_data.set_to_zero();
274 m_data.set_word_at(0, remainder);
290 const size_t new_size =
size + shift_words + (bits_free < shift_bits);
292 m_data.grow_to(new_size);
294 bigint_shl1(m_data.mutable_data(), new_size,
size, shift_words, shift_bits);
307 bigint_shr1(m_data.mutable_data(), m_data.size(), shift_words, shift_bits);
#define BOTAN_DEBUG_ASSERT(expr)
#define BOTAN_UNUSED(...)
#define BOTAN_ARG_CHECK(expr, msg)
BigInt & operator>>=(size_t shift)
BigInt & mod_mul(uint8_t y, const BigInt &mod, secure_vector< word > &ws)
BigInt & operator/=(const BigInt &y)
void set_word_at(size_t i, word w)
BigInt & rev_sub(const word y[], size_t y_words, secure_vector< word > &ws)
void grow_to(size_t n) const
void set_words(const word w[], size_t len)
BigInt & operator*=(const BigInt &y)
size_t top_bits_free() const
BigInt & mod_add(const BigInt &y, const BigInt &mod, secure_vector< word > &ws)
const word * data() const
word word_at(size_t n) const
BigInt & mul(const BigInt &y, secure_vector< word > &ws)
void cond_flip_sign(bool predicate)
BigInt & mod_sub(const BigInt &y, const BigInt &mod, secure_vector< word > &ws)
BigInt & operator%=(const BigInt &y)
BigInt & operator<<=(size_t shift)
BigInt & add(const word y[], size_t y_words, Sign sign)
size_t reduce_below(const BigInt &mod, secure_vector< word > &ws)
BigInt & square(secure_vector< word > &ws)
void swap_reg(secure_vector< word > ®)
#define BOTAN_MP_WORD_BITS
Mask< T > conditional_copy_mem(T cnd, T *to, const T *from0, const T *from1, size_t elems)
void bigint_sub2_rev(word x[], const word y[], size_t y_size)
void bigint_shr1(word x[], size_t x_size, size_t word_shift, size_t bit_shift)
void bigint_linmul3(word z[], const word x[], size_t x_size, word y)
word bigint_sub2(word x[], size_t x_size, const word y[], size_t y_size)
void bigint_shl1(word x[], size_t x_size, size_t x_words, size_t word_shift, size_t bit_shift)
void bigint_sqr(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, word workspace[], size_t ws_size)
CT::Mask< word > bigint_sub_abs(word z[], const word x[], const word y[], size_t N, word ws[])
void bigint_mul(word z[], size_t z_size, const word x[], size_t x_size, size_t x_sw, const word y[], size_t y_size, size_t y_sw, word workspace[], size_t ws_size)
void carry(int64_t &h0, int64_t &h1)
void bigint_add2(word x[], size_t x_size, const word y[], size_t y_size)
word bigint_add3_nc(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
word bigint_linmul2(word x[], size_t x_size, word y)
word bigint_modop(word n1, word n0, word d)
int32_t bigint_cmp(const word x[], size_t x_size, const word y[], size_t y_size)
std::vector< T, secure_allocator< T > > secure_vector
constexpr bool is_power_of_2(T arg)
word bigint_sub3(word z[], const word x[], size_t x_size, const word y[], size_t y_size)
constexpr void clear_mem(T *ptr, size_t n)
void bigint_mod_sub(word t[], const word s[], const word mod[], size_t mod_sw, word ws[])