1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-12-12 15:41:16 +03:00

bignum: harmonize gcrypt, libcrypto and libmcrypt bignum

Ensure most of the abstraction around the 3 libs are consistent.

Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Aris Adamantiadis
2015-12-31 10:48:34 +01:00
committed by Andreas Schneider
parent 43a4f86b6e
commit afe2673cfa
11 changed files with 178 additions and 219 deletions

View File

@@ -99,4 +99,22 @@ char *ssh_gcry_bn2dec(bignum bn) {
return ret;
}
/** @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;
bits = bignum_num_bits(max) + 64;
rnd = bignum_new();
if (rnd == NULL) {
return 0;
}
bignum_rand(rnd, bits);
gcry_mpi_mod(dest, rnd, max);
bignum_safe_free(rnd);
return 1;
}
#endif