aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/libssh/libcrypto.h8
-rw-r--r--include/libssh/libgcrypt.h7
-rw-r--r--include/libssh/libmbedcrypto.h8
3 files changed, 23 insertions, 0 deletions
diff --git a/include/libssh/libcrypto.h b/include/libssh/libcrypto.h
index 27cb6ad9..541912b5 100644
--- a/include/libssh/libcrypto.h
+++ b/include/libssh/libcrypto.h
@@ -102,6 +102,14 @@ typedef BN_CTX* bignum_CTX;
#define bignum_bn2bin(num,len, ptr) BN_bn2bin(num, ptr)
#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
#define bignum_rshift1(dest, src) BN_rshift1(dest, src)
+#define bignum_dup(orig, dest) do { \
+ if (*(dest) == NULL) { \
+ *(dest) = BN_dup(orig); \
+ } else { \
+ BN_copy(*(dest), orig); \
+ } \
+ } while(0)
+
/* Returns true if the OpenSSL is operating in FIPS mode */
#define ssh_fips_mode() (FIPS_mode() != 0)
diff --git a/include/libssh/libgcrypt.h b/include/libssh/libgcrypt.h
index 4d98ece3..795d33e1 100644
--- a/include/libssh/libgcrypt.h
+++ b/include/libssh/libgcrypt.h
@@ -92,6 +92,13 @@ int ssh_gcry_rand_range(bignum rnd, bignum max);
#define bignum_sub(dst, a, b) gcry_mpi_sub(dst, a, b)
#define bignum_mod(dst, a, b, ctx) 1,gcry_mpi_mod(dst, a, b)
#define bignum_rand_range(rnd, max) ssh_gcry_rand_range(rnd, max);
+#define bignum_dup(orig, dest) do { \
+ if (*(dest) == NULL) { \
+ *(dest) = gcry_mpi_copy(orig); \
+ } else { \
+ gcry_mpi_set(*(dest), orig); \
+ } \
+ } while(0)
/* Helper functions for data conversions. */
/* Extract an MPI from the given s-expression SEXP named NAME which is
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);