Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
test-info.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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 int g_count = 42
const char * g_names []
int(* g_tests [])(void)
const char * g_descs []

Function Documentation

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:

Here is the caller 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

Definition at line 44 of file test-info.c.

const char* g_descs[]

Definition at line 150 of file test-info.c.

const char* g_names[]

Definition at line 45 of file test-info.c.

int(* g_tests[])(void)