tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

README (28010B)


      1 This Source Code Form is subject to the terms of the Mozilla Public
      2 License, v. 2.0. If a copy of the MPL was not distributed with this
      3 file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 
      5 About the MPI Library
      6 ---------------------
      7 
      8 The files 'mpi.h' and 'mpi.c' define a simple, arbitrary precision
      9 signed integer arithmetic package.  The implementation is not the most
     10 efficient possible, but the code is small and should be fairly easily
     11 portable to just about any machine that supports an ANSI C compiler,
     12 as long as it is capable of at least 16-bit arithmetic (but also see
     13 below for more on this).
     14 
     15 This library was written with an eye to cryptographic applications;
     16 thus, some care is taken to make sure that temporary values are not
     17 left lying around in memory when they are no longer in use.  This adds
     18 some overhead for zeroing buffers before they are released back into
     19 the free pool; however, it gives you the assurance that there is only
     20 one copy of your important values residing in your process's address
     21 space at a time.  Obviously, it is difficult to guarantee anything, in
     22 a pre-emptive multitasking environment, but this at least helps you
     23 keep a lid on the more obvious ways your data can get spread around in
     24 memory.
     25 
     26 
     27 Using the Library
     28 -----------------
     29 
     30 To use the MPI library in your program, you must include the header:
     31 
     32 #include "mpi.h"
     33 
     34 This header provides all the type and function declarations you'll
     35 need to use the library.  Almost all the names defined by the library
     36 begin with the prefix 'mp_', so it should be easy to keep them from
     37 clashing with your program's namespace (he says, glibly, knowing full
     38 well there are always pathological cases).
     39 
     40 There are a few things you may want to configure about the library.
     41 By default, the MPI library uses an unsigned short for its digit type,
     42 and an unsigned int for its word type.  The word type must be big
     43 enough to contain at least two digits, for the primitive arithmetic to
     44 work out.  On my machine, a short is 2 bytes and an int is 4 bytes --
     45 but if you have 64-bit ints, you might want to use a 4-byte digit and
     46 an 8-byte word.  I have tested the library using 1-byte digits and
     47 2-byte words, as well.  Whatever you choose to do, the things you need
     48 to change are:
     49 
     50 (1) The type definitions for mp_digit and mp_word.
     51 
     52 (2) The macro DIGIT_FMT which tells mp_print() how to display a
     53     single digit.  This is just a printf() format string, so you
     54     can adjust it appropriately.
     55 
     56 (3) The macros DIGIT_MAX and MP_WORD_MAX, which specify the
     57     largest value expressible in an mp_digit and an mp_word,
     58     respectively.
     59 
     60 Both the mp_digit and mp_word should be UNSIGNED integer types.  The
     61 code relies on having the full positive precision of the type used for
     62 digits and words.
     63 
     64 The remaining type definitions should be left alone, for the most
     65 part.  The code in the library does not make any significant
     66 assumptions about the sizes of things, but there is little if any
     67 reason to change the other parameters, so I would recommend you leave
     68 them as you found them.
     69 
     70 
     71 Conventions
     72 -----------
     73 
     74 Most functions in the library return a value of type mp_err.  This
     75 permits the library to communicate success or various kinds of failure
     76 to the calling program.  The return values currently defined are:
     77 
     78         MP_OKAY         - okay, operation succeeded, all's well
     79         MP_YES          - okay, the answer is yes (same as MP_OKAY)
     80         MP_NO           - okay, but answer is no (not MP_OKAY)
     81         MP_MEM          - operation ran out of memory
     82         MP_RANGE        - input parameter was out of range
     83         MP_BADARG       - an invalid input parameter was provided
     84         MP_UNDEF        - no output value is defined for this input
     85 
     86 The only function which currently uses MP_UNDEF is mp_invmod().
     87 Division by zero is undefined, but the division functions will return
     88 MP_RANGE for a zero divisor.  MP_BADARG usually means you passed a
     89 bogus mp_int structure to the function.  MP_YES and MP_NO are not used
     90 by the library itself; they're defined so you can use them in your own
     91 extensions.
     92 
     93 If you need a readable interpretation of these error codes in your
     94 program, you may also use the mp_strerror() function.  This function
     95 takes an mp_err as input, and returns a pointer to a human-readable
     96 string describing the meaning of the error.  These strings are stored
     97 as constants within the library, so the caller should not attempt to
     98 modify or free the memory associated with these strings.
     99 
    100 The library represents values in signed-magnitude format.  Values
    101 strictly less than zero are negative, all others are considered
    102 positive (zero is positive by fiat).  You can access the 'sign' member
    103 of the mp_int structure directly, but better is to use the mp_cmp_z()
    104 function, to find out which side of zero the value lies on.
    105 
    106 Most arithmetic functions have a single-digit variant, as well as the
    107 full arbitrary-precision.  An mp_digit is an unsigned value between 0
    108 and DIGIT_MAX inclusive.  The radix is available as RADIX.  The number
    109 of bits in a given digit is given as DIGIT_BIT.
    110 
    111 Generally, input parameters are given before output parameters.
    112 Unless otherwise specified, any input parameter can be re-used as an
    113 output parameter, without confusing anything.
    114 
    115 The basic numeric type defined by the library is an mp_int.  Virtually
    116 all the functions in the library take a pointer to an mp_int as one of
    117 their parameters.  An explanation of how to create and use these
    118 structures follows.  And so, without further ado...
    119 
    120 
    121 Initialization and Cleanup
    122 --------------------------
    123 
    124 The basic numeric type defined by the library is an 'mp_int'.
    125 However, it is not sufficient to simply declare a variable of type
    126 mp_int in your program.  These variables also need to be initialized
    127 before they can be used, to allocate the internal storage they require
    128 for computation.
    129 
    130 This is done using one of the following functions:
    131 
    132         mp_init(mp_int *mp);
    133         mp_init_copy(mp_int *mp, mp_int *from);
    134         mp_init_size(mp_int *mp, mp_size p);
    135 
    136 Each of these requires a pointer to a structure of type mp_int.  The
    137 basic mp_init() simply initializes the mp_int to a default size, and
    138 sets its value to zero.  If you would like to initialize a copy of an
    139 existing mp_int, use mp_init_copy(), where the 'from' parameter is the
    140 mp_int you'd like to make a copy of.  The third function,
    141 mp_init_size(), permits you to specify how many digits of precision
    142 should be preallocated for your mp_int.  This can help the library
    143 avoid unnecessary re-allocations later on.
    144 
    145 The default precision used by mp_init() can be retrieved using:
    146 
    147         precision = mp_get_prec();
    148 
    149 This returns the number of digits that will be allocated.  You can
    150 change this value by using:
    151 
    152         mp_set_prec(unsigned int prec);
    153 
    154 Any positive value is acceptable -- if you pass zero, the default
    155 precision will be re-set to the compiled-in library default (this is
    156 specified in the header file 'mpi-config.h', and typically defaults to
    157 8 or 16).
    158 
    159 Just as you must allocate an mp_int before you can use it, you must
    160 clean up the structure when you are done with it.  This is performed
    161 using the mp_clear() function.  Remember that any mp_int that you
    162 create as a local variable in a function must be mp_clear()'d before
    163 that function exits, or else the memory allocated to that mp_int will
    164 be orphaned and unrecoverable.
    165 
    166 To set an mp_int to a given value, the following functions are given:
    167 
    168         mp_set(mp_int *mp, mp_digit d);
    169         mp_set_int(mp_int *mp, long z);
    170         mp_set_ulong(mp_int *mp, unsigned long z);
    171 
    172 The mp_set() function sets the mp_int to a single digit value, while
    173 mp_set_int() sets the mp_int to a signed long integer value.
    174 
    175 To set an mp_int to zero, use:
    176 
    177         mp_zero(mp_int *mp);
    178 
    179 
    180 Copying and Moving
    181 ------------------
    182 
    183 If you have two initialized mp_int's, and you want to copy the value
    184 of one into the other, use:
    185 
    186         mp_copy(from, to)
    187 
    188 This takes care of clearing the old value of 'to', and copies the new
    189 value into it.  If 'to' is not yet initialized, use mp_init_copy()
    190 instead (see above).
    191 
    192 Note:   The library tries, whenever possible, to avoid allocating
    193 ----    new memory.  Thus, mp_copy() tries first to satisfy the needs
    194         of the copy by re-using the memory already allocated to 'to'.
    195         Only if this proves insufficient will mp_copy() actually
    196         allocate new memory.
    197 
    198         For this reason, if you know a priori that 'to' has enough
    199         available space to hold 'from', you don't need to check the
    200         return value of mp_copy() for memory failure.  The USED()
    201         macro tells you how many digits are used by an mp_int, and
    202         the ALLOC() macro tells you how many are allocated.
    203 
    204 If you have two initialized mp_int's, and you want to exchange their
    205 values, use:
    206 
    207         mp_exch(a, b)
    208 
    209 This is better than using mp_copy() with a temporary, since it will
    210 not (ever) touch the memory allocator -- it just swaps the exact
    211 contents of the two structures.  The mp_exch() function cannot fail;
    212 if you pass it an invalid structure, it just ignores it, and does
    213 nothing.
    214 
    215 
    216 Basic Arithmetic
    217 ----------------
    218 
    219 Once you have initialized your integers, you can operate on them.  The
    220 basic arithmetic functions on full mp_int values are:
    221 
    222 mp_add(a, b, c)         - computes c = a + b
    223 mp_sub(a, b, c)         - computes c = a - b
    224 mp_mul(a, b, c)         - computes c = a * b
    225 mp_sqr(a, b)            - computes b = a * a
    226 mp_div(a, b, q, r)      - computes q, r such that a = bq + r
    227 mp_div_2d(a, d, q, r)   - computes q = a / 2^d, r = a % 2^d
    228 mp_expt(a, b, c)        - computes c = a ** b
    229 mp_2expt(a, k)          - computes a = 2^k
    230 
    231 The mp_div_2d() function efficiently computes division by powers of
    232 two.  Either the q or r parameter may be NULL, in which case that
    233 portion of the computation will be discarded.
    234 
    235 The algorithms used for some of the computations here are described in
    236 the following files which are included with this distribution:
    237 
    238 mul.txt         Describes the multiplication algorithm
    239 div.txt         Describes the division algorithm
    240 expt.txt        Describes the exponentiation algorithm
    241 sqrt.txt        Describes the square-root algorithm
    242 square.txt      Describes the squaring algorithm
    243 
    244 There are single-digit versions of most of these routines, as well.
    245 In the following prototypes, 'd' is a single mp_digit:
    246 
    247 mp_add_d(a, d, c)       - computes c = a + d
    248 mp_sub_d(a, d, c)       - computes c = a - d
    249 mp_mul_d(a, d, c)       - computes c = a * d
    250 mp_mul_2(a, c)          - computes c = a * 2
    251 mp_div_d(a, d, q, r)    - computes q, r such that a = bq + r
    252 mp_div_2(a, c)          - computes c = a / 2
    253 mp_expt_d(a, d, c)      - computes c = a ** d
    254 
    255 The mp_mul_2() and mp_div_2() functions take advantage of the internal
    256 representation of an mp_int to do multiplication by two more quickly
    257 than mp_mul_d() would.  Other basic functions of an arithmetic variety
    258 include:
    259 
    260 mp_zero(a)              - assign 0 to a
    261 mp_neg(a, c)            - negate a: c = -a
    262 mp_abs(a, c)            - absolute value: c = |a|
    263 
    264 
    265 Comparisons
    266 -----------
    267 
    268 Several comparison functions are provided.  Each of these, unless
    269 otherwise specified, returns zero if the comparands are equal, < 0 if
    270 the first is less than the second, and > 0 if the first is greater
    271 than the second:
    272 
    273 mp_cmp_z(a)             - compare a <=> 0
    274 mp_cmp_d(a, d)          - compare a <=> d, d is a single digit
    275 mp_cmp(a, b)            - compare a <=> b
    276 mp_cmp_mag(a, b)        - compare |a| <=> |b|
    277 mp_isodd(a)             - return nonzero if odd, zero otherwise
    278 mp_iseven(a)            - return nonzero if even, zero otherwise
    279 
    280 
    281 Modular Arithmetic
    282 ------------------
    283 
    284 Modular variations of the basic arithmetic functions are also
    285 supported.  These are available if the MP_MODARITH parameter in
    286 mpi-config.h is turned on (it is by default).  The modular arithmetic
    287 functions are:
    288 
    289 mp_mod(a, m, c)         - compute c = a (mod m), 0 <= c < m
    290 mp_mod_d(a, d, c)       - compute c = a (mod d), 0 <= c < d (see below)
    291 mp_addmod(a, b, m, c)   - compute c = (a + b) mod m
    292 mp_submod(a, b, m, c)   - compute c = (a - b) mod m
    293 mp_mulmod(a, b, m, c)   - compute c = (a * b) mod m
    294 mp_sqrmod(a, m, c)      - compute c = (a * a) mod m
    295 mp_exptmod(a, b, m, c)  - compute c = (a ** b) mod m
    296 mp_exptmod_d(a, d, m, c)- compute c = (a ** d) mod m
    297 
    298 The mp_sqr() function squares its input argument.  A call to mp_sqr(a,
    299 c) is identical in meaning to mp_mul(a, a, c); however, if the
    300 MP_SQUARE variable is set true in mpi-config.h (see below), then it
    301 will be implemented with a different algorithm, that is supposed to
    302 take advantage of the redundant computation that takes place during
    303 squaring.  Unfortunately, some compilers result in worse performance
    304 on this code, so you can change the behaviour at will.  There is a
    305 utility program "mulsqr.c" that lets you test which does better on
    306 your system.
    307 
    308 The mp_sqrmod() function is analogous to the mp_sqr() function; it
    309 uses the mp_sqr() function rather than mp_mul(), and then performs the
    310 modular reduction.  This probably won't help much unless you are doing
    311 a lot of them.
    312 
    313 See the file 'square.txt' for a synopsis of the algorithm used.
    314 
    315 Note:   The mp_mod_d() function computes a modular reduction around
    316 ----    a single digit d.  The result is a single digit c.
    317 
    318 Because an inverse is defined for a (mod m) if and only if (a, m) = 1
    319 (that is, if a and m are relatively prime), mp_invmod() may not be
    320 able to compute an inverse for the arguments.  In this case, it
    321 returns the value MP_UNDEF, and does not modify c.  If an inverse is
    322 defined, however, it returns MP_OKAY, and sets c to the value of the
    323 inverse (mod m).
    324 
    325 See the file 'redux.txt' for a description of the modular reduction
    326 algorithm used by mp_exptmod().
    327 
    328 
    329 Greatest Common Divisor
    330 -----------------------
    331 
    332 If The greates common divisor of two values can be found using one of the
    333 following functions:
    334 
    335 mp_gcd(a, b, c)         - compute c = (a, b) using binary algorithm
    336 mp_lcm(a, b, c)         - compute c = [a, b] = ab / (a, b)
    337 mp_xgcd(a, b, g, x, y)  - compute g, x, y so that ax + by = g = (a, b)
    338 
    339 Also provided is a function to compute modular inverses, if they
    340 exist:
    341 
    342 mp_invmod(a, m, c)      - compute c = a^-1 (mod m), if it exists
    343 
    344 The function mp_xgcd() computes the greatest common divisor, and also
    345 returns values of x and y satisfying Bezout's identity.  This is used
    346 by mp_invmod() to find modular inverses.  However, if you do not need
    347 these values, you will find that mp_gcd() is MUCH more efficient,
    348 since it doesn't need all the intermediate values that mp_xgcd()
    349 requires in order to compute x and y.
    350 
    351 The mp_gcd() (and mp_xgcd()) functions use the binary (extended) GCD
    352 algorithm due to Josef Stein.
    353 
    354 
    355 Input & Output Functions
    356 ------------------------
    357 
    358 The following basic I/O routines are provided.  These are present at
    359 all times:
    360 
    361 mp_read_radix(mp, str, r)  - convert a string in radix r to an mp_int
    362 mp_read_raw(mp, s, len)    - convert a string of bytes to an mp_int
    363 mp_radix_size(mp, r)       - return length of buffer needed by mp_toradix()
    364 mp_raw_size(mp)            - return length of buffer needed by mp_toraw()
    365 mp_toradix(mp, str, r)     - convert an mp_int to a string of radix r
    366                              digits
    367 mp_toraw(mp, str)          - convert an mp_int to a string of bytes
    368 mp_tovalue(ch, r)          - convert ch to its value when taken as
    369                              a radix r digit, or -1 if invalid
    370 mp_strerror(err)           - get a string describing mp_err value 'err'
    371 
    372 If you compile the MPI library with MP_IOFUNC defined, you will also
    373 have access to the following additional I/O function:
    374 
    375 mp_print(mp, ofp)       - print an mp_int as text to output stream ofp
    376 
    377 Note that mp_radix_size() returns a size in bytes guaranteed to be AT
    378 LEAST big enough for the digits output by mp_toradix().  Because it
    379 uses an approximation technique to figure out how many digits will be
    380 needed, it may return a figure which is larger than necessary.  Thus,
    381 the caller should not rely on the value to determine how many bytes
    382 will actually be written by mp_toradix().  The string mp_toradix()
    383 creates will be NUL terminated, so the standard C library function
    384 strlen() should be able to ascertain this for you, if you need it.
    385 
    386 The mp_read_radix() and mp_toradix() functions support bases from 2 to
    387 64 inclusive.  If you require more general radix conversion facilities
    388 than this, you will need to write them yourself (that's why mp_div_d()
    389 is provided, after all).
    390 
    391 Note:   mp_read_radix() will accept as digits either capital or
    392 ----    lower-case letters.  However, the current implementation of
    393         mp_toradix() only outputs upper-case letters, when writing
    394         bases betwee 10 and 36.  The underlying code supports using
    395         lower-case letters, but the interface stub does not have a
    396         selector for it.  You can add one yourself if you think it
    397         is worthwhile -- I do not.  Bases from 36 to 64 use lower-
    398         case letters as distinct from upper-case.  Bases 63 and
    399         64 use the characters '+' and '/' as digits.
    400 
    401         Note also that compiling with MP_IOFUNC defined will cause
    402         inclusion of <stdio.h>, so if you are trying to write code
    403         which does not depend on the standard C library, you will
    404         probably want to avoid this option.  This is needed because
    405         the mp_print() function takes a standard library FILE * as
    406         one of its parameters, and uses the fprintf() function.
    407 
    408 The mp_toraw() function converts the integer to a sequence of bytes,
    409 in big-endian ordering (most-significant byte first).  Assuming your
    410 bytes are 8 bits wide, this corresponds to base 256.  The sign is
    411 encoded as a single leading byte, whose value is 0 for zero or
    412 positive values, or 1 for negative values.  The mp_read_raw() function
    413 reverses this process -- it takes a buffer of bytes, interprets the
    414 first as a sign indicator (0 = zero/positive, nonzero = negative), and
    415 the rest as a sequence of 1-byte digits in big-endian ordering.
    416 
    417 The mp_raw_size() function returns the exact number of bytes required
    418 to store the given integer in "raw" format (as described in the
    419 previous paragraph).  Zero is returned in case of error; a valid
    420 integer will require at least three bytes of storage.
    421 
    422 In previous versions of the MPI library, an "external representation
    423 format" was supported.  This was removed, however, because I found I
    424 was never using it, it was not as portable as I would have liked, and
    425 I decided it was a waste of space.
    426 
    427 
    428 Other Functions
    429 ---------------
    430 
    431 The files 'mpprime.h' and 'mpprime.c' define some routines which are
    432 useful for divisibility testing and probabilistic primality testing.
    433 The routines defined are:
    434 
    435 mpp_divis(a, b)          - is a divisible by b?
    436 mpp_divis_d(a, d)        - is a divisible by digit d?
    437 mpp_random(a)            - set a to random value at current precision
    438 mpp_random_size(a, prec) - set a to random value at given precision
    439 
    440 Note:  The mpp_random() and mpp_random_size() functions use the C
    441 ----   library's rand() function to generate random values.  It is
    442        up to the caller to seed this generator before it is called.
    443        These functions are not suitable for generating quantities
    444        requiring cryptographic-quality randomness; they are intended
    445        primarily for use in primality testing.
    446 
    447        Note too that the MPI library does not call srand(), so your
    448        application should do this, if you ever want the sequence
    449        to change.
    450 
    451 mpp_divis_vector(a, v, s, w)  - is a divisible by any of the s digits
    452                                 in v?  If so, let w be the index of
    453                                 that digit
    454 
    455 mpp_divis_primes(a, np)       - is a divisible by any of the first np
    456                                 primes?  If so, set np to the prime
    457                                 which divided a.
    458 
    459 mpp_fermat(a, d)              - test if w^a = w (mod a).  If so,
    460                                 returns MP_YES, otherwise MP_NO.
    461 
    462 mpp_pprime(a, nt)             - perform nt iterations of the Rabin-
    463                                 Miller probabilistic primality test
    464                                 on a.  Returns MP_YES if all tests
    465                                 passed, or MP_NO if any test fails.
    466 
    467 The mpp_fermat() function works based on Fermat's little theorem, a
    468 consequence of which is that if p is a prime, and (w, p) = 1, then:
    469 
    470         w^p = w (mod p)
    471 
    472 Put another way, if w^p != w (mod p), then p is not prime.  The test
    473 is expensive to compute, but it helps to quickly eliminate an enormous
    474 class of composite numbers prior to Rabin-Miller testing.
    475 
    476 Building the Library
    477 --------------------
    478 
    479 The MPI library is designed to be as self-contained as possible.  You
    480 should be able to compile it with your favourite ANSI C compiler, and
    481 link it into your program directly.  If you are on a Unix system using
    482 the GNU C compiler (gcc), the following should work:
    483 
    484 % gcc -ansi -pedantic -Wall -O2 -c mpi.c
    485 
    486 The file 'mpi-config.h' defines several configurable parameters for
    487 the library, which you can adjust to suit your application.  At the
    488 time of this writing, the available options are:
    489 
    490 MP_IOFUNC       - Define true to include the mp_print() function,
    491                   which is moderately useful for debugging.  This
    492                   implicitly includes <stdio.h>.
    493 
    494 MP_MODARITH     - Define true to include the modular arithmetic
    495                   functions.  If you don't need modular arithmetic
    496                   in your application, you can set this to zero to
    497                   leave out all the modular routines.
    498 
    499 MP_LOGTAB       - If true, the file "logtab.h" is included, which
    500                   is basically a static table of base 2 logarithms.
    501                   These are used to compute how big the buffers for
    502                   radix conversion need to be.  If you set this false,
    503                   the library includes <math.h> and uses log().  This
    504                   typically forces you to link against math libraries.
    505 
    506 
    507 MP_ARGCHK       - Set to 0, 1, or 2.  This defines how the argument
    508                   checking macro, ARGCHK(), gets expanded.  If this
    509                   is set to zero, ARGCHK() expands to nothing; no
    510                   argument checks are performed.  If this is 1, the
    511                   ARGCHK() macro expands to code that returns MP_BADARG
    512                   or similar at runtime.  If it is 2, ARGCHK() expands
    513                   to an assert() call that aborts the program on a
    514                   bad input.
    515 
    516 MP_DEBUG        - Turns on debugging output.  This is probably not at
    517                   all useful unless you are debugging the library.  It
    518                   tends to spit out a LOT of output.
    519 
    520 MP_DEFPREC      - The default precision of a newly-created mp_int, in
    521                   digits.  The precision can be changed at runtime by
    522                   the mp_set_prec() function, but this is its initial
    523                   value.
    524 
    525 MP_SQUARE       - If this is set to a nonzero value, the mp_sqr()
    526                   function will use an alternate algorithm that takes
    527                   advantage of the redundant inner product computation
    528                   when both multiplicands are identical.  Unfortunately,
    529                   with some compilers this is actually SLOWER than just
    530                   calling mp_mul() with the same argument twice.  So
    531                   if you set MP_SQUARE to zero, mp_sqr() will be expan-
    532                   ded into a call to mp_mul().  This applies to all
    533                   the uses of mp_sqr(), including mp_sqrmod() and the
    534                   internal calls to s_mp_sqr() inside mpi.c
    535 
    536                   The program 'mulsqr' (mulsqr.c) can be used to test
    537                   which works best for your configuration.  Set up the
    538                   CC and CFLAGS variables in the Makefile, then type:
    539 
    540                         make mulsqr
    541 
    542                   Invoke it with arguments similar to the following:
    543 
    544                         mulsqr 25000 1024
    545 
    546                   That is, 25000 products computed on 1024-bit values.
    547                   The output will compare the two timings, and recommend
    548                   a setting for MP_SQUARE.  It is off by default.
    549 
    550 If you would like to use the mp_print() function (see above), be sure
    551 to define MP_IOFUNC in mpi-config.h.  Many of the test drivers in the
    552 'tests' subdirectory expect this to be defined (although the test
    553 driver 'mpi-test' doesn't need it)
    554 
    555 The Makefile which comes with the library should take care of building
    556 the library for you, if you have set the CC and CFLAGS variables at
    557 the top of the file appropriately.  By default, they are set up to
    558 use the GNU C compiler:
    559 
    560 CC=gcc
    561 CFLAGS=-ansi -pedantic -Wall -O2
    562 
    563 If all goes well, the library should compile without warnings using
    564 this combination.  You should, of course, make whatever adjustments
    565 you find necessary.
    566 
    567 The MPI library distribution comes with several additional programs
    568 which are intended to demonstrate the use of the library, and provide
    569 a framework for testing it.  There are a handful of test driver
    570 programs, in the files named 'mptest-X.c', where X is a digit.  Also,
    571 there are some simple command-line utilities (in the 'utils'
    572 directory) for manipulating large numbers.  These include:
    573 
    574 basecvt.c       A radix-conversion program, supporting bases from
    575                 2 to 64 inclusive.
    576 
    577 bbsrand.c       A BBS (quadratic residue) pseudo-random number
    578                 generator.  The file 'bbsrand.c' is just the driver
    579                 for the program; the real code lives in the files
    580                 'bbs_rand.h' and 'bbs_rand.c'
    581 
    582 dec2hex.c       Converts decimal to hexadecimal
    583 
    584 gcd.c           Computes the greatest common divisor of two values.
    585                 If invoked as 'xgcd', also computes constants x and
    586                 y such that (a, b) = ax + by, in accordance with
    587                 Bezout's identity.
    588 
    589 hex2dec.c       Converts hexadecimal to decimal
    590 
    591 invmod.c        Computes modular inverses
    592 
    593 isprime.c       Performs the Rabin-Miller probabilistic primality
    594                 test on a number.  Values which fail this test are
    595                 definitely composite, and those which pass are very
    596                 likely to be prime (although there are no guarantees)
    597 
    598 lap.c           Computes the order (least annihilating power) of
    599                 a value v modulo m.  Very dumb algorithm.
    600 
    601 primegen.c      Generates large (probable) primes.
    602 
    603 prng.c          A pseudo-random number generator based on the
    604                 BBS generator code in 'bbs_rand.c'
    605 
    606 sieve.c         Implements the Sieve of Eratosthenes, using a big
    607                 bitmap, to generate a list of prime numbers.
    608 
    609 fact.c          Computes the factorial of an arbitrary precision
    610                 integer (iterative).
    611 
    612 exptmod.c       Computes arbitrary precision modular exponentiation
    613                 from the command line (exptmod a b m -> a^b (mod m))
    614 
    615 Most of these can be built from the Makefile that comes with the
    616 library.  Try 'make tools', if your environment supports it.
    617 
    618 
    619 Acknowledgements:
    620 ----------------
    621 
    622 The algorithms used in this library were drawn primarily from Volume
    623 2 of Donald Knuth's magnum opus, _The Art of Computer Programming_,
    624 "Semi-Numerical Methods".  Barrett's algorithm for modular reduction
    625 came from Menezes, Oorschot, and Vanstone's _Handbook of Applied
    626 Cryptography_, Chapter 14.
    627 
    628 Thanks are due to Tom St. Denis, for finding an obnoxious sign-related
    629 bug in mp_read_raw() that made things break on platforms which use
    630 signed chars.
    631 
    632 About the Author
    633 ----------------
    634 
    635 This software was written by Michael J. Fromberger.  You can contact
    636 the author as follows:
    637 
    638 E-mail:   <sting@linguist.dartmouth.edu>
    639 
    640 Postal:   8000 Cummings Hall, Thayer School of Engineering
    641           Dartmouth College, Hanover, New Hampshire, USA
    642 
    643 PGP key:  http://linguist.dartmouth.edu/~sting/keys/mjf.html
    644           9736 188B 5AFA 23D6 D6AA  BE0D 5856 4525 289D 9907
    645 
    646 Last updated:  16-Jan-2000