8#include <botan/internal/divide.h>
10#include <botan/internal/bit_ops.h>
11#include <botan/internal/ct_utils.h>
12#include <botan/internal/mp_core.h>
22 q.cond_flip_sign(x.sign() != y.sign());
24 if(x.is_negative() && r.is_nonzero()) {
59 const size_t x_bits = x.
bits();
65 for(
size_t i = 0; i != x_bits; ++i) {
66 const size_t b = x_bits - 1 - i;
78 sign_fixup(x, y, q, r);
88 const size_t x_bits = k + 1;
89 const size_t y_bits = y.
bits();
104 for(
size_t i = y_bits - 1; i != x_bits; ++i) {
105 const size_t b = x_bits - 1 - i;
129 const size_t x_bits = x.
bits();
134 for(
size_t i = 0; i != x_bits; ++i) {
135 const size_t b = x_bits - 1 - i;
141 r +=
static_cast<word>(x_b);
145 r = r_gte_y.select(r - y, r);
172 const size_t x_bits = x.
bits();
176 for(
size_t i = 0; i != x_bits; ++i) {
177 const size_t b = x_bits - 1 - i;
183 r +=
static_cast<word>(x_b);
186 r = r_gte_y.select(r - y, r);
199 const size_t x_bits = x.
bits();
204 for(
size_t i = 0; i != x_bits; ++i) {
205 const size_t b = x_bits - 1 - i;
235 const size_t y_words = y_arg.
sig_words();
257 const size_t t = y_words - 1;
258 const size_t n = std::max(y_words, r.
sig_words()) - 1;
275 for(
size_t j = n; j != t; --j) {
283 for(
size_t k = 0; k != 2; ++k) {
284 if(division_check_vartime(qjt, y_t0, y_t1, x_j0, x_j1, x_j2)) {
295 r -= qjt * shifted_y;
302 q_words[j - t - 1] = qjt;
309 sign_fixup(x, y_arg, q, r);
#define BOTAN_ASSERT_NOMSG(expr)
#define BOTAN_DEBUG_ASSERT(expr)
#define BOTAN_ARG_CHECK(expr, msg)
void conditionally_set_bit(size_t n, bool set_it)
void grow_to(size_t n) const
size_t top_bits_free() const
word word_at(size_t n) const
const word * _data() const
void ct_cond_swap(bool predicate, BigInt &other)
size_t reduce_below(const BigInt &mod, secure_vector< word > &ws)
bool get_bit(size_t n) const
static BigInt with_capacity(size_t n)
static constexpr Mask< T > is_gte(T x, T y)
static constexpr Mask< T > expand_top_bit(T v)
constexpr void bigint_cnd_swap(W cnd, W x[], W y[], size_t size)
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
word ct_mod_word(const BigInt &x, word y)
constexpr auto word_madd2(W a, W b, W *c) -> W
constexpr auto bigint_sub3(W z[], const W x[], size_t x_size, const W y[], size_t y_size) -> W
constexpr void bigint_shl1(W x[], size_t x_size, size_t x_words, size_t shift)
BigInt ct_modulo(const BigInt &x, const BigInt &y)
void ct_divide(const BigInt &x, const BigInt &y, BigInt &q_out, BigInt &r_out)
void ct_divide_word(const BigInt &x, word y, BigInt &q_out, word &r_out)
BigInt ct_divide_pow2k(size_t k, const BigInt &y)
std::vector< T, secure_allocator< T > > secure_vector
std::conditional_t< HasNative64BitRegisters, std::uint64_t, uint32_t > word
constexpr auto bigint_divop_vartime(W n1, W n0, W d) -> W