aboutsummaryrefslogtreecommitdiff
path: root/include/libssh/libmbedcrypto.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libssh/libmbedcrypto.h')
-rw-r--r--include/libssh/libmbedcrypto.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/include/libssh/libmbedcrypto.h b/include/libssh/libmbedcrypto.h
index 13b41c99..0b156fb2 100644
--- a/include/libssh/libmbedcrypto.h
+++ b/include/libssh/libmbedcrypto.h
@@ -92,8 +92,12 @@ int ssh_mbedcry_hex2bn(bignum *dest, char *data);
#define bignum_ctx_invalid(ctx) (ctx == NULL?0:1)
#define bignum_set_word(bn, n) (mbedtls_mpi_lset(bn, n)==0?1:0) /* TODO fix
overflow/underflow */
-#define bignum_bin2bn(data, datalen, bn) mbedtls_mpi_read_binary(bn, data, \
- datalen)
+#define bignum_bin2bn(data, datalen, bn) do { \
+ *(bn) = bignum_new(); \
+ if (*(bn) != NULL) { \
+ mbedtls_mpi_read_binary(*(bn), data, datalen); \
+ } \
+ } while(0)
#define bignum_bn2dec(num) ssh_mbedcry_bn2num(num, 10)
#define bignum_dec2bn(data, bn) mbedtls_mpi_read_string(bn, 10, data)
#define bignum_bn2hex(num, dest) (*dest)=ssh_mbedcry_bn2num(num, 16)