8 #ifndef CRYPTOPP_POLYNOMI_H 9 #define CRYPTOPP_POLYNOMI_H 41 RandomizationParameter(
unsigned int coefficientCount,
const typename T::RandomizationParameter &coefficientParameter )
42 : m_coefficientCount(coefficientCount), m_coefficientParameter(coefficientParameter) {}
47 friend class PolynomialOver<
T>;
99 CoefficientType
GetCoefficient(
unsigned int i,
const Ring &ring)
const;
111 void SetCoefficient(
unsigned int i,
const CoefficientType &value,
const Ring &ring);
114 void Negate(
const Ring &ring);
134 bool IsUnit(
const Ring &ring)
const;
144 CoefficientType
EvaluateAt(
const CoefficientType &
x,
const Ring &ring)
const;
155 std::istream&
Input(std::istream &in,
const Ring &ring);
156 std::ostream&
Output(std::ostream &out,
const Ring &ring)
const;
160 void FromStr(
const char *str,
const Ring &ring);
210 static const ThisType &Zero();
211 static const ThisType &One();
216 int Degree()
const {
return B::Degree(ms_fixedRing);}
221 CoefficientType
GetCoefficient(
unsigned int i)
const {
return B::GetCoefficient(i, ms_fixedRing);}
223 CoefficientType
operator[](
unsigned int i)
const {
return B::GetCoefficient(i, ms_fixedRing);}
228 ThisType& operator=(
const ThisType& t) {B::operator=(t);
return *
this;}
231 ThisType&
operator+=(
const ThisType& t) {Accumulate(t, ms_fixedRing);
return *
this;}
233 ThisType&
operator-=(
const ThisType& t) {Reduce(t, ms_fixedRing);
return *
this;}
235 ThisType&
operator*=(
const ThisType& t) {
return *
this = *
this*t;}
237 ThisType&
operator/=(
const ThisType& t) {
return *
this = *
this/t;}
239 ThisType&
operator%=(
const ThisType& t) {
return *
this = *
this%t;}
242 ThisType&
operator<<=(
unsigned int n) {ShiftLeft(n, ms_fixedRing);
return *
this;}
244 ThisType&
operator>>=(
unsigned int n) {ShiftRight(n, ms_fixedRing);
return *
this;}
247 void SetCoefficient(
unsigned int i,
const CoefficientType &value) {B::SetCoefficient(i, value, ms_fixedRing);}
260 bool operator!()
const {
return CoefficientCount()==0;}
265 ThisType
operator-()
const {
return ThisType(Inverse(ms_fixedRing));}
270 friend ThisType
operator>>(ThisType
a,
unsigned int n) {
return ThisType(a>>=n);}
273 friend ThisType
operator<<(ThisType a,
unsigned int n) {
return ThisType(a<<=n);}
278 ThisType MultiplicativeInverse()
const {
return ThisType(B::MultiplicativeInverse(ms_fixedRing));}
281 bool IsUnit()
const {
return B::IsUnit(ms_fixedRing);}
284 ThisType
Doubled()
const {
return ThisType(B::Doubled(ms_fixedRing));}
286 ThisType
Squared()
const {
return ThisType(B::Squared(ms_fixedRing));}
288 CoefficientType
EvaluateAt(
const CoefficientType &
x)
const {
return B::EvaluateAt(x, ms_fixedRing);}
291 static void Divide(ThisType &r, ThisType &q,
const ThisType &a,
const ThisType &
d)
297 friend std::istream&
operator>>(std::istream& in, ThisType &a)
299 {
return a.
Input(in, ms_fixedRing);}
301 friend std::ostream&
operator<<(std::ostream& out,
const ThisType &a)
302 {
return a.
Output(out, ms_fixedRing);}
310 return new ThisType(ms_fixedRing.MultiplicativeIdentity());
329 {
return Element(rng, parameter, m_ring);}
331 bool Equal(
const Element &
a,
const Element &
b)
const 332 {
return a.
Equals(b, m_ring);}
335 {
return this->result = m_ring.Identity();}
337 const Element&
Add(
const Element &
a,
const Element &
b)
const 338 {
return this->result = a.
Plus(b, m_ring);}
344 {
return this->result = a.
Inverse(m_ring);}
346 const Element&
Subtract(
const Element &
a,
const Element &
b)
const 347 {
return this->result = a.
Minus(b, m_ring);}
349 Element&
Reduce(Element &
a,
const Element &
b)
const 350 {
return a.
Reduce(b, m_ring);}
353 {
return this->result = a.
Doubled(m_ring);}
356 {
return this->result = m_ring.MultiplicativeIdentity();}
358 const Element&
Multiply(
const Element &
a,
const Element &
b)
const 359 {
return this->result = a.
Times(b, m_ring);}
362 {
return this->result = a.
Squared(m_ring);}
365 {
return a.
IsUnit(m_ring);}
370 const Element&
Divide(
const Element &
a,
const Element &
b)
const 371 {
return this->result = a.
DividedBy(b, m_ring);}
373 const Element&
Mod(
const Element &
a,
const Element &
b)
const 374 {
return this->result = a.
Modulo(b, m_ring);}
385 Element Interpolate(
const CoefficientType
x[],
const CoefficientType y[],
unsigned int n)
const;
388 CoefficientType InterpolateAt(
const CoefficientType &position,
const CoefficientType x[],
const CoefficientType y[],
unsigned int n)
const;
395 void CalculateAlpha(std::vector<CoefficientType> &alpha,
const CoefficientType x[],
const CoefficientType y[],
unsigned int n)
const;
400 template <
class Ring,
class Element>
402 template <
class Ring,
class Element>
404 template <
class Ring,
class Element>
408 template <
class T,
int instance>
409 inline bool operator==(
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
410 {
return a.Equals(b, a.ms_fixedRing);}
412 template <
class T,
int instance>
413 inline bool operator!=(
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
417 template <
class T,
int instance>
418 inline bool operator> (
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
419 {
return a.Degree() > b.Degree();}
421 template <
class T,
int instance>
422 inline bool operator>=(
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
423 {
return a.Degree() >= b.Degree();}
425 template <
class T,
int instance>
426 inline bool operator< (const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
427 {
return a.Degree() <
b.Degree();}
429 template <
class T,
int instance>
430 inline bool operator<=(const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
431 {
return a.Degree() <=
b.Degree();}
434 template <
class T,
int instance>
435 inline CryptoPP::PolynomialOverFixedRing<T, instance>
operator+(
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
436 {
return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Plus(b, a.ms_fixedRing));}
438 template <
class T,
int instance>
439 inline CryptoPP::PolynomialOverFixedRing<T, instance>
operator-(
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
440 {
return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Minus(b, a.ms_fixedRing));}
442 template <
class T,
int instance>
443 inline CryptoPP::PolynomialOverFixedRing<T, instance>
operator*(
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
444 {
return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Times(b, a.ms_fixedRing));}
446 template <
class T,
int instance>
447 inline CryptoPP::PolynomialOverFixedRing<T, instance>
operator/(
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
448 {
return CryptoPP::PolynomialOverFixedRing<T, instance>(a.DividedBy(b, a.ms_fixedRing));}
450 template <
class T,
int instance>
451 inline CryptoPP::PolynomialOverFixedRing<T, instance>
operator%(
const CryptoPP::PolynomialOverFixedRing<T, instance> &
a,
const CryptoPP::PolynomialOverFixedRing<T, instance> &
b)
452 {
return CryptoPP::PolynomialOverFixedRing<T, instance>(a.Modulo(b, a.ms_fixedRing));}
461 template<
class T,
int i>
inline void swap(CryptoPP::PolynomialOverFixedRing<T,i> &
a, CryptoPP::PolynomialOverFixedRing<T,i> &
b)
Base class for all exceptions thrown by the library.
PolynomialOverFixedRing(Iterator first, Iterator last)
construct polynomial with specified coefficients, starting from coefficient of x^0 ...
PolynomialOver< Ring > & operator=(const PolynomialOver< Ring > &t)
specify the distribution for randomization functions
PolynomialOver< Ring > Doubled(const Ring &ring) const
Element::CoefficientType CoefficientType
CoefficientType operator[](unsigned int i) const
return coefficient for x^i
void SetCoefficient(unsigned int i, const CoefficientType &value, const Ring &ring)
set the coefficient for x^i to value
bool operator>(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
PolynomialOver(Iterator begin, Iterator end)
construct polynomial with specified coefficients, starting from coefficient of x^0 ...
Utility functions for the Crypto++ library.
PolynomialOver(const PolynomialOver< Ring > &t)
copy constructor
CoefficientType EvaluateAt(const CoefficientType &x) const
void PrepareBulkPolynomialInterpolationAt(const Ring &ring, Element *v, const Element &position, const Element x[], const Element w[], unsigned int n)
const Element & Double(const Element &a) const
Doubles an element in the group.
PolynomialOverFixedRing(const byte *encodedPoly, unsigned int byteCount)
convert from big-endian byte array
PolynomialOver< Ring > Minus(const PolynomialOver< Ring > &t, const Ring &ring) const
RandomizationParameter(unsigned int coefficientCount, const typename T::RandomizationParameter &coefficientParameter)
CryptoPP::PolynomialOverFixedRing< T, instance > operator-(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
PolynomialOverFixedRing(const char *str)
convert from string
unsigned int CoefficientCount() const
degree + 1
#define NAMESPACE_BEGIN(x)
bool IsUnit(const Element &a) const
Determines whether an element is a unit in the group.
CryptoPP::PolynomialOverFixedRing< T, instance > operator/(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
PolynomialOver< Ring > & ShiftRight(unsigned int n, const Ring &ring)
const Element & Identity() const
Provides the Identity element.
bool operator>=(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
bool operator!=(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
Abstract base classes that provide a uniform interface to this library.
PolynomialOverFixedRing(const ThisType &t)
copy constructor
T::RandomizationParameter m_coefficientParameter
CoefficientType GetCoefficient(unsigned int i, const Ring &ring) const
return coefficient for x^i
Abstract Euclidean domain.
void DivisionAlgorithm(Element &r, Element &q, const Element &a, const Element &d) const
Performs the division algorithm on two elements in the ring.
void PrepareBulkPolynomialInterpolation(const Ring &ring, Element *w, const Element x[], unsigned int n)
PolynomialOverFixedRing(const byte *BEREncodedPoly)
convert from Basic Encoding Rules encoded byte array
std::hash for asio::adress
Interface for random number generators.
const Element & Square(const Element &a) const
Square an element in the group.
RingOfPolynomialsOver(const CoefficientRing &ring)
PolynomialOverFixedRing(const CoefficientType &element)
construct constant polynomial
CryptoPP::PolynomialOverFixedRing< T, instance > operator%(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
bool Equals(const PolynomialOver< Ring > &t, const Ring &ring) const
PolynomialOver< Ring > Inverse(const Ring &ring) const
Classes for performing mathematics over different fields.
bool operator==(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
unsigned int CoefficientCount(const Ring &ring) const
Element & Reduce(Element &a, const Element &b) const
Reduces an element in the congruence class.
friend ThisType operator<<(ThisType a, unsigned int n)
represents single-variable polynomials over arbitrary rings
PolynomialOver(const char *str, const Ring &ring)
convert from string
T::Element CoefficientType
Element::RandomizationParameter RandomizationParameter
Ring of polynomials over another ring.
B::DivideByZero DivideByZero
bool IsUnit(const Ring &ring) const
ThisType & operator%=(const ThisType &t)
Classes and functions for secure memory allocations.
CoefficientType EvaluateAt(const CoefficientType &x, const Ring &ring) const
bool IsZero(const Ring &ring) const
PolynomialOver< Ring > Plus(const PolynomialOver< Ring > &t, const Ring &ring) const
const Element & Inverse(const Element &a) const
Inverts the element in the group.
NAMESPACE_END void swap(CryptoPP::PolynomialOver< T > &a, CryptoPP::PolynomialOver< T > &b)
void FromStr(const char *str, const Ring &ring)
PolynomialOverFixedRing(const B &t)
const Element & Add(const Element &a, const Element &b) const
Adds elements in the group.
PolynomialOverFixedRing< T, instance > ThisType
PolynomialOver< Ring > & Accumulate(const PolynomialOver< Ring > &t, const Ring &ring)
void Randomize(RandomNumberGenerator &rng, const RandomizationParameter ¶meter, const Ring &ring)
const Element & Multiply(const Element &a, const Element &b) const
Multiplies elements in the group.
ThisType & operator*=(const ThisType &t)
ThisType * operator()() const
CryptoPP::PolynomialOverFixedRing< T, instance > operator+(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
ThisType & operator-=(const ThisType &t)
PolynomialOver< Ring > Modulo(const PolynomialOver< Ring > &t, const Ring &ring) const
Element RandomElement(RandomNumberGenerator &rng, const RandomizationParameter ¶meter)
const Element & MultiplicativeIdentity() const
Retrieves the multiplicative identity.
void Divide(word *R, word *Q, word *T, const word *A, size_t NA, const word *B, size_t NB)
unsigned int m_coefficientCount
Polynomials over a fixed ring.
void Randomize(RandomNumberGenerator &rng, const RandomizationParameter ¶meter)
PolynomialOver< Ring > & ShiftLeft(unsigned int n, const Ring &ring)
CoefficientType GetCoefficient(unsigned int i) const
return coefficient for x^i
ThisType operator+() const
ThisType & operator+=(const ThisType &t)
static const Ring ms_fixedRing
ThisType & operator/=(const ThisType &t)
PolynomialOver< Ring > DividedBy(const PolynomialOver< Ring > &t, const Ring &ring) const
Element BulkPolynomialInterpolateAt(const Ring &ring, const Element y[], const Element v[], unsigned int n)
PolynomialOver()
creates the zero polynomial
void SetCoefficient(unsigned int i, const CoefficientType &value)
set the coefficient for x^i to value
const Element & Divide(const Element &a, const Element &b) const
Divides elements in the group.
PolynomialOver(RandomNumberGenerator &rng, const RandomizationParameter ¶meter, const Ring &ring)
create a random PolynomialOver<T>
PolynomialOver< Ring > Squared(const Ring &ring) const
ThisType & operator>>=(unsigned int n)
PolynomialOver(const CoefficientType &element)
construct constant polynomial
PolynomialOver(const Ring &ring, unsigned int count)
const Element & Mod(const Element &a, const Element &b) const
Performs a modular reduction in the ring.
static void Divide(ThisType &r, ThisType &q, const ThisType &a, const ThisType &d)
calculate r and q such that (a == d*q + r) && (0 <= r < abs(d))
uint8_t const size_t const size
PolynomialOver< Ring > & Reduce(const PolynomialOver< Ring > &t, const Ring &ring)
std::ostream & Output(std::ostream &out, const Ring &ring) const
friend std::ostream & operator<<(std::ostream &out, const ThisType &a)
std::istream & operator>>(std::istream &in, Integer &a)
PolynomialOverFixedRing(BufferedTransformation &bt)
convert from BER encoded byte array stored in a BufferedTransformation object
std::vector< CoefficientType > m_coefficients
Element & Accumulate(Element &a, const Element &b) const
TODO.
const Element & MultiplicativeInverse(const Element &a) const
Calculate the multiplicative inverse of an element in the group.
CryptoPP::PolynomialOverFixedRing< T, instance > operator*(const CryptoPP::PolynomialOverFixedRing< T, instance > &a, const CryptoPP::PolynomialOverFixedRing< T, instance > &b)
division by zero exception
PolynomialOver< T > Element
B::RandomizationParameter RandomizationParameter
ThisType operator-() const
PolynomialOver< Ring > Times(const PolynomialOver< Ring > &t, const Ring &ring) const
void Negate(const Ring &ring)
int Degree(const Ring &ring) const
the zero polynomial will return a degree of -1
const Element & Subtract(const Element &a, const Element &b) const
Subtracts elements in the group.
bool Equal(const Element &a, const Element &b) const
Compare two elements for equality.
T::Element CoefficientType
ThisType & operator<<=(unsigned int n)
PolynomialOver< Ring > MultiplicativeInverse(const Ring &ring) const
std::istream & Input(std::istream &in, const Ring &ring)
PolynomialOverFixedRing(RandomNumberGenerator &rng, const RandomizationParameter ¶meter)
create a random PolynomialOverFixedRing