summaryrefslogtreecommitdiff
path: root/gf2n.h
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-11-29 10:54:33 -0500
committerJeffrey Walton <noloader@gmail.com>2017-11-29 10:54:33 -0500
commit61ec50dabe14c5d4582ac187706ea27645b3562b (patch)
tree18a2eebb7adc8c9556ce132d7081a105fa058d6b /gf2n.h
parent16ebfa72bf130c4725e652e4d3688d97d3feb0ee (diff)
downloadcryptopp-git-61ec50dabe14c5d4582ac187706ea27645b3562b.tar.gz
Change Doxygen comment style from //! to ///
Also see https://groups.google.com/forum/#!topic/cryptopp-users/A7-Xt5Knlzw
Diffstat (limited to 'gf2n.h')
-rw-r--r--gf2n.h216
1 files changed, 108 insertions, 108 deletions
diff --git a/gf2n.h b/gf2n.h
index 381a9ba8..40cf3934 100644
--- a/gf2n.h
+++ b/gf2n.h
@@ -1,7 +1,7 @@
// gf2n.h - originally written and placed in the public domain by Wei Dai
-//! \file gf2n.h
-//! \brief Classes and functions for schemes over GF(2^n)
+/// \file gf2n.h
+/// \brief Classes and functions for schemes over GF(2^n)
#ifndef CRYPTOPP_GF2N_H
#define CRYPTOPP_GF2N_H
@@ -21,14 +21,14 @@
NAMESPACE_BEGIN(CryptoPP)
-//! \brief Polynomial with Coefficients in GF(2)
+/// \brief Polynomial with Coefficients in GF(2)
/*! \nosubgrouping */
class CRYPTOPP_DLL PolynomialMod2
{
public:
- //! \name ENUMS, EXCEPTIONS, and TYPEDEFS
+ /// \name ENUMS, EXCEPTIONS, and TYPEDEFS
//@{
- //! \brief Excpetion thrown when divide by zero is encountered
+ /// \brief Excpetion thrown when divide by zero is encountered
class DivideByZero : public Exception
{
public:
@@ -38,209 +38,209 @@ public:
typedef unsigned int RandomizationParameter;
//@}
- //! \name CREATORS
+ /// \name CREATORS
//@{
- //! \brief Construct the zero polynomial
+ /// \brief Construct the zero polynomial
PolynomialMod2();
- //! Copy construct a PolynomialMod2
+ /// Copy construct a PolynomialMod2
PolynomialMod2(const PolynomialMod2& t);
- //! \brief Construct a PolynomialMod2 from a word
- //! \details value should be encoded with the least significant bit as coefficient to x^0
- //! and most significant bit as coefficient to x^(WORD_BITS-1)
- //! bitLength denotes how much memory to allocate initially
+ /// \brief Construct a PolynomialMod2 from a word
+ /// \details value should be encoded with the least significant bit as coefficient to x^0
+ /// and most significant bit as coefficient to x^(WORD_BITS-1)
+ /// bitLength denotes how much memory to allocate initially
PolynomialMod2(word value, size_t bitLength=WORD_BITS);
- //! \brief Construct a PolynomialMod2 from big-endian byte array
+ /// \brief Construct a PolynomialMod2 from big-endian byte array
PolynomialMod2(const byte *encodedPoly, size_t byteCount)
{Decode(encodedPoly, byteCount);}
- //! \brief Construct a PolynomialMod2 from big-endian form stored in a BufferedTransformation
+ /// \brief Construct a PolynomialMod2 from big-endian form stored in a BufferedTransformation
PolynomialMod2(BufferedTransformation &encodedPoly, size_t byteCount)
{Decode(encodedPoly, byteCount);}
- //! \brief Create a uniformly distributed random polynomial
- //! \details Create a random polynomial uniformly distributed over all polynomials with degree less than bitcount
+ /// \brief Create a uniformly distributed random polynomial
+ /// \details Create a random polynomial uniformly distributed over all polynomials with degree less than bitcount
PolynomialMod2(RandomNumberGenerator &rng, size_t bitcount)
{Randomize(rng, bitcount);}
- //! \brief Provides x^i
- //! \returns x^i
+ /// \brief Provides x^i
+ /// \returns x^i
static PolynomialMod2 CRYPTOPP_API Monomial(size_t i);
- //! \brief Provides x^t0 + x^t1 + x^t2
- //! \returns x^t0 + x^t1 + x^t2
+ /// \brief Provides x^t0 + x^t1 + x^t2
+ /// \returns x^t0 + x^t1 + x^t2
static PolynomialMod2 CRYPTOPP_API Trinomial(size_t t0, size_t t1, size_t t2);
- //! \brief Provides x^t0 + x^t1 + x^t2 + x^t3 + x^t4
- //! \returns x^t0 + x^t1 + x^t2 + x^t3 + x^t4
+ /// \brief Provides x^t0 + x^t1 + x^t2 + x^t3 + x^t4
+ /// \returns x^t0 + x^t1 + x^t2 + x^t3 + x^t4
static PolynomialMod2 CRYPTOPP_API Pentanomial(size_t t0, size_t t1, size_t t2, size_t t3, size_t t4);
- //! \brief Provides x^(n-1) + ... + x + 1
- //! \returns x^(n-1) + ... + x + 1
+ /// \brief Provides x^(n-1) + ... + x + 1
+ /// \returns x^(n-1) + ... + x + 1
static PolynomialMod2 CRYPTOPP_API AllOnes(size_t n);
- //! \brief The Zero polinomial
- //! \returns the zero polynomial
+ /// \brief The Zero polinomial
+ /// \returns the zero polynomial
static const PolynomialMod2 & CRYPTOPP_API Zero();
- //! \brief The One polinomial
- //! \returns the one polynomial
+ /// \brief The One polinomial
+ /// \returns the one polynomial
static const PolynomialMod2 & CRYPTOPP_API One();
//@}
- //! \name ENCODE/DECODE
+ /// \name ENCODE/DECODE
//@{
- //! minimum number of bytes to encode this polynomial
+ /// minimum number of bytes to encode this polynomial
/*! MinEncodedSize of 0 is 1 */
unsigned int MinEncodedSize() const {return STDMAX(1U, ByteCount());}
- //! encode in big-endian format
- //! \details if outputLen < MinEncodedSize, the most significant bytes will be dropped
- //! if outputLen > MinEncodedSize, the most significant bytes will be padded
+ /// encode in big-endian format
+ /// \details if outputLen < MinEncodedSize, the most significant bytes will be dropped
+ /// if outputLen > MinEncodedSize, the most significant bytes will be padded
void Encode(byte *output, size_t outputLen) const;
- //!
+ ///
void Encode(BufferedTransformation &bt, size_t outputLen) const;
- //!
+ ///
void Decode(const byte *input, size_t inputLen);
- //!
+ ///
//* Precondition: bt.MaxRetrievable() >= inputLen
void Decode(BufferedTransformation &bt, size_t inputLen);
- //! encode value as big-endian octet string
+ /// encode value as big-endian octet string
void DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const;
- //! decode value as big-endian octet string
+ /// decode value as big-endian octet string
void BERDecodeAsOctetString(BufferedTransformation &bt, size_t length);
//@}
- //! \name ACCESSORS
+ /// \name ACCESSORS
//@{
- //! number of significant bits = Degree() + 1
+ /// number of significant bits = Degree() + 1
unsigned int BitCount() const;
- //! number of significant bytes = ceiling(BitCount()/8)
+ /// number of significant bytes = ceiling(BitCount()/8)
unsigned int ByteCount() const;
- //! number of significant words = ceiling(ByteCount()/sizeof(word))
+ /// number of significant words = ceiling(ByteCount()/sizeof(word))
unsigned int WordCount() const;
- //! return the n-th bit, n=0 being the least significant bit
+ /// return the n-th bit, n=0 being the least significant bit
bool GetBit(size_t n) const {return GetCoefficient(n)!=0;}
- //! return the n-th byte
+ /// return the n-th byte
byte GetByte(size_t n) const;
- //! the zero polynomial will return a degree of -1
+ /// the zero polynomial will return a degree of -1
signed int Degree() const {return (signed int)(BitCount()-1U);}
- //! degree + 1
+ /// degree + 1
unsigned int CoefficientCount() const {return BitCount();}
- //! return coefficient for x^i
+ /// return coefficient for x^i
int GetCoefficient(size_t i) const
{return (i/WORD_BITS < reg.size()) ? int(reg[i/WORD_BITS] >> (i % WORD_BITS)) & 1 : 0;}
- //! return coefficient for x^i
+ /// return coefficient for x^i
int operator[](unsigned int i) const {return GetCoefficient(i);}
- //!
+ ///
bool IsZero() const {return !*this;}
- //!
+ ///
bool Equals(const PolynomialMod2 &rhs) const;
//@}
- //! \name MANIPULATORS
+ /// \name MANIPULATORS
//@{
- //!
+ ///
PolynomialMod2& operator=(const PolynomialMod2& t);
- //!
+ ///
PolynomialMod2& operator&=(const PolynomialMod2& t);
- //!
+ ///
PolynomialMod2& operator^=(const PolynomialMod2& t);
- //!
+ ///
PolynomialMod2& operator+=(const PolynomialMod2& t) {return *this ^= t;}
- //!
+ ///
PolynomialMod2& operator-=(const PolynomialMod2& t) {return *this ^= t;}
- //!
+ ///
PolynomialMod2& operator*=(const PolynomialMod2& t);
- //!
+ ///
PolynomialMod2& operator/=(const PolynomialMod2& t);
- //!
+ ///
PolynomialMod2& operator%=(const PolynomialMod2& t);
- //!
+ ///
PolynomialMod2& operator<<=(unsigned int);
- //!
+ ///
PolynomialMod2& operator>>=(unsigned int);
- //!
+ ///
void Randomize(RandomNumberGenerator &rng, size_t bitcount);
- //!
+ ///
void SetBit(size_t i, int value = 1);
- //! set the n-th byte to value
+ /// set the n-th byte to value
void SetByte(size_t n, byte value);
- //!
+ ///
void SetCoefficient(size_t i, int value) {SetBit(i, value);}
- //!
+ ///
void swap(PolynomialMod2 &a) {reg.swap(a.reg);}
//@}
- //! \name UNARY OPERATORS
+ /// \name UNARY OPERATORS
//@{
- //!
+ ///
bool operator!() const;
- //!
+ ///
PolynomialMod2 operator+() const {return *this;}
- //!
+ ///
PolynomialMod2 operator-() const {return *this;}
//@}
- //! \name BINARY OPERATORS
+ /// \name BINARY OPERATORS
//@{
- //!
+ ///
PolynomialMod2 And(const PolynomialMod2 &b) const;
- //!
+ ///
PolynomialMod2 Xor(const PolynomialMod2 &b) const;
- //!
+ ///
PolynomialMod2 Plus(const PolynomialMod2 &b) const {return Xor(b);}
- //!
+ ///
PolynomialMod2 Minus(const PolynomialMod2 &b) const {return Xor(b);}
- //!
+ ///
PolynomialMod2 Times(const PolynomialMod2 &b) const;
- //!
+ ///
PolynomialMod2 DividedBy(const PolynomialMod2 &b) const;
- //!
+ ///
PolynomialMod2 Modulo(const PolynomialMod2 &b) const;
- //!
+ ///
PolynomialMod2 operator>>(unsigned int n) const;
- //!
+ ///
PolynomialMod2 operator<<(unsigned int n) const;
//@}
- //! \name OTHER ARITHMETIC FUNCTIONS
+ /// \name OTHER ARITHMETIC FUNCTIONS
//@{
- //! sum modulo 2 of all coefficients
+ /// sum modulo 2 of all coefficients
unsigned int Parity() const;
- //! check for irreducibility
+ /// check for irreducibility
bool IsIrreducible() const;
- //! is always zero since we're working modulo 2
+ /// is always zero since we're working modulo 2
PolynomialMod2 Doubled() const {return Zero();}
- //!
+ ///
PolynomialMod2 Squared() const;
- //! only 1 is a unit
+ /// only 1 is a unit
bool IsUnit() const {return Equals(One());}
- //! return inverse if *this is a unit, otherwise return 0
+ /// return inverse if *this is a unit, otherwise return 0
PolynomialMod2 MultiplicativeInverse() const {return IsUnit() ? One() : Zero();}
- //! greatest common divisor
+ /// greatest common divisor
static PolynomialMod2 CRYPTOPP_API Gcd(const PolynomialMod2 &a, const PolynomialMod2 &n);
- //! calculate multiplicative inverse of *this mod n
+ /// calculate multiplicative inverse of *this mod n
PolynomialMod2 InverseMod(const PolynomialMod2 &) const;
- //! calculate r and q such that (a == d*q + r) && (deg(r) < deg(d))
+ /// calculate r and q such that (a == d*q + r) && (deg(r) < deg(d))
static void CRYPTOPP_API Divide(PolynomialMod2 &r, PolynomialMod2 &q, const PolynomialMod2 &a, const PolynomialMod2 &d);
//@}
- //! \name INPUT/OUTPUT
+ /// \name INPUT/OUTPUT
//@{
- //!
+ ///
friend std::ostream& operator<<(std::ostream& out, const PolynomialMod2 &a);
//@}
@@ -250,37 +250,37 @@ private:
SecWordBlock reg;
};
-//!
+///
inline bool operator==(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
{return a.Equals(b);}
-//!
+///
inline bool operator!=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
{return !(a==b);}
-//! compares degree
+/// compares degree
inline bool operator> (const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
{return a.Degree() > b.Degree();}
-//! compares degree
+/// compares degree
inline bool operator>=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
{return a.Degree() >= b.Degree();}
-//! compares degree
+/// compares degree
inline bool operator< (const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
{return a.Degree() < b.Degree();}
-//! compares degree
+/// compares degree
inline bool operator<=(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b)
{return a.Degree() <= b.Degree();}
-//!
+///
inline CryptoPP::PolynomialMod2 operator&(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.And(b);}
-//!
+///
inline CryptoPP::PolynomialMod2 operator^(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Xor(b);}
-//!
+///
inline CryptoPP::PolynomialMod2 operator+(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Plus(b);}
-//!
+///
inline CryptoPP::PolynomialMod2 operator-(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Minus(b);}
-//!
+///
inline CryptoPP::PolynomialMod2 operator*(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Times(b);}
-//!
+///
inline CryptoPP::PolynomialMod2 operator/(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.DividedBy(b);}
-//!
+///
inline CryptoPP::PolynomialMod2 operator%(const CryptoPP::PolynomialMod2 &a, const CryptoPP::PolynomialMod2 &b) {return a.Modulo(b);}
// CodeWarrior 8 workaround: put these template instantiations after overloaded operator declarations,
@@ -291,7 +291,7 @@ CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain<PolynomialMod2>;
CRYPTOPP_DLL_TEMPLATE_CLASS EuclideanDomainOf<PolynomialMod2>;
CRYPTOPP_DLL_TEMPLATE_CLASS QuotientRing<EuclideanDomainOf<PolynomialMod2> >;
-//! \brief GF(2^n) with Polynomial Basis
+/// \brief GF(2^n) with Polynomial Basis
class CRYPTOPP_DLL GF2NP : public QuotientRing<EuclideanDomainOf<PolynomialMod2> >
{
public:
@@ -327,7 +327,7 @@ protected:
unsigned int m;
};
-//! \brief GF(2^n) with Trinomial Basis
+/// \brief GF(2^n) with Trinomial Basis
class CRYPTOPP_DLL GF2NT : public GF2NP
{
public:
@@ -351,7 +351,7 @@ private:
mutable PolynomialMod2 result;
};
-//! \brief GF(2^n) with Pentanomial Basis
+/// \brief GF(2^n) with Pentanomial Basis
class CRYPTOPP_DLL GF2NPP : public GF2NP
{
public: