aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libssh/libmbedcrypto.h8
-rw-r--r--src/bignum.c6
-rw-r--r--src/curve25519.c13
-rw-r--r--src/dh.c16
4 files changed, 6 insertions, 37 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)
diff --git a/src/bignum.c b/src/bignum.c
index 9039933d..fdd2d81f 100644
--- a/src/bignum.c
+++ b/src/bignum.c
@@ -71,13 +71,7 @@ bignum ssh_make_string_bn(ssh_string string)
len * 8, len);
#endif /* DEBUG_CRYPTO */
-#if defined HAVE_LIBMBEDCRYPTO
- bn = bignum_new();
- bignum_bin2bn(string->data, len, bn);
-#else
- // FIXME
bignum_bin2bn(string->data, len, &bn);
-#endif
return bn;
}
diff --git a/src/curve25519.c b/src/curve25519.c
index 470b81d2..3a914a41 100644
--- a/src/curve25519.c
+++ b/src/curve25519.c
@@ -88,14 +88,6 @@ int ssh_client_curve25519_init(ssh_session session){
static int ssh_curve25519_build_k(ssh_session session) {
ssh_curve25519_pubkey k;
-#if defined HAVE_LIBMBEDCRYPTO
- session->next_crypto->k = bignum_new();
-
- if (session->next_crypto->k == NULL) {
- return SSH_ERROR;
- }
-#endif
-
if (session->server)
crypto_scalarmult(k, session->next_crypto->curve25519_privkey,
session->next_crypto->curve25519_client_pubkey);
@@ -103,12 +95,7 @@ static int ssh_curve25519_build_k(ssh_session session) {
crypto_scalarmult(k, session->next_crypto->curve25519_privkey,
session->next_crypto->curve25519_server_pubkey);
-#if defined HAVE_LIBMBEDCRYPTO
- /* FIXME */
- bignum_bin2bn(k, CURVE25519_PUBKEY_SIZE, session->next_crypto->k);
-#else
bignum_bin2bn(k, CURVE25519_PUBKEY_SIZE, &session->next_crypto->k);
-#endif
if (session->next_crypto->k == NULL) {
return SSH_ERROR;
}
diff --git a/src/dh.c b/src/dh.c
index b6ae33c6..5bfa8b35 100644
--- a/src/dh.c
+++ b/src/dh.c
@@ -247,20 +247,6 @@ int ssh_dh_init(void)
goto error;
}
-#if defined(HAVE_LIBMBEDCRYPTO)
- /* FIXME */
- p_group1 = bignum_new();
- bignum_bin2bn(p_group1_value, P_GROUP1_LEN, p_group1);
-
- p_group14 = bignum_new();
- bignum_bin2bn(p_group14_value, P_GROUP14_LEN, p_group14);
-
- p_group16 = bignum_new();
- bignum_bin2bn(p_group16_value, P_GROUP16_LEN, p_group16);
-
- p_group18 = bignum_new();
- bignum_bin2bn(p_group18_value, P_GROUP18_LEN, p_group18);
-#else
bignum_bin2bn(p_group1_value, P_GROUP1_LEN, &p_group1);
if (p_group1 == NULL) {
goto error;
@@ -278,8 +264,6 @@ int ssh_dh_init(void)
goto error;
}
-#endif
-
dh_crypto_initialized = 1;
return 0;