8#include <botan/bigint.h>
10#include <botan/internal/bit_ops.h>
11#include <botan/internal/mp_core.h>
19 grow_to(std::max(x_sw, y_words) + 1);
21 if(
sign() == y_sign) {
26 if(relative_size >= 0) {
35 if(relative_size < 0) {
37 }
else if(relative_size == 0) {
47 throw Invalid_Argument(
"BigInt::mod_add expects all arguments are positive");
64 BOTAN_ARG_CHECK(mod_sw > 0,
"BigInt::mod_add modulus must be positive");
70 if(ws.size() < 3 * mod_sw) {
71 ws.resize(3 * mod_sw);
92 throw Invalid_Argument(
"BigInt::mod_sub expects all arguments are positive");
104 if(ws.size() < mod_sw) {
110 }
else if(mod_sw == 6) {
125 *
this *=
static_cast<word
>(y);
132 throw Invalid_State(
"BigInt::sub_rev requires this is positive");
137 ws.resize(std::max(x_sw, y_sw));
153 return this->
mul(y, ws);
161 if(x_sw == 0 || y_sw == 0) {
164 }
else if(x_sw == 1 && y_sw) {
167 }
else if(y_sw == 1 && x_sw) {
171 const size_t new_size = x_sw + y_sw + 1;
214 (*this) >>= (y.
bits() - 1);
216 (*this) = (*this) / y;
225 return (*
this = (*
this) % mod);
239 remainder = (
word_at(0) & (mod - 1));
242 for(
size_t i = sw; i > 0; --i) {
248 remainder = mod - remainder;
251 m_data.set_to_zero();
252 m_data.set_word_at(0, remainder);
264 m_data.grow_to(new_size);
266 bigint_shl1(m_data.mutable_data(), new_size, sw, shift);
275 bigint_shr1(m_data.mutable_data(), m_data.size(), shift);
#define BOTAN_DEBUG_ASSERT(expr)
#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)
BigInt & mod_add(const BigInt &y, const BigInt &mod, secure_vector< word > &ws)
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)
const word * _data() const
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
constexpr Mask< T > conditional_copy_mem(Mask< T > mask, T *to, const T *from0, const T *from1, size_t elems)
constexpr void bigint_linmul3(W z[], const W x[], size_t x_size, W y)
constexpr bool is_power_of_2(T arg)
constexpr void bigint_shr1(W x[], size_t x_size, size_t shift)
constexpr void bigint_mod_sub_n(W t[], const W s[], const W mod[], W ws[])
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)
constexpr auto bigint_sub3(W z[], const W x[], size_t x_size, const W y[], size_t y_size) -> W
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)
constexpr void bigint_shl1(W x[], size_t x_size, size_t x_words, size_t shift)
constexpr int32_t bigint_cmp(const W x[], size_t x_size, const W y[], size_t y_size)
void carry(int64_t &h0, int64_t &h1)
constexpr auto bigint_modop_vartime(W n1, W n0, W d) -> W
constexpr auto bigint_sub_abs(W z[], const W x[], const W y[], size_t N, W ws[]) -> CT::Mask< W >
constexpr void bigint_add2(W x[], size_t x_size, const W y[], size_t y_size)
std::vector< T, secure_allocator< T > > secure_vector
constexpr auto bigint_sub2(W x[], size_t x_size, const W y[], size_t y_size) -> W
constexpr void bigint_sub2_rev(W x[], const W y[], size_t y_size)
constexpr void clear_mem(T *ptr, size_t n)
constexpr void bigint_mod_sub(W t[], const W s[], const W mod[], size_t mod_sw, W ws[])
constexpr auto bigint_add3_nc(W z[], const W x[], size_t x_size, const W y[], size_t y_size) -> W
constexpr auto bigint_linmul2(W x[], size_t x_size, W y) -> W