4
* Botan is released under the Simplified BSD License (see license.txt)
7
#include <botan/internal/poly_dbl.h>
8
#include <botan/loadstor.h>
9
#include <botan/exceptn.h>
15
template<size_t LIMBS, uint64_t POLY>
16
void poly_double(uint8_t out[], const uint8_t in[])
19
load_be(W, in, LIMBS);
21
const uint64_t carry = POLY * (W[0] >> 63);
22
for(size_t i = 0; i != LIMBS - 1; ++i)
23
W[i] = (W[i] << 1) ^ (W[i+1] >> 63);
24
W[LIMBS-1] = (W[LIMBS-1] << 1) ^ carry;
26
copy_out_be(out, LIMBS*8, W);
29
template<size_t LIMBS, uint64_t POLY>
30
void poly_double_le(uint8_t out[], const uint8_t in[])
33
load_le(W, in, LIMBS);
35
const uint64_t carry = POLY * (W[LIMBS-1] >> 63);
36
for(size_t i = 0; i != LIMBS - 1; ++i)
37
W[LIMBS-1-i] = (W[LIMBS-1-i] << 1) ^ (W[LIMBS-2-i] >> 63);
38
W[0] = (W[0] << 1) ^ carry;
40
copy_out_le(out, LIMBS*8, W);
45
void poly_double_n(uint8_t out[], const uint8_t in[], size_t n)
50
return poly_double<1, 0x1B>(out, in);
52
return poly_double<2, 0x87>(out, in);
54
return poly_double<3, 0x87>(out, in);
56
return poly_double<4, 0x425>(out, in);
58
return poly_double<8, 0x125>(out, in);
60
throw Invalid_Argument("Unsupported size for poly_double_n");
64
void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n)
69
return poly_double_le<1, 0x1B>(out, in);
71
return poly_double_le<2, 0x87>(out, in);
73
return poly_double_le<3, 0x87>(out, in);
75
return poly_double_le<4, 0x425>(out, in);
77
return poly_double_le<8, 0x125>(out, in);
79
throw Invalid_Argument("Unsupported size for poly_double_n_le");