00001 #ifndef CRYPTOPP_INTEGER_H 00002 #define CRYPTOPP_INTEGER_H 00003 00004 /** \file */ 00005 00006 #include "cryptlib.h" 00007 #include "secblock.h" 00008 #include "stdcpp.h" 00009 00010 #include <iosfwd> 00011 00012 NAMESPACE_BEGIN(CryptoPP) 00013 00014 //! \struct InitializeInteger 00015 //! Performs static intialization of the Integer class 00016 struct InitializeInteger 00017 { 00018 InitializeInteger(); 00019 }; 00020 00021 typedef SecBlock<word, AllocatorWithCleanup<word, CRYPTOPP_BOOL_X86> > IntegerSecBlock; 00022 00023 //! \brief Multiple precision integer with arithmetic operations 00024 //! \details The Integer class can represent positive and negative integers 00025 //! with absolute value less than (256**sizeof(word))<sup>(256**sizeof(int))</sup>. 00026 //! \details Internally, the library uses a sign magnitude representation, and the class 00027 //! has two data members. The first is a IntegerSecBlock (a SecBlock<word>) and it i 00028 //! used to hold the representation. The second is a Sign, and its is used to track 00029 //! the sign of the Integer. 00030 //! \nosubgrouping 00031 class CRYPTOPP_DLL Integer : private InitializeInteger, public ASN1Object 00032 { 00033 public: 00034 //! \name ENUMS, EXCEPTIONS, and TYPEDEFS 00035 //@{ 00036 //! \brief Exception thrown when division by 0 is encountered 00037 class DivideByZero : public Exception 00038 { 00039 public: 00040 DivideByZero() : Exception(OTHER_ERROR, "Integer: division by zero") {} 00041 }; 00042 00043 //! \brief Exception thrown when a random number cannot be found that 00044 //! satisfies the condition 00045 class RandomNumberNotFound : public Exception 00046 { 00047 public: 00048 RandomNumberNotFound() : Exception(OTHER_ERROR, "Integer: no integer satisfies the given parameters") {} 00049 }; 00050 00051 //! \enum Sign 00052 //! \brief Used internally to represent the integer 00053 //! \details Sign is used internally to represent the integer. It is also used in a few API functions. 00054 //! \sa Signedness 00055 enum Sign { 00056 //! \brief the value is positive or 0 00057 POSITIVE=0, 00058 //! \brief the value is negative 00059 NEGATIVE=1}; 00060 00061 //! \enum Signedness 00062 //! \brief Used when importing and exporting integers 00063 //! \details Signedness is usually used in API functions. 00064 //! \sa Sign 00065 enum Signedness { 00066 //! \brief an unsigned value 00067 UNSIGNED, 00068 //! \brief a signed value 00069 SIGNED}; 00070 00071 //! \enum RandomNumberType 00072 //! \brief Properties of a random integer 00073 enum RandomNumberType { 00074 //! \brief a number with no special properties 00075 ANY, 00076 //! \brief a number which is probabilistically prime 00077 PRIME}; 00078 //@} 00079 00080 //! \name CREATORS 00081 //@{ 00082 //! \brief Creates the zero integer 00083 Integer(); 00084 00085 //! copy constructor 00086 Integer(const Integer& t); 00087 00088 //! \brief Convert from signed long 00089 Integer(signed long value); 00090 00091 //! \brief Convert from lword 00092 //! \param sign enumeration indicating Sign 00093 //! \param value the long word 00094 Integer(Sign sign, lword value); 00095 00096 //! \brief Convert from two words 00097 //! \param sign enumeration indicating Sign 00098 //! \param highWord the high word 00099 //! \param lowWord the low word 00100 Integer(Sign sign, word highWord, word lowWord); 00101 00102 //! \brief Convert from a C-string 00103 //! \param str C-string value 00104 //! \details \p str can be in base 2, 8, 10, or 16. Base is determined by a case 00105 //! insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10. 00106 explicit Integer(const char *str); 00107 00108 //! \brief Convert from a wide C-string 00109 //! \param str wide C-string value 00110 //! \details \p str can be in base 2, 8, 10, or 16. Base is determined by a case 00111 //! insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10. 00112 explicit Integer(const wchar_t *str); 00113 00114 //! \brief Convert from a big-endian byte array 00115 //! \param encodedInteger big-endian byte array 00116 //! \param byteCount length of the byte array 00117 //! \param sign enumeration indicating Signedness 00118 Integer(const byte *encodedInteger, size_t byteCount, Signedness sign=UNSIGNED); 00119 00120 //! \brief Convert from a big-endian array 00121 //! \param bt BufferedTransformation object with big-endian byte array 00122 //! \param byteCount length of the byte array 00123 //! \param sign enumeration indicating Signedness 00124 Integer(BufferedTransformation &bt, size_t byteCount, Signedness sign=UNSIGNED); 00125 00126 //! \brief Convert from a BER encoded byte array 00127 //! \param bt BufferedTransformation object with BER encoded byte array 00128 explicit Integer(BufferedTransformation &bt); 00129 00130 //! \brief Create a random integer 00131 //! \param rng RandomNumberGenerator used to generate material 00132 //! \param bitCount the number of bits in the resulting integer 00133 //! \details The random integer created is uniformly distributed over <tt>[0, 2<sup>bitCount</sup>]</tt>. 00134 Integer(RandomNumberGenerator &rng, size_t bitCount); 00135 00136 //! \brief Integer representing 0 00137 //! \returns an Integer representing 0 00138 //! \details Zero() avoids calling constructors for frequently used integers 00139 static const Integer & CRYPTOPP_API Zero(); 00140 //! \brief Integer representing 1 00141 //! \returns an Integer representing 1 00142 //! \details One() avoids calling constructors for frequently used integers 00143 static const Integer & CRYPTOPP_API One(); 00144 //! \brief Integer representing 2 00145 //! \returns an Integer representing 2 00146 //! \details Two() avoids calling constructors for frequently used integers 00147 static const Integer & CRYPTOPP_API Two(); 00148 00149 //! \brief Create a random integer of special form 00150 //! \param rng RandomNumberGenerator used to generate material 00151 //! \param min the minimum value 00152 //! \param max the maximum value 00153 //! \param rnType RandomNumberType to specify the type 00154 //! \param equiv the equivalence class based on the parameter \p mod 00155 //! \param mod the modulus used to reduce the equivalence class 00156 //! \throw RandomNumberNotFound if the set is empty. 00157 //! \details Ideally, the random integer created should be uniformly distributed 00158 //! over <tt>{x | min <= x <= max</tt> and \p x is of rnType and <tt>x \% mod == equiv}</tt>. 00159 //! However the actual distribution may not be uniform because sequential 00160 //! search is used to find an appropriate number from a random starting 00161 //! point. 00162 //! \details May return (with very small probability) a pseudoprime when a prime 00163 //! is requested and <tt>max > lastSmallPrime*lastSmallPrime</tt>. \p lastSmallPrime 00164 //! is declared in nbtheory.h. 00165 Integer(RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType=ANY, const Integer &equiv=Zero(), const Integer &mod=One()); 00166 00167 //! \brief Exponentiates to a power of 2 00168 //! \returns the Integer 2<sup>e</sup> 00169 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00170 static Integer CRYPTOPP_API Power2(size_t e); 00171 //@} 00172 00173 //! \name ENCODE/DECODE 00174 //@{ 00175 //! \brief The minimum number of bytes to encode this integer 00176 //! \param sign enumeration indicating Signedness 00177 //! \note The MinEncodedSize() of 0 is 1. 00178 size_t MinEncodedSize(Signedness sign=UNSIGNED) const; 00179 00180 //! \brief Encode in big-endian format 00181 //! \param output big-endian byte array 00182 //! \param outputLen length of the byte array 00183 //! \param sign enumeration indicating Signedness 00184 //! \details Unsigned means encode absolute value, signed means encode two's complement if negative. 00185 //! \details outputLen can be used to ensure an Integer is encoded to an exact size (rather than a 00186 //! minimum size). An exact size is useful, for example, when encoding to a field element size. 00187 void Encode(byte *output, size_t outputLen, Signedness sign=UNSIGNED) const; 00188 00189 //! \brief Encode in big-endian format 00190 //! \param bt BufferedTransformation object 00191 //! \param outputLen length of the encoding 00192 //! \param sign enumeration indicating Signedness 00193 //! \details Unsigned means encode absolute value, signed means encode two's complement if negative. 00194 //! \details outputLen can be used to ensure an Integer is encoded to an exact size (rather than a 00195 //! minimum size). An exact size is useful, for example, when encoding to a field element size. 00196 void Encode(BufferedTransformation &bt, size_t outputLen, Signedness sign=UNSIGNED) const; 00197 00198 //! \brief Encode in DER format 00199 //! \param bt BufferedTransformation object 00200 //! \details Encodes the Integer using Distinguished Encoding Rules 00201 //! The result is placed into a BufferedTransformation object 00202 void DEREncode(BufferedTransformation &bt) const; 00203 00204 //! encode absolute value as big-endian octet string 00205 //! \param bt BufferedTransformation object 00206 //! \param length the number of mytes to decode 00207 void DEREncodeAsOctetString(BufferedTransformation &bt, size_t length) const; 00208 00209 //! \brief Encode absolute value in OpenPGP format 00210 //! \param output big-endian byte array 00211 //! \param bufferSize length of the byte array 00212 //! \returns length of the output 00213 //! \details OpenPGPEncode places result into a BufferedTransformation object and returns the 00214 //! number of bytes used for the encoding 00215 size_t OpenPGPEncode(byte *output, size_t bufferSize) const; 00216 00217 //! \brief Encode absolute value in OpenPGP format 00218 //! \param bt BufferedTransformation object 00219 //! \returns length of the output 00220 //! \details OpenPGPEncode places result into a BufferedTransformation object and returns the 00221 //! number of bytes used for the encoding 00222 size_t OpenPGPEncode(BufferedTransformation &bt) const; 00223 00224 //! \brief Decode from big-endian byte array 00225 //! \param input big-endian byte array 00226 //! \param inputLen length of the byte array 00227 //! \param sign enumeration indicating Signedness 00228 void Decode(const byte *input, size_t inputLen, Signedness sign=UNSIGNED); 00229 00230 //! \brief Decode nonnegative value from big-endian byte array 00231 //! \param bt BufferedTransformation object 00232 //! \param inputLen length of the byte array 00233 //! \param sign enumeration indicating Signedness 00234 //! \note <tt>bt.MaxRetrievable() >= inputLen</tt>. 00235 void Decode(BufferedTransformation &bt, size_t inputLen, Signedness sign=UNSIGNED); 00236 00237 //! \brief Decode from BER format 00238 //! \param input big-endian byte array 00239 //! \param inputLen length of the byte array 00240 void BERDecode(const byte *input, size_t inputLen); 00241 00242 //! \brief Decode from BER format 00243 //! \param bt BufferedTransformation object 00244 void BERDecode(BufferedTransformation &bt); 00245 00246 //! \brief Decode nonnegative value from big-endian octet string 00247 //! \param bt BufferedTransformation object 00248 //! \param length length of the byte array 00249 void BERDecodeAsOctetString(BufferedTransformation &bt, size_t length); 00250 00251 //! \brief Exception thrown when an error is encountered decoding an OpenPGP integer 00252 class OpenPGPDecodeErr : public Exception 00253 { 00254 public: 00255 OpenPGPDecodeErr() : Exception(INVALID_DATA_FORMAT, "OpenPGP decode error") {} 00256 }; 00257 00258 //! \brief Decode from OpenPGP format 00259 //! \param input big-endian byte array 00260 //! \param inputLen length of the byte array 00261 void OpenPGPDecode(const byte *input, size_t inputLen); 00262 //! \brief Decode from OpenPGP format 00263 //! \param bt BufferedTransformation object 00264 void OpenPGPDecode(BufferedTransformation &bt); 00265 //@} 00266 00267 //! \name ACCESSORS 00268 //@{ 00269 //! return true if *this can be represented as a signed long 00270 bool IsConvertableToLong() const; 00271 //! return equivalent signed long if possible, otherwise undefined 00272 signed long ConvertToLong() const; 00273 00274 //! number of significant bits = floor(log2(abs(*this))) + 1 00275 unsigned int BitCount() const; 00276 //! number of significant bytes = ceiling(BitCount()/8) 00277 unsigned int ByteCount() const; 00278 //! number of significant words = ceiling(ByteCount()/sizeof(word)) 00279 unsigned int WordCount() const; 00280 00281 //! return the i-th bit, i=0 being the least significant bit 00282 bool GetBit(size_t i) const; 00283 //! return the i-th byte 00284 byte GetByte(size_t i) const; 00285 //! return n lowest bits of *this >> i 00286 lword GetBits(size_t i, size_t n) const; 00287 00288 //! 00289 bool IsZero() const {return !*this;} 00290 //! 00291 bool NotZero() const {return !IsZero();} 00292 //! 00293 bool IsNegative() const {return sign == NEGATIVE;} 00294 //! 00295 bool NotNegative() const {return !IsNegative();} 00296 //! 00297 bool IsPositive() const {return NotNegative() && NotZero();} 00298 //! 00299 bool NotPositive() const {return !IsPositive();} 00300 //! 00301 bool IsEven() const {return GetBit(0) == 0;} 00302 //! 00303 bool IsOdd() const {return GetBit(0) == 1;} 00304 //@} 00305 00306 //! \name MANIPULATORS 00307 //@{ 00308 //! 00309 Integer& operator=(const Integer& t); 00310 00311 //! 00312 Integer& operator+=(const Integer& t); 00313 //! 00314 Integer& operator-=(const Integer& t); 00315 //! 00316 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00317 Integer& operator*=(const Integer& t) {return *this = Times(t);} 00318 //! 00319 Integer& operator/=(const Integer& t) {return *this = DividedBy(t);} 00320 //! 00321 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00322 Integer& operator%=(const Integer& t) {return *this = Modulo(t);} 00323 //! 00324 Integer& operator/=(word t) {return *this = DividedBy(t);} 00325 //! 00326 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00327 Integer& operator%=(word t) {return *this = Integer(POSITIVE, 0, Modulo(t));} 00328 00329 //! 00330 Integer& operator<<=(size_t); 00331 //! 00332 Integer& operator>>=(size_t); 00333 00334 //! \brief Set this Integer to random integer 00335 //! \param rng RandomNumberGenerator used to generate material 00336 //! \param bitCount the number of bits in the resulting integer 00337 //! \details The random integer created is uniformly distributed over <tt>[0, 2<sup>bitCount</sup>]</tt>. 00338 void Randomize(RandomNumberGenerator &rng, size_t bitCount); 00339 00340 //! \brief Set this Integer to random integer 00341 //! \param rng RandomNumberGenerator used to generate material 00342 //! \param min the minimum value 00343 //! \param max the maximum value 00344 //! \details The random integer created is uniformly distributed over <tt>[min, max]</tt>. 00345 void Randomize(RandomNumberGenerator &rng, const Integer &min, const Integer &max); 00346 00347 //! \brief Set this Integer to random integer of special form 00348 //! \param rng RandomNumberGenerator used to generate material 00349 //! \param min the minimum value 00350 //! \param max the maximum value 00351 //! \param rnType RandomNumberType to specify the type 00352 //! \param equiv the equivalence class based on the parameter \p mod 00353 //! \param mod the modulus used to reduce the equivalence class 00354 //! \throw RandomNumberNotFound if the set is empty. 00355 //! \details Ideally, the random integer created should be uniformly distributed 00356 //! over <tt>{x | min <= x <= max</tt> and \p x is of rnType and <tt>x \% mod == equiv}</tt>. 00357 //! However the actual distribution may not be uniform because sequential 00358 //! search is used to find an appropriate number from a random starting 00359 //! point. 00360 //! \details May return (with very small probability) a pseudoprime when a prime 00361 //! is requested and <tt>max > lastSmallPrime*lastSmallPrime</tt>. \p lastSmallPrime 00362 //! is declared in nbtheory.h. 00363 bool Randomize(RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType, const Integer &equiv=Zero(), const Integer &mod=One()); 00364 00365 bool GenerateRandomNoThrow(RandomNumberGenerator &rng, const NameValuePairs ¶ms = g_nullNameValuePairs); 00366 void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs ¶ms = g_nullNameValuePairs) 00367 { 00368 if (!GenerateRandomNoThrow(rng, params)) 00369 throw RandomNumberNotFound(); 00370 } 00371 00372 //! \brief Set the n-th bit to value 00373 //! \details 0-based numbering. 00374 void SetBit(size_t n, bool value=1); 00375 00376 //! \brief Set the n-th byte to value 00377 //! \details 0-based numbering. 00378 void SetByte(size_t n, byte value); 00379 00380 //! \brief Reverse the Sign of the Integer 00381 void Negate(); 00382 00383 //! \brief Sets the Integer to positive 00384 void SetPositive() {sign = POSITIVE;} 00385 00386 //! \brief Sets the Integer to negative 00387 void SetNegative() {if (!!(*this)) sign = NEGATIVE;} 00388 00389 //! \brief Swaps this Integer with another Integer 00390 void swap(Integer &a); 00391 //@} 00392 00393 //! \name UNARY OPERATORS 00394 //@{ 00395 //! 00396 bool operator!() const; 00397 //! 00398 Integer operator+() const {return *this;} 00399 //! 00400 Integer operator-() const; 00401 //! 00402 Integer& operator++(); 00403 //! 00404 Integer& operator--(); 00405 //! 00406 Integer operator++(int) {Integer temp = *this; ++*this; return temp;} 00407 //! 00408 Integer operator--(int) {Integer temp = *this; --*this; return temp;} 00409 //@} 00410 00411 //! \name BINARY OPERATORS 00412 //@{ 00413 //! \brief Perform signed comparison 00414 //! \param a the Integer to comapre 00415 //! \retval -1 if <tt>*this < a</tt> 00416 //! \retval 0 if <tt>*this = a</tt> 00417 //! \retval 1 if <tt>*this > a</tt> 00418 int Compare(const Integer& a) const; 00419 00420 //! 00421 Integer Plus(const Integer &b) const; 00422 //! 00423 Integer Minus(const Integer &b) const; 00424 //! 00425 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00426 Integer Times(const Integer &b) const; 00427 //! 00428 Integer DividedBy(const Integer &b) const; 00429 //! 00430 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00431 Integer Modulo(const Integer &b) const; 00432 //! 00433 Integer DividedBy(word b) const; 00434 //! 00435 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00436 word Modulo(word b) const; 00437 00438 //! 00439 Integer operator>>(size_t n) const {return Integer(*this)>>=n;} 00440 //! 00441 Integer operator<<(size_t n) const {return Integer(*this)<<=n;} 00442 //@} 00443 00444 //! \name OTHER ARITHMETIC FUNCTIONS 00445 //@{ 00446 //! 00447 Integer AbsoluteValue() const; 00448 //! 00449 Integer Doubled() const {return Plus(*this);} 00450 //! 00451 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00452 Integer Squared() const {return Times(*this);} 00453 //! extract square root, if negative return 0, else return floor of square root 00454 Integer SquareRoot() const; 00455 //! return whether this integer is a perfect square 00456 bool IsSquare() const; 00457 00458 //! is 1 or -1 00459 bool IsUnit() const; 00460 //! return inverse if 1 or -1, otherwise return 0 00461 Integer MultiplicativeInverse() const; 00462 00463 //! calculate r and q such that (a == d*q + r) && (0 <= r < abs(d)) 00464 static void CRYPTOPP_API Divide(Integer &r, Integer &q, const Integer &a, const Integer &d); 00465 //! use a faster division algorithm when divisor is short 00466 static void CRYPTOPP_API Divide(word &r, Integer &q, const Integer &a, word d); 00467 00468 //! returns same result as Divide(r, q, a, Power2(n)), but faster 00469 static void CRYPTOPP_API DivideByPowerOf2(Integer &r, Integer &q, const Integer &a, unsigned int n); 00470 00471 //! greatest common divisor 00472 static Integer CRYPTOPP_API Gcd(const Integer &a, const Integer &n); 00473 //! calculate multiplicative inverse of *this mod n 00474 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00475 Integer InverseMod(const Integer &n) const; 00476 //! 00477 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00478 word InverseMod(word n) const; 00479 //@} 00480 00481 //! \name INPUT/OUTPUT 00482 //@{ 00483 //! \brief Extraction operator 00484 //! \param in a reference to a std::istream 00485 //! \param a a reference to an Integer 00486 //! \returns a reference to a std::istream reference 00487 friend CRYPTOPP_DLL std::istream& CRYPTOPP_API operator>>(std::istream& in, Integer &a); 00488 //! 00489 //! \brief Insertion operator 00490 //! \param out a reference to a std::ostream 00491 //! \param a a constant reference to an Integer 00492 //! \returns a reference to a std::ostream reference 00493 //! \details The output integer responds to std::hex, std::oct, std::hex, std::upper and 00494 //! std::lower. The output includes the suffix \a \b h (for hex), \a \b . (\a \b dot, for dec) 00495 //! and \a \b o (for octal). There is currently no way to supress the suffix. 00496 //! \details If you want to print an Integer without the suffix or using an arbitrary base, then 00497 //! use IntToString<Integer>(). 00498 //! \sa IntToString<Integer> 00499 friend CRYPTOPP_DLL std::ostream& CRYPTOPP_API operator<<(std::ostream& out, const Integer &a); 00500 //@} 00501 00502 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 00503 //! modular multiplication 00504 CRYPTOPP_DLL friend Integer CRYPTOPP_API a_times_b_mod_c(const Integer &x, const Integer& y, const Integer& m); 00505 //! modular exponentiation 00506 CRYPTOPP_DLL friend Integer CRYPTOPP_API a_exp_b_mod_c(const Integer &x, const Integer& e, const Integer& m); 00507 #endif 00508 00509 private: 00510 00511 Integer(word value, size_t length); 00512 int PositiveCompare(const Integer &t) const; 00513 00514 IntegerSecBlock reg; 00515 Sign sign; 00516 00517 #ifndef CRYPTOPP_DOXYGEN_PROCESSING 00518 friend class ModularArithmetic; 00519 friend class MontgomeryRepresentation; 00520 friend class HalfMontgomeryRepresentation; 00521 00522 friend void PositiveAdd(Integer &sum, const Integer &a, const Integer &b); 00523 friend void PositiveSubtract(Integer &diff, const Integer &a, const Integer &b); 00524 friend void PositiveMultiply(Integer &product, const Integer &a, const Integer &b); 00525 friend void PositiveDivide(Integer &remainder, Integer "ient, const Integer ÷nd, const Integer &divisor); 00526 #endif 00527 }; 00528 00529 //! 00530 inline bool operator==(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)==0;} 00531 //! 00532 inline bool operator!=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)!=0;} 00533 //! 00534 inline bool operator> (const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)> 0;} 00535 //! 00536 inline bool operator>=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)>=0;} 00537 //! 00538 inline bool operator< (const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)< 0;} 00539 //! 00540 inline bool operator<=(const CryptoPP::Integer& a, const CryptoPP::Integer& b) {return a.Compare(b)<=0;} 00541 //! 00542 inline CryptoPP::Integer operator+(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Plus(b);} 00543 //! 00544 inline CryptoPP::Integer operator-(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Minus(b);} 00545 //! 00546 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00547 inline CryptoPP::Integer operator*(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Times(b);} 00548 //! 00549 inline CryptoPP::Integer operator/(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.DividedBy(b);} 00550 //! 00551 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00552 inline CryptoPP::Integer operator%(const CryptoPP::Integer &a, const CryptoPP::Integer &b) {return a.Modulo(b);} 00553 //! 00554 inline CryptoPP::Integer operator/(const CryptoPP::Integer &a, CryptoPP::word b) {return a.DividedBy(b);} 00555 //! 00556 //! \sa a_times_b_mod_c() and a_exp_b_mod_c() 00557 inline CryptoPP::word operator%(const CryptoPP::Integer &a, CryptoPP::word b) {return a.Modulo(b);} 00558 00559 NAMESPACE_END 00560 00561 #ifndef __BORLANDC__ 00562 NAMESPACE_BEGIN(std) 00563 inline void swap(CryptoPP::Integer &a, CryptoPP::Integer &b) 00564 { 00565 a.swap(b); 00566 } 00567 NAMESPACE_END 00568 #endif 00569 00570 #endif