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:
committed by
Andreas Schneider
parent
43a4f86b6e
commit
afe2673cfa
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user