mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
dh: Fix CVE-2016-0739
Due to a byte/bit confusion, the DH secret was too short. This file was completely reworked and will be commited in a future version. Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
committed by
Andreas Schneider
parent
f8bde7156f
commit
4e6ff36a9a
22
src/dh.c
22
src/dh.c
@@ -227,15 +227,21 @@ void ssh_crypto_finalize(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ssh_dh_generate_x(ssh_session session) {
|
int ssh_dh_generate_x(ssh_session session) {
|
||||||
|
int keysize;
|
||||||
|
if (session->next_crypto->kex_type == SSH_KEX_DH_GROUP1_SHA1) {
|
||||||
|
keysize = 1023;
|
||||||
|
} else {
|
||||||
|
keysize = 2047;
|
||||||
|
}
|
||||||
session->next_crypto->x = bignum_new();
|
session->next_crypto->x = bignum_new();
|
||||||
if (session->next_crypto->x == NULL) {
|
if (session->next_crypto->x == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
bignum_rand(session->next_crypto->x, 128);
|
bignum_rand(session->next_crypto->x, keysize);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
bignum_rand(session->next_crypto->x, 128, 0, -1);
|
bignum_rand(session->next_crypto->x, keysize, -1, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* not harder than this */
|
/* not harder than this */
|
||||||
@@ -248,15 +254,21 @@ int ssh_dh_generate_x(ssh_session session) {
|
|||||||
|
|
||||||
/* used by server */
|
/* used by server */
|
||||||
int ssh_dh_generate_y(ssh_session session) {
|
int ssh_dh_generate_y(ssh_session session) {
|
||||||
session->next_crypto->y = bignum_new();
|
int keysize;
|
||||||
|
if (session->next_crypto->kex_type == SSH_KEX_DH_GROUP1_SHA1) {
|
||||||
|
keysize = 1023;
|
||||||
|
} else {
|
||||||
|
keysize = 2047;
|
||||||
|
}
|
||||||
|
session->next_crypto->y = bignum_new();
|
||||||
if (session->next_crypto->y == NULL) {
|
if (session->next_crypto->y == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBGCRYPT
|
#ifdef HAVE_LIBGCRYPT
|
||||||
bignum_rand(session->next_crypto->y, 128);
|
bignum_rand(session->next_crypto->y, keysize);
|
||||||
#elif defined HAVE_LIBCRYPTO
|
#elif defined HAVE_LIBCRYPTO
|
||||||
bignum_rand(session->next_crypto->y, 128, 0, -1);
|
bignum_rand(session->next_crypto->y, keysize, -1, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* not harder than this */
|
/* not harder than this */
|
||||||
|
|||||||
Reference in New Issue
Block a user