8#include <botan/internal/divide.h>
10#include <botan/internal/ct_utils.h>
11#include <botan/internal/mp_core.h>
21 q.cond_flip_sign(x.sign() != y.sign());
23 if(x.is_negative() && r.is_nonzero()) {
58 const size_t x_bits = x.
bits();
64 for(
size_t i = 0; i != x_bits; ++i) {
65 const size_t b = x_bits - 1 - i;
77 sign_fixup(x, y, q, r);
87 const size_t x_bits = k + 1;
88 const size_t y_bits = y.
bits();
103 for(
size_t i = y_bits - 1; i != x_bits; ++i) {
104 const size_t b = x_bits - 1 - i;
128 const size_t x_bits = x.
bits();
133 for(
size_t i = 0; i != x_bits; ++i) {
134 const size_t b = x_bits - 1 - i;
140 r +=
static_cast<word>(x_b);
144 r = r_gte_y.select(r - y, r);
171 const size_t x_bits = x.
bits();
175 for(
size_t i = 0; i != x_bits; ++i) {
176 const size_t b = x_bits - 1 - i;
182 r +=
static_cast<word>(x_b);
185 r = r_gte_y.select(r - y, r);
198 const size_t x_bits = x.
bits();
203 for(
size_t i = 0; i != x_bits; ++i) {
204 const size_t b = x_bits - 1 - i;
248 const size_t t = y_words - 1;
249 const size_t n = std::max(y_words, r.
sig_words()) - 1;
258 BigInt shifted_y = y << (WB * (n - t));
270 for(
size_t i = n; i != t; --i) {
278 for(
size_t j = 0; j != 2; ++j) {
279 if(division_check_vartime(qit, y_t0, y_t1, x_i0, x_i1, x_i2)) {
302 r -= qit * shifted_y;
313 q_words[i - t - 1] = qit;
331 const size_t y_words = y_arg.
sig_words();
353 const size_t t = y_words - 1;
354 const size_t n = std::max(y_words, r.
sig_words()) - 1;
362 BigInt shifted_y = y << (WB * (n - t));
373 for(
size_t i = n; i != t; --i) {
381 for(
size_t j = 0; j != 2; ++j) {
382 if(division_check_vartime(qit, y_t0, y_t1, x_i0, x_i1, x_i2)) {
394 r -= qit * shifted_y;
403 q_words[i - t - 1] = qit;
410 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 W vartime_div_2to1(W n1, W n0) const
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)
BigInt vartime_divide_pow2k(size_t k, const BigInt &y_arg)
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