10 #include <botan/bigint.h>
11 #include <botan/internal/mp_core.h>
12 #include <botan/internal/mp_madd.h>
13 #include <botan/internal/mp_asmi.h>
14 #include <botan/internal/ct_utils.h>
15 #include <botan/mem_ops.h>
23 const word p[],
size_t p_size,
24 word p_dash, word ws[])
26 const size_t z_size = 2*(p_size+1);
32 const size_t blocks_of_8 = p_size - (p_size % 8);
34 for(
size_t i = 0; i != p_size; ++i)
38 const word y = z_i[0] * p_dash;
47 for(
size_t j = 0; j != blocks_of_8; j += 8)
50 for(
size_t j = blocks_of_8; j != p_size; ++j)
53 word z_sum = z_i[p_size] + carry;
54 carry = (z_sum < z_i[p_size]);
57 for(
size_t j = p_size + 1; j < z_size - i; ++j)
60 carry = carry & !z_i[j];
78 for(
size_t i = 0; i != p_size; ++i)
79 ws[i] =
word_sub(z[p_size + i], p[i], &borrow);
81 ws[p_size] =
word_sub(z[p_size+p_size], 0, &borrow);
83 copy_mem(ws + p_size + 1, z + p_size, p_size + 1);
86 clear_mem(z + p_size + 1, z_size - p_size - 1);
94 BOTAN_ASSERT(borrow == 0 || borrow == 1,
"Expected borrow");
98 const word p[],
size_t p_size, word p_dash,
104 &p[0], p_size, p_dash,
110 size_t p_size, word p_dash, word ws[])
116 &p[0], p_size, p_dash,
void conditional_copy_mem(T value, T *to, const T *from0, const T *from1, size_t elems)
void clear_mem(T *ptr, size_t n)
word word_madd3(word a, word b, word c, word *d)
void poison(const T *p, size_t n)
#define BOTAN_ASSERT(expr, assertion_made)
void bigint_monty_sqr(BigInt &z, const BigInt &x, const word p[], size_t p_size, word p_dash, word workspace[])
word word8_madd3(word z[8], const word x[8], word y, word carry)
void bigint_sqr(word z[], size_t z_size, word workspace[], const word x[], size_t x_size, size_t x_sw)
void bigint_monty_mul(BigInt &z, const BigInt &x, const BigInt &y, const word p[], size_t p_size, word p_dash, word workspace[])
const word * data() const
void copy_mem(T *out, const T *in, size_t n)
word word_sub(word x, word y, word *carry)
void bigint_mul(BigInt &z, const BigInt &x, const BigInt &y, word workspace[])
void unpoison(const T *p, size_t n)
void bigint_monty_redc(word z[], const word p[], size_t p_size, word p_dash, word workspace[])