#include <integer.h>
ENUMS, EXCEPTIONS, and TYPEDEFS | |
| enum | Signedness { UNSIGNED, SIGNED } |
| enum | RandomNumberType { ANY, PRIME } |
CREATORS | |
| Integer () | |
| creates the zero integer. More... | |
| Integer (const Integer &t) | |
| copy constructor. More... | |
| Integer (signed long value) | |
| convert from signed long. More... | |
| Integer (const char *str) | |
| convert from string. More... | |
| Integer (const byte *encodedInteger,unsigned int byteCount,Signedness s=UNSIGNED) | |
| convert from big-endian byte array. More... | |
| Integer (BufferedTransformation &bt,unsigned int byteCount,Signedness s=UNSIGNED) | |
| convert from big-endian form stored in a BufferedTransformation. More... | |
| Integer (BufferedTransformation &bt) | |
| convert from BER encoded byte array stored in a BufferedTransformation object. More... | |
| Integer (RandomNumberGenerator &rng,unsigned int bitcount) | |
| create a random integer. More... | |
| Integer (RandomNumberGenerator &rng,const Integer &min,const Integer &max,RandomNumberType rnType=ANY,const Integer &equiv=Zero(),const Integer &mod=One()) | |
| create a random integer of special type. More... | |
| const Integer& | Zero () |
| avoid calling constructors for these frequently used integers. More... | |
| const Integer& | One () |
| avoid calling constructors for these frequently used integers. More... | |
| Integer | Power2 (unsigned int e) |
| return the integer 2**e. More... | |
ENCODE/DECODE | |
| unsigned int | MinEncodedSize (Signedness=UNSIGNED)const |
| minimum number of bytes to encode this integer. More... | |
| unsigned int | Encode (byte *output,unsigned int outputLen,Signedness=UNSIGNED)const |
| encode in big-endian format. More... | |
| unsigned int | Encode (BufferedTransformation &bt,unsigned int outputLen,Signedness=UNSIGNED)const |
| void | DEREncode (BufferedTransformation &bt)const |
| encode using Distinguished Encoding Rules, put result into a BufferedTransformation object. More... | |
| void | DEREncodeAsOctetString (BufferedTransformation &bt,unsigned int length)const |
| encode absolute value as big-endian octet string. More... | |
| unsigned int | OpenPGPEncode (byte *output,unsigned int bufferSize)const |
| encode absolute value in OpenPGP format, return length of output. More... | |
| unsigned int | OpenPGPEncode (BufferedTransformation &bt)const |
| encode absolute value in OpenPGP format, put result into a BufferedTransformation object. More... | |
| void | Decode (const byte *input,unsigned int inputLen,Signedness=UNSIGNED) |
| void | Decode (BufferedTransformation &bt,unsigned int inputLen,Signedness=UNSIGNED) |
| void | BERDecode (const byte *input,unsigned int inputLen) |
| void | BERDecode (BufferedTransformation &bt) |
| void | BERDecodeAsOctetString (BufferedTransformation &bt,unsigned int length) |
| decode nonnegative value as big-endian octet string. More... | |
| void | OpenPGPDecode (const byte *input,unsigned int inputLen) |
| void | OpenPGPDecode (BufferedTransformation &bt) |
ACCESSORS | |
| bool | IsConvertableToLong ()const |
| return true if *this can be represented as a signed long. More... | |
| signed long | ConvertToLong ()const |
| return equivalent signed long if possible, otherwise undefined. More... | |
| unsigned int | BitCount ()const |
| number of significant bits = floor(log2(abs(*this))) + 1. More... | |
| unsigned int | ByteCount ()const |
| number of significant bytes = ceiling(BitCount()/8). More... | |
| unsigned int | WordCount ()const |
| number of significant words = ceiling(ByteCount()/sizeof(word)). More... | |
| bool | GetBit (unsigned int i)const |
| return the i-th bit, i=0 being the least significant bit. More... | |
| byte | GetByte (unsigned int i)const |
| return the i-th byte. More... | |
| unsigned long | GetBits (unsigned int i,unsigned int n)const |
| return n lowest bits of *this >> i. More... | |
| bool | IsZero ()const |
| bool | NotZero ()const |
| bool | IsNegative ()const |
| bool | NotNegative ()const |
| bool | IsPositive ()const |
| bool | NotPositive ()const |
| bool | IsEven ()const |
| bool | IsOdd ()const |
MANIPULATORS | |
| Integer& | operator= (const Integer &t) |
| Integer& | operator+= (const Integer &t) |
| Integer& | operator-= (const Integer &t) |
| Integer& | operator *= (const Integer &t) |
| Integer& | operator/= (const Integer &t) |
| Integer& | operator%= (const Integer &t) |
| Integer& | operator/= (word t) |
| Integer& | operator%= (word t) |
| Integer& | operator<<= (unsigned int) |
| Integer& | operator>>= (unsigned int) |
| void | Randomize (RandomNumberGenerator &rng,unsigned int bitcount) |
| void | Randomize (RandomNumberGenerator &rng,const Integer &min,const Integer &max) |
| bool | Randomize (RandomNumberGenerator &rng,const Integer &min,const Integer &max,RandomNumberType rnType,const Integer &equiv=Zero(),const Integer &mod=One()) |
| set this Integer to a random element of {x | min <= x <= max and x is of rnType and x % mod == equiv}. More... | |
| void | SetBit (unsigned int n,bool value=1) |
| set the n-th bit to value. More... | |
| void | SetByte (unsigned int n,byte value) |
| set the n-th byte to value. More... | |
| void | Negate () |
| void | SetPositive () |
| void | SetNegative () |
| void | swap (Integer &a) |
UNARY OPERATORS | |
| bool | operator! ()const |
| Integer | operator+ ()const |
| Integer | operator- ()const |
| Integer& | operator++ () |
| Integer& | operator-- () |
| Integer | operator++ (int) |
| Integer | operator-- (int) |
BINARY OPERATORS | |
| int | Compare (const Integer &a)const |
| signed comparison. More... | |
| Integer | Plus (const Integer &b)const |
| Integer | Minus (const Integer &b)const |
| Integer | Times (const Integer &b)const |
| Integer | DividedBy (const Integer &b)const |
| Integer | Modulo (const Integer &b)const |
| Integer | DividedBy (word b)const |
| word | Modulo (word b)const |
| Integer | operator>> (unsigned int n)const |
| Integer | operator<< (unsigned int n)const |
OTHER ARITHMETIC FUNCTIONS | |
| Integer | AbsoluteValue ()const |
| Integer | Doubled ()const |
| Integer | Squared ()const |
| Integer | SquareRoot ()const |
| extract square root, if negative return 0, else return floor of square root. More... | |
| bool | IsSquare ()const |
| return whether this integer is a perfect square. More... | |
| bool | IsUnit ()const |
| is 1 or -1. More... | |
| Integer | MultiplicativeInverse ()const |
| return inverse if 1 or -1, otherwise return 0. More... | |
| Integer | InverseMod (const Integer &n)const |
| calculate multiplicative inverse of *this mod n. More... | |
| word | InverseMod (word n)const |
| void | Divide (Integer &r,Integer &q,const Integer &a,const Integer &d) |
| calculate r and q such that (a == d*q + r) && (0 <= r < abs(d)). More... | |
| void | Divide (word &r,Integer &q,const Integer &a,word d) |
| use a faster division algorithm when divisor is short. More... | |
| void | DivideByPowerOf2 (Integer &r,Integer &q,const Integer &a,unsigned int n) |
| returns same result as Divide(r, q, a, Power2(n)), but faster. More... | |
| Integer | Gcd (const Integer &a,const Integer &n) |
| greatest common divisor. More... | |
| Integer | a_times_b_mod_c (const Integer &x,const Integer &y,const Integer &m) |
| modular multiplication. More... | |
| Integer | a_exp_b_mod_c (const Integer &x,const Integer &e,const Integer &m) |
| modular exponentiation. More... | |
INPUT/OUTPUT | |
| class | operator>> |
| class | operator<< |
Friends | |
| class | ModularArithmetic |
| class | MontgomeryRepresentation |
| class | HalfMontgomeryRepresentation |
| class | PositiveAdd |
| class | PositiveSubtract |
| class | PositiveMultiply |
| class | PositiveDivide |
This class can represent positive and negative integers with absolute value less than (256**sizeof(word)) ** (256**sizeof(int)).
Definition at line 18 of file integer.h.
|
|
|
|
|
|
|
|
creates the zero integer.
Definition at line 1403 of file integer.cpp. |
|
|
copy constructor.
Definition at line 1409 of file integer.cpp. |
|
|
convert from signed long.
Definition at line 1415 of file integer.cpp. |
|
|
convert from string. str can be in base 2, 8, 10, or 16. Base is determined by a case insensitive suffix of 'h', 'o', or 'b'. No suffix means base 10. Definition at line 1585 of file integer.cpp. |
|
|
convert from big-endian byte array.
Definition at line 1455 of file integer.cpp. |
|
|
convert from big-endian form stored in a BufferedTransformation.
Definition at line 1450 of file integer.cpp. |
|
|
convert from BER encoded byte array stored in a BufferedTransformation object.
Definition at line 1460 of file integer.cpp. |
|
|
create a random integer. The random integer created is uniformly distributed over [0, 2**bitcount). Definition at line 1465 of file integer.cpp. |
|
|
create a random integer of special type. Ideally, the random integer created should be uniformly distributed over {x | min <= x <= max and x is of rnType and x % mod == equiv}. However the actual distribution may not be uniform because sequential search is used to find an appropriate number from a random starting point. May return (with very small probability) a pseudoprime when a prime is requested and max > lastSmallPrime*lastSmallPrime (lastSmallPrime is declared in nbtheory.h).
Definition at line 1470 of file integer.cpp. |
|
|
Definition at line 1564 of file integer.cpp. |
|
|
Definition at line 1749 of file integer.cpp. |
|
|
Definition at line 1743 of file integer.cpp. |
|
|
decode nonnegative value as big-endian octet string.
Definition at line 1765 of file integer.cpp. |
|
|
number of significant bits = floor(log2(abs(*this))) + 1.
Definition at line 1655 of file integer.cpp. Referenced by OpenPGPEncode(), and SquareRoot(). |
|
|
number of significant bytes = ceiling(BitCount()/8).
Definition at line 1646 of file integer.cpp. Referenced by XTR_DH::AgreedValueLength(), LUCDIF::AgreedValueLength(), IsConvertableToLong(), MinEncodedSize(), XTR_DH::PrivateKeyLength(), LUCDIF::PrivateKeyLength(), XTR_DH::PublicKeyLength(), and LUCDIF::PublicKeyLength(). |
|
|
signed comparison.
Definition at line 2412 of file integer.cpp. |
|
|
return equivalent signed long if possible, otherwise undefined.
Definition at line 1443 of file integer.cpp. |
|
|
encode using Distinguished Encoding Rules, put result into a BufferedTransformation object.
Definition at line 1736 of file integer.cpp. |
|
|
encode absolute value as big-endian octet string.
Definition at line 1758 of file integer.cpp. |
|
|
Definition at line 1670 of file integer.cpp. |
|
|
Definition at line 1664 of file integer.cpp. |
|
|
use a faster division algorithm when divisor is short.
Definition at line 2316 of file integer.cpp. |
|
|
calculate r and q such that (a == d*q + r) && (0 <= r < abs(d)).
Definition at line 2256 of file integer.cpp. |
|
|
returns same result as Divide(r, q, a, Power2(n)), but faster.
Definition at line 2274 of file integer.cpp. |
|
|
Definition at line 2352 of file integer.cpp. |
|
|
Definition at line 2302 of file integer.cpp. |
|
|
|
|
|
Definition at line 1719 of file integer.cpp. |
|
|
encode in big-endian format. unsigned means encode absolute value, signed means encode two's complement if negative. if outputLen < MinEncodedSize, the most significant bytes will be dropped if outputLen > MinEncodedSize, the most significant bytes will be padded Definition at line 1713 of file integer.cpp. Referenced by LUCDIF::Agree(), DEREncode(), DEREncodeAsOctetString(), LUCELG_Decryptor::Decrypt(), ElGamalDecryptor::Decrypt(), LUCELG_Encryptor::Encrypt(), XTR_DH::GenerateKeyPair(), LUCDIF::GenerateKeyPair(), and OpenPGPEncode(). |
|
|
greatest common divisor.
Definition at line 2475 of file integer.cpp. |
|
|
return the i-th bit, i=0 being the least significant bit.
Definition at line 1511 of file integer.cpp. Referenced by PublicBlumBlumShub::GenerateBit(), and GetBits(). |
|
|
return n lowest bits of *this >> i.
Definition at line 1548 of file integer.cpp. |
|
|
return the i-th byte.
Definition at line 1533 of file integer.cpp. Referenced by MinEncodedSize(). |
|
|
Definition at line 2505 of file integer.cpp. |
|
|
calculate multiplicative inverse of *this mod n.
Definition at line 2480 of file integer.cpp. |
|
|
return true if *this can be represented as a signed long.
Definition at line 1429 of file integer.cpp. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return whether this integer is a perfect square.
Definition at line 2448 of file integer.cpp. |
|
|
is 1 or -1.
Definition at line 2454 of file integer.cpp. Referenced by MultiplicativeInverse(). |
|
|
|
|
|
minimum number of bytes to encode this integer. MinEncodedSize of 0 is 1 Definition at line 1701 of file integer.cpp. Referenced by DEREncode(). |
|
|
Definition at line 2106 of file integer.cpp. |
|
|
Definition at line 2360 of file integer.cpp. |
|
|
Definition at line 2309 of file integer.cpp. |
|
|
return inverse if 1 or -1, otherwise return 0.
Definition at line 2459 of file integer.cpp. |
|
|
Definition at line 2396 of file integer.cpp. |
|
|
|
|
|
|
|
|
|
|
|
avoid calling constructors for these frequently used integers.
Definition at line 1489 of file integer.cpp. Referenced by InverseMod(), and Randomize(). |
|
|
Definition at line 1793 of file integer.cpp. |
|
|
Definition at line 1787 of file integer.cpp. |
|
|
encode absolute value in OpenPGP format, put result into a BufferedTransformation object.
Definition at line 1780 of file integer.cpp. |
|
|
encode absolute value in OpenPGP format, return length of output.
Definition at line 1774 of file integer.cpp. |
|
|
Definition at line 2060 of file integer.cpp. |
|
|
return the integer 2**e.
Definition at line 1476 of file integer.cpp. Referenced by DivideByPowerOf2(), MinEncodedSize(), and SquareRoot(). |
|
|
set this Integer to a random element of {x | min <= x <= max and x is of rnType and x % mod == equiv}. returns false if the set is empty Definition at line 1827 of file integer.cpp. Referenced by Integer(). |
|
|
Definition at line 1811 of file integer.cpp. |
|
|
Definition at line 1801 of file integer.cpp. |
|
|
set the n-th bit to value.
Definition at line 1519 of file integer.cpp. Referenced by Power2(). |
|
|
set the n-th byte to value.
Definition at line 1541 of file integer.cpp. |
|
|
|
|
|
|
|
|
extract square root, if negative return 0, else return floor of square root.
Definition at line 2430 of file integer.cpp. Referenced by IsSquare(). |
|
|
Definition at line 298 of file integer.h. Referenced by XTR_DH::ValidateDomainParameters(). |
|
|
Definition at line 2198 of file integer.cpp. |
|
|
number of significant words = ceiling(ByteCount()/sizeof(word)).
Definition at line 1641 of file integer.cpp. Referenced by BitCount(), ByteCount(), Divide(), DivideByPowerOf2(), and IsUnit(). |
|
|
avoid calling constructors for these frequently used integers.
Definition at line 1483 of file integer.cpp. Referenced by InverseMod(), MultiplicativeInverse(), Randomize(), SquareRoot(), and XTR_DH::ValidateDomainParameters(). |
|
|
|
|
|
Definition at line 1495 of file integer.cpp. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Definition at line 1958 of file integer.cpp. |
|
|
Definition at line 2083 of file integer.cpp. |
|
|
Definition at line 1557 of file integer.cpp. |
|
|
|
|
|
Definition at line 1978 of file integer.cpp. |
|
|
Definition at line 2129 of file integer.cpp. |
|
|
|
|
|
|
|
|
|
|
|
Definition at line 2152 of file integer.cpp. |
|
|
Definition at line 1500 of file integer.cpp. |
|
|
|
|
|
Definition at line 2164 of file integer.cpp. |
|
|
Definition at line 1571 of file integer.cpp. |
|
|
|
|
|
|
|
|
|
|
|
Definition at line 1996 of file integer.cpp. |
|
|
Definition at line 2227 of file integer.cpp. |
|
|
Definition at line 2178 of file integer.cpp. |
|
|
Definition at line 2022 of file integer.cpp. |
|
|
modular exponentiation.
Definition at line 2469 of file integer.cpp. |
|
|
modular multiplication.
Definition at line 2464 of file integer.cpp. |
|
|
Definition at line 1903 of file integer.cpp. |
|
|
Definition at line 1878 of file integer.cpp. |
1.2.4 written by Dimitri van Heesch,
© 1997-2000