diff options
author | Anderson Toshiyuki Sasaki <ansasaki@redhat.com> | 2019-06-07 19:05:01 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2019-06-12 12:36:32 +0200 |
commit | 765691195394a0daa8215beb7899b5653247cc08 (patch) | |
tree | 9b1482ec704bc985c6bffb4577891a8ee91fc9f4 /include/libssh | |
parent | 9f7f5dee18dea225d94655ea61db33ef51bf1e94 (diff) | |
download | libssh-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')
-rw-r--r-- | include/libssh/libcrypto.h | 8 | ||||
-rw-r--r-- | include/libssh/libgcrypt.h | 7 | ||||
-rw-r--r-- | include/libssh/libmbedcrypto.h | 8 |
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); |