7#include <botan/internal/poly_dbl.h>
9#include <botan/exceptn.h>
10#include <botan/internal/ct_utils.h>
11#include <botan/internal/loadstor.h>
24enum class MinWeightPolynomial : uint32_t {
38template <MinWeightPolynomial P>
39inline uint64_t return_carry(uint64_t c) {
43template <
size_t LIMBS, MinWeightPolynomial P>
44void poly_double(uint8_t out[],
const uint8_t in[]) {
48 const uint64_t
carry = return_carry<P>(W[0]);
50 if constexpr(LIMBS > 0) {
51 for(
size_t i = 0; i != LIMBS - 1; ++i) {
52 W[i] = (W[i] << 1) ^ (W[i + 1] >> 63);
56 W[LIMBS - 1] = (W[LIMBS - 1] << 1) ^
carry;
61template <
size_t LIMBS, MinWeightPolynomial P>
62void poly_double_le(uint8_t out[],
const uint8_t in[]) {
66 const uint64_t
carry = return_carry<P>(W[LIMBS - 1]);
68 if constexpr(LIMBS > 0) {
69 for(
size_t i = 0; i != LIMBS - 1; ++i) {
70 W[LIMBS - 1 - i] = (W[LIMBS - 1 - i] << 1) ^ (W[LIMBS - 2 - i] >> 63);
74 W[0] = (W[0] << 1) ^
carry;
84 return poly_double<1, MinWeightPolynomial::P64>(out, in);
86 return poly_double<2, MinWeightPolynomial::P128>(out, in);
88 return poly_double<3, MinWeightPolynomial::P192>(out, in);
90 return poly_double<4, MinWeightPolynomial::P256>(out, in);
92 return poly_double<8, MinWeightPolynomial::P512>(out, in);
94 return poly_double<16, MinWeightPolynomial::P1024>(out, in);
103 return poly_double_le<1, MinWeightPolynomial::P64>(out, in);
105 return poly_double_le<2, MinWeightPolynomial::P128>(out, in);
107 return poly_double_le<3, MinWeightPolynomial::P192>(out, in);
109 return poly_double_le<4, MinWeightPolynomial::P256>(out, in);
111 return poly_double_le<8, MinWeightPolynomial::P512>(out, in);
113 return poly_double_le<16, MinWeightPolynomial::P1024>(out, in);
121 constexpr size_t LIMBS = 2;
126 for(
size_t i = 1; i < blocks_in_tweak; ++i) {
127 const uint64_t
carry = return_carry<MinWeightPolynomial::P128>(W[1]);
128 W[1] = (W[1] << 1) ^ (W[0] >> 63);
129 W[0] = (W[0] << 1) ^
carry;
133 for(
size_t i = 1; i < blocks_in_tweak; ++i) {
134 const uint8_t* prev = &tweak[(i - 1) * BS];
135 uint8_t* cur = &tweak[i * BS];
static constexpr Mask< T > expand_top_bit(T v)
void copy_out_be(std::span< uint8_t > out, InR &&in)
void xts_update_tweak_block(uint8_t tweak[], size_t BS, size_t blocks_in_tweak)
void poly_double_n_le(uint8_t out[], const uint8_t in[], size_t n)
void carry(int64_t &h0, int64_t &h1)
void copy_out_le(std::span< uint8_t > out, InR &&in)
constexpr auto load_le(ParamTs &&... params)
void poly_double_n(uint8_t out[], const uint8_t in[], size_t n)
constexpr auto load_be(ParamTs &&... params)