Esempio n. 1
0
static mp_result s_rsa_transform(mp_int msg, mp_int exp, 
				 mp_int mod, mp_int out)
{
  if(mp_int_compare_zero(msg) < 0 ||
     mp_int_compare(msg, mod) >= 0)
    return MP_RANGE;

  return mp_int_exptmod(msg, exp, mod, out);
}
Esempio n. 2
0
int test_exptmod(testspec_t *t, FILE *ofp)
{
  mp_int in[4], out[1];
  mp_result res, expect;

  if(!parse_int_values(t, in, out, &expect))
    return imath_errno = MP_BADARG, 0;

  if((res = mp_int_exptmod(in[0], in[1], in[2], in[3])) != expect)
    return imath_errno = res, 0;

  if(expect == MP_OK && mp_int_compare(in[3], out[0]) != 0) {
    mp_int_to_string(in[3], 10, g_output, OUTPUT_LIMIT);
    return imath_errno = OTHER_ERROR, 0;
  }

  return 1;
}
Esempio n. 3
0
double get_exptmod_time(int nt, int prec)
{
  clock_t start, end;
  mp_int values;
  int i;

  if((values = alloc_values(4, prec)) == NULL)
    return 0.0;
  randomize_values(values, 3, prec);

  start = clock(); 
  for(i = 0; i < nt; ++i)
    mp_int_exptmod(values, values + 1, values + 2, values + 3);
  end = clock();

  release_values(values, 4);

  return clocks_to_seconds(start, end);
}