Crypto++  5.6.3
Free C++ class library of cryptographic schemes
integer.h
Go to the documentation of this file.
1 #ifndef CRYPTOPP_INTEGER_H
2 #define CRYPTOPP_INTEGER_H
3 
4 /** \file */
5 
6 #include "cryptlib.h"
7 #include "secblock.h"
8 #include "stdcpp.h"
9 
10 #include <iosfwd>
11 
12 NAMESPACE_BEGIN(CryptoPP)
13 
14 //! \struct InitializeInteger
15 //! Performs static intialization of the Integer class
17 {
18  InitializeInteger();
19 };
20 
22 
23 //! \brief Multiple precision integer with arithmetic operations
24 //! \details The Integer class can represent positive and negative integers
25 //! with absolute value less than (256**sizeof(word))<sup>(256**sizeof(int))</sup>.
26 //! \details Internally, the library uses a sign magnitude representation, and the class
27 //! has two data members. The first is a IntegerSecBlock (a SecBlock<word>) and it i
28 //! used to hold the representation. The second is a Sign, and its is used to track
29 //! the sign of the Integer.
30 //! \nosubgrouping
31 class CRYPTOPP_DLL Integer : private InitializeInteger, public ASN1Object
32 {
33 public:
34  //! \name ENUMS, EXCEPTIONS, and TYPEDEFS
35  //@{
36  //! \brief Exception thrown when division by 0 is encountered
37  class DivideByZero : public Exception
38  {
39  public:
40  DivideByZero() : Exception(OTHER_ERROR, "Integer: division by zero") {}
41  };
42 
43  //! \brief Exception thrown when a random number cannot be found that
44  //! satisfies the condition
46  {
47  public:
48  RandomNumberNotFound() : Exception(OTHER_ERROR, "Integer: no integer satisfies the given parameters") {}
49  };
50 
51  //! \enum Sign
52  //! \brief Used internally to represent the integer
53  //! \details Sign is used internally to represent the integer. It is also used in a few API functions.
54  //! \sa Signedness
55  enum Sign {
56  //! \brief the value is positive or 0
57  POSITIVE=0,
58  //! \brief the value is negative
59  NEGATIVE=1};
60 
61  //! \enum Signedness
62  //! \brief Used when importing and exporting integers
63  //! \details Signedness is usually used in API functions.
64  //! \sa Sign
65  enum Signedness {
66  //! \brief an unsigned value
68  //! \brief a signed value
69  SIGNED};
70 
71  //! \enum RandomNumberType
72  //! \brief Properties of a random integer
74  //! \brief a number with no special properties
75  ANY,
76  //! \brief a number which is probabilistically prime
77  PRIME};
78  //@}
79 
80  //! \name CREATORS
81  //@{
82  //! \brief Creates the zero integer
83  Integer();
84 
85  //! copy constructor
86  Integer(const Integer& t);
87 
88  //! \brief Convert from signed long
89  Integer(signed long value);
90 
91  //! \brief Convert from lword
92  //! \param sign enumeration indicating Sign
93  //! \param value the long word
94  Integer(Sign sign, lword value);
95 
96  //! \brief Convert from two words
97  //! \param sign enumeration indicating Sign
98  //! \param highWord the high word
99  //! \param lowWord the low word
100  Integer(Sign sign, word highWord, word lowWord);
101 
102  //! \brief Convert from a C-string
103  //! \param str C-string value
104  //! \details \p str can be in base 2, 8, 10, or 16. Base is determined by a case
105  //! insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10.
106  explicit Integer(const char *str);
107 
108  //! \brief Convert from a wide C-string
109  //! \param str wide C-string value
110  //! \details \p str can be in base 2, 8, 10, or 16. Base is determined by a case
111  //! insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10.
112  explicit Integer(const wchar_t *str);
113 
114  //! \brief Convert from a big-endian byte array
115  //! \param encodedInteger big-endian byte array
116  //! \param byteCount length of the byte array
117  //! \param sign enumeration indicating Signedness
118  Integer(const byte *encodedInteger, size_t byteCount, Signedness sign=UNSIGNED);
119 
120  //! \brief Convert from a big-endian array
121  //! \param bt BufferedTransformation object with big-endian byte array
122  //! \param byteCount length of the byte array
123  //! \param sign enumeration indicating Signedness
124  Integer(BufferedTransformation &bt, size_t byteCount, Signedness sign=UNSIGNED);
125 
126  //! \brief Convert from a BER encoded byte array
127  //! \param bt BufferedTransformation object with BER encoded byte array
128  explicit Integer(BufferedTransformation &bt);
129 
130  //! \brief Create a random integer
131  //! \param rng RandomNumberGenerator used to generate material
132  //! \param bitCount the number of bits in the resulting integer
133  //! \details The random integer created is uniformly distributed over <tt>[0, 2<sup>bitCount</sup>]</tt>.
134  Integer(RandomNumberGenerator &rng, size_t bitCount);
135 
136  //! \brief Integer representing 0
137  //! \returns an Integer representing 0
138  //! \details Zero() avoids calling constructors for frequently used integers
139  static const Integer & CRYPTOPP_API Zero();
140  //! \brief Integer representing 1
141  //! \returns an Integer representing 1
142  //! \details One() avoids calling constructors for frequently used integers
143  static const Integer & CRYPTOPP_API One();
144  //! \brief Integer representing 2
145  //! \returns an Integer representing 2
146  //! \details Two() avoids calling constructors for frequently used integers
147  static const Integer & CRYPTOPP_API Two();
148 
149  //! \brief Create a random integer of special form
150  //! \param rng RandomNumberGenerator used to generate material
151  //! \param min the minimum value
152  //! \param max the maximum value
153  //! \param rnType RandomNumberType to specify the type
154  //! \param equiv the equivalence class based on the parameter \p mod
155  //! \param mod the modulus used to reduce the equivalence class
156  //! \throw RandomNumberNotFound if the set is empty.
157  //! \details Ideally, the random integer created should be uniformly distributed
158  //! over <tt>{x | min <= x <= max</tt> and \p x is of rnType and <tt>x \% mod == equiv}</tt>.
159  //! However the actual distribution may not be uniform because sequential
160  //! search is used to find an appropriate number from a random starting
161  //! point.
162  //! \details May return (with very small probability) a pseudoprime when a prime
163  //! is requested and <tt>max > lastSmallPrime*lastSmallPrime</tt>. \p lastSmallPrime
164  //! is declared in nbtheory.h.
165  Integer(RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType=ANY, const Integer &equiv=Zero(), const Integer &mod=One());
166 
167  //! \brief Exponentiates to a power of 2
168  //! \returns the Integer 2<sup>e</sup>
169  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
170  static Integer CRYPTOPP_API Power2(size_t e);
171  //@}
172 
173  //! \name ENCODE/DECODE
174  //@{
175  //! \brief The minimum number of bytes to encode this integer
176  //! \param sign enumeration indicating Signedness
177  //! \note The MinEncodedSize() of 0 is 1.
178  size_t MinEncodedSize(Signedness sign=UNSIGNED) const;
179 
180  //! \brief Encode in big-endian format
181  //! \param output big-endian byte array
182  //! \param outputLen length of the byte array
183  //! \param sign enumeration indicating Signedness
184  //! \details Unsigned means encode absolute value, signed means encode two's complement if negative.
185  //! \details outputLen can be used to ensure an Integer is encoded to an exact size (rather than a
186  //! minimum size). An exact size is useful, for example, when encoding to a field element size.
187  void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const;
188 
189  //! \brief Encode in big-endian format
190  //! \param bt BufferedTransformation object
191  //! \param outputLen length of the encoding
192  //! \param sign enumeration indicating Signedness
193  //! \details Unsigned means encode absolute value, signed means encode two's complement if negative.
194  //! \details outputLen can be used to ensure an Integer is encoded to an exact size (rather than a
195  //! minimum size). An exact size is useful, for example, when encoding to a field element size.
196  void Encode(BufferedTransformation &bt, size_t outputLen, Signedness sign=UNSIGNED) const;
197 
198  //! \brief Encode in DER format
199  //! \param bt BufferedTransformation object
200  //! \details Encodes the Integer using Distinguished Encoding Rules
201  //! The result is placed into a BufferedTransformation object
202  void DEREncode(BufferedTransformation &bt) const;
203 
204  //! encode absolute value as big-endian octet string
205  //! \param bt BufferedTransformation object
206  //! \param length the number of mytes to decode
207  void DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const;
208 
209  //! \brief Encode absolute value in OpenPGP format
210  //! \param output big-endian byte array
211  //! \param bufferSize length of the byte array
212  //! \returns length of the output
213  //! \details OpenPGPEncode places result into a BufferedTransformation object and returns the
214  //! number of bytes used for the encoding
215  size_t OpenPGPEncode(byte *output, size_t bufferSize) const;
216 
217  //! \brief Encode absolute value in OpenPGP format
218  //! \param bt BufferedTransformation object
219  //! \returns length of the output
220  //! \details OpenPGPEncode places result into a BufferedTransformation object and returns the
221  //! number of bytes used for the encoding
222  size_t OpenPGPEncode(BufferedTransformation &bt) const;
223 
224  //! \brief Decode from big-endian byte array
225  //! \param input big-endian byte array
226  //! \param inputLen length of the byte array
227  //! \param sign enumeration indicating Signedness
228  void Decode(const byte *input, size_t inputLen, Signedness sign=UNSIGNED);
229 
230  //! \brief Decode nonnegative value from big-endian byte array
231  //! \param bt BufferedTransformation object
232  //! \param inputLen length of the byte array
233  //! \param sign enumeration indicating Signedness
234  //! \note <tt>bt.MaxRetrievable() >= inputLen</tt>.
235  void Decode(BufferedTransformation &bt, size_t inputLen, Signedness sign=UNSIGNED);
236 
237  //! \brief Decode from BER format
238  //! \param input big-endian byte array
239  //! \param inputLen length of the byte array
240  void BERDecode(const byte *input, size_t inputLen);
241 
242  //! \brief Decode from BER format
243  //! \param bt BufferedTransformation object
244  void BERDecode(BufferedTransformation &bt);
245 
246  //! \brief Decode nonnegative value from big-endian octet string
247  //! \param bt BufferedTransformation object
248  //! \param length length of the byte array
249  void BERDecodeAsOctetString(BufferedTransformation &bt, size_t length);
250 
251  //! \brief Exception thrown when an error is encountered decoding an OpenPGP integer
253  {
254  public:
255  OpenPGPDecodeErr() : Exception(INVALID_DATA_FORMAT, "OpenPGP decode error") {}
256  };
257 
258  //! \brief Decode from OpenPGP format
259  //! \param input big-endian byte array
260  //! \param inputLen length of the byte array
261  void OpenPGPDecode(const byte *input, size_t inputLen);
262  //! \brief Decode from OpenPGP format
263  //! \param bt BufferedTransformation object
264  void OpenPGPDecode(BufferedTransformation &bt);
265  //@}
266 
267  //! \name ACCESSORS
268  //@{
269  //! return true if *this can be represented as a signed long
270  bool IsConvertableToLong() const;
271  //! return equivalent signed long if possible, otherwise undefined
272  signed long ConvertToLong() const;
273 
274  //! number of significant bits = floor(log2(abs(*this))) + 1
275  unsigned int BitCount() const;
276  //! number of significant bytes = ceiling(BitCount()/8)
277  unsigned int ByteCount() const;
278  //! number of significant words = ceiling(ByteCount()/sizeof(word))
279  unsigned int WordCount() const;
280 
281  //! return the i-th bit, i=0 being the least significant bit
282  bool GetBit(size_t i) const;
283  //! return the i-th byte
284  byte GetByte(size_t i) const;
285  //! return n lowest bits of *this >> i
286  lword GetBits(size_t i, size_t n) const;
287 
288  //!
289  bool IsZero() const {return !*this;}
290  //!
291  bool NotZero() const {return !IsZero();}
292  //!
293  bool IsNegative() const {return sign == NEGATIVE;}
294  //!
295  bool NotNegative() const {return !IsNegative();}
296  //!
297  bool IsPositive() const {return NotNegative() && NotZero();}
298  //!
299  bool NotPositive() const {return !IsPositive();}
300  //!
301  bool IsEven() const {return GetBit(0) == 0;}
302  //!
303  bool IsOdd() const {return GetBit(0) == 1;}
304  //@}
305 
306  //! \name MANIPULATORS
307  //@{
308  //!
309  Integer& operator=(const Integer& t);
310 
311  //!
312  Integer& operator+=(const Integer& t);
313  //!
314  Integer& operator-=(const Integer& t);
315  //!
316  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
317  Integer& operator*=(const Integer& t) {return *this = Times(t);}
318  //!
319  Integer& operator/=(const Integer& t) {return *this = DividedBy(t);}
320  //!
321  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
322  Integer& operator%=(const Integer& t) {return *this = Modulo(t);}
323  //!
324  Integer& operator/=(word t) {return *this = DividedBy(t);}
325  //!
326  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
327  Integer& operator%=(word t) {return *this = Integer(POSITIVE, 0, Modulo(t));}
328 
329  //!
330  Integer& operator<<=(size_t);
331  //!
332  Integer& operator>>=(size_t);
333 
334  //! \brief Set this Integer to random integer
335  //! \param rng RandomNumberGenerator used to generate material
336  //! \param bitCount the number of bits in the resulting integer
337  //! \details The random integer created is uniformly distributed over <tt>[0, 2<sup>bitCount</sup>]</tt>.
338  void Randomize(RandomNumberGenerator &rng, size_t bitCount);
339 
340  //! \brief Set this Integer to random integer
341  //! \param rng RandomNumberGenerator used to generate material
342  //! \param min the minimum value
343  //! \param max the maximum value
344  //! \details The random integer created is uniformly distributed over <tt>[min, max]</tt>.
345  void Randomize(RandomNumberGenerator &rng, const Integer &min, const Integer &max);
346 
347  //! \brief Set this Integer to random integer of special form
348  //! \param rng RandomNumberGenerator used to generate material
349  //! \param min the minimum value
350  //! \param max the maximum value
351  //! \param rnType RandomNumberType to specify the type
352  //! \param equiv the equivalence class based on the parameter \p mod
353  //! \param mod the modulus used to reduce the equivalence class
354  //! \throw RandomNumberNotFound if the set is empty.
355  //! \details Ideally, the random integer created should be uniformly distributed
356  //! over <tt>{x | min <= x <= max</tt> and \p x is of rnType and <tt>x \% mod == equiv}</tt>.
357  //! However the actual distribution may not be uniform because sequential
358  //! search is used to find an appropriate number from a random starting
359  //! point.
360  //! \details May return (with very small probability) a pseudoprime when a prime
361  //! is requested and <tt>max > lastSmallPrime*lastSmallPrime</tt>. \p lastSmallPrime
362  //! is declared in nbtheory.h.
363  bool Randomize(RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType, const Integer &equiv=Zero(), const Integer &mod=One());
364 
365  bool GenerateRandomNoThrow(RandomNumberGenerator &rng, const NameValuePairs &params = g_nullNameValuePairs);
366  void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params = g_nullNameValuePairs)
367  {
368  if (!GenerateRandomNoThrow(rng, params))
369  throw RandomNumberNotFound();
370  }
371 
372  //! \brief Set the n-th bit to value
373  //! \details 0-based numbering.
374  void SetBit(size_t n, bool value=1);
375 
376  //! \brief Set the n-th byte to value
377  //! \details 0-based numbering.
378  void SetByte(size_t n, byte value);
379 
380  //! \brief Reverse the Sign of the Integer
381  void Negate();
382 
383  //! \brief Sets the Integer to positive
384  void SetPositive() {sign = POSITIVE;}
385 
386  //! \brief Sets the Integer to negative
387  void SetNegative() {if (!!(*this)) sign = NEGATIVE;}
388 
389  //! \brief Swaps this Integer with another Integer
390  void swap(Integer &a);
391  //@}
392 
393  //! \name UNARY OPERATORS
394  //@{
395  //!
396  bool operator!() const;
397  //!
398  Integer operator+() const {return *this;}
399  //!
400  Integer operator-() const;
401  //!
402  Integer& operator++();
403  //!
404  Integer& operator--();
405  //!
406  Integer operator++(int) {Integer temp = *this; ++*this; return temp;}
407  //!
408  Integer operator--(int) {Integer temp = *this; --*this; return temp;}
409  //@}
410 
411  //! \name BINARY OPERATORS
412  //@{
413  //! \brief Perform signed comparison
414  //! \param a the Integer to comapre
415  //! \retval -1 if <tt>*this < a</tt>
416  //! \retval 0 if <tt>*this = a</tt>
417  //! \retval 1 if <tt>*this > a</tt>
418  int Compare(const Integer& a) const;
419 
420  //!
421  Integer Plus(const Integer &b) const;
422  //!
423  Integer Minus(const Integer &b) const;
424  //!
425  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
426  Integer Times(const Integer &b) const;
427  //!
428  Integer DividedBy(const Integer &b) const;
429  //!
430  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
431  Integer Modulo(const Integer &b) const;
432  //!
433  Integer DividedBy(word b) const;
434  //!
435  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
436  word Modulo(word b) const;
437 
438  //!
439  Integer operator>>(size_t n) const {return Integer(*this)>>=n;}
440  //!
441  Integer operator<<(size_t n) const {return Integer(*this)<<=n;}
442  //@}
443 
444  //! \name OTHER ARITHMETIC FUNCTIONS
445  //@{
446  //!
447  Integer AbsoluteValue() const;
448  //!
449  Integer Doubled() const {return Plus(*this);}
450  //!
451  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
452  Integer Squared() const {return Times(*this);}
453  //! extract square root, if negative return 0, else return floor of square root
454  Integer SquareRoot() const;
455  //! return whether this integer is a perfect square
456  bool IsSquare() const;
457 
458  //! is 1 or -1
459  bool IsUnit() const;
460  //! return inverse if 1 or -1, otherwise return 0
461  Integer MultiplicativeInverse() const;
462 
463  //! calculate r and q such that (a == d*q + r) && (0 <= r < abs(d))
464  static void CRYPTOPP_API Divide(Integer &r, Integer &q, const Integer &a, const Integer &d);
465  //! use a faster division algorithm when divisor is short
466  static void CRYPTOPP_API Divide(word &r, Integer &q, const Integer &a, word d);
467 
468  //! returns same result as Divide(r, q, a, Power2(n)), but faster
469  static void CRYPTOPP_API DivideByPowerOf2(Integer &r, Integer &q, const Integer &a, unsigned int n);
470 
471  //! greatest common divisor
472  static Integer CRYPTOPP_API Gcd(const Integer &a, const Integer &n);
473  //! calculate multiplicative inverse of *this mod n
474  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
475  Integer InverseMod(const Integer &n) const;
476  //!
477  //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
478  word InverseMod(word n) const;
479  //@}
480 
481  //! \name INPUT/OUTPUT
482  //@{
483  //! \brief Extraction operator
484  //! \param in a reference to a std::istream
485  //! \param a a reference to an Integer
486  //! \returns a reference to a std::istream reference
487  friend CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>>(std::istream& in, Integer &a);
488  //!
489  //! \brief Insertion operator
490  //! \param out a reference to a std::ostream
491  //! \param a a constant reference to an Integer
492  //! \returns a reference to a std::ostream reference
493  //! \details The output integer responds to std::hex, std::oct, std::hex, std::upper and
494  //! std::lower. The output includes the suffix \a \b h (for hex), \a \b . (\a \b dot, for dec)
495  //! and \a \b o (for octal). There is currently no way to supress the suffix.
496  //! \details If you want to print an Integer without the suffix or using an arbitrary base, then
497  //! use IntToString<Integer>().
498  //! \sa IntToString<Integer>
499  friend CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<<(std::ostream& out, const Integer &a);
500  //@}
501 
502 #ifndef CRYPTOPP_DOXYGEN_PROCESSING
503  //! modular multiplication
504  CRYPTOPP_DLL friend Integer CRYPTOPP_API a_times_b_mod_c(const Integer &x, const Integer& y, const Integer& m);
505  //! modular exponentiation
506  CRYPTOPP_DLL friend Integer CRYPTOPP_API a_exp_b_mod_c(const Integer &x, const Integer& e, const Integer& m);
507 #endif
508 
509 private:
510 
511  Integer(word value, size_t length);
512  int PositiveCompare(const Integer &t) const;
513 
514  IntegerSecBlock reg;
515  Sign sign;
516 
517 #ifndef CRYPTOPP_DOXYGEN_PROCESSING
518  friend class ModularArithmetic;
519  friend class MontgomeryRepresentation;
520  friend class HalfMontgomeryRepresentation;
521 
522  friend void PositiveAdd(Integer &sum, const Integer &a, const Integer &b);
523  friend void PositiveSubtract(Integer &diff, const Integer &a, const Integer &b);
524  friend void PositiveMultiply(Integer &product, const Integer &a, const Integer &b);
525  friend void PositiveDivide(Integer &remainder, Integer &quotient, const Integer &dividend, const Integer &divisor);
526 #endif
527 };
528 
529 //!
530 inline bool operator==(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)==0;}
531 //!
532 inline bool operator!=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)!=0;}
533 //!
534 inline bool operator> (const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)> 0;}
535 //!
536 inline bool operator>=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)>=0;}
537 //!
538 inline bool operator< (const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)< 0;}
539 //!
540 inline bool operator<=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)<=0;}
541 //!
542 inline CryptoPP::Integer operator+(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Plus(b);}
543 //!
544 inline CryptoPP::Integer operator-(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Minus(b);}
545 //!
546 //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
547 inline CryptoPP::Integer operator*(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Times(b);}
548 //!
549 inline CryptoPP::Integer operator/(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.DividedBy(b);}
550 //!
551 //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
552 inline CryptoPP::Integer operator%(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Modulo(b);}
553 //!
554 inline CryptoPP::Integer operator/(const CryptoPP::Integer &a, CryptoPP::word b) {return a.DividedBy(b);}
555 //!
556 //! \sa a_times_b_mod_c() and a_exp_b_mod_c()
557 inline CryptoPP::word operator%(const CryptoPP::Integer &a, CryptoPP::word b) {return a.Modulo(b);}
558 
559 NAMESPACE_END
560 
561 #ifndef __BORLANDC__
562 NAMESPACE_BEGIN(std)
563 inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b)
564 {
565  a.swap(b);
566 }
567 NAMESPACE_END
568 #endif
569 
570 #endif
Base class for all exceptions thrown by Crypto++.
Definition: cryptlib.h:124
bool operator>=(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
Definition: gf2n.h:250
bool operator>(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
Definition: gf2n.h:247
void SetNegative()
Sets the Integer to negative.
Definition: integer.h:387
inline::Integer operator*(const ::Integer &a, const ::Integer &b)
Definition: integer.h:547
an unsigned value
Definition: integer.h:67
void SetPositive()
Sets the Integer to positive.
Definition: integer.h:384
inline::Integer operator%(const ::Integer &a, const ::Integer &b)
Definition: integer.h:552
Secure memory block with allocator and cleanup.
Definition: secblock.h:422
Abstract base classes that provide a uniform interface to this library.
Signedness
Used when importing and exporting integers.
Definition: integer.h:65
Ring of congruence classes modulo n.
Definition: modarith.h:27
STL namespace.
Interface for random number generators.
Definition: cryptlib.h:1085
Interface for buffered transformations.
Definition: cryptlib.h:1247
Sign
Used internally to represent the integer.
Definition: integer.h:55
Classes and functions for secure memory allocations.
a number with no special properties
Definition: integer.h:75
Integer Squared() const
Definition: integer.h:452
Exception thrown when an error is encountered decoding an OpenPGP integer.
Definition: integer.h:252
Interface for encoding and decoding ASN1 objects.
Definition: cryptlib.h:2628
Performs static intialization of the Integer class.
Definition: integer.h:16
Multiple precision integer with arithmetic operations.
Definition: integer.h:31
const NameValuePairs & g_nullNameValuePairs
An empty set of name-value pairs.
Definition: cryptlib.cpp:79
RandomNumberType
Properties of a random integer.
Definition: integer.h:73
bool operator<(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
Definition: gf2n.h:253
Integer & operator*=(const Integer &t)
Definition: integer.h:317
Exception thrown when division by 0 is encountered.
Definition: integer.h:37
Exception thrown when a random number cannot be found that satisfies the condition.
Definition: integer.h:45
Performs modular arithmetic in Montgomery representation for increased speed.
Definition: modarith.h:137
Crypto++ library namespace.
Integer & operator%=(word t)
Definition: integer.h:327
unsigned int GetByte(ByteOrder order, T value, unsigned int index)
Gets a byte from a value.
Definition: misc.h:1540
Integer & operator%=(const Integer &t)
Definition: integer.h:322
bool operator<=(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
Definition: gf2n.h:256
Interface for retrieving values given their names.
Definition: cryptlib.h:261