aboutsummaryrefslogtreecommitdiff
path: root/include/libssh/libmbedcrypto.h
diff options
context:
space:
mode:
authorAnderson Toshiyuki Sasaki <ansasaki@redhat.com>2019-06-07 19:05:01 +0200
committerAndreas Schneider <asn@cryptomilk.org>2019-06-12 12:36:32 +0200
commit765691195394a0daa8215beb7899b5653247cc08 (patch)
tree9b1482ec704bc985c6bffb4577891a8ee91fc9f4 /include/libssh/libmbedcrypto.h
parent9f7f5dee18dea225d94655ea61db33ef51bf1e94 (diff)
downloadlibssh-765691195394a0daa8215beb7899b5653247cc08.tar.gz
libssh-765691195394a0daa8215beb7899b5653247cc08.tar.xz
libssh-765691195394a0daa8215beb7899b5653247cc08.zip
bignum: Define bignum_dup(bignum orig, bignum *dest)
The macro is defined for each crypto back end. If (*dest) is NULL, a new bignum is allocated. Otherwise the value of orig is copied to (*dest). Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Diffstat (limited to 'include/libssh/libmbedcrypto.h')
-rw-r--r--include/libssh/libmbedcrypto.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/libssh/libmbedcrypto.h b/include/libssh/libmbedcrypto.h
index c2afddf5..00d5ba8c 100644
--- a/include/libssh/libmbedcrypto.h
+++ b/include/libssh/libmbedcrypto.h
@@ -118,6 +118,14 @@ int ssh_mbedcry_hex2bn(bignum *dest, char *data);
mbedtls_mpi_size(num))
#define bignum_cmp(num1, num2) mbedtls_mpi_cmp_mpi(num1, num2)
#define bignum_rshift1(dest, src) mbedtls_mpi_copy(dest, src), mbedtls_mpi_shift_r(dest, 1)
+#define bignum_dup(orig, dest) do { \
+ if (*(dest) == NULL) { \
+ *(dest) = bignum_new(); \
+ } \
+ if (*(dest) != NULL) { \
+ mbedtls_mpi_copy(orig, *(dest)); \
+ } \
+ } while(0)
mbedtls_ctr_drbg_context *ssh_get_mbedtls_ctr_drbg_context(void);