Return the absolute value
- Parameters
- Returns
- absolute value of n
Compute the greatest common divisor
- Parameters
BigInt a |
positive integer x |
BigInt b |
positive integer y |
- Returns
- gcd(x,y)
Compute the Jacobi symbol. If n is prime, this is equivalent
to the Legendre symbol.
@see http://mathworld.wolfram.com/JacobiSymbol.html
- Parameters
BigInt a |
is a non-negative integer |
BigInt n |
is an odd integer > 1 |
- Returns
- (n / m)
Compute the square root of x modulo a prime using the
Shanks-Tonnelli algorithm
- Parameters
BigInt a |
the input x |
BigInt p |
the prime p |
- Returns
- y such that (y*y)%p == x, or -1 if no such integer
Check for primality using Miller-Rabin
- Parameters
BigInt n |
a positive integer to test for primality |
RandomNumberGenerator rng |
a random number generator |
size_t prob |
chance of false positive is bounded by 1/2**prob |
bool is_random |
true if n was randomly chosen by us |
- Returns
- true if all primality tests passed, otherwise false
Randomly generate a prime
- Parameters
RandomNumberGenerator rng |
a random number generator |
size_t bits |
how large the resulting prime should be in bits |
BigInt coprime |
a positive integer the result should be coprime to |
size_t equiv |
a non-negative number that the result should be
equivalent to modulo equiv_mod |
size_t modulo |
the modulus equiv should be checked against |
- Returns
- random prime with the specified criteria
Return a random 'safe' prime, of the form p=2*q+1 with q prime
- Parameters
RandomNumberGenerator rng |
a random number generator |
size_t bits |
is how long the resulting prime should be |
- Returns
- prime randomly chosen from safe primes of length bits
Generate DSA parameters using the FIPS 186 kosherizer
- Parameters
RandomNumberGenerator rng |
a random number generator |
AlgorithmFactory af |
an algorithm factory |
BigInt p_out |
where the prime p will be stored |
BigInt q_out |
where the prime q will be stored |
size_t pbits |
how long p will be in bits |
size_t qbits |
how long q will be in bits |
- Returns
- random seed used to generate this parameter set
Generate DSA parameters using the FIPS 186 kosherizer
- Parameters
RandomNumberGenerator rng |
a random number generator |
AlgorithmFactory af |
an algorithm factory |
BigInt p_out |
where the prime p will be stored |
BigInt q_out |
where the prime q will be stored |
size_t pbits |
how long p will be in bits |
size_t qbits |
how long q will be in bits |
Vector!ubyte seed_c |
the seed used to generate the parameters |
- Returns
- true if seed generated a valid DSA parameter set, otherwise
false. p_out and q_out are only valid if true was returned.