BigDigits
2.6.1
|
Interface to core BigDigits "mp" functions using fixed-length arrays. More...
Typedefs | |
typedef uint32_t | DIGIT_T |
The basic BigDigit element, an unsigned 32-bit integer. More... | |
Functions | |
int | mpAbs (DIGIT_T x[], const DIGIT_T y[], size_t ndigits) |
Sets x = |y|, the absolute value of y. More... | |
DIGIT_T | mpAdd (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], size_t ndigits) |
Computes w = u + v, returns carry. More... | |
void | mpAndBits (DIGIT_T a[], const DIGIT_T b[], const DIGIT_T c[], size_t ndigits) |
Computes bitwise a = b AND c. More... | |
size_t | mpBitLength (const DIGIT_T a[], size_t ndigits) |
Returns number of significant bits in a. More... | |
int | mpChs (DIGIT_T x[], const DIGIT_T y[], size_t ndigits) |
Sets x = -y. More... | |
int | mpCompare (const DIGIT_T a[], const DIGIT_T b[], size_t ndigits) |
Returns sign of (a-b) as {-1,0,+1} More... | |
int | mpCompare_ct (const DIGIT_T a[], const DIGIT_T b[], size_t ndigits) |
Returns sign of (a-b) as {-1,0,+1} using constant-time algorithm. More... | |
const char * | mpCompileTime (void) |
Returns a pointer to a static string containing the time of compilation. More... | |
size_t | mpConvFromDecimal (DIGIT_T a[], size_t ndigits, const char *s) |
Converts a string in decimal format to a big digit. More... | |
size_t | mpConvFromHex (DIGIT_T a[], size_t ndigits, const char *s) |
Converts a string in hexadecimal format to a big digit. More... | |
size_t | mpConvFromOctets (DIGIT_T a[], size_t ndigits, const unsigned char *c, size_t nbytes) |
Converts nbytes octets into big digit a of max size ndigits. More... | |
size_t | mpConvToDecimal (const DIGIT_T a[], size_t ndigits, char *s, size_t smax) |
Converts big digit a into a string in decimal format, where s has size smax including the terminating zero. More... | |
size_t | mpConvToHex (const DIGIT_T a[], size_t ndigits, char *s, size_t smax) |
Converts big digit a into a string in hexadecimal format, where s has size smax including the terminating zero. More... | |
size_t | mpConvToOctets (const DIGIT_T a[], size_t ndigits, unsigned char *c, size_t nbytes) |
Converts big digit a into string of octets, in big-endian order, padding to nbytes or truncating if necessary. More... | |
int | mpCubeRoot (DIGIT_T s[], const DIGIT_T x[], size_t ndigits) |
Computes integer cube root s = floor(cuberoot(x)) More... | |
int | mpDivide (DIGIT_T q[], DIGIT_T r[], const DIGIT_T u[], size_t udigits, DIGIT_T v[], size_t vdigits) |
Computes integer division of u by v such that u=qv+r. More... | |
int | mpEqual (const DIGIT_T a[], const DIGIT_T b[], size_t ndigits) |
Returns true if a == b, else false. More... | |
int | mpEqual_ct (const DIGIT_T a[], const DIGIT_T b[], size_t ndigits) |
Returns true if a == b, else false, using constant-time algorithm. More... | |
int | mpGcd (DIGIT_T g[], const DIGIT_T x[], const DIGIT_T y[], size_t ndigits) |
Computes g = gcd(x, y), the greatest common divisor of x and y. More... | |
int | mpGetBit (const DIGIT_T a[], size_t ndigits, size_t n) |
Returns value 1 or 0 of bit n (0..nbits-1) More... | |
int | mpIsNegative (const DIGIT_T x[], size_t ndigits) |
Returns true (1) if x < 0, else false (0) More... | |
int | mpIsPrime (DIGIT_T w[], size_t ndigits, size_t t) |
Returns true (1) if w is probably prime. More... | |
int | mpIsZero (const DIGIT_T a[], size_t ndigits) |
Returns true if a is zero, else false. More... | |
int | mpIsZero_ct (const DIGIT_T a[], size_t ndigits) |
Returns true if a is zero, else false, using constant-time algorithm. More... | |
int | mpJacobi (const DIGIT_T a[], const DIGIT_T n[], size_t ndigits) |
Returns the Jacobi symbol (a/n) in {-1, 0, +1}. More... | |
void | mpModAdd (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], const DIGIT_T m[], size_t ndigits) |
Computes w = u + v (mod m) More... | |
int | mpModExp (DIGIT_T y[], const DIGIT_T x[], const DIGIT_T e[], DIGIT_T m[], size_t ndigits) |
Computes y = x^e mod m. More... | |
int | mpModExp_ct (DIGIT_T yout[], const DIGIT_T x[], const DIGIT_T e[], DIGIT_T m[], size_t ndigits) |
Computes y = x^e mod m in constant time. More... | |
void | mpModHalve (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T p[], size_t ndigits) |
Computes w = u/2 (mod p) for an odd prime p. More... | |
int | mpModInv (DIGIT_T inv[], const DIGIT_T u[], const DIGIT_T m[], size_t ndigits) |
Computes the inverse of u modulo m , inv = u^{-1} mod m. More... | |
int | mpModMult (DIGIT_T a[], const DIGIT_T x[], const DIGIT_T y[], DIGIT_T m[], size_t ndigits) |
Computes a = (x * y) mod m. More... | |
void | mpModPowerOf2 (DIGIT_T a[], size_t ndigits, size_t L) |
Computes a = a mod 2^L, ie clears all bits greater than L. More... | |
void | mpModSpecial (DIGIT_T u[], const DIGIT_T v[], const DIGIT_T m[], size_t ndigits) |
Computes u = v (mod m) in the special case where 0<=v<km for small k. More... | |
int | mpModSqrt (DIGIT_T x[], const DIGIT_T a[], DIGIT_T p[], size_t ndigits) |
Computes x = one square root of an integer a modulo an odd prime p More... | |
int | mpModSquare (DIGIT_T a[], const DIGIT_T x[], DIGIT_T m[], size_t ndigits) |
Computes a = x^2 mod m. More... | |
void | mpModSub (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], const DIGIT_T m[], size_t ndigits) |
Computes w = u - v (mod m) More... | |
int | mpModulo (DIGIT_T r[], const DIGIT_T u[], size_t udigits, DIGIT_T v[], size_t vdigits) |
Computes remainder r = u mod v. More... | |
int | mpMultiply (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], size_t ndigits) |
Computes product w = u * v. More... | |
void | mpNotBits (DIGIT_T a[], const DIGIT_T b[], size_t ndigits) |
Computes bitwise a = NOT b. More... | |
void | mpOrBits (DIGIT_T a[], const DIGIT_T b[], const DIGIT_T c[], size_t ndigits) |
Computes bitwise a = b OR c. More... | |
void | mpPrint (const DIGIT_T *a, size_t ndigits) |
Print all digits in hex incl leading zero digits. More... | |
void | mpPrintBits (const char *prefix, DIGIT_T *a, size_t ndigits, const char *suffix) |
Print in bit (0/1) format with optional prefix and suffix strings. More... | |
void | mpPrintDecimal (const char *prefix, const DIGIT_T *a, size_t ndigits, const char *suffix) |
Print in decimal format with optional prefix and suffix strings. More... | |
void | mpPrintDecimalSigned (const char *prefix, DIGIT_T *a, size_t ndigits, const char *suffix) |
Print a signed integer in decimal format with optional prefix and suffix strings. More... | |
void | mpPrintHex (const char *prefix, const DIGIT_T *a, size_t ndigits, const char *suffix) |
Print in hex format with optional prefix and suffix strings. More... | |
void | mpPrintNL (const DIGIT_T *a, size_t ndigits) |
Print all digits in hex with newlines. More... | |
void | mpPrintTrim (const DIGIT_T *a, size_t ndigits) |
Print in hex but trim leading zero digits. More... | |
void | mpPrintTrimNL (const DIGIT_T *a, size_t ndigits) |
Print in hex, trim leading zeroes, add newlines. More... | |
size_t | mpQuickRandBits (DIGIT_T a[], size_t ndigits, size_t nbits) |
Generate a quick-and-dirty random mp number a of bit length at most nbits using plain-old-rand. More... | |
int | mpRabinMiller (DIGIT_T w[], size_t ndigits, size_t t) |
Returns true (1) if w is probably prime using just the Rabin-Miller test. More... | |
int | mpSetBit (DIGIT_T a[], size_t ndigits, size_t n, int value) |
Sets bit n of a (0..nbits-1) with value 1 or 0. More... | |
void | mpSetDigit (DIGIT_T a[], DIGIT_T d, size_t ndigits) |
Sets a = d where d is a single digit. More... | |
void | mpSetEqual (DIGIT_T a[], const DIGIT_T b[], size_t ndigits) |
Sets a = b. More... | |
volatile DIGIT_T | mpSetZero (volatile DIGIT_T a[], size_t ndigits) |
Sets a = 0. More... | |
DIGIT_T | mpShiftLeft (DIGIT_T a[], const DIGIT_T b[], size_t x, size_t ndigits) |
Computes a = b << x. More... | |
DIGIT_T | mpShiftRight (DIGIT_T a[], const DIGIT_T b[], size_t x, size_t ndigits) |
Computes a = b >> x. More... | |
DIGIT_T | mpShortAdd (DIGIT_T w[], const DIGIT_T u[], DIGIT_T d, size_t ndigits) |
Computes w = u + d, returns carry. More... | |
int | mpShortCmp (const DIGIT_T a[], DIGIT_T d, size_t ndigits) |
Returns sign of (a - d) where d is a single digit. More... | |
DIGIT_T | mpShortDiv (DIGIT_T q[], const DIGIT_T u[], DIGIT_T d, size_t ndigits) |
Computes quotient q = u div d, returns remainder. More... | |
int | mpShortIsEqual (const DIGIT_T a[], DIGIT_T d, size_t ndigits) |
Returns true if a == d, else false, where d is a single digit. More... | |
DIGIT_T | mpShortMod (const DIGIT_T a[], DIGIT_T d, size_t ndigits) |
Computes remainder r = a mod d. More... | |
DIGIT_T | mpShortMult (DIGIT_T p[], const DIGIT_T x[], DIGIT_T d, size_t ndigits) |
Computes product p = x * d. More... | |
DIGIT_T | mpShortSub (DIGIT_T w[], const DIGIT_T u[], DIGIT_T d, size_t ndigits) |
Computes w = u - d, returns borrow. More... | |
size_t | mpSizeof (const DIGIT_T a[], size_t ndigits) |
Returns number of significant non-zero digits in a. More... | |
int | mpSqrt (DIGIT_T s[], const DIGIT_T x[], size_t ndigits) |
Computes integer square root s = floor(sqrt(x)) More... | |
int | mpSquare (DIGIT_T w[], const DIGIT_T x[], size_t ndigits) |
Computes square w = x^2. More... | |
DIGIT_T | mpSubtract (DIGIT_T w[], const DIGIT_T u[], const DIGIT_T v[], size_t ndigits) |
Computes w = u - v, returns borrow. More... | |
DIGIT_T | mpToShort (const DIGIT_T a[], size_t ndigits) |
Returns the least significant digit in a. More... | |
int | mpVersion (void) |
Returns version number = major*1000+minor*100+release*10+PP_OPTIONS. More... | |
void | mpXorBits (DIGIT_T a[], const DIGIT_T b[], const DIGIT_T c[], size_t ndigits) |
Computes bitwise a = b XOR c. More... | |
DIGIT_T | spDivide (DIGIT_T *q, DIGIT_T *r, const DIGIT_T u[2], DIGIT_T v) |
Computes quotient q = u div v, remainder r = u mod v, where q, r and v are single digits. More... | |
int | spMultiply (DIGIT_T p[2], DIGIT_T x, DIGIT_T y) |
Computes p = x * y, where x and y are single digits. More... | |
DIGIT_T | spSimpleRand (DIGIT_T lower, DIGIT_T upper) |
Returns a simple pseudo-random digit between lower and upper. More... | |
Interface to core BigDigits "mp" functions using fixed-length arrays.
typedef uint32_t DIGIT_T |
The basic BigDigit element, an unsigned 32-bit integer.
Sets x = |y|, the absolute value of y.
Computes w = u + v, returns carry.
w
and v
must not overlap. Computes bitwise a = b AND c.
size_t mpBitLength | ( | const DIGIT_T | a[], |
size_t | ndigits | ||
) |
Returns number of significant bits in a.
Sets x = -y.
Returns sign of (a-b)
as {-1,0,+1}
Returns sign of (a-b)
as {-1,0,+1}
using constant-time algorithm.
const char* mpCompileTime | ( | void | ) |
Returns a pointer to a static string containing the time of compilation.
size_t mpConvFromDecimal | ( | DIGIT_T | a[], |
size_t | ndigits, | ||
const char * | s | ||
) |
Converts a string in decimal format to a big digit.
size_t mpConvFromHex | ( | DIGIT_T | a[], |
size_t | ndigits, | ||
const char * | s | ||
) |
Converts a string in hexadecimal format to a big digit.
size_t mpConvFromOctets | ( | DIGIT_T | a[], |
size_t | ndigits, | ||
const unsigned char * | c, | ||
size_t | nbytes | ||
) |
Converts nbytes octets into big digit a of max size ndigits.
size_t mpConvToDecimal | ( | const DIGIT_T | a[], |
size_t | ndigits, | ||
char * | s, | ||
size_t | smax | ||
) |
Converts big digit a into a string in decimal format, where s has size smax including the terminating zero.
size_t mpConvToHex | ( | const DIGIT_T | a[], |
size_t | ndigits, | ||
char * | s, | ||
size_t | smax | ||
) |
Converts big digit a into a string in hexadecimal format, where s has size smax including the terminating zero.
size_t mpConvToOctets | ( | const DIGIT_T | a[], |
size_t | ndigits, | ||
unsigned char * | c, | ||
size_t | nbytes | ||
) |
Converts big digit a into string of octets, in big-endian order, padding to nbytes or truncating if necessary.
Computes integer cube root s = floor(cuberoot(x))
int mpDivide | ( | DIGIT_T | q[], |
DIGIT_T | r[], | ||
const DIGIT_T | u[], | ||
size_t | udigits, | ||
DIGIT_T | v[], | ||
size_t | vdigits | ||
) |
Computes integer division of u by v such that u=qv+r.
[out] | q | to receive quotient = u div v, an array of size udigits |
[out] | r | to receive divisor = u mod v, an array of size udigits |
[in] | u | dividend of size udigits |
[in] | udigits | size of arrays q r and u |
[in] | v | divisor of size vdigits |
[in] | vdigits | size of array v |
q
and r
must be independent of u
and v
. Returns true if a == b, else false.
Returns true if a == b, else false, using constant-time algorithm.
Computes g = gcd(x, y), the greatest common divisor of x and y.
int mpGetBit | ( | const DIGIT_T | a[], |
size_t | ndigits, | ||
size_t | n | ||
) |
Returns value 1 or 0 of bit n (0..nbits-1)
int mpIsNegative | ( | const DIGIT_T | x[], |
size_t | ndigits | ||
) |
Returns true (1) if x < 0, else false (0)
int mpIsPrime | ( | DIGIT_T | w[], |
size_t | ndigits, | ||
size_t | t | ||
) |
Returns true (1) if w
is probably prime.
[in] | w | Number to test |
[in] | ndigits | size of array w |
[in] | t | The count of Rabin-Miller primality tests to carry out (recommended at least 80) |
int mpIsZero | ( | const DIGIT_T | a[], |
size_t | ndigits | ||
) |
Returns true if a is zero, else false.
int mpIsZero_ct | ( | const DIGIT_T | a[], |
size_t | ndigits | ||
) |
Returns true if a is zero, else false, using constant-time algorithm.
Returns the Jacobi symbol (a/n) in {-1, 0, +1}.
void mpModAdd | ( | DIGIT_T | w[], |
const DIGIT_T | u[], | ||
const DIGIT_T | v[], | ||
const DIGIT_T | m[], | ||
size_t | ndigits | ||
) |
Computes w = u + v (mod m)
[0, m-1]
. The variables w
and v
must not overlap. Computes y = x^e mod m.
int mpModExp_ct | ( | DIGIT_T | yout[], |
const DIGIT_T | x[], | ||
const DIGIT_T | e[], | ||
DIGIT_T | m[], | ||
size_t | ndigits | ||
) |
Computes y = x^e mod m in constant time.
Computes w = u/2 (mod p) for an odd prime p.
[0,p-1]
Computes the inverse of u
modulo m
, inv = u^{-1} mod m.
Computes a = (x * y) mod m.
void mpModPowerOf2 | ( | DIGIT_T | a[], |
size_t | ndigits, | ||
size_t | L | ||
) |
Computes a = a mod 2^L, ie clears all bits greater than L.
Computes u = v (mod m) in the special case where 0<=v<km
for small k.
v
is in the range [0,km]
where k
is a small integer k
is small, say < 3. Computes x = one square root of an integer a
modulo an odd prime p
x | To receive the result |
a | An integer expected to be a quadratic residue modulo p |
p | An odd prime |
ndigits | The number of digits in each of the parameters |
p - x
. x
. Computes a = x^2 mod m.
void mpModSub | ( | DIGIT_T | w[], |
const DIGIT_T | u[], | ||
const DIGIT_T | v[], | ||
const DIGIT_T | m[], | ||
size_t | ndigits | ||
) |
Computes w = u - v (mod m)
[0, m-1]
. The variables w
and v
must not overlap. Computes remainder r = u mod v.
[out] | r | to receive divisor = u mod v, an array of size vdigits |
[in] | u | dividend of size udigits |
[in] | udigits | size of arrays r and u |
[in] | v | divisor of size vdigits |
[in] | vdigits | size of array v |
r
and u
must not overlap. r
is vdigits
long here, but is udigits
long in mpDivide(). Computes product w = u * v.
[out] | w | To receive the product, an array of size 2 x ndigits |
[in] | u | An array of size ndigits |
[in] | v | An array of size ndigits |
[in] | ndigits | size of arrays u and v |
w
and u
must not overlap. ndigits
Computes bitwise a = b OR c.
void mpPrint | ( | const DIGIT_T * | a, |
size_t | ndigits | ||
) |
Print all digits in hex incl leading zero digits.
void mpPrintBits | ( | const char * | prefix, |
DIGIT_T * | a, | ||
size_t | ndigits, | ||
const char * | suffix | ||
) |
Print in bit (0/1) format with optional prefix and suffix strings.
void mpPrintDecimal | ( | const char * | prefix, |
const DIGIT_T * | a, | ||
size_t | ndigits, | ||
const char * | suffix | ||
) |
Print in decimal format with optional prefix and suffix strings.
void mpPrintDecimalSigned | ( | const char * | prefix, |
DIGIT_T * | a, | ||
size_t | ndigits, | ||
const char * | suffix | ||
) |
Print a signed integer in decimal format with optional prefix and suffix strings.
void mpPrintHex | ( | const char * | prefix, |
const DIGIT_T * | a, | ||
size_t | ndigits, | ||
const char * | suffix | ||
) |
Print in hex format with optional prefix and suffix strings.
void mpPrintNL | ( | const DIGIT_T * | a, |
size_t | ndigits | ||
) |
Print all digits in hex with newlines.
void mpPrintTrim | ( | const DIGIT_T * | a, |
size_t | ndigits | ||
) |
Print in hex but trim leading zero digits.
void mpPrintTrimNL | ( | const DIGIT_T * | a, |
size_t | ndigits | ||
) |
Print in hex, trim leading zeroes, add newlines.
size_t mpQuickRandBits | ( | DIGIT_T | a[], |
size_t | ndigits, | ||
size_t | nbits | ||
) |
Generate a quick-and-dirty random mp number a of bit length at most nbits
using plain-old-rand.
int mpRabinMiller | ( | DIGIT_T | w[], |
size_t | ndigits, | ||
size_t | t | ||
) |
Returns true (1) if w
is probably prime using just the Rabin-Miller test.
int mpSetBit | ( | DIGIT_T | a[], |
size_t | ndigits, | ||
size_t | n, | ||
int | value | ||
) |
Sets bit n of a (0..nbits-1) with value 1 or 0.
Computes a = b << x.
Computes a = b >> x.
Computes w = u + d, returns carry.
Returns sign of (a - d) where d is a single digit.
Computes quotient q = u div d, returns remainder.
Returns true if a == d, else false, where d is a single digit.
Computes product p = x * d.
Computes w = u - d, returns borrow.
size_t mpSizeof | ( | const DIGIT_T | a[], |
size_t | ndigits | ||
) |
Returns number of significant non-zero digits in a.
Computes integer square root s = floor(sqrt(x))
Computes square w = x^2.
[out] | w | array of size 2 x ndigits to receive square |
[in] | x | array of size ndigits |
[in] | ndigits | size of array x |
w
and x
must not overlap. w
must be of size 2 x ndigits
Computes w = u - v, returns borrow.
w
and v
must not overlap. int mpVersion | ( | void | ) |
Returns version number = major*1000+minor*100+release*10+PP_OPTIONS.
Computes bitwise a = b XOR c.
Computes quotient q = u div v, remainder r = u mod v, where q, r and v are single digits.
Computes p = x * y, where x and y are single digits.
Returns a simple pseudo-random digit between lower and upper.