mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-07 10:40:28 +09:00
crypto: Add ssh_crypto_free().
The intention is that this releases memory allocated by the crypto library, for functions like bignum_bn2hex() and bignum_bn2dec(). Consequently, ssh_gcry_bn2dec and ssh_mbedcry_bn2num should use gcry_malloc() and mbedtls_calloc() respectively to allocate memory since it will/should be released by ssh_crypto_free() so that the internal APIs are consistent between crypto libraries. Signed-off-by: Simon Josefsson <simon@josefsson.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
committed by
Jakub Jelen
parent
06fbf5c159
commit
504faca67a
@@ -88,11 +88,5 @@ void ssh_print_bignum(const char *name, const_bignum num)
|
||||
}
|
||||
SSH_LOG(SSH_LOG_DEBUG, "%s value: %s", name,
|
||||
(hex == NULL) ? "(null)" : (char *)hex);
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
SAFE_FREE(hex);
|
||||
#elif defined HAVE_LIBCRYPTO
|
||||
OPENSSL_free(hex);
|
||||
#elif defined HAVE_LIBMBEDCRYPTO
|
||||
SAFE_FREE(hex);
|
||||
#endif
|
||||
ssh_crypto_free(hex);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ char *ssh_gcry_bn2dec(bignum bn) {
|
||||
size = gcry_mpi_get_nbits(bn) * 3;
|
||||
rsize = size / 10 + size / 1000 + 2;
|
||||
|
||||
ret = malloc(rsize + 1);
|
||||
ret = gcry_malloc(rsize + 1);
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ char *ssh_mbedcry_bn2num(const_bignum num, int radix)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buf = malloc(olen);
|
||||
buf = mbedtls_calloc(1, olen);
|
||||
if (buf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user