Ejemplo n.º 1
0
int test_read_uns(testspec_t *t, FILE *ofp)
{
  mp_int out[1], in = g_zreg + 1;
  int in_len;
  mp_result res, expect;

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

  trim_line(t->input[0]);
  if((in_len = parse_binary(t->input[0], g_bin1, sizeof(g_bin1))) < 0)
    return imath_errno = MP_BADARG, 0;

  if((res = mp_int_read_unsigned(in, g_bin1, in_len)) != expect)
    return imath_errno = res, 0;

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

  return 1;
}
Ejemplo n.º 2
0
    goto CLEANUP;
  }

  /* Clear bits beyond the number requested */
  if(n_bits % CHAR_BIT != 0) {
    unsigned char b_mask = (1 << (n_bits % CHAR_BIT)) - 1;
    unsigned char t_mask = (1 << (n_bits % CHAR_BIT)) >> 1;

    buf[0] &= b_mask;
    buf[0] |= t_mask;
  }

  /* Set low-order bit to insure value is odd */
  buf[n_bytes - 1] |= 1;

  res = mp_int_read_unsigned(a, buf, n_bytes);

 CLEANUP:
  memset(buf, 0, n_bytes);
  free(buf);

  return res;
}

mp_result find_prime(mp_int seed, FILE *fb)
{
  mp_result res;
  int       count = 0;

  if(mp_int_is_even(seed))
    if((res = mp_int_add_value(seed, 1, seed)) != MP_OK)