mbedcrypto: Make bignum_bin2bn behave like others
Signed-off-by: Simo Sorce <simo@redhat.com> Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
родитель
fd30cf0676
Коммит
997fe4d418
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
16
src/dh.c
16
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;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user