Botan 3.6.0
Crypto and TLS for C&
Botan::CRYSTALS::Polynomial< Trait, D > Class Template Reference

#include <pqcrystals.h>

Public Member Functions

void _const_time_poison () const
 
void _const_time_unpoison () const
 
decltype(auto) begin ()
 
decltype(auto) begin () const
 
ThisPolynomial clone () const
 
std::span< T, Trait::N > coefficients ()
 
std::span< const T, Trait::N > coefficients () const
 
ThisPolynomialconditional_add_q ()
 
constexpr bool ct_validate_value_range (T min, T max) const noexcept
 
constexpr Domain domain () const noexcept
 
decltype(auto) end ()
 
decltype(auto) end () const
 
constexpr size_t hamming_weight () const noexcept
 
decltype(auto) operator+= (const ThisPolynomial &other)
 
decltype(auto) operator-= (const ThisPolynomial &other)
 
ThisPolynomialoperator= (const ThisPolynomial &other)=delete
 
ThisPolynomialoperator= (ThisPolynomial &&other) noexcept
 
T & operator[] (size_t i)
 
operator[] (size_t i) const
 
constexpr bool owns_storage () const
 
 Polynomial ()
 
 Polynomial (const ThisPolynomial &other)=delete
 
 Polynomial (std::span< T, Trait::N > coeffs)
 
 Polynomial (ThisPolynomial &&other) noexcept
 
ThisPolynomialreduce ()
 
constexpr size_t size () const
 
 ~Polynomial ()=default
 

Static Public Member Functions

template<Domain OtherD>
requires (D != OtherD)
static Polynomial< Trait, D > from_domain_cast (Polynomial< Trait, OtherD > &&p)
 

Friends

template<Domain To, template< typename, Domain > class StructureT, crystals_trait C, Domain From>
requires (To != From)
StructureT< C, To > detail::domain_cast (StructureT< C, From > &&)
 
template<crystals_trait OtherTrait, Domain OtherD>
class Polynomial
 

Detailed Description

template<crystals_trait Trait, Domain D = Domain::Normal>
class Botan::CRYSTALS::Polynomial< Trait, D >

Represents a polynomial with Trait::N coefficients of type Trait::T. The domain of the polynomial can be either Domain::Normal or Domain::NTT and this information is represented in the C++ type system.

Polynomials may either own their storage of piggy-back on external storage when they are part of a PolynomialVector.

Definition at line 211 of file pqcrystals.h.

Constructor & Destructor Documentation

◆ Polynomial() [1/4]

template<crystals_trait Trait, Domain D = Domain::Normal>
Botan::CRYSTALS::Polynomial< Trait, D >::Polynomial ( )
inline

Definition at line 252 of file pqcrystals.h.

252: m_coeffs_storage(Trait::N), m_coeffs(m_coeffs_storage) { BOTAN_DEBUG_ASSERT(owns_storage()); }
#define BOTAN_DEBUG_ASSERT(expr)
Definition assert.h:98
constexpr bool owns_storage() const
Definition pqcrystals.h:316

References BOTAN_DEBUG_ASSERT, and Botan::CRYSTALS::Polynomial< Trait, D >::owns_storage().

◆ Polynomial() [2/4]

template<crystals_trait Trait, Domain D = Domain::Normal>
Botan::CRYSTALS::Polynomial< Trait, D >::Polynomial ( std::span< T, Trait::N > coeffs)
inlineexplicit

Definition at line 254 of file pqcrystals.h.

254: m_coeffs(coeffs) { BOTAN_DEBUG_ASSERT(!owns_storage()); }

References BOTAN_DEBUG_ASSERT, and Botan::CRYSTALS::Polynomial< Trait, D >::owns_storage().

◆ Polynomial() [3/4]

template<crystals_trait Trait, Domain D = Domain::Normal>
Botan::CRYSTALS::Polynomial< Trait, D >::Polynomial ( const ThisPolynomial< Trait, D > & other)
delete

◆ Polynomial() [4/4]

template<crystals_trait Trait, Domain D = Domain::Normal>
Botan::CRYSTALS::Polynomial< Trait, D >::Polynomial ( ThisPolynomial< Trait, D > && other)
inlinenoexcept

Definition at line 258 of file pqcrystals.h.

258 :
259 m_coeffs_storage(std::move(other.m_coeffs_storage)), m_coeffs(other.m_coeffs) {}

◆ ~Polynomial()

template<crystals_trait Trait, Domain D = Domain::Normal>
Botan::CRYSTALS::Polynomial< Trait, D >::~Polynomial ( )
default

Member Function Documentation

◆ _const_time_poison()

template<crystals_trait Trait, Domain D = Domain::Normal>
void Botan::CRYSTALS::Polynomial< Trait, D >::_const_time_poison ( ) const
inline

Definition at line 328 of file pqcrystals.h.

328{ CT::poison(m_coeffs); }
constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:53

References Botan::CT::poison().

◆ _const_time_unpoison()

template<crystals_trait Trait, Domain D = Domain::Normal>
void Botan::CRYSTALS::Polynomial< Trait, D >::_const_time_unpoison ( ) const
inline

Definition at line 330 of file pqcrystals.h.

330{ CT::unpoison(m_coeffs); }
constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:64

References Botan::CT::unpoison().

◆ begin() [1/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
decltype(auto) Botan::CRYSTALS::Polynomial< Trait, D >::begin ( )
inline

Definition at line 308 of file pqcrystals.h.

308{ return m_coeffs.begin(); }

◆ begin() [2/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
decltype(auto) Botan::CRYSTALS::Polynomial< Trait, D >::begin ( ) const
inline

Definition at line 310 of file pqcrystals.h.

310{ return m_coeffs.begin(); }

◆ clone()

template<crystals_trait Trait, Domain D = Domain::Normal>
ThisPolynomial Botan::CRYSTALS::Polynomial< Trait, D >::clone ( ) const
inline

Definition at line 278 of file pqcrystals.h.

278 {
279 ThisPolynomial res;
280 copy_mem(res.m_coeffs_storage, m_coeffs);
281 res.m_coeffs = std::span<T, Trait::N>(res.m_coeffs_storage);
282 BOTAN_DEBUG_ASSERT(res.owns_storage());
283 return res;
284 }
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:146

References BOTAN_DEBUG_ASSERT, Botan::copy_mem(), and Botan::CRYSTALS::Polynomial< Trait, D >::owns_storage().

◆ coefficients() [1/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
std::span< T, Trait::N > Botan::CRYSTALS::Polynomial< Trait, D >::coefficients ( )
inline

◆ coefficients() [2/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
std::span< const T, Trait::N > Botan::CRYSTALS::Polynomial< Trait, D >::coefficients ( ) const
inline

Definition at line 302 of file pqcrystals.h.

302{ return m_coeffs; }

◆ conditional_add_q()

template<crystals_trait Trait, Domain D = Domain::Normal>
ThisPolynomial & Botan::CRYSTALS::Polynomial< Trait, D >::conditional_add_q ( )
inline

Definition at line 323 of file pqcrystals.h.

323 {
324 Trait::poly_cadd_q(m_coeffs);
325 return *this;
326 }

◆ ct_validate_value_range()

template<crystals_trait Trait, Domain D = Domain::Normal>
bool Botan::CRYSTALS::Polynomial< Trait, D >::ct_validate_value_range ( T min,
T max ) const
inlineconstexprnoexcept
Returns
true if all coefficients are within the range [min, max]

Definition at line 287 of file pqcrystals.h.

287 {
288 return detail::ct_all_within_range(coefficients(), min, max);
289 }
std::span< T, Trait::N > coefficients()
Definition pqcrystals.h:300

References Botan::CRYSTALS::Polynomial< Trait, D >::coefficients().

Referenced by Botan::Dilithium_Algos::sample_in_ball().

◆ domain()

template<crystals_trait Trait, Domain D = Domain::Normal>
Domain Botan::CRYSTALS::Polynomial< Trait, D >::domain ( ) const
inlineconstexprnoexcept

Definition at line 276 of file pqcrystals.h.

276{ return D; }

◆ end() [1/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
decltype(auto) Botan::CRYSTALS::Polynomial< Trait, D >::end ( )
inline

Definition at line 312 of file pqcrystals.h.

312{ return m_coeffs.end(); }

◆ end() [2/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
decltype(auto) Botan::CRYSTALS::Polynomial< Trait, D >::end ( ) const
inline

Definition at line 314 of file pqcrystals.h.

314{ return m_coeffs.end(); }

◆ from_domain_cast()

template<crystals_trait Trait, Domain D = Domain::Normal>
template<Domain OtherD>
requires (D != OtherD)
static Polynomial< Trait, D > Botan::CRYSTALS::Polynomial< Trait, D >::from_domain_cast ( Polynomial< Trait, OtherD > && p)
inlinestatic

Definition at line 247 of file pqcrystals.h.

247 {
248 return Polynomial<Trait, D>(std::move(p));
249 }

References Botan::CRYSTALS::Polynomial< Trait, D >::Polynomial.

◆ hamming_weight()

template<crystals_trait Trait, Domain D = Domain::Normal>
size_t Botan::CRYSTALS::Polynomial< Trait, D >::hamming_weight ( ) const
inlineconstexprnoexcept
Returns
the number of non-zero coefficients in the polynomial

Definition at line 292 of file pqcrystals.h.

292 {
293 size_t weight = 0;
294 for(const auto c : m_coeffs) {
295 weight += (c != 0);
296 }
297 return weight;
298 }

Referenced by Botan::Dilithium_Algos::sample_in_ball().

◆ operator+=()

template<crystals_trait Trait, Domain D = Domain::Normal>
decltype(auto) Botan::CRYSTALS::Polynomial< Trait, D >::operator+= ( const ThisPolynomial< Trait, D > & other)
inline

Adds two polynomials element-wise. Does not perform a reduction after the addition. Therefore this operation might cause an integer overflow.

Definition at line 336 of file pqcrystals.h.

336 {
337 Trait::poly_add(m_coeffs, m_coeffs, other.m_coeffs);
338 return *this;
339 }

◆ operator-=()

template<crystals_trait Trait, Domain D = Domain::Normal>
decltype(auto) Botan::CRYSTALS::Polynomial< Trait, D >::operator-= ( const ThisPolynomial< Trait, D > & other)
inline

Subtracts two polynomials element-wise. Does not perform a reduction after the subtraction. Therefore this operation might cause an integer underflow.

Definition at line 345 of file pqcrystals.h.

345 {
346 Trait::poly_sub(m_coeffs, m_coeffs, other.m_coeffs);
347 return *this;
348 }

◆ operator=() [1/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
ThisPolynomial & Botan::CRYSTALS::Polynomial< Trait, D >::operator= ( const ThisPolynomial< Trait, D > & other)
delete

◆ operator=() [2/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
ThisPolynomial & Botan::CRYSTALS::Polynomial< Trait, D >::operator= ( ThisPolynomial< Trait, D > && other)
inlinenoexcept

Definition at line 263 of file pqcrystals.h.

263 {
264 if(this != &other) {
266 m_coeffs_storage = std::move(other.m_coeffs_storage);
267 m_coeffs = std::span<T, Trait::N>(m_coeffs_storage);
268 }
269 return *this;
270 }
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59

References BOTAN_ASSERT_NOMSG, and Botan::CRYSTALS::Polynomial< Trait, D >::owns_storage().

◆ operator[]() [1/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
T & Botan::CRYSTALS::Polynomial< Trait, D >::operator[] ( size_t i)
inline

Definition at line 304 of file pqcrystals.h.

304{ return m_coeffs[i]; }

◆ operator[]() [2/2]

template<crystals_trait Trait, Domain D = Domain::Normal>
T Botan::CRYSTALS::Polynomial< Trait, D >::operator[] ( size_t i) const
inline

Definition at line 306 of file pqcrystals.h.

306{ return m_coeffs[i]; }

◆ owns_storage()

template<crystals_trait Trait, Domain D = Domain::Normal>
bool Botan::CRYSTALS::Polynomial< Trait, D >::owns_storage ( ) const
inlineconstexpr

◆ reduce()

template<crystals_trait Trait, Domain D = Domain::Normal>
ThisPolynomial & Botan::CRYSTALS::Polynomial< Trait, D >::reduce ( )
inline

Definition at line 318 of file pqcrystals.h.

318 {
319 Trait::barrett_reduce(m_coeffs);
320 return *this;
321 }

Referenced by Botan::CRYSTALS::detail::dot_product().

◆ size()

template<crystals_trait Trait, Domain D = Domain::Normal>
size_t Botan::CRYSTALS::Polynomial< Trait, D >::size ( ) const
inlineconstexpr

Friends And Related Symbol Documentation

◆ detail::domain_cast

template<crystals_trait Trait, Domain D = Domain::Normal>
template<Domain To, template< typename, Domain > class StructureT, crystals_trait C, Domain From>
requires (To != From)
StructureT< C, To > detail::domain_cast ( StructureT< C, From > && )
friend

◆ Polynomial

template<crystals_trait Trait, Domain D = Domain::Normal>
template<crystals_trait OtherTrait, Domain OtherD>
friend class Polynomial
friend

The documentation for this class was generated from the following file: