| 
    Crypto++ 8.9
    
   Free C++ class library of cryptographic schemes 
   | 
 
Classes and functions for number theoretic operations. More...
Go to the source code of this file.
Classes | |
| class | PrimeSelector | 
| Application callback to signal suitability of a cabdidate prime.  More... | |
| class | PrimeAndGenerator | 
| Generator of prime numbers of special forms.  More... | |
Functions | |
| CRYPTOPP_DLL const word16 * | GetPrimeTable (unsigned int &size) | 
| The Small Prime table.   | |
| CRYPTOPP_DLL Integer | MaurerProvablePrime (RandomNumberGenerator &rng, unsigned int bits) | 
| Generates a provable prime.   | |
| CRYPTOPP_DLL Integer | MihailescuProvablePrime (RandomNumberGenerator &rng, unsigned int bits) | 
| Generates a provable prime.   | |
| CRYPTOPP_DLL bool | IsSmallPrime (const Integer &p) | 
| Tests whether a number is a small prime.   | |
| CRYPTOPP_DLL bool | TrialDivision (const Integer &p, unsigned bound) | 
| Tests whether a number is divisible by a small prime.   | |
| CRYPTOPP_DLL bool | SmallDivisorsTest (const Integer &p) | 
| Tests whether a number is divisible by a small prime.   | |
| CRYPTOPP_DLL bool | IsFermatProbablePrime (const Integer &n, const Integer &b) | 
| Determine if a number is probably prime.   | |
| CRYPTOPP_DLL bool | IsLucasProbablePrime (const Integer &n) | 
| Determine if a number is probably prime.   | |
| CRYPTOPP_DLL bool | IsStrongProbablePrime (const Integer &n, const Integer &b) | 
| Determine if a number is probably prime.   | |
| CRYPTOPP_DLL bool | IsStrongLucasProbablePrime (const Integer &n) | 
| Determine if a number is probably prime.   | |
| CRYPTOPP_DLL bool | RabinMillerTest (RandomNumberGenerator &rng, const Integer &n, unsigned int rounds) | 
| Determine if a number is probably prime.   | |
| CRYPTOPP_DLL bool | IsPrime (const Integer &p) | 
| Verifies a number is probably prime.   | |
| CRYPTOPP_DLL bool | VerifyPrime (RandomNumberGenerator &rng, const Integer &p, unsigned int level=1) | 
| Verifies a number is probably prime.   | |
| CRYPTOPP_DLL bool | FirstPrime (Integer &p, const Integer &max, const Integer &equiv, const Integer &mod, const PrimeSelector *pSelector) | 
| Finds a random prime of special form.   | |
| CRYPTOPP_DLL unsigned int | PrimeSearchInterval (const Integer &max) | 
| CRYPTOPP_DLL AlgorithmParameters | MakeParametersForTwoPrimesOfEqualSize (unsigned int productBitLength) | 
| Integer | GCD (const Integer &a, const Integer &b) | 
| Calculate the greatest common divisor.   | |
| bool | RelativelyPrime (const Integer &a, const Integer &b) | 
| Determine relative primality.   | |
| Integer | LCM (const Integer &a, const Integer &b) | 
| Calculate the least common multiple.   | |
| Integer | EuclideanMultiplicativeInverse (const Integer &a, const Integer &b) | 
| Calculate multiplicative inverse.   | |
| CRYPTOPP_DLL Integer | CRT (const Integer &xp, const Integer &p, const Integer &xq, const Integer &q, const Integer &u) | 
| Chinese Remainder Theorem.   | |
| CRYPTOPP_DLL int | Jacobi (const Integer &a, const Integer &b) | 
| Calculate the Jacobi symbol.   | |
| CRYPTOPP_DLL Integer | Lucas (const Integer &e, const Integer &p, const Integer &n) | 
| Calculate the Lucas value.   | |
| CRYPTOPP_DLL Integer | InverseLucas (const Integer &e, const Integer &m, const Integer &p, const Integer &q, const Integer &u) | 
| Calculate the inverse Lucas value.   | |
| Integer | ModularMultiplication (const Integer &x, const Integer &y, const Integer &m) | 
| Modular multiplication.   | |
| Integer | ModularExponentiation (const Integer &x, const Integer &e, const Integer &m) | 
| Modular exponentiation.   | |
| CRYPTOPP_DLL Integer | ModularSquareRoot (const Integer &a, const Integer &p) | 
| Extract a modular square root.   | |
| CRYPTOPP_DLL Integer | ModularRoot (const Integer &a, const Integer &dp, const Integer &dq, const Integer &p, const Integer &q, const Integer &u) | 
| Extract a modular root.   | |
| CRYPTOPP_DLL bool | SolveModularQuadraticEquation (Integer &r1, Integer &r2, const Integer &a, const Integer &b, const Integer &c, const Integer &p) | 
| Solve a Modular Quadratic Equation.   | |
| CRYPTOPP_DLL unsigned int | DiscreteLogWorkFactor (unsigned int bitlength) | 
| Estimate work factor.   | |
| CRYPTOPP_DLL unsigned int | FactoringWorkFactor (unsigned int bitlength) | 
| Estimate work factor.   | |
Classes and functions for number theoretic operations.
Definition in file nbtheory.h.
| CRYPTOPP_DLL const word16 * GetPrimeTable | ( | unsigned int & | size | ) | 
The Small Prime table.
| size | number of elements in the table | 
GetPrimeTable() obtains pointer to small prime table and provides the size of the table. /p size is an out parameter.
| CRYPTOPP_DLL Integer MaurerProvablePrime | ( | RandomNumberGenerator & | rng, | 
| unsigned int | bits | ||
| ) | 
Generates a provable prime.
| rng | a RandomNumberGenerator to produce random material | 
| bits | the number of bits in the prime number | 
| CRYPTOPP_DLL Integer MihailescuProvablePrime | ( | RandomNumberGenerator & | rng, | 
| unsigned int | bits | ||
| ) | 
Generates a provable prime.
| rng | a RandomNumberGenerator to produce random material | 
| bits | the number of bits in the prime number | 
Mihailescu's methods performs a search using algorithmic progressions.
| CRYPTOPP_DLL bool IsSmallPrime | ( | const Integer & | p | ) | 
Tests whether a number is a small prime.
| p | a candidate prime to test | 
Internally, the library maintains a table of the first 32719 prime numbers in sorted order. IsSmallPrime searches the table and returns true if p is in the table.
| CRYPTOPP_DLL bool TrialDivision | ( | const Integer & | p, | 
| unsigned | bound | ||
| ) | 
Tests whether a number is divisible by a small prime.
TrialDivision() returns true if p is divisible by some prime less than bound. bound should not be greater than the largest entry in the prime table, which is 32719. 
| CRYPTOPP_DLL bool SmallDivisorsTest | ( | const Integer & | p | ) | 
Tests whether a number is divisible by a small prime.
SmallDivisorsTest() returns true if p is NOT divisible by some prime less than 32719. 
Determine if a number is probably prime.
| n | the number to test | 
| b | the base to exponentiate | 
IsFermatProbablePrime raises b to the n-1 power and checks if the result is congruent to 1 modulo n.
These is no reason to use IsFermatProbablePrime, use IsStrongProbablePrime or IsStrongLucasProbablePrime instead.
| CRYPTOPP_DLL bool IsLucasProbablePrime | ( | const Integer & | n | ) | 
Determine if a number is probably prime.
| n | the number to test | 
These is no reason to use IsLucasProbablePrime, use IsStrongProbablePrime or IsStrongLucasProbablePrime instead.
Determine if a number is probably prime.
| n | the number to test | 
| b | the base to exponentiate | 
| CRYPTOPP_DLL bool IsStrongLucasProbablePrime | ( | const Integer & | n | ) | 
Determine if a number is probably prime.
| n | the number to test | 
| CRYPTOPP_DLL bool RabinMillerTest | ( | RandomNumberGenerator & | rng, | 
| const Integer & | n, | ||
| unsigned int | rounds | ||
| ) | 
Determine if a number is probably prime.
| rng | a RandomNumberGenerator to produce random material | 
| n | the number to test | 
| rounds | the number of tests to perform | 
This is the Rabin-Miller primality test, i.e. repeating the strong probable prime test for several rounds with random bases
| CRYPTOPP_DLL bool IsPrime | ( | const Integer & | p | ) | 
Verifies a number is probably prime.
| p | a candidate prime to test | 
IsPrime() is suitable for testing candidate primes when creating them. Internally, IsPrime() utilizes SmallDivisorsTest(), IsStrongProbablePrime() and IsStrongLucasProbablePrime().
| CRYPTOPP_DLL bool VerifyPrime | ( | RandomNumberGenerator & | rng, | 
| const Integer & | p, | ||
| unsigned int | level = 1  | 
        ||
| ) | 
Verifies a number is probably prime.
| rng | a RandomNumberGenerator for randomized testing | 
| p | a candidate prime to test | 
| level | the level of thoroughness of testing | 
VerifyPrime() is suitable for testing candidate primes created by others. Internally, VerifyPrime() utilizes IsPrime() and one-round RabinMillerTest(). If the candidate passes and level is greater than 1, then 10 round RabinMillerTest() primality testing is performed.
| CRYPTOPP_DLL bool FirstPrime | ( | Integer & | p, | 
| const Integer & | max, | ||
| const Integer & | equiv, | ||
| const Integer & | mod, | ||
| const PrimeSelector * | pSelector | ||
| ) | 
Finds a random prime of special form.
| p | an Integer reference to receive the prime | 
| max | the maximum value | 
| equiv | the equivalence class based on the parameter mod | 
| mod | the modulus used to reduce the equivalence class | 
| pSelector | pointer to a PrimeSelector function for the application to signal suitability | 
FirstPrime() uses a fast sieve to find the first probable prime in {x | p<=x<=max and xmod==equiv} 
Calculate the greatest common divisor.
| a | the first term | 
| b | the second term | 
Definition at line 146 of file nbtheory.h.
Determine relative primality.
| a | the first term | 
| b | the second term | 
a and b are relatively prime, false otherwise. Definition at line 153 of file nbtheory.h.
Calculate the least common multiple.
| a | the first term | 
| b | the second term | 
a and b. Definition at line 160 of file nbtheory.h.
Calculate multiplicative inverse.
| a | the number to test | 
| b | the modulus | 
(a ^ -1) % n or 0 if none exists.EuclideanMultiplicativeInverse returns the multiplicative inverse of the Integer *a modulo the Integer b. If no Integer exists then Integer 0 is returned. 
Definition at line 169 of file nbtheory.h.
| CRYPTOPP_DLL Integer CRT | ( | const Integer & | xp, | 
| const Integer & | p, | ||
| const Integer & | xq, | ||
| const Integer & | q, | ||
| const Integer & | u | ||
| ) | 
Chinese Remainder Theorem.
| xp | the first number, mod p | 
| p | the first prime modulus | 
| xq | the second number, mod q | 
| q | the second prime modulus | 
| u | inverse of p mod q | 
CRT uses the Chinese Remainder Theorem to calculate x given x mod p and x mod q, and u the inverse of p mod q. 
Calculate the Jacobi symbol.
| a | the first term | 
| b | the second term | 
Jacobi symbols are calculated using the following rules:
b is prime, then Jacobi(a, b), then return 0ab==0 AND a is quadratic residue mod b, then return 1return -1 otherwise
Refer to a number theory book for what Jacobi symbol means when b is not prime. 
Calculate the Lucas value.
Lucas() calculates the Lucas function V_e(p, 1) mod n. 
| CRYPTOPP_DLL Integer InverseLucas | ( | const Integer & | e, | 
| const Integer & | m, | ||
| const Integer & | p, | ||
| const Integer & | q, | ||
| const Integer & | u | ||
| ) | 
Calculate the inverse Lucas value.
InverseLucas() calculates x such that m==Lucas(e, x, p*q), p q primes, u is inverse of p mod q. 
Modular multiplication.
| x | the first term | 
| y | the second term | 
| m | the modulus | 
(x * y) % m. Definition at line 211 of file nbtheory.h.
Modular exponentiation.
| x | the base | 
| e | the exponent | 
| m | the modulus | 
(a ^ b) % m. Definition at line 219 of file nbtheory.h.
Extract a modular square root.
| a | the number to extract square root | 
| p | the prime modulus | 
ModularSquareRoot returns x such that x*xp == a, p prime 
| CRYPTOPP_DLL Integer ModularRoot | ( | const Integer & | a, | 
| const Integer & | dp, | ||
| const Integer & | dq, | ||
| const Integer & | p, | ||
| const Integer & | q, | ||
| const Integer & | u | ||
| ) | 
Extract a modular root.
ModularRoot returns x such that a==ModularExponentiation(x, e, p*q), p q primes, and e relatively prime to (p-1)*(q-1), dp=d%(p-1), dq=d%(q-1), (d is inverse of e mod (p-1)*(q-1)) and u=inverse of p mod q. 
| CRYPTOPP_DLL bool SolveModularQuadraticEquation | ( | Integer & | r1, | 
| Integer & | r2, | ||
| const Integer & | a, | ||
| const Integer & | b, | ||
| const Integer & | c, | ||
| const Integer & | p | ||
| ) | 
Solve a Modular Quadratic Equation.
| r1 | the first residue | 
| r2 | the second residue | 
| a | the first coefficient | 
| b | the second coefficient | 
| c | the third constant | 
| p | the prime modulus | 
SolveModularQuadraticEquation() finds r1 and r2 such that ax^2 + bx + c == 0 (mod p) for x in {r1, r2}, p prime. 
| CRYPTOPP_DLL unsigned int DiscreteLogWorkFactor | ( | unsigned int | bitlength | ) | 
Estimate work factor.
| bitlength | the size of the number, in bits | 
DiscreteLogWorkFactor returns log base 2 of estimated number of operations to calculate discrete log or factor a number.
| CRYPTOPP_DLL unsigned int FactoringWorkFactor | ( | unsigned int | bitlength | ) | 
Estimate work factor.
| bitlength | the size of the number, in bits | 
FactoringWorkFactor returns log base 2 of estimated number of operations to calculate discrete log or factor a number.