GClasses
|
Represents an integer of arbitrary size, and provides basic arithmetic functionality. Also contains functionality for implementing RSA symmetric-key cryptography.
#include <GBigInt.h>
Public Member Functions | |
GBigInt () | |
GBigInt (GDomNode *pNode) | |
virtual | ~GBigInt () |
void | add (GBigInt *pBigNumber) |
Add another big number to this one. More... | |
void | And (GBigInt *pBigNumber) |
bitwise and More... | |
void | calculatePrivateKey (GBigInt *pPublicKey, GBigInt *pProd) |
Input: pProd is the product of (p - 1) * (q - 1) where p and q are prime pPublicKey is a number that has no common factors with pProd Output: this will become a private key to go with the public key. More... | |
int | compareTo (GBigInt *pBigNumber) |
Returns -1 if this is less than pBigNumber Returns 0 if this is equal to pBigNumber Returns 1 if this is greater than pBigNumber. More... | |
void | copy (GBigInt *pBigNumber) |
Copies the value of pBigNumber into this object. More... | |
void | decrement () |
Subtracts one from the number. More... | |
void | divide (GBigInt *pInNominator, GBigInt *pInDenominator, GBigInt *pOutRemainder) |
Set this value to the ratio of two big numbers and return the remainder. More... | |
void | euclid (GBigInt *pA1, GBigInt *pB1, GBigInt *pOutX=NULL, GBigInt *pOutY=NULL) |
Input: integers a, b Output: this will be set to the greatest common divisor of a,b. (If pOutX and pOutY are not NULL, they will be values such that "this" = ax + by.) More... | |
void | fromBuffer (const unsigned int *pBuffer, int nBufferSize) |
Deserializes the number. little-Endian (first bit in buffer will be LSB) More... | |
void | fromByteBuffer (const unsigned char *pBuffer, int nBufferChars) |
Deserializes the number. More... | |
bool | fromHex (const char *szHexValue) |
Extract a value from a big endian hexadecimal string. More... | |
bool | getBit (unsigned int n) |
Returns the value of the nth bit where 0 represents the least significant bit (little endian) More... | |
unsigned int | getBitCount () |
Returns the number of bits in the number. More... | |
bool | getSign () |
Returns true if the number is positive and false if it is negative. More... | |
unsigned int | getUInt (unsigned int nPos) |
Returns the nth unsigned integer used to represent this number. More... | |
unsigned int | getUIntCount () |
Returns the number of unsigned integers required to represent this number. More... | |
void | increment () |
Adds one to the number. More... | |
bool | isPrime () |
Output: true = pretty darn sure (like 99.999%) it's prime false = definately (100%) not prime. More... | |
bool | isZero () |
Returns true if the number is zero. More... | |
bool | millerRabin (GBigInt *pA) |
Input: "this" must be >= 3, and 2 <= a < "this" Output: "true" if this is either prime or a strong pseudoprime to base a, "false" otherwise. More... | |
void | multiply (GBigInt *pBigNumber, unsigned int nUInt) |
Set this value to the product of another big number and an unsigned integer. More... | |
void | multiply (GBigInt *pFirst, GBigInt *pSecond) |
Set this value to the product of two big numbers. More... | |
void | negate () |
Multiplies the number by -1. More... | |
void | Or (GBigInt *pBigNumber) |
bitwise or More... | |
void | powerMod (GBigInt *pA, GBigInt *pK, GBigInt *pN) |
Input: a, k>=0, n>=2 Output: this will be set to ((a raised to the power of k) modulus n) More... | |
void | selectPublicKey (const unsigned int *pRandomData, int nRandomDataUInts, GBigInt *pProd) |
Input: pProd is the product of (p - 1) * (q - 1) where p and q are prime pRandomData is some random data that will be used to pick the key. Output: It will return a key that has no common factors with pProd. It starts with the random data you provide and increments it until it fits this criteria. More... | |
GDomNode * | serialize (GDom *pDoc) const |
Marshal this object into a DOM that can be converted to a variety of serial formats. More... | |
void | setBit (unsigned int nPos, bool bVal) |
Sets the value of the nth bit where 0 represents the least significant bit (little endian) More... | |
void | setRandom (unsigned int nBits) |
DO NOT use for crypto–This is NOT a cryptographic random number generator. More... | |
void | setSign (bool bSign) |
Makes the number positive if bSign is true and negative if bSign is false. More... | |
void | setToZero () |
Sets the number to zero. More... | |
void | setUInt (unsigned int nPos, unsigned int nVal) |
Sets the value of the nth unsigned integer used to represent this number. More... | |
void | shiftLeft (unsigned int nBits) |
Shift left (multiply by 2) More... | |
void | shiftRight (unsigned int nBits) |
Shift right (divide by 2 and round down) More... | |
void | subtract (GBigInt *pBigNumber) |
Subtract another big number from this one. More... | |
bool | toBuffer (unsigned int *pBuffer, int nBufferSize) |
Serializes the number. little-Endian (first bit in buffer will be LSB) More... | |
unsigned int * | toBufferGiveOwnership () |
This gives you ownership of the buffer. (You must delete it.) It also sets the value to zero. More... | |
bool | toHex (char *szBuff, int nBufferSize) |
Produces a big endian hexadecimal representation of this number. More... | |
void | Xor (GBigInt *pBigNumber) |
bitwise xor More... | |
Protected Types |
Protected Member Functions | |
void | resize (unsigned int nBits) |
void | shiftLeftBits (unsigned int nBits) |
void | shiftLeftUInts (unsigned int nBits) |
void | shiftRightBits (unsigned int nBits) |
void | shiftRightUInts (unsigned int nBits) |
Protected Attributes | |
bool | m_bSign |
unsigned int | m_nUInts |
unsigned int * | m_pBits |
GClasses::GBigInt::GBigInt | ( | ) |
GClasses::GBigInt::GBigInt | ( | GDomNode * | pNode | ) |
|
virtual |
void GClasses::GBigInt::add | ( | GBigInt * | pBigNumber | ) |
Add another big number to this one.
void GClasses::GBigInt::And | ( | GBigInt * | pBigNumber | ) |
bitwise and
Input: pProd is the product of (p - 1) * (q - 1) where p and q are prime pPublicKey is a number that has no common factors with pProd Output: this will become a private key to go with the public key.
int GClasses::GBigInt::compareTo | ( | GBigInt * | pBigNumber | ) |
Returns -1 if this is less than pBigNumber Returns 0 if this is equal to pBigNumber Returns 1 if this is greater than pBigNumber.
void GClasses::GBigInt::copy | ( | GBigInt * | pBigNumber | ) |
Copies the value of pBigNumber into this object.
void GClasses::GBigInt::decrement | ( | ) |
Subtracts one from the number.
void GClasses::GBigInt::divide | ( | GBigInt * | pInNominator, |
GBigInt * | pInDenominator, | ||
GBigInt * | pOutRemainder | ||
) |
Set this value to the ratio of two big numbers and return the remainder.
void GClasses::GBigInt::euclid | ( | GBigInt * | pA1, |
GBigInt * | pB1, | ||
GBigInt * | pOutX = NULL , |
||
GBigInt * | pOutY = NULL |
||
) |
Input: integers a, b Output: this will be set to the greatest common divisor of a,b. (If pOutX and pOutY are not NULL, they will be values such that "this" = ax + by.)
void GClasses::GBigInt::fromBuffer | ( | const unsigned int * | pBuffer, |
int | nBufferSize | ||
) |
Deserializes the number. little-Endian (first bit in buffer will be LSB)
void GClasses::GBigInt::fromByteBuffer | ( | const unsigned char * | pBuffer, |
int | nBufferChars | ||
) |
Deserializes the number.
bool GClasses::GBigInt::fromHex | ( | const char * | szHexValue | ) |
Extract a value from a big endian hexadecimal string.
|
inline |
Returns the value of the nth bit where 0 represents the least significant bit (little endian)
unsigned int GClasses::GBigInt::getBitCount | ( | ) |
Returns the number of bits in the number.
|
inline |
Returns true if the number is positive and false if it is negative.
|
inline |
Returns the nth unsigned integer used to represent this number.
|
inline |
Returns the number of unsigned integers required to represent this number.
void GClasses::GBigInt::increment | ( | ) |
Adds one to the number.
bool GClasses::GBigInt::isPrime | ( | ) |
Output: true = pretty darn sure (like 99.999%) it's prime false = definately (100%) not prime.
bool GClasses::GBigInt::isZero | ( | ) |
Returns true if the number is zero.
bool GClasses::GBigInt::millerRabin | ( | GBigInt * | pA | ) |
Input: "this" must be >= 3, and 2 <= a < "this" Output: "true" if this is either prime or a strong pseudoprime to base a, "false" otherwise.
void GClasses::GBigInt::multiply | ( | GBigInt * | pBigNumber, |
unsigned int | nUInt | ||
) |
Set this value to the product of another big number and an unsigned integer.
Set this value to the product of two big numbers.
void GClasses::GBigInt::negate | ( | ) |
Multiplies the number by -1.
void GClasses::GBigInt::Or | ( | GBigInt * | pBigNumber | ) |
bitwise or
Input: a, k>=0, n>=2 Output: this will be set to ((a raised to the power of k) modulus n)
|
protected |
void GClasses::GBigInt::selectPublicKey | ( | const unsigned int * | pRandomData, |
int | nRandomDataUInts, | ||
GBigInt * | pProd | ||
) |
Input: pProd is the product of (p - 1) * (q - 1) where p and q are prime pRandomData is some random data that will be used to pick the key. Output: It will return a key that has no common factors with pProd. It starts with the random data you provide and increments it until it fits this criteria.
Marshal this object into a DOM that can be converted to a variety of serial formats.
void GClasses::GBigInt::setBit | ( | unsigned int | nPos, |
bool | bVal | ||
) |
Sets the value of the nth bit where 0 represents the least significant bit (little endian)
void GClasses::GBigInt::setRandom | ( | unsigned int | nBits | ) |
DO NOT use for crypto–This is NOT a cryptographic random number generator.
|
inline |
Makes the number positive if bSign is true and negative if bSign is false.
void GClasses::GBigInt::setToZero | ( | ) |
Sets the number to zero.
void GClasses::GBigInt::setUInt | ( | unsigned int | nPos, |
unsigned int | nVal | ||
) |
Sets the value of the nth unsigned integer used to represent this number.
void GClasses::GBigInt::shiftLeft | ( | unsigned int | nBits | ) |
Shift left (multiply by 2)
|
protected |
|
protected |
void GClasses::GBigInt::shiftRight | ( | unsigned int | nBits | ) |
Shift right (divide by 2 and round down)
|
protected |
|
protected |
void GClasses::GBigInt::subtract | ( | GBigInt * | pBigNumber | ) |
Subtract another big number from this one.
bool GClasses::GBigInt::toBuffer | ( | unsigned int * | pBuffer, |
int | nBufferSize | ||
) |
Serializes the number. little-Endian (first bit in buffer will be LSB)
unsigned int* GClasses::GBigInt::toBufferGiveOwnership | ( | ) |
This gives you ownership of the buffer. (You must delete it.) It also sets the value to zero.
bool GClasses::GBigInt::toHex | ( | char * | szBuff, |
int | nBufferSize | ||
) |
Produces a big endian hexadecimal representation of this number.
void GClasses::GBigInt::Xor | ( | GBigInt * | pBigNumber | ) |
bitwise xor
|
protected |
|
protected |
|
protected |