Libtommath User Manual V0.39: Tom ST Denis Tomstdenis@Iahu - Ca April 4, 2006
Libtommath User Manual V0.39: Tom ST Denis Tomstdenis@Iahu - Ca April 4, 2006
v0.39
Tom St Denis
[email protected]
April 4, 2006
This text, the library and the accompanying textbook are all hereby placed
in the public domain. This book has been formatted for B5 [176x250] paper
using the LATEX book macro package.
Tom St Denis,
Ontario, Canada
Contents
1 Introduction 1
1.1 What is LibTomMath? . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Building LibTomMath . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.1 Static Libraries . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.2 Shared Libraries . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.3 Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Build Configuration . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4.1 Build Depends . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.2 Build Tweaks . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4.3 Build Trims . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.5 Purpose of LibTomMath . . . . . . . . . . . . . . . . . . . . . . . 5
iii
3 Basic Operations 19
3.1 Small Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1.1 Single Digit . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1.2 Long Constants . . . . . . . . . . . . . . . . . . . . . . . . 20
3.1.3 Initialize and Setting Constants . . . . . . . . . . . . . . . 21
3.2 Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.2.1 Unsigned comparison . . . . . . . . . . . . . . . . . . . . . 23
3.2.2 Signed comparison . . . . . . . . . . . . . . . . . . . . . . 24
3.2.3 Single Digit . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.3 Logical Operations . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.3.1 Multiplication by two . . . . . . . . . . . . . . . . . . . . 26
3.3.2 Polynomial Basis Operations . . . . . . . . . . . . . . . . 28
3.3.3 AND, OR and XOR Operations . . . . . . . . . . . . . . 29
3.4 Addition and Subtraction . . . . . . . . . . . . . . . . . . . . . . 29
3.5 Sign Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.1 Negation . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5.2 Absolute . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.6 Integer Division and Remainder . . . . . . . . . . . . . . . . . . . 30
5 Modular Reduction 35
5.1 Straight Division . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
5.2 Barrett Reduction . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.3 Montgomery Reduction . . . . . . . . . . . . . . . . . . . . . . . 37
5.4 Restricted Dimminished Radix . . . . . . . . . . . . . . . . . . . 40
5.5 Unrestricted Dimminshed Radix . . . . . . . . . . . . . . . . . . 41
6 Exponentiation 43
6.1 Single Digit Exponentiation . . . . . . . . . . . . . . . . . . . . . 43
6.2 Modular Exponentiation . . . . . . . . . . . . . . . . . . . . . . . 43
6.3 Root Finding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
7 Prime Numbers 45
7.1 Trial Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.2 Fermat Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.3 Miller-Rabin Test . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
7.3.1 Required Number of Tests . . . . . . . . . . . . . . . . . . 46
7.4 Primality Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
7.5 Next Prime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
7.6 Random Primes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
7.6.1 Extended Generation . . . . . . . . . . . . . . . . . . . . . 47
9 Algebraic Functions 51
9.1 Extended Euclidean Algorithm . . . . . . . . . . . . . . . . . . . 51
9.2 Greatest Common Divisor . . . . . . . . . . . . . . . . . . . . . . 51
9.3 Least Common Multiple . . . . . . . . . . . . . . . . . . . . . . . 51
9.4 Jacobi Symbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
9.5 Modular Inverse . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
9.6 Single Digit Functions . . . . . . . . . . . . . . . . . . . . . . . . 52
List of Figures
vii
Chapter 1
Introduction
1.2 License
As of the v0.25 the library source code has been placed in the public domain with
every new release. As of the v0.28 release the textbook “Implementing Multiple
Precision Arithmetic” has been placed in the public domain with every new
release as well. This textbook is meant to compliment the project by providing
a more solid walkthrough of the development algorithms used in the library.
Since both1 are in the public domain everyone is entitled to do with them
1 Note that the MPI files under mtest/ are copyrighted by Michael Fromberger. They are
not required to use LibTomMath.
1
2 CHAPTER 1. INTRODUCTION
1.3.3 Testing
To build the library and the test harness type
make test
This will build the library, “test” and “mtest/mtest”. The “test” program
will accept test vectors and verify the results. “mtest/mtest” will generate test
vectors using the MPI library by Michael Fromberger2 . Simply pipe mtest into
test using
mtest/mtest | test
If you do not have a “/dev/urandom” style RNG source you will have to
write your own PRNG and simply pipe that into mtest. For example, if your
PRNG program is called “myprng” simply invoke
This will output a row of numbers that are increasing. Each column is a
different test (such as addition, multiplication, etc) that is being performed. The
numbers represent how many times the test was invoked. If an error is detected
the program will exit with a dump of the relevent numbers it was working with.
In the file tommath class.h you will see a large list of C “defines” followed by a
series of “ifdefs” which further define symbols. All of the symbols (technically
they’re macros . . .) represent a given C source file. For instance, BN MP ADD C
represents the file “bn mp add.c”. When a define has been enabled the function
in the respective file will be compiled and linked into the library. Accordingly
when the define is absent the file will not be compiled and not contribute any
size to the library.
You will also note that the header tommath class.h is actually recursively
included (it includes itself twice). This is to help resolve as many dependencies
as possible. In the last pass the symbol LTM LAST will be defined. This is
useful for “trims”.
Define Purpose
BN MP DIV SMALL Enables a slower, smaller and equally
functional mp div() function
Moduli Related
Restriction Undefine
Exponentiation with odd moduli only BN S MP EXPTMOD C
BN MP REDUCE C
BN MP REDUCE SETUP C
BN S MP MUL HIGH DIGS C
BN FAST S MP MUL HIGH DIGS C
Exponentiation with random odd moduli (The above plus the following)
BN MP REDUCE 2K C
BN MP REDUCE 2K SETUP C
BN MP REDUCE IS 2K C
BN MP DR IS MODULUS C
BN MP DR REDUCE C
BN MP DR SETUP C
Modular inverse odd moduli only BN MP INVMOD SLOW C
Modular inverse (both, smaller/slower) BN FAST MP INVMOD C
Code Meaning
MP OKAY The function succeeded.
MP VAL The function input was invalid.
MP MEM Heap memory exhausted.
The last two codes listed are not actually “return’ed” by a function. They
9
10 CHAPTER 2. GETTING STARTED WITH LIBTOMMATH
are placed in an integer (the caller must provide the address of an integer it can
store to) which the caller can access. To convert one of the three return codes
to a string use the following function.
This will return a pointer to a string which describes the given error code.
It will not work for the return codes MP YES and MP NO.
typedef struct {
int used, alloc, sign;
mp_digit *dp;
} mp_int;
Where “mp digit” is a data type that represents individual digits of the
integer. By default, an mp digit is the ISO C “unsigned long” data type and
each digit is 28−bits long. The mp digit type can be configured to suit other
platforms by defining the appropriate macros.
All LTM functions that use the mp int type will expect a pointer to mp int
structure. You must allocate memory to hold the structure itself by yourself
(whether off stack or heap it doesn’t matter). The very first thing that must be
done to use an mp int is that it must be initialized.
Another feature of the way the functions have been implemented is that
source operands can be destination operands as well. For instance,
2.5 Initialization
2.5.1 Single Initialization
A single mp int can be initialized with the “mp init” function.
This function expects a pointer to an mp int structure and will initialize the
members of the structure so the mp int represents the default integer which is
zero. If the functions returns MP OKAY then the mp int is ready to be used
by the other LibTomMath functions.
int main(void)
{
mp_int number;
int result;
return EXIT_SUCCESS;
}
int main(void)
{
mp_int number;
int result;
return EXIT_SUCCESS;
}
int main(void)
{
mp_int num1, num2, num3;
int result;
if ((result = mp_init_multi(&num1,
&num2,
&num3, NULL)) != MP OKAY) {
printf("Error initializing the numbers. %s",
mp_error_to_string(result));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
This function will initialize a and make it a copy of b if all goes well.
int main(void)
{
mp_int num1, num2;
int result;
return EXIT_SUCCESS;
}
Another less common initializer is mp init size() which allows the user to ini-
tialize an mp int with a given default number of digits. By default, all initializers
allocate MP PREC digits. This function lets you override this behaviour.
The size parameter must be greater than zero. If the function succeeds the
mp int a will be initialized to have size digits (which are all initially zero).
int main(void)
{
mp_int number;
int result;
return EXIT_SUCCESS;
}
2.6. MAINTENANCE FUNCTIONS 15
This will remove excess digits of the mp int a. If the operation fails the
mp int should be intact without the excess digits being removed. Note that
you can use a shrunk mp int in further computations, however, such operations
will require heap operations which can be slow. It is not ideal to shrink mp int
variables that you will further modify in the system (unless you are seriously
low on memory).
int main(void)
{
mp_int number;
int result;
/* use it .... */
mp_clear(&number);
return EXIT_SUCCESS;
}
This will grow the array of digits of a to size. If the alloc parameter is
already bigger than size the function will not do anything.
int main(void)
{
mp_int number;
int result;
return EXIT_SUCCESS;
}
18 CHAPTER 2. GETTING STARTED WITH LIBTOMMATH
Chapter 3
Basic Operations
This will zero the contents of a and make it represent an integer equal to the
value of b. Note that this function has a return type of void. It cannot cause
an error so it is safe to assume the function succeeded.
int main(void)
{
mp_int number;
int result;
19
20 CHAPTER 3. BASIC OPERATIONS
return EXIT_SUCCESS;
}
This will assign the value of the 32-bit variable b to the mp int a. Unlike
mp set() this function will always accept a 32-bit input regardless of the size of
a single digit. However, since the value may span several digits this function
can fail if it runs out of heap memory.
To get the “unsigned long” copy of an mp int the following function can be
used.
int main(void)
{
mp_int number;
int result;
return EXIT_SUCCESS;
}
number == 654321
Both functions work like the previous counterparts except they first mp init
a before setting the values.
int main(void)
{
mp_int number1, number2;
int result;
/* display */
printf("Number1, Number2 == %lu, %lu",
mp_get_int(&number1), mp_get_int(&number2));
/* clear */
mp_clear_multi(&number1, &number2, NULL);
return EXIT_SUCCESS;
}
3.2 Comparisons
Comparisons in LibTomMath are always performed in a “left to right” fashion.
There are three possible return codes for any comparison.
In figure 3.1 two integers a and b are being compared. In this case a is said
to be “to the left” of b.
3.2. COMPARISONS 23
This will compare a to b placing a to the left of b. This function cannot fail and
will return one of the three compare codes listed in figure 3.1.
int main(void)
{
mp_int number1, number2;
int result;
switch(mp_cmp_mag(&number1, &number2)) {
case MP_GT: printf("|number1| > |number2|"); break;
case MP_EQ: printf("|number1| = |number2|"); break;
case MP_LT: printf("|number1| < |number2|"); break;
}
return EXIT_SUCCESS;
}
This will compare a to the left of b. It will first compare the signs of the two
mp int variables. If they differ it will return immediately based on their signs.
If the signs are equal then it will compare the digits individually. This function
will return one of the compare conditions codes listed in figure 3.1.
int main(void)
{
mp_int number1, number2;
int result;
mp_error_to_string(result));
return EXIT_FAILURE;
}
switch(mp_cmp(&number1, &number2)) {
case MP_GT: printf("number1 > number2"); break;
case MP_EQ: printf("number1 = number2"); break;
case MP_LT: printf("number1 < number2"); break;
}
return EXIT_SUCCESS;
}
This will compare a to the left of b using a signed comparison. Note that it
will always treat b as positive. This function is rather handy when you have to
compare against small values such as 1 (which often comes up in cryptography).
The function cannot fail and will return one of the tree compare condition codes
listed in figure 3.1.
int main(void)
{
mp_int number;
int result;
mp_error_to_string(result));
return EXIT_FAILURE;
}
switch(mp_cmp_d(&number, 7)) {
case MP_GT: printf("number > 7"); break;
case MP_EQ: printf("number = 7"); break;
case MP_LT: printf("number < 7"); break;
}
return EXIT_SUCCESS;
}
int main(void)
{
mp_int number;
int result;
/* multiply by two */
if ((result = mp mul 2(&number, &number)) != MP_OKAY) {
printf("Error multiplying the number. %s",
mp_error_to_string(result));
return EXIT_FAILURE;
}
switch(mp_cmp_d(&number, 7)) {
case MP_GT: printf("2*number > 7"); break;
case MP_EQ: printf("2*number = 7"); break;
case MP_LT: printf("2*number < 7"); break;
}
return EXIT_SUCCESS;
28 CHAPTER 3. BASIC OPERATIONS
Which assigns −a to b.
3.5.2 Absolute
Simple integer absolutes can be performed with the following.
This divides a by b and stores the quotient in c and d. The signed quotient is
computed such that bc + d = a. Note that either of c or d can be set to NULL
if their value is not required. If b is zero the function returns MP VAL.
Chapter 4
4.1 Multiplication
A full signed integer multiplication can be performed with the following.
Which assigns the full signed product ab to c. This function actually breaks into
one of four cases which are specific multiplication routines optimized for given
parameters. First there are the Toom-Cook multiplications which should only
be used with very large inputs. This is followed by the Karatsuba multiplications
which are for moderate sized inputs. Then followed by the Comba and baseline
multipliers.
Fortunately for the developer you don’t really need to know this unless you
really want to fine tune the system. mp mul() will determine on its own1 what
routine to use automatically when it is called.
int main(void)
{
mp_int number1, number2;
int result;
31
32 CHAPTER 4. MULTIPLICATION AND SQUARING
/* multiply them */
if ((result = mp_mul(&number1, &number2,
&number1)) != MP_OKAY) {
printf("Error multiplying terms. %s",
mp_error_to_string(result));
return EXIT_FAILURE;
}
/* display */
printf("number1 * number2 == %lu", mp_get_int(&number1));
return EXIT_SUCCESS;
}
4.2 Squaring
Since squaring can be performed faster than multiplication it is performed it’s
own function instead of just using mp mul().
Will square a and store it in b. Like the case of multiplication there are four
different squaring algorithms all which can be called from mp sqr(). It is ideal
to use mp sqr over mp mul when squaring terms because of the speed difference.
make XXX
Where “XXX” is one of the following entries from the table 4.1.
When the program is running it will output a series of measurements for
different cutoff points. It will first find good Karatsuba squaring and multi-
plication points. Then it proceeds to find Toom-Cook points. Note that the
Toom-Cook tuning takes a very long time as the cutoff points are likely to be
very high.
34 CHAPTER 4. MULTIPLICATION AND SQUARING
Modular Reduction
a ≡ b (mod c) (5.1)
This reduces a modulo b and stores the result in c. The sign of c shall agree
with the sign of b. This algorithm accepts an input a of any range and is not
limited by 0 ≤ a < b2 .
35
36 CHAPTER 5. MODULAR REDUCTION
Given a modulus in b this produces the required µ value in a. For any given
modulus this only has to be computed once. Modular reduction can now be
performed with the following.
int main(void)
{
mp_int a, b, c, mu;
int result;
/* get mu value */
if ((result = mp_reduce_setup(&mu, b)) != MP_OKAY) {
printf("Error getting mu. %s",
mp_error_to_string(result));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
This program will calculate a3 mod b if all the functions succeed.
This reduces a in place modulo m with the pre–computed value mp. a must be
in the range 0 ≤ a < b2 .
Montgomery reduction is faster than Barrett reduction for moduli smaller
than the “comba” limit. With the default setup for instance, the limit is 127
digits (3556–bits). Note that this function is not limited to 127 digits just that
it falls back to a baseline algorithm after that point.
An important observation is that this reduction does not return a mod m
but aR−1 mod m where R = β n , n is the n number of digits in m and β is radix
used (default is 228 ).
To quickly calculate R the following function was provided.
int main(void)
{
mp_int a, b, c, R;
mp_digit mp;
int result;
/* get normalization */
if ((result = mp_montgomery_calc_normalization(&R, b)) != MP_OKAY) {
printf("Error getting norm. %s",
mp_error_to_string(result));
return EXIT_FAILURE;
}
/* get mp value */
if ((result = mp_montgomery_setup(&c, &mp)) != MP_OKAY) {
5.3. MONTGOMERY REDUCTION 39
return EXIT_SUCCESS;
}
This particular example does not look too efficient but it demonstrates the
point of the algorithm. By normalizing the inputs the reduced results are always
of the form aR for some variable a. This allows a single final reduction to correct
for the normalization and the fast reduction used within the algorithm.
For more details consider examining the file bn mp exptmod fast.c.
This computes the value required for the modulus a and stores it in d.
This function cannot fail and does not return any error codes. After the pre–
computation a reduction can be performed with the following.
This reduces a in place modulo b with the pre–computed value mp. b must
be of a restricted dimminished radix form and a must be in the range 0 ≤
a < b2 . Dimminished radix reductions are much faster than both Barrett and
Montgomery reductions as they have a much lower asymtotic running time.
5.5. UNRESTRICTED DIMMINSHED RADIX 41
Since the moduli are restricted this algorithm is not particularly useful for
something like Rabin, RSA or BBS cryptographic purposes. This reduction al-
gorithm is useful for Diffie-Hellman and ECC where fixed primes are acceptable.
Note that unlike Montgomery reduction there is no normalization process.
The result of this function is equal to the correct residue.
This will compute the required d value for the given moduli a.
This will reduce a in place modulo n with the pre–computed value d. From
my experience this routine is slower than mp dr reduce but faster for most
moduli sizes than the Montgomery reduction.
42 CHAPTER 5. MODULAR REDUCTION
Chapter 6
Exponentiation
43
44 CHAPTER 6. EXPONENTIATION
This computes c = a1/b such that cb ≤ a and (c + 1)b > a. The implementation
of this function is not ideal for values of b greater than three. It will work but
become very slow. So unless you are working with very small numbers (less than
1000 bits) I’d avoid b > 3 situations. Will return a positive root only for even
roots and return a root with the sign of the input for odd roots. For example,
performing 41/2 will return 2 whereas (−8)1/3 will return −2.
This algorithm uses the “Newton Approximation” method and will converge
on the correct root fairly quickly. Since the algorithm requires raising a to
the power of b it is not ideal to attempt to find roots for large values of b. If
particularly large roots are required then a factor method could be used instead.
1/2 1/2
1/4 1/4 1/2 1/2
1/16
For example, a is equivalent to a or simply a
Chapter 7
Prime Numbers
This will attempt to evenly divide a by a list of primes1 and store the outcome in
“result”. That is if result = 0 then a is not divisible by the primes, otherwise it
is. Note that if the function does not return MP OKAY the value in “result”
should be considered undefined2 .
45
46 CHAPTER 7. PRIME NUMBERS
Performs a Miller-Rabin test to the base b of a. This test is much stronger than
the Fermat test and is very hard to fool (besides with Carmichael numbers). If
a passes the test (therefore is probably prime) result is set to one. Otherwise
result is set to zero.
Note that is suggested that you use the Miller-Rabin test instead of the
Fermat test since all of the failures of Miller-Rabin are a subset of the failures
of the Fermat test.
This returns the number of trials required for a 2−96 (or lower) probability of
failure for a given “size” expressed in bits. This comes in handy specially since
larger numbers are slower to test. For example, a 512-bit number would require
ten tests whereas a 1024-bit number would only require four tests.
You should always still perform a trial division before a Miller-Rabin test
though.
This finds the next prime after a that passes mp prime is prime() with t tests.
Set bbs style to one if you want only the next prime congruent to 3 mod 4,
otherwise set it to zero to find any next prime.
This will find a prime greater than 256size which can be “bbs style” or not
depending on bbs and must pass t rounds of tests. The “ltm prime callback” is
a typedef for
Which is a function that must read len bytes (and return the amount stored)
into dst. The dat variable is simply copied from the original input. It can be used
to pass RNG context data to the callback. The function mp prime random()
is more suitable for generating primes which must be secret (as in the case of
RSA) since there is no skew on the least significant bits.
Note: As of v0.30 of the LibTomMath library this function has been depre-
cated. It is still available but users are encouraged to use the new mp prime random ex()
function instead.
This will generate a prime in a using t tests of the primality testing algorithms.
The variable size specifies the bit length of the prime desired. The variable
f lags specifies one of several options available (see fig. 7.1) which can be OR’ed
together. The callback parameters are used as in mp prime random().
48 CHAPTER 7. PRIME NUMBERS
Flag Meaning
LTM PRIME BBS Make the prime congruent to 3 modulo 4
LTM PRIME SAFE Make a prime p such that (p − 1)/2 is also prime.
This option implies LTM PRIME BBS as well.
LTM PRIME 2MSB OFF Makes sure that the bit adjacent to the most significant bit
Is forced to zero.
LTM PRIME 2MSB ON Makes sure that the bit adjacent to the most significant bit
Is forced to one.
This still store a in “str” as a base-“radix” string of ASCII chars. This function
appends a NUL character to terminate the string. Valid values of “radix” line
in the range [2, 64]. To determine the size (exact) required by the conversion
before storing any data use the following function.
This stores in “size” the number of characters (including space for the NUL
terminator) required. Upon error this function returns an error code and “size”
will be zero.
This will read the base-“radix” NUL terminated string from “str” into a. It will
stop reading when it reads a character it does not recognize (which happens to
include th NUL char... imagine that...). A single leading − sign can be used to
denote a negative number.
49
50 CHAPTER 8. INPUT AND OUTPUT
This will return the number of bytes (octets) required to store the unsigned
copy of the integer a.
This will store a into the buffer b in big–endian format. Fortunately this is
exactly what DER (or is it ASN?) requires. It does not store the sign of the
integer.
This will read in an unsigned big–endian array of bytes (octets) from b of length
c into a. The resulting integer a will always be positive.
For those who acknowledge the existence of negative numbers (heretic!)
there are “signed” versions of the previous functions.
They operate essentially the same as the unsigned copies except they prefix the
data with zero or non–zero byte depending on the sign. If the sign is zpos (e.g.
not negative) the prefix is zero, otherwise the prefix is non–zero.
Chapter 9
Algebraic Functions
This finds the triple U1/U2/U3 using the Extended Euclidean algorithm
such that the following equation holds.
a · U1 + b · U2 = U3 (9.1)
Any of the U1/U2/U3 paramters can be set to NULL if they are not desired.
This will compute the greatest common divisor of a and b and store it in c.
This will compute the least common multiple of a and b and store it in c.
51
52 CHAPTER 9. ALGEBRAIC FUNCTIONS
This will compute the Jacobi symbol for a with respect to p. If p is prime this
essentially computes the Legendre symbol. The result is stored in c and can
take on one of three values {−1, 0, 1}. If p is prime then the result will be −1
when a is not a quadratic residue modulo p. The result will be 0 if a divides p
and the result will be 1 if a is a quadratic residue modulo p.
These work like the full mp int capable variants except the second parameter
b is a mp digit. These functions fairly handy if you have to work with relatively
small numbers since you will not have to allocate an entire mp int to store a
number like 1 or 2.
Index
mp add, 29 mp invmod, 52
mp add d, 52 mp jacobi, 52
mp and, 29 mp lcm, 51
mp clear, 11 mp lshd, 28
mp clear multi, 12 MP LT, 22
mp cmp, 24 MP MEM, 9
mp cmp d, 25 mp mod, 35
mp cmp mag, 23 mp mod d, 52
mp div, 30 mp montgomery calc normalization, 38
mp div 2, 26 mp montgomery reduce, 37
mp div 2d, 28 mp montgomery setup, 37
mp div d, 52 mp mul, 31
mp dr reduce, 40 mp mul 2, 26
mp dr setup, 40 mp mul 2d, 28
MP EQ, 22 mp mul d, 52
mp error to string, 10 mp n root, 44
mp expt d, 43 mp neg, 29
mp exptmod, 43 MP NO, 9
mp exteuclid, 51 MP OKAY, 9
mp gcd, 51 mp or, 29
mp get int, 20 mp prime fermat, 45
mp grow, 16 mp prime is divisible, 45
MP GT, 22 mp prime is prime, 46
mp init, 11 mp prime miller rabin, 45
mp init copy, 13 mp prime next prime, 46
mp init multi, 12 mp prime rabin miller trials, 46
mp init set, 21 mp prime random, 47
mp init set int, 21 mp prime random ex, 47
mp init size, 14 mp radix size, 49
mp int, 10 mp read radix, 49
53
54 INDEX