12#ifndef BOTAN_DILITHIUM_POLYNOMIAL_H_
13#define BOTAN_DILITHIUM_POLYNOMIAL_H_
15#include <botan/internal/dilithium_constants.h>
16#include <botan/internal/pqcrystals.h>
24 static constexpr T montgomery_reduce_coefficient(
T2 a) {
25 const T2 t =
static_cast<T>(
static_cast<T2>(
static_cast<T>(a)) *
Q_inverse);
26 return static_cast<T>((a -
static_cast<T2>(t) *
Q) >> (
sizeof(
T) * 8));
29 static constexpr T barrett_reduce_coefficient(
T a) {
31 const T t = (a + (1 << 22)) >> 23;
48 static constexpr void ntt(std::span<T, N> coeffs) {
52 for(
size_t len =
N / 2; len > 0; len >>= 1) {
53 for(
size_t start = 0; start <
N; start = j + len) {
55 for(j = start; j < start + len; ++j) {
57 const T t =
fqmul(zeta, coeffs[j + len]);
58 coeffs[j + len] = coeffs[j] - t;
59 coeffs[j] = coeffs[j] + t;
79 for(
size_t len = 1; len <
N; len <<= 1) {
80 for(
size_t start = 0; start <
N; start = j + len) {
81 const T zeta = -
zetas[--k];
82 for(j = start; j < start + len; ++j) {
83 const T t = coeffs[j];
84 coeffs[j] = t + coeffs[j + len];
85 coeffs[j + len] = t - coeffs[j + len];
87 coeffs[j + len] =
fqmul(zeta, coeffs[j + len]);
92 for(
auto& coeff : coeffs) {
104 std::span<const T, N> lhs,
105 std::span<const T, N> rhs) {
106 for(
size_t i = 0; i <
N; ++i) {
107 result[i] =
fqmul(lhs[i], rhs[i]);
static constexpr T F_WITH_MONTY_SQUARED
next_longer_int_t< T > T2
static constexpr T Q_inverse
static constexpr T fqmul(T a, T b)
static constexpr auto zetas
static constexpr void poly_pointwise_montgomery(std::span< T, N > result, std::span< const T, N > lhs, std::span< const T, N > rhs)
static constexpr void ntt(std::span< T, N > coeffs)
static constexpr void inverse_ntt(std::span< T, N > coeffs)