Botan 3.9.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 213 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

◆ 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 256 of file pqcrystals.h.

◆ 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 260 of file pqcrystals.h.

260 :
261 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 330 of file pqcrystals.h.

constexpr void poison(const T *p, size_t n)
Definition ct_utils.h:54

◆ _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 332 of file pqcrystals.h.

constexpr void unpoison(const T *p, size_t n)
Definition ct_utils.h:65

◆ begin() [1/2]

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

Definition at line 310 of file pqcrystals.h.

310{ 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 312 of file pqcrystals.h.

312{ 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 280 of file pqcrystals.h.

280 {
282 copy_mem(res.m_coeffs_storage, m_coeffs);
283 res.m_coeffs = std::span<T, Trait::N>(res.m_coeffs_storage);
285 return res;
286 }
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:145

◆ 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 304 of file pqcrystals.h.

304{ 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 325 of file pqcrystals.h.

325 {
327 return *this;
328 }

◆ 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 289 of file pqcrystals.h.

289 {
291 }
std::span< T, Trait::N > coefficients()
Definition pqcrystals.h:302

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 278 of file pqcrystals.h.

278{ 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 314 of file pqcrystals.h.

314{ 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 316 of file pqcrystals.h.

316{ return m_coeffs.end(); }

◆ from_domain_cast()

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

Definition at line 249 of file pqcrystals.h.

249 {
251 }

◆ 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 294 of file pqcrystals.h.

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

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 338 of file pqcrystals.h.

338 {
340 return *this;
341 }

◆ 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 347 of file pqcrystals.h.

347 {
349 return *this;
350 }

◆ 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 265 of file pqcrystals.h.

265 {
266 if(this != &other) {
268 m_coeffs_storage = std::move(other.m_coeffs_storage);
270 }
271 return *this;
272 }
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

◆ 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 306 of file pqcrystals.h.

306{ 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 308 of file pqcrystals.h.

308{ return m_coeffs[i]; }

◆ owns_storage()

◆ reduce()

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

Definition at line 320 of file pqcrystals.h.

320 {
322 return *this;
323 }

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

◆ 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

Definition at line 225 of file pqcrystals.h.


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