|
Crypto++
5.6.3
Free C++ class library of cryptographic schemes
|
Multiple precision integer with arithmetic operations. More...
Inheritance diagram for Integer:Classes | |
| class | DivideByZero |
| Exception thrown when division by 0 is encountered. More... | |
| class | OpenPGPDecodeErr |
| Exception thrown when an error is encountered decoding an OpenPGP integer. More... | |
| class | RandomNumberNotFound |
| Exception thrown when a random number cannot be found that satisfies the condition. More... | |
Public Member Functions | |
| virtual void | BEREncode (BufferedTransformation &bt) const |
| Encode this object into a BufferedTransformation. More... | |
ENUMS, EXCEPTIONS, and TYPEDEFS | |
| enum | Sign { POSITIVE =0, NEGATIVE =1 } |
| Used internally to represent the integer. More... | |
| enum | Signedness { UNSIGNED, SIGNED } |
| Used when importing and exporting integers. More... | |
| enum | RandomNumberType { ANY, PRIME } |
| Properties of a random integer. More... | |
CREATORS | |
| Integer () | |
| Creates the zero integer. | |
| Integer (const Integer &t) | |
| copy constructor | |
| Integer (signed long value) | |
| Convert from signed long. | |
| Integer (Sign sign, lword value) | |
| Convert from lword. More... | |
| Integer (Sign sign, word highWord, word lowWord) | |
| Convert from two words. More... | |
| Integer (const char *str) | |
| Convert from a C-string. More... | |
| Integer (const wchar_t *str) | |
| Convert from a wide C-string. More... | |
| Integer (const byte *encodedInteger, size_t byteCount, Signedness sign=UNSIGNED) | |
| Convert from a big-endian byte array. More... | |
| Integer (BufferedTransformation &bt, size_t byteCount, Signedness sign=UNSIGNED) | |
| Convert from a big-endian array. More... | |
| Integer (BufferedTransformation &bt) | |
| Convert from a BER encoded byte array. More... | |
| Integer (RandomNumberGenerator &rng, size_t 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 form. More... | |
| static const Integer & | Zero () |
| Integer representing 0. More... | |
| static const Integer & | One () |
| Integer representing 1. More... | |
| static const Integer & | Two () |
| Integer representing 2. More... | |
| static Integer | Power2 (size_t e) |
| Exponentiates to a power of 2. More... | |
ENCODE/DECODE | |
| size_t | MinEncodedSize (Signedness sign=UNSIGNED) const |
| The minimum number of bytes to encode this integer. More... | |
| void | Encode (byte *output, size_t outputLen, Signedness sign=UNSIGNED) const |
| Encode in big-endian format. More... | |
| void | Encode (BufferedTransformation &bt, size_t outputLen, Signedness sign=UNSIGNED) const |
| Encode in big-endian format. More... | |
| void | DEREncode (BufferedTransformation &bt) const |
| Encode in DER format. More... | |
| void | DEREncodeAsOctetString (BufferedTransformation &bt, size_t length) const |
| encode absolute value as big-endian octet string More... | |
| size_t | OpenPGPEncode (byte *output, size_t bufferSize) const |
| Encode absolute value in OpenPGP format. More... | |
| size_t | OpenPGPEncode (BufferedTransformation &bt) const |
| Encode absolute value in OpenPGP format. More... | |
| void | Decode (const byte *input, size_t inputLen, Signedness sign=UNSIGNED) |
| Decode from big-endian byte array. More... | |
| void | Decode (BufferedTransformation &bt, size_t inputLen, Signedness sign=UNSIGNED) |
| Decode nonnegative value from big-endian byte array. More... | |
| void | BERDecode (const byte *input, size_t inputLen) |
| Decode from BER format. More... | |
| void | BERDecode (BufferedTransformation &bt) |
| Decode from BER format. More... | |
| void | BERDecodeAsOctetString (BufferedTransformation &bt, size_t length) |
| Decode nonnegative value from big-endian octet string. More... | |
| void | OpenPGPDecode (const byte *input, size_t inputLen) |
| Decode from OpenPGP format. More... | |
| void | OpenPGPDecode (BufferedTransformation &bt) |
| Decode from OpenPGP format. More... | |
ACCESSORS | |
| bool | IsConvertableToLong () const |
| return true if *this can be represented as a signed long | |
| signed long | ConvertToLong () const |
| return equivalent signed long if possible, otherwise undefined | |
| unsigned int | BitCount () const |
| number of significant bits = floor(log2(abs(*this))) + 1 | |
| unsigned int | ByteCount () const |
| number of significant bytes = ceiling(BitCount()/8) | |
| unsigned int | WordCount () const |
| number of significant words = ceiling(ByteCount()/sizeof(word)) | |
| bool | GetBit (size_t i) const |
| return the i-th bit, i=0 being the least significant bit | |
| byte | GetByte (size_t i) const |
| return the i-th byte | |
| lword | GetBits (size_t i, size_t n) const |
| return n lowest bits of *this >> i | |
| 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<<= (size_t) |
| Integer & | operator>>= (size_t) |
| void | Randomize (RandomNumberGenerator &rng, size_t bitCount) |
| Set this Integer to random integer. More... | |
| void | Randomize (RandomNumberGenerator &rng, const Integer &min, const Integer &max) |
| Set this Integer to random integer. More... | |
| bool | Randomize (RandomNumberGenerator &rng, const Integer &min, const Integer &max, RandomNumberType rnType, const Integer &equiv=Zero(), const Integer &mod=One()) |
| Set this Integer to random integer of special form. More... | |
| bool | GenerateRandomNoThrow (RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs) |
| void | GenerateRandom (RandomNumberGenerator &rng, const NameValuePairs ¶ms=g_nullNameValuePairs) |
| void | SetBit (size_t n, bool value=1) |
| Set the n-th bit to value. More... | |
| void | SetByte (size_t n, byte value) |
| Set the n-th byte to value. More... | |
| void | Negate () |
| Reverse the Sign of the Integer. | |
| void | SetPositive () |
| Sets the Integer to positive. | |
| void | SetNegative () |
| Sets the Integer to negative. | |
| void | swap (Integer &a) |
| Swaps this Integer with another Integer. | |
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 |
| Perform 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>> (size_t n) const |
| Integer | operator<< (size_t 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 | |
| bool | IsSquare () const |
| return whether this integer is a perfect square | |
| bool | IsUnit () const |
| is 1 or -1 | |
| Integer | MultiplicativeInverse () const |
| return inverse if 1 or -1, otherwise return 0 | |
| Integer | InverseMod (const Integer &n) const |
| calculate multiplicative inverse of *this mod n More... | |
| word | InverseMod (word n) const |
| static 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)) | |
| static void | Divide (word &r, Integer &q, const Integer &a, word d) |
| use a faster division algorithm when divisor is short | |
| static void | DivideByPowerOf2 (Integer &r, Integer &q, const Integer &a, unsigned int n) |
| returns same result as Divide(r, q, a, Power2(n)), but faster | |
| static Integer | Gcd (const Integer &a, const Integer &n) |
| greatest common divisor | |
INPUT/OUTPUT | |
| std::istream & | operator>> (std::istream &in, Integer &a) |
| Extraction operator. More... | |
| std::ostream & | operator<< (std::ostream &out, const Integer &a) |
| Insertion operator. More... | |
Multiple precision integer with arithmetic operations.
The Integer class can represent positive and negative integers with absolute value less than (256**sizeof(word))(256**sizeof(int)).
Internally, the library uses a sign magnitude representation, and the class has two data members. The first is a IntegerSecBlock (a SecBlock<word>) and it i used to hold the representation. The second is a Sign, and its is used to track the sign of the Integer.
| enum Integer::Sign |
Used internally to represent the integer.
Sign is used internally to represent the integer. It is also used in a few API functions.
| Enumerator | |
|---|---|
| POSITIVE |
the value is positive or 0 |
| NEGATIVE |
the value is negative |
| enum Integer::Signedness |
| Integer::Integer | ( | Sign | sign, |
| lword | value | ||
| ) |
Convert from lword.
| sign | enumeration indicating Sign |
| value | the long word |
Definition at line 2833 of file integer.cpp.
| Integer::Integer | ( | Sign | sign, |
| word | highWord, | ||
| word | lowWord | ||
| ) |
Convert from two words.
| sign | enumeration indicating Sign |
| highWord | the high word |
| lowWord | the low word |
Definition at line 2854 of file integer.cpp.
|
explicit |
Convert from a C-string.
| str | C-string value |
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 3092 of file integer.cpp.
|
explicit |
Convert from a wide C-string.
| str | wide C-string value |
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 3098 of file integer.cpp.
| Integer::Integer | ( | const byte * | encodedInteger, |
| size_t | byteCount, | ||
| Signedness | sign = UNSIGNED |
||
| ) |
Convert from a big-endian byte array.
| encodedInteger | big-endian byte array |
| byteCount | length of the byte array |
| sign | enumeration indicating Signedness |
Definition at line 2889 of file integer.cpp.
References Decode().
| Integer::Integer | ( | BufferedTransformation & | bt, |
| size_t | byteCount, | ||
| Signedness | sign = UNSIGNED |
||
| ) |
Convert from a big-endian array.
| bt | BufferedTransformation object with big-endian byte array |
| byteCount | length of the byte array |
| sign | enumeration indicating Signedness |
Definition at line 2884 of file integer.cpp.
References Decode().
|
explicit |
Convert from a BER encoded byte array.
| bt | BufferedTransformation object with BER encoded byte array |
Definition at line 2894 of file integer.cpp.
References BERDecode().
| Integer::Integer | ( | RandomNumberGenerator & | rng, |
| size_t | bitCount | ||
| ) |
Create a random integer.
| rng | RandomNumberGenerator used to generate material |
| bitCount | the number of bits in the resulting integer |
The random integer created is uniformly distributed over [0, 2bitCount].
Definition at line 2899 of file integer.cpp.
References Randomize().
| Integer::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 form.
| rng | RandomNumberGenerator used to generate material |
| min | the minimum value |
| max | the maximum value |
| rnType | RandomNumberType to specify the type |
| equiv | the equivalence class based on the parameter mod |
| mod | the modulus used to reduce the equivalence class |
| RandomNumberNotFound | if the set is empty. |
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 2904 of file integer.cpp.
References Randomize().
|
static |
Integer representing 0.
Zero() avoids calling constructors for frequently used integers
Definition at line 2926 of file integer.cpp.
Referenced by RWFunction::ApplyFunction(), DL_GroupParameters_EC< EC >::AssignFrom(), InvertibleESIGNFunction::CalculateRandomizedInverse(), TF_DecryptorBase::Decrypt(), KDF2_RNG::GenerateBlock(), XTR_DH::GeneratePrivateKey(), DL_GroupParameters_EC< EC >::GenerateRandom(), TF_VerifierBase::InputSignature(), InverseMod(), MaurerProvablePrime(), MultiplicativeInverse(), SquareRoot(), Times(), and DL_GroupParameters_DSA::ValidateGroup().
|
static |
Integer representing 1.
One() avoids calling constructors for frequently used integers
Definition at line 2931 of file integer.cpp.
Referenced by InvertibleRSAFunction::DEREncodePrivateKey(), DL_EncryptorBase< SCHEME_OPTIONS::Element >::Encrypt(), FirstPrime(), FixedRNG::GenerateBlock(), KDF2_RNG::GenerateBlock(), MQV_Domain< GROUP_PARAMETERS, COFACTOR_OPTION >::GenerateEphemeralPrivateKey(), DL_SimpleKeyAgreementDomainBase< GROUP_PARAMETERS::Element >::GeneratePrivateKey(), DL_GroupParameters_EC< EC >::GenerateRandom(), InvertibleRabinFunction::GenerateRandom(), InvertibleRWFunction::GenerateRandom(), DL_PrivateKeyImpl< DL_GroupParameters_EC< EC > >::GenerateRandom(), MQV_Domain< GROUP_PARAMETERS, COFACTOR_OPTION >::GenerateStaticPrivateKey(), InverseMod(), XTR_DH::Validate(), ESIGNFunction::Validate(), RabinFunction::Validate(), RSAFunction::Validate(), RWFunction::Validate(), LUCFunction::Validate(), InvertibleRabinFunction::Validate(), InvertibleESIGNFunction::Validate(), InvertibleRWFunction::Validate(), InvertibleLUCFunction::Validate(), InvertibleRSAFunction::Validate(), DL_PrivateKeyImpl< DL_GroupParameters_EC< EC > >::Validate(), and DL_GroupParameters_DSA::ValidateGroup().
|
static |
Integer representing 2.
Two() avoids calling constructors for frequently used integers
Definition at line 2936 of file integer.cpp.
References SecBlock< T, A >::size(), and WordCount().
Referenced by MaurerProvablePrime().
|
static |
Exponentiates to a power of 2.
Definition at line 2910 of file integer.cpp.
References BitsToWords(), and SetBit().
Referenced by MQV_Domain< GROUP_PARAMETERS, COFACTOR_OPTION >::Agree(), DL_GroupParameters_IntegerBased::AssignFrom(), DivideByPowerOf2(), Encode(), KDF2_RNG::GenerateBlock(), InvertibleESIGNFunction::GenerateRandom(), ESIGNFunction::ImageBound(), MaurerProvablePrime(), MihailescuProvablePrime(), MinEncodedSize(), SquareRoot(), and VerifyPrime().
| size_t Integer::MinEncodedSize | ( | Signedness | sign = UNSIGNED | ) | const |
The minimum number of bytes to encode this integer.
| sign | enumeration indicating Signedness |
Definition at line 3167 of file integer.cpp.
References ByteCount(), GetByte(), Power2(), STDMAX(), and UNSIGNED.
Referenced by DEREncode(), and TestDataNameValuePairs::GetVoidValue().
| void Integer::Encode | ( | byte * | output, |
| size_t | outputLen, | ||
| Signedness | sign = UNSIGNED |
||
| ) | const |
Encode in big-endian format.
| output | big-endian byte array |
| outputLen | length of the byte array |
| sign | enumeration indicating Signedness |
Unsigned means encode absolute value, signed means encode two's complement if negative.
outputLen can be used to ensure an Integer is encoded to an exact size (rather than a minimum size). An exact size is useful, for example, when encoding to a field element size.
Definition at line 3179 of file integer.cpp.
Referenced by TF_DecryptorBase::Decrypt(), DEREncode(), DEREncodeAsOctetString(), DSAConvertSignatureFormat(), Encode(), XTR_DH::GeneratePrivateKey(), DL_SimpleKeyAgreementDomainBase< GROUP_PARAMETERS::Element >::GeneratePrivateKey(), DL_GroupParameters_IntegerBased::GenerateRandom(), MQV_Domain< GROUP_PARAMETERS, COFACTOR_OPTION >::GenerateStaticPrivateKey(), TestDataNameValuePairs::GetVoidValue(), TF_VerifierBase::InputSignature(), OpenPGPEncode(), DL_VerifierBase< SCHEME_OPTIONS::Element >::RecoverAndRestart(), and DL_GroupParameters_DSA::ValidateGroup().
| void Integer::Encode | ( | BufferedTransformation & | bt, |
| size_t | outputLen, | ||
| Signedness | sign = UNSIGNED |
||
| ) | const |
Encode in big-endian format.
| bt | BufferedTransformation object |
| outputLen | length of the encoding |
| sign | enumeration indicating Signedness |
Unsigned means encode absolute value, signed means encode two's complement if negative.
outputLen can be used to ensure an Integer is encoded to an exact size (rather than a minimum size). An exact size is useful, for example, when encoding to a field element size.
Definition at line 3186 of file integer.cpp.
References ByteCount(), Encode(), GetByte(), Power2(), BufferedTransformation::Put(), STDMAX(), and UNSIGNED.
|
virtual |
Encode in DER format.
| bt | BufferedTransformation object |
Encodes the Integer using Distinguished Encoding Rules The result is placed into a BufferedTransformation object
Implements ASN1Object.
Definition at line 3201 of file integer.cpp.
References Encode(), MinEncodedSize(), and SIGNED.
Referenced by ESIGNFunction::DEREncode(), DL_GroupParameters_IntegerBased::DEREncode(), InvertibleESIGNFunction::DEREncode(), RSAFunction::DEREncodePublicKey(), DSAConvertSignatureFormat(), KDF2_RNG::GenerateBlock(), InvertibleRabinFunction::GenerateRandom(), and InvertibleRWFunction::GenerateRandom().
| void Integer::DEREncodeAsOctetString | ( | BufferedTransformation & | bt, |
| size_t | length | ||
| ) | const |
encode absolute value as big-endian octet string
| bt | BufferedTransformation object |
| length | the number of mytes to decode |
Definition at line 3223 of file integer.cpp.
References Encode().
| size_t Integer::OpenPGPEncode | ( | byte * | output, |
| size_t | bufferSize | ||
| ) | const |
Encode absolute value in OpenPGP format.
| output | big-endian byte array |
| bufferSize | length of the byte array |
OpenPGPEncode places result into a BufferedTransformation object and returns the number of bytes used for the encoding
Definition at line 3239 of file integer.cpp.
Referenced by DSAConvertSignatureFormat().
| size_t Integer::OpenPGPEncode | ( | BufferedTransformation & | bt | ) | const |
Encode absolute value in OpenPGP format.
| bt | BufferedTransformation object |
OpenPGPEncode places result into a BufferedTransformation object and returns the number of bytes used for the encoding
Definition at line 3245 of file integer.cpp.
References BitCount(), BitsToBytes(), Encode(), and BufferedTransformation::PutWord16().
| void Integer::Decode | ( | const byte * | input, |
| size_t | inputLen, | ||
| Signedness | sign = UNSIGNED |
||
| ) |
Decode from big-endian byte array.
| input | big-endian byte array |
| inputLen | length of the byte array |
| sign | enumeration indicating Signedness |
Definition at line 3127 of file integer.cpp.
Referenced by BERDecode(), BERDecodeAsOctetString(), DL_PrivateKey_EC< EC >::BERDecodePrivateKey(), DSAConvertSignatureFormat(), DL_VerifierBase< SCHEME_OPTIONS::Element >::InputSignature(), Integer(), OpenPGPDecode(), and Randomize().
| void Integer::Decode | ( | BufferedTransformation & | bt, |
| size_t | inputLen, | ||
| Signedness | sign = UNSIGNED |
||
| ) |
Decode nonnegative value from big-endian byte array.
| bt | BufferedTransformation object |
| inputLen | length of the byte array |
| sign | enumeration indicating Signedness |
bt.MaxRetrievable() >= inputLen. Definition at line 3133 of file integer.cpp.
References BytesToWords(), SecBlock< T, A >::CleanNew(), BufferedTransformation::Get(), BufferedTransformation::MaxRetrievable(), NEGATIVE, BufferedTransformation::Peek(), POSITIVE, SIGNED, SecBlock< T, A >::size(), SecBlock< T, A >::SizeInBytes(), and BufferedTransformation::Skip().
| void Integer::BERDecode | ( | const byte * | input, |
| size_t | inputLen | ||
| ) |
Decode from BER format.
| input | big-endian byte array |
| inputLen | length of the byte array |
Definition at line 3208 of file integer.cpp.
Referenced by ESIGNFunction::BERDecode(), DL_GroupParameters_IntegerBased::BERDecode(), InvertibleESIGNFunction::BERDecode(), RSAFunction::BERDecodePublicKey(), DSAConvertSignatureFormat(), DL_GroupParameters_EC< EC >::GenerateRandom(), InvertibleRabinFunction::GenerateRandom(), InvertibleRWFunction::GenerateRandom(), and Integer().
|
virtual |
Decode from BER format.
| bt | BufferedTransformation object |
Implements ASN1Object.
Definition at line 3214 of file integer.cpp.
References Decode(), BufferedTransformation::MaxRetrievable(), and SIGNED.
| void Integer::BERDecodeAsOctetString | ( | BufferedTransformation & | bt, |
| size_t | length | ||
| ) |
Decode nonnegative value from big-endian octet string.
| bt | BufferedTransformation object |
| length | length of the byte array |
Definition at line 3230 of file integer.cpp.
References Decode().
| void Integer::OpenPGPDecode | ( | const byte * | input, |
| size_t | inputLen | ||
| ) |
Decode from OpenPGP format.
| input | big-endian byte array |
| inputLen | length of the byte array |
Definition at line 3254 of file integer.cpp.
Referenced by DSAConvertSignatureFormat().
| void Integer::OpenPGPDecode | ( | BufferedTransformation & | bt | ) |
Decode from OpenPGP format.
| bt | BufferedTransformation object |
Definition at line 3260 of file integer.cpp.
References BitsToBytes(), Decode(), BufferedTransformation::GetWord16(), and BufferedTransformation::MaxRetrievable().
|
inline |
Definition at line 327 of file integer.h.
References g_nullNameValuePairs.
| void Integer::Randomize | ( | RandomNumberGenerator & | rng, |
| size_t | bitCount | ||
| ) |
Set this Integer to random integer.
| rng | RandomNumberGenerator used to generate material |
| bitCount | the number of bits in the resulting integer |
The random integer created is uniformly distributed over [0, 2bitCount].
Definition at line 3268 of file integer.cpp.
References Crop(), Decode(), RandomNumberGenerator::GenerateBlock(), and UNSIGNED.
Referenced by InvertibleESIGNFunction::CalculateRandomizedInverse(), InvertibleRSAFunction::DEREncodePrivateKey(), KDF2_RNG::GenerateBlock(), InvertibleRWFunction::GenerateRandom(), Integer(), MaurerProvablePrime(), MihailescuProvablePrime(), Randomize(), and TrialDivision().
| void Integer::Randomize | ( | RandomNumberGenerator & | rng, |
| const Integer & | min, | ||
| const Integer & | max | ||
| ) |
Set this Integer to random integer.
| rng | RandomNumberGenerator used to generate material |
| min | the minimum value |
| max | the maximum value |
The random integer created is uniformly distributed over [min, max].
Definition at line 3278 of file integer.cpp.
References BitCount(), and Randomize().
| bool Integer::Randomize | ( | RandomNumberGenerator & | rng, |
| const Integer & | min, | ||
| const Integer & | max, | ||
| RandomNumberType | rnType, | ||
| const Integer & | equiv = Zero(), |
||
| const Integer & | mod = One() |
||
| ) |
Set this Integer to random integer of special form.
| rng | RandomNumberGenerator used to generate material |
| min | the minimum value |
| max | the maximum value |
| rnType | RandomNumberType to specify the type |
| equiv | the equivalence class based on the parameter mod |
| mod | the modulus used to reduce the equivalence class |
| RandomNumberNotFound | if the set is empty. |
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 3295 of file integer.cpp.
References MakeParameters().
| void Integer::SetBit | ( | size_t | n, |
| bool | value = 1 |
||
| ) |
Set the n-th bit to value.
0-based numbering.
Definition at line 2966 of file integer.cpp.
References BitsToWords().
Referenced by Power2().
| void Integer::SetByte | ( | size_t | n, |
| byte | value | ||
| ) |
Set the n-th byte to value.
0-based numbering.
Definition at line 2988 of file integer.cpp.
References BytesToWords().
| int Integer::Compare | ( | const Integer & | a | ) | const |
Perform signed comparison.
| a | the Integer to comapre |
| -1 | if *this < a |
| 0 | if *this = a |
| 1 | if *this > a |
Definition at line 3961 of file integer.cpp.
Referenced by InverseMod().
Definition at line 3747 of file integer.cpp.
References SecBlock< T, A >::CleanNew(), Divide(), POSITIVE, WordCount(), and Zero().
Definition at line 3858 of file integer.cpp.
References Divide().
Referenced by InverseMod().
| word Integer::Modulo | ( | word | b | ) | const |
Definition at line 3909 of file integer.cpp.
References WordCount().
|
inline |
Definition at line 452 of file integer.h.
References operator<(), operator<=(), operator>(), and operator>=().
Referenced by RabinFunction::ApplyFunction(), RWFunction::ApplyFunction(), IsSquare(), MaurerProvablePrime(), TrialDivision(), and XTR_DH::Validate().
calculate multiplicative inverse of *this mod n
Definition at line 4029 of file integer.cpp.
References InverseMod(), Modulo(), One(), SecBlock< T, A >::size(), and Zero().
Referenced by InvertibleRabinFunction::GenerateRandom(), InvertibleRWFunction::GenerateRandom(), InvertibleRSAFunction::Initialize(), and InverseMod().
| word Integer::InverseMod | ( | word | n | ) | const |
Definition at line 4054 of file integer.cpp.
References Compare(), and SecBlock< T, A >::size().
|
inlinevirtualinherited |
Encode this object into a BufferedTransformation.
| bt | BufferedTransformation object |
Uses Basic Encoding Rules (BER).
This may be useful if DEREncode() would be too inefficient.
Definition at line 2647 of file cryptlib.h.
|
friend |
Extraction operator.
| in | a reference to a std::istream |
| a | a reference to an Integer |
Definition at line 3414 of file integer.cpp.
|
friend |
Insertion operator.
| out | a reference to a std::ostream |
| a | a constant reference to an Integer |
The output integer responds to std::hex, std::oct, std::hex, std::upper and std::lower. The output includes the suffix h (for hex), . (dot, for dec) and o (for octal). There is currently no way to supress the suffix.
If you want to print an Integer without the suffix or using an arbitrary base, then use IntToString<Integer>().
Definition at line 3439 of file integer.cpp.
1.8.11