Exemple #1
0
/* used by server */
int dh_generate_y(ssh_session session) {
    session->next_crypto->y = bignum_new();
  if (session->next_crypto->y == NULL) {
    return -1;
  }

#ifdef HAVE_LIBGCRYPT
  bignum_rand(session->next_crypto->y, 128);
#elif defined HAVE_LIBCRYPTO
  bignum_rand(session->next_crypto->y, 128, 0, -1);
#endif

  /* not harder than this */
#ifdef DEBUG_CRYPTO
  ssh_print_bignum("y", session->next_crypto->y);
#endif

  return 0;
}
Exemple #2
0
/** @brief generates a random integer between 0 and max
 * @returns 1 in case of success, 0 otherwise
 */
int ssh_gcry_rand_range(bignum dest, bignum max)
{
    size_t bits;
    bignum rnd;
    int rc;

    bits = bignum_num_bits(max) + 64;
    rnd = bignum_new();
    if (rnd == NULL) {
        return 0;
    }
    rc = bignum_rand(rnd, bits);
    if (rc != 1) {
        return rc;
    }
    gcry_mpi_mod(dest, rnd, max);
    bignum_safe_free(rnd);
    return 1;
}