8#include <botan/internal/divide.h>
10#include <botan/exceptn.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.signum() < 0 && r.signum() != 0) {
63 const size_t x_bits = x.
bits();
65 const size_t r_words = y_words + 1;
71 for(
size_t i = 0; i != x_bits; ++i) {
72 const size_t b = x_bits - 1 - i;
84 sign_fixup(x, y, q, r);
94 const size_t x_bits = k + 1;
95 const size_t y_bits = y.
bits();
110 for(
size_t i = y_bits - 1; i != x_bits; ++i) {
111 const size_t b = x_bits - 1 - i;
135 const size_t x_bits = x.
bits();
140 for(
size_t i = 0; i != x_bits; ++i) {
141 const size_t b = x_bits - 1 - i;
147 r +=
static_cast<word>(x_b);
151 r = r_gte_y.select(r - y, r);
178 const size_t x_bits = x.
bits();
182 for(
size_t i = 0; i != x_bits; ++i) {
183 const size_t b = x_bits - 1 - i;
189 r +=
static_cast<word>(x_b);
192 r = r_gte_y.select(r - y, r);
204 const size_t r_words = y_words + 1;
206 const size_t x_bits = x.
bits();
211 for(
size_t i = 0; i != x_bits; ++i) {
212 const size_t b = x_bits - 1 - i;
256 const size_t t = y_words - 1;
257 const size_t n = std::max(y_words, r.
sig_words()) - 1;
266 BigInt shifted_y = y << (WB * (n - t));
278 for(
size_t i = n; i != t; --i) {
286 for(
size_t j = 0; j != 2; ++j) {
287 if(division_check_vartime(qit, y_t0, y_t1, x_i0, x_i1, x_i2)) {
310 r -= qit * shifted_y;
321 q_words[i - t - 1] = qit;
339 const size_t y_words = y_arg.
sig_words();
361 const size_t t = y_words - 1;
362 const size_t n = std::max(y_words, r.
sig_words()) - 1;
370 BigInt shifted_y = y << (WB * (n - t));
381 for(
size_t i = n; i != t; --i) {
389 for(
size_t j = 0; j != 2; ++j) {
390 if(division_check_vartime(qit, y_t0, y_t1, x_i0, x_i1, x_i2)) {
402 r -= qit * shifted_y;
411 q_words[i - t - 1] = qit;
418 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
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
The native machine word, used as the limb type for multiprecision integers.