aboutsummaryrefslogtreecommitdiff
path: root/include/libssh/libmbedcrypto.h
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2016-01-01 19:16:49 +0100
committerAndreas Schneider <asn@cryptomilk.org>2018-07-05 14:35:13 +0200
commitdb9da99a36a4d83b77f8f8e90482c2d6cc0e20de (patch)
tree46a2f939941cc85e736de5627e7430cf4e2937f7 /include/libssh/libmbedcrypto.h
parentc3dac948c916c1330419980f71a72c253efd19b8 (diff)
downloadlibssh-db9da99a36a4d83b77f8f8e90482c2d6cc0e20de.tar.gz
libssh-db9da99a36a4d83b77f8f8e90482c2d6cc0e20de.tar.xz
libssh-db9da99a36a4d83b77f8f8e90482c2d6cc0e20de.zip
bignum: Make bignum_free safer
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'include/libssh/libmbedcrypto.h')
-rw-r--r--include/libssh/libmbedcrypto.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/include/libssh/libmbedcrypto.h b/include/libssh/libmbedcrypto.h
index 101cdee9..7522cd14 100644
--- a/include/libssh/libmbedcrypto.h
+++ b/include/libssh/libmbedcrypto.h
@@ -78,7 +78,12 @@ int ssh_mbedcry_rand(bignum rnd, int bits, int top, int bottom);
int ssh_mbedcry_is_bit_set(bignum num, size_t pos);
#define bignum_new() ssh_mbedcry_bn_new()
-#define bignum_free(num) ssh_mbedcry_bn_free(num);
+#define bignum_safe_free(num) do { \
+ if ((num) != NULL) { \
+ ssh_mbedcry_bn_free(num); \
+ (num)=NULL; \
+ } \
+ } while(0)
#define bignum_set_word(bn, n) mbedtls_mpi_lset(bn, n) /* TODO fix
overflow/underflow */
#define bignum_bin2bn(data, datalen, bn) mbedtls_mpi_read_binary(bn, data, \