Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
mpi-test.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
#include <time.h>
#include "mpi.h"
#include "mpprime.h"
#include "test-info.c"

Go to the source code of this file.

Defines

#define ZS_DIGIT_FMT   "%X"
#define LOW_RADIX   5
#define HIGH_RADIX   64
#define IFOK(x)

Functions

int find_name (char *name)
void reason (char *fmt,...)
int main (int argc, char *argv[])
int test_list (void)
int test_copy (void)
int test_exch (void)
int test_zero (void)
int test_set (void)
int test_abs (void)
int test_neg (void)
int test_add_d (void)
int test_add (void)
int test_sub_d (void)
int test_sub (void)
int test_mul_d (void)
int test_mul (void)
int test_sqr (void)
int test_div_d (void)
int test_div_2 (void)
int test_div_2d (void)
int test_div (void)
int test_expt_d (void)
int test_expt (void)
int test_2expt (void)
int test_sqrt (void)
int test_mod_d (void)
int test_mod (void)
int test_addmod (void)
int test_submod (void)
int test_mulmod (void)
int test_sqrmod (void)
int test_exptmod (void)
int test_exptmod_d (void)
int test_invmod (void)
int test_cmp_d (void)
int test_cmp_z (void)
int test_cmp (void)
int test_cmp_mag (void)
int test_parity (void)
int test_gcd (void)
int test_lcm (void)
int test_convert (void)
int test_raw (void)
int test_pprime (void)
int test_fermat (void)

Variables

const char * mp1 = "639A868CDA0C569861B"
const char * mp2 = "AAFC0A3FE45E5E09DBE2C29"
const char * mp3 = "B55AA8DF8A7E83241F38AC7A9E479CAEF2E4D7C5"
const char * mp4 = "-63DBC2265B88268DC801C10EA68476B7BDE0090F"
const char * mp5 = "F595CB42"
const char * mp5a = "-4B597E"
const char * mp6 = "0"
const char * mp7 = "EBFA7121CD838CE6439CC59DDB4CBEF3"
const char * mp8 = "5"
const char * mp9 = "F74A2876A1432698923B0767DA19DCF3D71795EE"
const char * mp10 = "9184E72A000"
const char * mp11 = "54D79A3557E8"
const char * mp12 = "10000000000000000"
const char * mp13 = "D5A5C79F708BDE26E0CCF2DB66CD6D6089E29A877C45F2B050D226E6DA88"
const char * mp14 = "C1B1384BE4B2EB46"
const char * mp15 = "822AD9DDBFE4BD04"
const char * mp16 = "4A724340668DB150339A70"
const char * mp17 = "8ADB90F58"
const char * mp18 = "C64C230AB20E5"
const char * mp19 = "F1C9DACDA287F2E3C88DCE2393B8F53DAAAC1196DC36510962B6B59454CFE64B"
const char * mp20 = "D445662C8B6FE394107B867797750C326E0F4A967E135FC430F6CD7207913AC7"
const char * mp21 = "2"
const mp_digit md1 = 0
const mp_digit md2 = 0x1
const mp_digit md3 = 0x80
const mp_digit md4 = 0x9C97
const mp_digit md5 = 0xF5BF
const mp_digit md6 = 0x14A0
const mp_digit md7 = 0x03E8
const mp_digit md8 = 0x0101
const mp_digit md9 = 0xA
const char * p_mp12 = "4286AD72E095C9FE009938750743174ADDD7FD1E53"
const char * p_mp34 = "A1BFD6934C441EE369B60CA29BADC26845E918B"
const char * p_mp57 = "E260C265A0A27C17AD5F4E59D6E0360217A2EBA6"
const char * p_mp22 = "7233B5C1097FFC77CCF55928FDC3A5D31B712FDE7A1E91"
const char * p_mp1d4 = "3CECEA2331F4220BEF68DED"
const char * p_mp8d6 = "6720"
const char * p_mp1113 = "4340"
const char * p_mp1415 = "6ED65B18"
const char * p_mp2121 = "4"
const char * mp_mp345 = "B9B6D3A3"
const char * mp_mp335 = "16609C2D"
const char * s_mp13 = "B55AA8DF8A7E83241F38B2B446B06A4FB84E5DE0"
const char * s_mp34 = "517EE6B92EF65C965736EB6BF7C325F73504CEB6"
const char * s_mp46 = "-63DBC2265B88268DC801C10EA68476B7BDE0090F"
const char * s_mp5d4 = "F59667D9"
const char * s_mp2d5 = "AAFC0A3FE45E5E09DBF21E8"
const char * s_mp1415 = "A84A"
const char * ms_mp345 = "1E71E292"
const char * d_mp12 = "-AAFBA6A55DD183FD854A60E"
const char * d_mp34 = "119366B05E606A9B1E73A6D8944CC1366B0C4E0D4"
const char * d_mp5d4 = "F5952EAB"
const char * d_mp6d2 = "-1"
const char * md_mp345 = "26596B86"
const char * q_mp42 = "-95825A1FFA1A155D5"
const char * r_mp42 = "-6312E99D7700A3DCB32ADF2"
const char * q_mp45a = "15344CDA3D841F661D2B61B6EDF7828CE36"
const char * r_mp45a = "-47C47B"
const char * q_mp7c2 = "75FD3890E6C1C67321CE62CEEDA65F79"
const char * q_mp3d6 = "8CAFD53C272BD6FE8B0847BDC3B539EFAB5C3"
const char * r_mp3d6 = "1E5"
const char * r_mp5d5 = "1257"
const char * r_mp47 = "B3A9018D970281A90FB729A181D95CB8"
const char * q_mp1404 = "BD9E23E4D367A2C35762F209073DFF48F3"
const char * r_mp1404 = "12FF98621ABF63144BFFC3207AC8FC10D8D1A09"
const char * q_mp13c = "BDAB6163963CD5A5C79F708BDE26E0CCF2DB66CD6D6089E29A877C45"
const char * r_mp13c = "F2B050D226E6DA88"
const char * q_mp9c16 = "F74A2876A1432698923B0767DA19DCF3D71795E"
const char * r_mp9c16 = "E"
const char * e_mp5d9 = "13A5215AAC4E9AB1E96BD34E531209E03310400"
const char * e_mp78 = "D113175764F5D0B3C89B262D4702F4D9640A3"
const char * me_mp817 = "E504493ACB02F7F802B327AB13BF25"
const char * me_mp5d47 = "1D45ED0D78F2778157992C951DD2734C"
const char * me_mp1512 = "FB5B2A28D902B9D9"
const char * me_mp161718 = "423C6AC6DBD74"
const char * me_mp5114 = "FE8C"
const char * e_mpc2d3 = "100000000000000000000000000000000"
const char * t_mp9 = "FB9B6E32FF0452A34746"
const char * i_mp27 = "B6AD8DCCDAF92B6FE57D062FFEE3A99"
const char * i_mp2019 = "BDF3D88DC373A63EED92903115B03FC8501910AF68297B4C41870AED3EA9F839"
const char * t_mp15 = "BEE244F7DD3AC268CF512A0E52E4F5BE5B94"
const char * g_mp71 = "1"
const char * g_mp25 = "7"
const char * l_mp1011 = "C589E3D7D64A6942A000"
const char * v_mp9 []
const unsigned char b_mp4 []
char g_intbuf [4096]
char a_intbuf [4096]
int g_verbose = 1
int res

Define Documentation

#define HIGH_RADIX   64

Definition at line 327 of file mpi-test.c.

#define IFOK (   x)
Value:
{ if (MP_OKAY > (res = (x))) { \
  reason("test %s failed: error %d\n", #x, res); return 1; }}

Definition at line 415 of file mpi-test.c.

#define LOW_RADIX   5

Definition at line 326 of file mpi-test.c.

#define ZS_DIGIT_FMT   "%X"

Definition at line 65 of file mpi-test.c.


Function Documentation

int find_name ( char *  name)
int main ( int  argc,
char *  argv[] 
)

Definition at line 418 of file mpi-test.c.

{
  int which, res;

  srand((unsigned int)time(NULL));

  if (argc < 2) {
    fprintf(stderr, "Usage: %s <test-suite> | list\n"
           "Type '%s help' for assistance\n", argv[0], argv[0]);
    return 2;
  } else if(argc > 2) {
    if(strcmp(argv[2], "quiet") == 0)
      g_verbose = 0;
  }

  if(strcmp(argv[1], "help") == 0) {
    fprintf(stderr, "Help for mpi-test\n\n"
           "This program is a test driver for the MPI library, which\n"
           "tests all the various functions in the library to make sure\n"
           "they are working correctly.  The syntax is:\n"
           "    %s <suite-name>\n"
           "...where <suite-name> is the name of the test you wish to\n"
           "run.  To get a list of the tests, use '%s list'.\n\n"
           "The program exits with a status of zero if the test passes,\n"
           "or non-zero if it fails.  Ordinarily, failure is accompanied\n"
           "by a diagnostic message to standard error.  To suppress this\n"
           "add the keyword 'quiet' after the suite-name on the command\n"
           "line.\n\n", argv[0], argv[0]);
    return 0;
  }

  if ((which = find_name(argv[1])) < 0) {
    fprintf(stderr, "%s: test suite '%s' is not known\n", argv[0], argv[1]);
    return 2;
  }

  if((res = (g_tests[which])()) < 0) {
    fprintf(stderr, "%s: test suite not implemented yet\n", argv[0]);
    return 2;
  } else {
    return res; 
  }

}

Here is the call graph for this function:

void reason ( char *  fmt,
  ... 
)

Definition at line 1117 of file mpi-test.c.

{
  mp_int   a;

  mp_init(&a);
  mp_2expt(&a, md3);
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a);

  if(strcmp(g_intbuf, e_mpc2d3) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, e_mpc2d3);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

int test_abs ( void  )

Definition at line 610 of file mpi-test.c.

{
  mp_int  a;

  mp_init(&a); mp_read_radix(&a, mp4, 16);
  mp_abs(&a, &a);
  
  if(SIGN(&a) != ZPOS) {
    reason("error: sign of result is negative\n");
    mp_clear(&a);
    return 1;
  }

  mp_clear(&a);
  return 0;
}

Here is the call graph for this function:

int test_add ( void  )

Definition at line 682 of file mpi-test.c.

{
  mp_int  a, b;
  int     res = 0;

  mp_init(&a); mp_init(&b);

  mp_read_radix(&a, mp1, 16); mp_read_radix(&b, mp3, 16);
  mp_add(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, s_mp13) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, s_mp13);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp4, 16);
  mp_add(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, s_mp34) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, s_mp34);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp4, 16); mp_read_radix(&b, mp6, 16);
  mp_add(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, s_mp46) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, s_mp46);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp14, 16); mp_read_radix(&b, mp15, 16);
  mp_add(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, s_mp1415) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, s_mp1415);
    res = 1;
  }

 CLEANUP:
  mp_clear(&a); mp_clear(&b);
  return res;
}

Here is the call graph for this function:

Definition at line 650 of file mpi-test.c.

{
  mp_int  a;

  mp_init(&a);
  
  mp_read_radix(&a, mp5, 16);
  mp_add_d(&a, md4, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, s_mp5d4) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, s_mp5d4);
    mp_clear(&a);
    return 1;
  }

  mp_read_radix(&a, mp2, 16);
  mp_add_d(&a, md5, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, s_mp2d5) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, s_mp2d5);
    mp_clear(&a);
    return 1;
  }

  mp_clear(&a);
  return 0;
}

Here is the call graph for this function:

Definition at line 1206 of file mpi-test.c.

{
  mp_int a, b, m;

  mp_init(&a); mp_init(&b); mp_init(&m);
  mp_read_radix(&a, mp3, 16); mp_read_radix(&b, mp4, 16);
  mp_read_radix(&m, mp5, 16);

  IFOK( mp_addmod(&a, &b, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&b); mp_clear(&m);

  if(strcmp(g_intbuf, ms_mp345) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, ms_mp345);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

int test_cmp ( void  )

Definition at line 1695 of file mpi-test.c.

{
  mp_int  a, b;

  mp_init(&a); mp_init(&b);
  mp_read_radix(&a, mp3, 16); mp_read_radix(&b, mp4, 16);

  if(mp_cmp(&a, &b) <= 0) {
    reason("error: %s <= %s\n", mp3, mp4);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_read_radix(&b, mp3, 16);
  if(mp_cmp(&a, &b) != 0) {
    reason("error: %s != %s\n", mp3, mp3);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_read_radix(&a, mp5, 16);
  if(mp_cmp(&a, &b) >= 0) {
    reason("error: %s >= %s\n", mp5, mp3);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_read_radix(&a, mp5a, 16);
  if(mp_cmp_int(&a, 1000000) >= 0 ||
     (mp_cmp_int(&a, -5000000) <= 0) ||
     (mp_cmp_int(&a, -4938110) != 0)) {
    reason("error: long integer comparison failed (%s)", mp5a);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_clear(&a); mp_clear(&b);
  return 0;
}

Here is the call graph for this function:

Definition at line 1626 of file mpi-test.c.

{
  mp_int  a;

  mp_init(&a); mp_read_radix(&a, mp8, 16);

  if(mp_cmp_d(&a, md8) >= 0) {
    reason("error: %s >= " DIGIT_FMT "\n", mp8, md8);
    mp_clear(&a);
    return 1;
  }

  mp_read_radix(&a, mp5, 16);

  if(mp_cmp_d(&a, md8) <= 0) {
    reason("error: %s <= " DIGIT_FMT "\n", mp5, md8);
    mp_clear(&a);
    return 1;
  }

  mp_read_radix(&a, mp6, 16);

  if(mp_cmp_d(&a, md1) != 0) {
    reason("error: %s != " DIGIT_FMT "\n", mp6, md1);
    mp_clear(&a);
    return 1;
  }

  mp_clear(&a);
  return 0;

}

Here is the call graph for this function:

Definition at line 1737 of file mpi-test.c.

{
  mp_int  a, b;

  mp_init(&a); mp_init(&b);
  mp_read_radix(&a, mp5, 16); mp_read_radix(&b, mp4, 16);

  if(mp_cmp_mag(&a, &b) >= 0) {
    reason("error: %s >= %s\n", mp5, mp4);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_read_radix(&b, mp5, 16);
  if(mp_cmp_mag(&a, &b) != 0) {
    reason("error: %s != %s\n", mp5, mp5);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_read_radix(&a, mp1, 16);
  if(mp_cmp_mag(&b, &a) >= 0) {
    reason("error: %s >= %s\n", mp5, mp1);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_clear(&a); mp_clear(&b);
  return 0;

}

Here is the call graph for this function:

Definition at line 1661 of file mpi-test.c.

{
  mp_int  a;

  mp_init(&a); mp_read_radix(&a, mp6, 16);

  if(mp_cmp_z(&a) != 0) {
    reason("error: someone thinks a zero value is non-zero\n");
    mp_clear(&a);
    return 1;
  }

  mp_read_radix(&a, mp1, 16);
  
  if(mp_cmp_z(&a) <= 0) {
    reason("error: someone thinks a positive value is non-positive\n");
    mp_clear(&a);
    return 1;
  }

  mp_read_radix(&a, mp4, 16);

  if(mp_cmp_z(&a) >= 0) {
    reason("error: someone thinks a negative value is non-negative\n");
    mp_clear(&a);
    return 1;
  }

  mp_clear(&a);
  return 0;
}

Here is the call graph for this function:

Definition at line 1844 of file mpi-test.c.

{
  int    ix;
  mp_int a;

  mp_init(&a); mp_read_radix(&a, mp9, 16);

  for(ix = LOW_RADIX; ix <= HIGH_RADIX; ix++) {
    mp_toradix(&a, g_intbuf, ix);

    if(strcmp(g_intbuf, v_mp9[ix - LOW_RADIX]) != 0) {
      reason("error: radix %d, computed %s, expected %s\n",
            ix, g_intbuf, v_mp9[ix - LOW_RADIX]);
      mp_clear(&a);
      return 1;
    }
  }

  mp_clear(&a);
  return 0;
}

Here is the call graph for this function:

Definition at line 496 of file mpi-test.c.

{
  mp_int  a, b;
  int     ix;

  mp_init(&a); mp_init(&b);

  mp_read_radix(&a, mp3, 16);
  mp_copy(&a, &b);

  if(SIGN(&a) != SIGN(&b) || USED(&a) != USED(&b)) {
    if(SIGN(&a) != SIGN(&b)) {
      reason("error: sign of original is %d, sign of copy is %d\n", 
            SIGN(&a), SIGN(&b));
    } else {
      reason("error: original precision is %d, copy precision is %d\n",
            USED(&a), USED(&b));
    }
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  for(ix = 0; ix < USED(&b); ix++) {
    if(DIGIT(&a, ix) != DIGIT(&b, ix)) {
      reason("error: digit %d " DIGIT_FMT " != " DIGIT_FMT "\n",
            ix, DIGIT(&a, ix), DIGIT(&b, ix));
      mp_clear(&a); mp_clear(&b);
      return 1;
    }
  }
     
  mp_clear(&a); mp_clear(&b);
  return 0;
}

Here is the call graph for this function:

int test_div ( void  )

Definition at line 1015 of file mpi-test.c.

{
  mp_int  a, b, r;
  int     err = 0;

  mp_init(&a); mp_init(&b); mp_init(&r);

  mp_read_radix(&a, mp4, 16); mp_read_radix(&b, mp2, 16);
  IFOK( mp_div(&a, &b, &a, &r) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, q_mp42) != 0) {
    reason("error: test 1 computed quot %s, expected %s\n", g_intbuf, q_mp42);
    ++err;
  }

  mp_toradix(&r, g_intbuf, 16);

  if(strcmp(g_intbuf, r_mp42) != 0) {
    reason("error: test 1 computed rem %s, expected %s\n", g_intbuf, r_mp42);
    ++err;
  }

  mp_read_radix(&a, mp4, 16); mp_read_radix(&b, mp5a, 16);
  IFOK( mp_div(&a, &b, &a, &r) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, q_mp45a) != 0) {
    reason("error: test 2 computed quot %s, expected %s\n", g_intbuf, q_mp45a);
    ++err;
  }

  mp_toradix(&r, g_intbuf, 16);

  if(strcmp(g_intbuf, r_mp45a) != 0) {
    reason("error: test 2 computed rem %s, expected %s\n", g_intbuf, r_mp45a);
    ++err;
  }

  mp_read_radix(&a, mp14, 16); mp_read_radix(&b, mp4, 16);
  IFOK( mp_div(&a, &b, &a, &r) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, q_mp1404) != 0) {
    reason("error: test 3 computed quot %s, expected %s\n", g_intbuf, q_mp1404);
    ++err;
  }

  mp_toradix(&r, g_intbuf, 16);
  
  if(strcmp(g_intbuf, r_mp1404) != 0) {
    reason("error: test 3 computed rem %s, expected %s\n", g_intbuf, r_mp1404);
    ++err;
  }

  mp_clear(&a); mp_clear(&b); mp_clear(&r);

  return err;
}

Here is the call graph for this function:

Definition at line 962 of file mpi-test.c.

{
  mp_int  a;

  mp_init(&a); mp_read_radix(&a, mp7, 16);
  IFOK( mp_div_2(&a, &a) );
  mp_toradix(&a, g_intbuf, 16);

  mp_clear(&a);
  if(strcmp(g_intbuf, q_mp7c2) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, q_mp7c2);
    return 1;
  }
    
  return 0;
}

Here is the call graph for this function:

Definition at line 981 of file mpi-test.c.

{
  mp_int  a, q, r;

  mp_init(&q); mp_init(&r);
  mp_init(&a); mp_read_radix(&a, mp13, 16);

  IFOK( mp_div_2d(&a, 64, &q, &r) );
  mp_clear(&a);

  mp_toradix(&q, g_intbuf, 16);

  if(strcmp(g_intbuf, q_mp13c) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, q_mp13c);
    mp_clear(&q); mp_clear(&r);
    return 1;
  }

  mp_clear(&q);

  mp_toradix(&r, g_intbuf, 16);
  if(strcmp(g_intbuf, r_mp13c) != 0) {
    reason("error, computed %s, expected %s\n", g_intbuf, r_mp13c);
    mp_clear(&r);
    return 1;
  }

  mp_clear(&r);
  
  return 0;
}

Here is the call graph for this function:

Definition at line 916 of file mpi-test.c.

{
  mp_int    a, q;
  mp_digit  r;
  int       err = 0;

  mp_init(&a); mp_init(&q);
  mp_read_radix(&a, mp3, 16);

  IFOK( mp_div_d(&a, md6, &q, &r) );
  mp_toradix(&q, g_intbuf, 16);

  if(strcmp(g_intbuf, q_mp3d6) != 0) {
    reason("error: computed q = %s, expected %s\n", g_intbuf, q_mp3d6);
    ++err;
  }

  sprintf(g_intbuf, ZS_DIGIT_FMT, r);

  if(strcmp(g_intbuf, r_mp3d6) != 0) {
    reason("error: computed r = %s, expected %s\n", g_intbuf, r_mp3d6);
    ++err;
  }

  mp_read_radix(&a, mp9, 16);
  IFOK( mp_div_d(&a, 16, &q, &r) );
  mp_toradix(&q, g_intbuf, 16);

  if(strcmp(g_intbuf, q_mp9c16) != 0) {
    reason("error: computed q = %s, expected %s\n", g_intbuf, q_mp9c16);
    ++err;
  }

  sprintf(g_intbuf, ZS_DIGIT_FMT, r);

  if(strcmp(g_intbuf, r_mp9c16) != 0) {
    reason("error: computed r = %s, expected %s\n", g_intbuf, r_mp9c16);
    ++err;
  }

  mp_clear(&a); mp_clear(&q);
  return err;
}

Here is the call graph for this function:

Definition at line 533 of file mpi-test.c.

{
  mp_int  a, b;

  mp_init(&a); mp_init(&b);
  mp_read_radix(&a, mp7, 16); mp_read_radix(&b, mp1, 16);

  mp_exch(&a, &b);
  mp_toradix(&a, g_intbuf, 16);

  mp_clear(&a);
  if(strcmp(g_intbuf, mp1) != 0) {
    mp_clear(&b);
    reason("error: exchange failed\n");
    return 1;
  }

  mp_toradix(&b, g_intbuf, 16);

  mp_clear(&b);
  if(strcmp(g_intbuf, mp7) != 0) {
    reason("error: exchange failed\n");
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1096 of file mpi-test.c.

{
  mp_int   a, b;

  mp_init(&a); mp_init(&b);
  mp_read_radix(&a, mp7, 16); mp_read_radix(&b, mp8, 16);

  mp_expt(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&b);

  if(strcmp(g_intbuf, e_mp78) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, e_mp78);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1077 of file mpi-test.c.

{
  mp_int   a;

  mp_init(&a); mp_read_radix(&a, mp5, 16);
  mp_expt_d(&a, md9, &a);
  mp_toradix(&a, g_intbuf, 16);

  mp_clear(&a);
  if(strcmp(g_intbuf, e_mp5d9) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, e_mp5d9);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1293 of file mpi-test.c.

{
  mp_int  a, b, m;
  int     res = 0;

  mp_init(&a); mp_init(&b); mp_init(&m);
  mp_read_radix(&a, mp8, 16); mp_read_radix(&b, mp1, 16);
  mp_read_radix(&m, mp7, 16);

  IFOK( mp_exptmod(&a, &b, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, me_mp817) != 0) {
    reason("case 1: error: computed %s, expected %s\n", g_intbuf, me_mp817);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp1, 16); mp_read_radix(&b, mp5, 16);
  mp_read_radix(&m, mp12, 16);

  IFOK( mp_exptmod(&a, &b, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, me_mp1512) != 0) {
    reason("case 2: error: computed %s, expected %s\n", g_intbuf, me_mp1512);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp5, 16); mp_read_radix(&b, mp1, 16);
  mp_read_radix(&m, mp14, 16);

  IFOK( mp_exptmod(&a, &b, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, me_mp5114) != 0) {
    reason("case 3: error: computed %s, expected %s\n", g_intbuf, me_mp5114);
    res = 1;
  }

  mp_read_radix(&a, mp16, 16); mp_read_radix(&b, mp17, 16);
  mp_read_radix(&m, mp18, 16);

  IFOK( mp_exptmod(&a, &b, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, me_mp161718) != 0) {
    reason("case 4: error: computed %s, expected %s\n", g_intbuf, me_mp161718);
    res = 1;
  }

 CLEANUP:
  mp_clear(&a); mp_clear(&b); mp_clear(&m);
  return res;
}

Here is the call graph for this function:

Definition at line 1350 of file mpi-test.c.

{
  mp_int  a, m;

  mp_init(&a); mp_init(&m);
  mp_read_radix(&a, mp5, 16); mp_read_radix(&m, mp7, 16);

  IFOK( mp_exptmod_d(&a, md4, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&m);

  if(strcmp(g_intbuf, me_mp5d47) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, me_mp5d47);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1943 of file mpi-test.c.

{
  mp_int p;
  mp_err res;
  int    err = 0;

  mp_init(&p);
  mp_read_radix(&p, mp7, 16);
  
  if((res = mpp_fermat(&p, 2)) != MP_YES) {
    reason("error: %s failed Fermat test on 2: %s\n", mp7, 
          mp_strerror(res));
    ++err;
  }

  if((res = mpp_fermat(&p, 3)) != MP_YES) {
    reason("error: %s failed Fermat test on 3: %s\n", mp7, 
          mp_strerror(res));
    ++err;
  }

  mp_clear(&p);

  return err;

}

Here is the call graph for this function:

int test_gcd ( void  )

Definition at line 1797 of file mpi-test.c.

{
  mp_int  a, b;
  int     out = 0;

  mp_init(&a); mp_init(&b);
  mp_read_radix(&a, mp7, 16); mp_read_radix(&b, mp1, 16);

  mp_gcd(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, g_mp71) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, g_mp71);
    out = 1;
  }

  mp_clear(&a); mp_clear(&b);
  return out;

}

Here is the call graph for this function:

Definition at line 1371 of file mpi-test.c.

{
  mp_int  a, m, c;
  mp_int  p1, p2, p3, p4, p5;
  mp_int  t1, t2, t3, t4;
  mp_err  res;

  /* 5 128-bit primes. */
  static const char ivp1[] = { "AAD8A5A2A2BEF644BAEE7DB0CA643719" };
  static const char ivp2[] = { "CB371AD2B79A90BCC88D0430663E40B9" };
  static const char ivp3[] = { "C6C818D4DF2618406CA09280C0400099" };
  static const char ivp4[] = { "CE949C04512E68918006B1F0D7E93F27" };
  static const char ivp5[] = { "F8EE999B6416645040687440E0B89F51" };

  mp_init(&a); mp_init(&m);
  mp_read_radix(&a, mp2, 16); mp_read_radix(&m, mp7, 16);

  IFOK( mp_invmod(&a, &m, &a) );

  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&m);

  if(strcmp(g_intbuf, i_mp27) != 0) {
    reason("error: invmod test 1 computed %s, expected %s\n", g_intbuf, i_mp27);
    return 1;
  }

  mp_init(&a); mp_init(&m);
  mp_read_radix(&a, mp20, 16); mp_read_radix(&m, mp19, 16);

  IFOK( mp_invmod(&a, &m, &a) );

  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&m);

  if(strcmp(g_intbuf, i_mp2019) != 0) {
    reason("error: invmod test 2 computed %s, expected %s\n", g_intbuf, i_mp2019);
    return 1;
  }

/* Need the following test cases:
  Odd modulus
    - a is odd,      relatively prime to m
    - a is odd,  not relatively prime to m
    - a is even,     relatively prime to m
    - a is even, not relatively prime to m
  Even modulus
    - a is even  (should fail)
    - a is odd,  not relatively prime to m
    - a is odd,      relatively prime to m,
      m is not a power of 2
       - m has factor 2**k, k < 32
       - m has factor 2**k, k > 32
      m is a power of 2, 2**k
       - k < 32
       - k > 32
*/

  mp_init(&a);  mp_init(&m);  mp_init(&c);  
  mp_init(&p1); mp_init(&p2); mp_init(&p3); mp_init(&p4); mp_init(&p5); 
  mp_init(&t1); mp_init(&t2); mp_init(&t3); mp_init(&t4); 

  mp_read_radix(&p1, ivp1, 16);
  mp_read_radix(&p2, ivp2, 16);
  mp_read_radix(&p3, ivp3, 16);
  mp_read_radix(&p4, ivp4, 16);
  mp_read_radix(&p5, ivp5, 16);

  IFOK( mp_2expt(&t2, 68) );       /* t2 = 2**68 */
  IFOK( mp_2expt(&t3, 128) );      /* t3 = 2**128 */
  IFOK( mp_2expt(&t4, 31) );       /* t4 = 2**31 */

/* test 3: Odd modulus - a is odd, relatively prime to m */

  IFOK( mp_mul(&p1, &p2, &a) );
  IFOK( mp_mul(&p3, &p4, &m) );
  IFOK( mp_invmod(&a, &m, &t1) );
  IFOK( mp_invmod_xgcd(&a, &m, &c) );

  if (mp_cmp(&t1, &c) != 0) {
    mp_toradix(&t1, g_intbuf, 16);
    mp_toradix(&c,  a_intbuf, 16);
    reason("error: invmod test 3 computed %s, expected %s\n", 
           g_intbuf, a_intbuf);
    return 1;
  }
  mp_clear(&a);  mp_clear(&t1); mp_clear(&c);  
  mp_init(&a);   mp_init(&t1);  mp_init(&c);   

/* test 4: Odd modulus - a is odd, NOT relatively prime to m */

  IFOK( mp_mul(&p1, &p3, &a) );
  /* reuse same m as before */

  res = mp_invmod_xgcd(&a, &m, &c);
  if (res != MP_UNDEF) 
    goto CLEANUP4;

  res = mp_invmod(&a, &m, &t1); /* we expect this to fail. */
  if (res != MP_UNDEF) {
CLEANUP4:
    reason("error: invmod test 4 succeeded, should have failed.\n");
    return 1;
  }
  mp_clear(&a);  mp_clear(&t1); mp_clear(&c);  
  mp_init(&a);   mp_init(&t1);  mp_init(&c);   

/* test 5: Odd modulus - a is even, relatively prime to m */

  IFOK( mp_mul(&p1, &t2, &a) );
  /* reuse m */
  IFOK( mp_invmod(&a, &m, &t1) );
  IFOK( mp_invmod_xgcd(&a, &m, &c) );

  if (mp_cmp(&t1, &c) != 0) {
    mp_toradix(&t1, g_intbuf, 16);
    mp_toradix(&c,  a_intbuf, 16);
    reason("error: invmod test 5 computed %s, expected %s\n", 
           g_intbuf, a_intbuf);
    return 1;
  }
  mp_clear(&a);  mp_clear(&t1); mp_clear(&c);  
  mp_init(&a);   mp_init(&t1);  mp_init(&c);   

/* test 6: Odd modulus - a is odd, NOT relatively prime to m */

  /* reuse t2 */
  IFOK( mp_mul(&t2, &p3, &a) );
  /* reuse same m as before */

  res = mp_invmod_xgcd(&a, &m, &c);
  if (res != MP_UNDEF) 
    goto CLEANUP6;

  res = mp_invmod(&a, &m, &t1); /* we expect this to fail. */
  if (res != MP_UNDEF) {
CLEANUP6:
    reason("error: invmod test 6 succeeded, should have failed.\n");
    return 1;
  }
  mp_clear(&a);  mp_clear(&m); mp_clear(&c);  mp_clear(&t1); 
  mp_init(&a);   mp_init(&m);  mp_init(&c);   mp_init(&t1); 

/* test 7: Even modulus, even a, should fail */

  IFOK( mp_mul(&p3, &t3, &m) ); /* even m */
  /* reuse t2 */
  IFOK( mp_mul(&p1, &t2, &a) ); /* even a */

  res = mp_invmod_xgcd(&a, &m, &c);
  if (res != MP_UNDEF) 
    goto CLEANUP7;

  res = mp_invmod(&a, &m, &t1); /* we expect this to fail. */
  if (res != MP_UNDEF) {
CLEANUP7:
    reason("error: invmod test 7 succeeded, should have failed.\n");
    return 1;
  }
  mp_clear(&a);  mp_clear(&c);  mp_clear(&t1); 
  mp_init(&a);   mp_init(&c);   mp_init(&t1); 

/* test 8: Even modulus    - a is odd,  not relatively prime to m */

  /* reuse m */
  IFOK( mp_mul(&p3, &p1, &a) ); /* even a */

  res = mp_invmod_xgcd(&a, &m, &c);
  if (res != MP_UNDEF) 
    goto CLEANUP8;

  res = mp_invmod(&a, &m, &t1); /* we expect this to fail. */
  if (res != MP_UNDEF) {
CLEANUP8:
    reason("error: invmod test 8 succeeded, should have failed.\n");
    return 1;
  }
  mp_clear(&a);  mp_clear(&m); mp_clear(&c);  mp_clear(&t1); 
  mp_init(&a);   mp_init(&m);  mp_init(&c);   mp_init(&t1); 

/* test 9: Even modulus    - m has factor 2**k, k < 32
 *                        - a is odd, relatively prime to m,
 */
  IFOK( mp_mul(&p3, &t4, &m) ); /* even m */
  IFOK( mp_mul(&p1, &p2, &a) );
  IFOK( mp_invmod(&a, &m, &t1) );
  IFOK( mp_invmod_xgcd(&a, &m, &c) );

  if (mp_cmp(&t1, &c) != 0) {
    mp_toradix(&t1, g_intbuf, 16);
    mp_toradix(&c,  a_intbuf, 16);
    reason("error: invmod test 9 computed %s, expected %s\n", 
           g_intbuf, a_intbuf);
    return 1;
  }
  mp_clear(&m);  mp_clear(&t1); mp_clear(&c);  
  mp_init(&m);   mp_init(&t1);  mp_init(&c);   

/* test 10: Even modulus    - m has factor 2**k, k > 32
 *                         - a is odd, relatively prime to m,
 */
  IFOK( mp_mul(&p3, &t3, &m) ); /* even m */
  /* reuse a */
  IFOK( mp_invmod(&a, &m, &t1) );
  IFOK( mp_invmod_xgcd(&a, &m, &c) );

  if (mp_cmp(&t1, &c) != 0) {
    mp_toradix(&t1, g_intbuf, 16);
    mp_toradix(&c,  a_intbuf, 16);
    reason("error: invmod test 10 computed %s, expected %s\n", 
           g_intbuf, a_intbuf);
    return 1;
  }
  mp_clear(&t1); mp_clear(&c);  
  mp_init(&t1);  mp_init(&c);   

/* test 11: Even modulus    - m is a power of 2, 2**k | k < 32
 *                          - a is odd, relatively prime to m,
 */
  IFOK( mp_invmod(&a, &t4, &t1) );
  IFOK( mp_invmod_xgcd(&a, &t4, &c) );

  if (mp_cmp(&t1, &c) != 0) {
    mp_toradix(&t1, g_intbuf, 16);
    mp_toradix(&c,  a_intbuf, 16);
    reason("error: invmod test 11 computed %s, expected %s\n", 
           g_intbuf, a_intbuf);
    return 1;
  }
  mp_clear(&t1); mp_clear(&c);  
  mp_init(&t1);  mp_init(&c);   

/* test 12: Even modulus    - m is a power of 2, 2**k | k > 32
 *                          - a is odd, relatively prime to m,
 */
  IFOK( mp_invmod(&a, &t3, &t1) );
  IFOK( mp_invmod_xgcd(&a, &t3, &c) );

  if (mp_cmp(&t1, &c) != 0) {
    mp_toradix(&t1, g_intbuf, 16);
    mp_toradix(&c,  a_intbuf, 16);
    reason("error: invmod test 12 computed %s, expected %s\n", 
           g_intbuf, a_intbuf);
    return 1;
  }

  mp_clear(&a);  mp_clear(&m);  mp_clear(&c);  
  mp_clear(&t1); mp_clear(&t2); mp_clear(&t3); mp_clear(&t4); 
  mp_clear(&p1); mp_clear(&p2); mp_clear(&p3); mp_clear(&p4); mp_clear(&p5); 

  return 0;
}

Here is the call graph for this function:

int test_lcm ( void  )

Definition at line 1820 of file mpi-test.c.

{
  mp_int  a, b;
  int     out = 0;

  mp_init(&a); mp_init(&b);
  mp_read_radix(&a, mp10, 16); mp_read_radix(&b, mp11, 16);

  mp_lcm(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, l_mp1011) != 0) {
    reason("error: computed %s, expected%s\n", g_intbuf, l_mp1011);
    out = 1;
  }

  mp_clear(&a); mp_clear(&b);

  return out;

}

Here is the call graph for this function:

Definition at line 481 of file mpi-test.c.

{
  int ix;
  
  fprintf(stderr, "There are currently %d test suites available\n",
         g_count);
  
  for(ix = 1; ix < g_count; ix++)
    fprintf(stdout, "%-20s %s\n", g_names[ix], g_descs[ix]);
  
  return 0;
}

Here is the call graph for this function:

int test_mod ( void  )

Definition at line 1186 of file mpi-test.c.

{
  mp_int  a, m;

  mp_init(&a); mp_init(&m);
  mp_read_radix(&a, mp4, 16); mp_read_radix(&m, mp7, 16);
  IFOK( mp_mod(&a, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&m);

  if(strcmp(g_intbuf, r_mp47) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, r_mp47);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1166 of file mpi-test.c.

{
  mp_int     a;
  mp_digit   r;

  mp_init(&a); mp_read_radix(&a, mp5, 16);
  IFOK( mp_mod_d(&a, md5, &r) );
  sprintf(g_intbuf, ZS_DIGIT_FMT, r);
  mp_clear(&a);

  if(strcmp(g_intbuf, r_mp5d5) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, r_mp5d5);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

int test_mul ( void  )

Definition at line 827 of file mpi-test.c.

{
  mp_int   a, b;
  int      res = 0;

  mp_init(&a); mp_init(&b);
  mp_read_radix(&a, mp1, 16); mp_read_radix(&b, mp2, 16);

  IFOK( mp_mul(&a, &b, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, p_mp12) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp12);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp3, 16); mp_read_radix(&b, mp4, 16);
  IFOK( mp_mul(&a, &b, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, p_mp34) !=0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp34);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp5, 16); mp_read_radix(&b, mp7, 16);
  IFOK( mp_mul(&a, &b, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, p_mp57) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp57);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp11, 16); mp_read_radix(&b, mp13, 16);
  IFOK( mp_mul(&a, &b, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, p_mp1113) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp1113);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp14, 16); mp_read_radix(&b, mp15, 16);
  IFOK( mp_mul(&a, &b, &a) );
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, p_mp1415) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp1415);
    res = 1;
  }
  mp_read_radix(&a, mp21, 10); mp_read_radix(&b, mp21, 10);

  IFOK( mp_mul(&a, &b, &a) );
  mp_toradix(&a, g_intbuf, 10);

  if(strcmp(g_intbuf, p_mp2121) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp2121);
    res = 1; goto CLEANUP;
  }

 CLEANUP:
  mp_clear(&a); mp_clear(&b);
  return res;

}

Here is the call graph for this function:

Definition at line 796 of file mpi-test.c.

{
  mp_int   a;

  mp_init(&a);
  mp_read_radix(&a, mp1, 16);

  IFOK( mp_mul_d(&a, md4, &a) );
  mp_toradix(&a, g_intbuf, 16);
  
  if(strcmp(g_intbuf, p_mp1d4) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp1d4);    
    mp_clear(&a);
    return 1;
  }

  mp_read_radix(&a, mp8, 16);
  IFOK( mp_mul_d(&a, md6, &a) );
  mp_toradix(&a, g_intbuf, 16);

  mp_clear(&a);
  if(strcmp(g_intbuf, p_mp8d6) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp8d6); 
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1250 of file mpi-test.c.

{
  mp_int a, b, m;

  mp_init(&a); mp_init(&b); mp_init(&m);
  mp_read_radix(&a, mp3, 16); mp_read_radix(&b, mp4, 16);
  mp_read_radix(&m, mp5, 16);

  IFOK( mp_mulmod(&a, &b, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&b); mp_clear(&m);

  if(strcmp(g_intbuf, mp_mp345) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, mp_mp345);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

int test_neg ( void  )

Definition at line 629 of file mpi-test.c.

{
  mp_int  a;
  mp_sign s;

  mp_init(&a); mp_read_radix(&a, mp4, 16);

  s = SIGN(&a);
  mp_neg(&a, &a);
  if(SIGN(&a) == s) {
    reason("error: sign of result is same as sign of nonzero input\n");
    mp_clear(&a);
    return 1;
  }

  mp_clear(&a);
  return 0;
}

Here is the call graph for this function:

Definition at line 1771 of file mpi-test.c.

{
  mp_int  a;

  mp_init(&a); mp_read_radix(&a, mp1, 16);

  if(!mp_isodd(&a)) {
    reason("error: expected operand to be odd, but it isn't\n");
    mp_clear(&a);
    return 1;
  }

  mp_read_radix(&a, mp6, 16);
  
  if(!mp_iseven(&a)) {
    reason("error: expected operand to be even, but it isn't\n");
    mp_clear(&a);
    return 1;
  }

  mp_clear(&a);
  return 0;
}

Here is the call graph for this function:

Definition at line 1901 of file mpi-test.c.

{
  mp_int   p;
  int      err = 0;
  mp_err   res;

  mp_init(&p);
  mp_read_radix(&p, mp7, 16);

  if(mpp_pprime(&p, 5) != MP_YES) {
    reason("error: %s failed Rabin-Miller test, but is prime\n", mp7);
    err = 1;
  }

  IFOK( mp_set_int(&p, 9) );
  res = mpp_pprime(&p, 50);
  if (res == MP_YES) {
    reason("error: 9 is composite but passed Rabin-Miller test\n");
    err = 1;
  } else if (res != MP_NO) {
    reason("test mpp_pprime(9, 50) failed: error %d\n", res); 
    err = 1;
  }

  IFOK( mp_set_int(&p, 15) );
  res = mpp_pprime(&p, 50);
  if (res == MP_YES) {
    reason("error: 15 is composite but passed Rabin-Miller test\n");
    err = 1;
  } else if (res != MP_NO) {
    reason("test mpp_pprime(15, 50) failed: error %d\n", res); 
    err = 1;
  }

  mp_clear(&p);

  return err;

}

Here is the call graph for this function:

int test_raw ( void  )

Definition at line 1868 of file mpi-test.c.

{
  int    len, out = 0;
  mp_int a;
  char   *buf;

  mp_init(&a); mp_read_radix(&a, mp4, 16);

  len = mp_raw_size(&a);
  if(len != sizeof(b_mp4)) {
    reason("error: test_raw: expected length %d, computed %d\n", sizeof(b_mp4),
          len);
    mp_clear(&a);
    return 1;
  }

  buf = calloc(len, sizeof(char));
  mp_toraw(&a, buf);

  if(memcmp(buf, b_mp4, sizeof(b_mp4)) != 0) {
    reason("error: test_raw: binary output does not match test vector\n");
    out = 1;
  }

  free(buf);
  mp_clear(&a);

  return out;

}

Here is the call graph for this function:

int test_set ( void  )

Definition at line 583 of file mpi-test.c.

{
  mp_int   a;

  /* Test single digit set */
  mp_init(&a); mp_set(&a, 5);
  if(DIGIT(&a, 0) != 5) {
    mp_toradix(&a, g_intbuf, 16);
    reason("error: result is %s, expected 5\n", g_intbuf);
    mp_clear(&a);
    return 1;
  }

  /* Test integer set */
  mp_set_int(&a, -4938110);
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a);
  if(strcmp(g_intbuf, mp5a) != 0) {
    reason("error: result is %s, expected %s\n", g_intbuf, mp5a);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

int test_sqr ( void  )

Definition at line 896 of file mpi-test.c.

{
  mp_int  a;

  mp_init(&a); mp_read_radix(&a, mp2, 16);

  mp_sqr(&a, &a);
  mp_toradix(&a, g_intbuf, 16);

  mp_clear(&a);
  if(strcmp(g_intbuf, p_mp22) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, p_mp22);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1272 of file mpi-test.c.

{
  mp_int a, m;

  mp_init(&a); mp_init(&m);
  mp_read_radix(&a, mp3, 16); mp_read_radix(&m, mp5, 16);

  IFOK( mp_sqrmod(&a, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&m);

  if(strcmp(g_intbuf, mp_mp335) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, mp_mp335);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1136 of file mpi-test.c.

{
  mp_int  a;
  int     res = 0;

  mp_init(&a); mp_read_radix(&a, mp9, 16);
  mp_sqrt(&a, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, t_mp9) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, t_mp9);
    res = 1; goto CLEANUP;
  }

  mp_read_radix(&a, mp15, 16);
  mp_sqrt(&a, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, t_mp15) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, t_mp15);
    res = 1;
  }

 CLEANUP:
  mp_clear(&a);
  return res;
}

Here is the call graph for this function:

int test_sub ( void  )

Definition at line 764 of file mpi-test.c.

{
  mp_int  a, b;

  mp_init(&a); mp_init(&b);

  mp_read_radix(&a, mp1, 16); mp_read_radix(&b, mp2, 16);
  mp_sub(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, d_mp12) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, d_mp12);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_read_radix(&a, mp3, 16); mp_read_radix(&b, mp4, 16);
  mp_sub(&a, &b, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, d_mp34) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, d_mp34);
    mp_clear(&a); mp_clear(&b);
    return 1;
  }

  mp_clear(&a); mp_clear(&b);
  return 0;
}

Here is the call graph for this function:

Definition at line 732 of file mpi-test.c.

{
  mp_int   a;

  mp_init(&a);
  mp_read_radix(&a, mp5, 16);

  mp_sub_d(&a, md4, &a);
  mp_toradix(&a, g_intbuf, 16);

  if(strcmp(g_intbuf, d_mp5d4) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, d_mp5d4);
    mp_clear(&a);
    return 1;
  }

  mp_read_radix(&a, mp6, 16);
  
  mp_sub_d(&a, md2, &a);
  mp_toradix(&a, g_intbuf, 16);
  
  mp_clear(&a);
  if(strcmp(g_intbuf, d_mp6d2) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, d_mp6d2);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 1228 of file mpi-test.c.

{
  mp_int a, b, m;

  mp_init(&a); mp_init(&b); mp_init(&m);
  mp_read_radix(&a, mp3, 16); mp_read_radix(&b, mp4, 16);
  mp_read_radix(&m, mp5, 16);

  IFOK( mp_submod(&a, &b, &m, &a) );
  mp_toradix(&a, g_intbuf, 16);
  mp_clear(&a); mp_clear(&b); mp_clear(&m);

  if(strcmp(g_intbuf, md_mp345) != 0) {
    reason("error: computed %s, expected %s\n", g_intbuf, md_mp345);
    return 1;
  }

  return 0;
}

Here is the call graph for this function:

Definition at line 563 of file mpi-test.c.

{
  mp_int   a;

  mp_init(&a); mp_read_radix(&a, mp7, 16);
  mp_zero(&a);

  if(USED(&a) != 1 || DIGIT(&a, 1) != 0) {
    mp_toradix(&a, g_intbuf, 16);
    reason("error: result is %s\n", g_intbuf);
    mp_clear(&a);
    return 1;
  }

  mp_clear(&a);
  return 0;
}

Here is the call graph for this function:


Variable Documentation

char a_intbuf[4096]

Definition at line 411 of file mpi-test.c.

const unsigned char b_mp4[]
Initial value:
 {
  0x01, 



  0x63, 0xDB, 0xC2, 0x26, 
  0x5B, 0x88, 0x26, 0x8D, 
  0xC8, 0x01, 0xC1, 0x0E, 
  0xA6, 0x84, 0x76, 0xB7, 
  0xBD, 0xE0, 0x09, 0x0F
}

Definition at line 391 of file mpi-test.c.

const char* d_mp12 = "-AAFBA6A55DD183FD854A60E"

Definition at line 234 of file mpi-test.c.

const char* d_mp34 = "119366B05E606A9B1E73A6D8944CC1366B0C4E0D4"

Definition at line 235 of file mpi-test.c.

const char* d_mp5d4 = "F5952EAB"

Definition at line 236 of file mpi-test.c.

const char* d_mp6d2 = "-1"

Definition at line 237 of file mpi-test.c.

const char* e_mp5d9 = "13A5215AAC4E9AB1E96BD34E531209E03310400"

Definition at line 274 of file mpi-test.c.

const char* e_mp78 = "D113175764F5D0B3C89B262D4702F4D9640A3"

Definition at line 276 of file mpi-test.c.

const char* e_mpc2d3 = "100000000000000000000000000000000"

Definition at line 302 of file mpi-test.c.

char g_intbuf[4096]

Definition at line 410 of file mpi-test.c.

const char* g_mp25 = "7"

Definition at line 322 of file mpi-test.c.

const char* g_mp71 = "1"

Definition at line 321 of file mpi-test.c.

Definition at line 412 of file mpi-test.c.

const char* i_mp2019 = "BDF3D88DC373A63EED92903115B03FC8501910AF68297B4C41870AED3EA9F839"

Definition at line 306 of file mpi-test.c.

const char* i_mp27 = "B6AD8DCCDAF92B6FE57D062FFEE3A99"

Definition at line 305 of file mpi-test.c.

const char* l_mp1011 = "C589E3D7D64A6942A000"

Definition at line 323 of file mpi-test.c.

Definition at line 139 of file mpi-test.c.

Definition at line 140 of file mpi-test.c.

const mp_digit md3 = 0x80

Definition at line 141 of file mpi-test.c.

const mp_digit md4 = 0x9C97

Definition at line 142 of file mpi-test.c.

const mp_digit md5 = 0xF5BF

Definition at line 143 of file mpi-test.c.

const mp_digit md6 = 0x14A0

Definition at line 144 of file mpi-test.c.

const mp_digit md7 = 0x03E8

Definition at line 145 of file mpi-test.c.

const mp_digit md8 = 0x0101

Definition at line 146 of file mpi-test.c.

Definition at line 147 of file mpi-test.c.

const char* md_mp345 = "26596B86"

Definition at line 238 of file mpi-test.c.

const char* me_mp1512 = "FB5B2A28D902B9D9"

Definition at line 282 of file mpi-test.c.

const char* me_mp161718 = "423C6AC6DBD74"

Definition at line 283 of file mpi-test.c.

const char* me_mp5114 = "FE8C"

Definition at line 284 of file mpi-test.c.

const char* me_mp5d47 = "1D45ED0D78F2778157992C951DD2734C"

Definition at line 281 of file mpi-test.c.

const char* me_mp817 = "E504493ACB02F7F802B327AB13BF25"

Definition at line 280 of file mpi-test.c.

const char* mp1 = "639A868CDA0C569861B"

Definition at line 82 of file mpi-test.c.

const char* mp10 = "9184E72A000"

Definition at line 92 of file mpi-test.c.

const char* mp11 = "54D79A3557E8"

Definition at line 93 of file mpi-test.c.

const char* mp12 = "10000000000000000"

Definition at line 94 of file mpi-test.c.

const char* mp13 = "D5A5C79F708BDE26E0CCF2DB66CD6D6089E29A877C45F2B050D226E6DA88"

Definition at line 95 of file mpi-test.c.

const char* mp14 = "C1B1384BE4B2EB46"

Definition at line 98 of file mpi-test.c.

const char* mp15 = "822AD9DDBFE4BD04"

Definition at line 114 of file mpi-test.c.

const char* mp16 = "4A724340668DB150339A70"

Definition at line 130 of file mpi-test.c.

const char* mp17 = "8ADB90F58"

Definition at line 131 of file mpi-test.c.

const char* mp18 = "C64C230AB20E5"

Definition at line 132 of file mpi-test.c.

const char* mp19 = "F1C9DACDA287F2E3C88DCE2393B8F53DAAAC1196DC36510962B6B59454CFE64B"

Definition at line 133 of file mpi-test.c.

const char* mp2 = "AAFC0A3FE45E5E09DBE2C29"

Definition at line 83 of file mpi-test.c.

const char* mp20 = "D445662C8B6FE394107B867797750C326E0F4A967E135FC430F6CD7207913AC7"

Definition at line 135 of file mpi-test.c.

const char* mp21 = "2"

Definition at line 137 of file mpi-test.c.

const char* mp3 = "B55AA8DF8A7E83241F38AC7A9E479CAEF2E4D7C5"

Definition at line 84 of file mpi-test.c.

const char* mp4 = "-63DBC2265B88268DC801C10EA68476B7BDE0090F"

Definition at line 85 of file mpi-test.c.

const char* mp5 = "F595CB42"

Definition at line 86 of file mpi-test.c.

const char* mp5a = "-4B597E"

Definition at line 87 of file mpi-test.c.

const char* mp6 = "0"

Definition at line 88 of file mpi-test.c.

const char* mp7 = "EBFA7121CD838CE6439CC59DDB4CBEF3"

Definition at line 89 of file mpi-test.c.

const char* mp8 = "5"

Definition at line 90 of file mpi-test.c.

const char* mp9 = "F74A2876A1432698923B0767DA19DCF3D71795EE"

Definition at line 91 of file mpi-test.c.

const char* mp_mp335 = "16609C2D"

Definition at line 207 of file mpi-test.c.

const char* mp_mp345 = "B9B6D3A3"

Definition at line 206 of file mpi-test.c.

const char* ms_mp345 = "1E71E292"

Definition at line 232 of file mpi-test.c.

const char* p_mp1113 = "4340"

Definition at line 169 of file mpi-test.c.

const char* p_mp12 = "4286AD72E095C9FE009938750743174ADDD7FD1E53"

Definition at line 162 of file mpi-test.c.

const char* p_mp1415 = "6ED65B18"

Definition at line 173 of file mpi-test.c.

const char* p_mp1d4 = "3CECEA2331F4220BEF68DED"

Definition at line 167 of file mpi-test.c.

const char* p_mp2121 = "4"

Definition at line 205 of file mpi-test.c.

const char* p_mp22 = "7233B5C1097FFC77CCF55928FDC3A5D31B712FDE7A1E91"

Definition at line 166 of file mpi-test.c.

const char* p_mp34 = "A1BFD6934C441EE369B60CA29BADC26845E918B"

Definition at line 163 of file mpi-test.c.

const char* p_mp57 = "E260C265A0A27C17AD5F4E59D6E0360217A2EBA6"

Definition at line 165 of file mpi-test.c.

const char* p_mp8d6 = "6720"

Definition at line 168 of file mpi-test.c.

const char* q_mp13c = "BDAB6163963CD5A5C79F708BDE26E0CCF2DB66CD6D6089E29A877C45"

Definition at line 267 of file mpi-test.c.

const char* q_mp1404 = "BD9E23E4D367A2C35762F209073DFF48F3"

Definition at line 249 of file mpi-test.c.

const char* q_mp3d6 = "8CAFD53C272BD6FE8B0847BDC3B539EFAB5C3"

Definition at line 245 of file mpi-test.c.

const char* q_mp42 = "-95825A1FFA1A155D5"

Definition at line 240 of file mpi-test.c.

const char* q_mp45a = "15344CDA3D841F661D2B61B6EDF7828CE36"

Definition at line 242 of file mpi-test.c.

const char* q_mp7c2 = "75FD3890E6C1C67321CE62CEEDA65F79"

Definition at line 244 of file mpi-test.c.

const char* q_mp9c16 = "F74A2876A1432698923B0767DA19DCF3D71795E"

Definition at line 271 of file mpi-test.c.

const char* r_mp13c = "F2B050D226E6DA88"

Definition at line 270 of file mpi-test.c.

const char* r_mp1404 = "12FF98621ABF63144BFFC3207AC8FC10D8D1A09"

Definition at line 265 of file mpi-test.c.

const char* r_mp3d6 = "1E5"

Definition at line 246 of file mpi-test.c.

const char* r_mp42 = "-6312E99D7700A3DCB32ADF2"

Definition at line 241 of file mpi-test.c.

const char* r_mp45a = "-47C47B"

Definition at line 243 of file mpi-test.c.

const char* r_mp47 = "B3A9018D970281A90FB729A181D95CB8"

Definition at line 248 of file mpi-test.c.

const char* r_mp5d5 = "1257"

Definition at line 247 of file mpi-test.c.

const char* r_mp9c16 = "E"

Definition at line 272 of file mpi-test.c.

Definition at line 413 of file mpi-test.c.

const char* s_mp13 = "B55AA8DF8A7E83241F38B2B446B06A4FB84E5DE0"

Definition at line 209 of file mpi-test.c.

const char* s_mp1415 = "A84A"

Definition at line 214 of file mpi-test.c.

const char* s_mp2d5 = "AAFC0A3FE45E5E09DBF21E8"

Definition at line 213 of file mpi-test.c.

const char* s_mp34 = "517EE6B92EF65C965736EB6BF7C325F73504CEB6"

Definition at line 210 of file mpi-test.c.

const char* s_mp46 = "-63DBC2265B88268DC801C10EA68476B7BDE0090F"

Definition at line 211 of file mpi-test.c.

const char* s_mp5d4 = "F59667D9"

Definition at line 212 of file mpi-test.c.

const char* t_mp15 = "BEE244F7DD3AC268CF512A0E52E4F5BE5B94"

Definition at line 311 of file mpi-test.c.

const char* t_mp9 = "FB9B6E32FF0452A34746"

Definition at line 304 of file mpi-test.c.

const char* v_mp9[]

Definition at line 328 of file mpi-test.c.