The unified diff between revisions [d0935a5d..] and [e0686662..] is displayed below. It can also be downloaded as a raw diff.
This diff has been restricted to the following files: 'common-kex.c'
#
#
# patch "common-kex.c"
# from [cd4c38b3cda9c8a7d9ac70a585baa1ad2e078c54]
# to [960bfda8deaa204b5866f14647f3cd86d262d93f]
#
============================================================
--- common-kex.c cd4c38b3cda9c8a7d9ac70a585baa1ad2e078c54
+++ common-kex.c 960bfda8deaa204b5866f14647f3cd86d262d93f
@@ -457,7 +457,6 @@ void recv_msg_kexinit() {
/* the rest of ses.kexhashbuf will be done after DH exchange */
ses.kexstate.recvkexinit = 1;
-// ses.expecting = 0; // client matt
TRACE(("leave recv_msg_kexinit"))
}
@@ -470,18 +469,13 @@ void gen_kexdh_vals(mp_int *dh_pub, mp_i
DEF_MP_INT(dh_p);
DEF_MP_INT(dh_q);
DEF_MP_INT(dh_g);
- unsigned char randbuf[DH_P_LEN];
- int dh_q_len;
TRACE(("enter send_msg_kexdh_reply"))
m_mp_init_multi(&dh_g, &dh_p, &dh_q, NULL);
/* read the prime and generator*/
- if (mp_read_unsigned_bin(&dh_p, (unsigned char*)dh_p_val, DH_P_LEN)
- != MP_OKAY) {
- dropbear_exit("Diffie-Hellman error");
- }
+ bytes_to_mp(&dh_p, (unsigned char*)dh_p_val, DH_P_LEN);
if (mp_set_int(&dh_g, DH_G_VAL) != MP_OKAY) {
dropbear_exit("Diffie-Hellman error");
@@ -496,17 +490,9 @@ void gen_kexdh_vals(mp_int *dh_pub, mp_i
dropbear_exit("Diffie-Hellman error");
}
- dh_q_len = mp_unsigned_bin_size(&dh_q);
+ /* Generate a private portion 0 < dh_priv < dh_q */
+ gen_random_mpint(&dh_q, dh_priv);
- /* calculate our random value dh_y */
- do {
- assert((unsigned int)dh_q_len <= sizeof(randbuf));
- genrandom(randbuf, dh_q_len);
- if (mp_read_unsigned_bin(dh_priv, randbuf, dh_q_len) != MP_OKAY) {
- dropbear_exit("Diffie-Hellman error");
- }
- } while (mp_cmp(dh_priv, &dh_q) == MP_GT || mp_cmp_d(dh_priv, 0) != MP_GT);
-
/* f = g^y mod p */
if (mp_exptmod(&dh_g, dh_priv, &dh_p, dh_pub) != MP_OKAY) {
dropbear_exit("Diffie-Hellman error");
@@ -527,10 +513,7 @@ void kexdh_comb_key(mp_int *dh_pub_us, m
/* read the prime and generator*/
mp_init(&dh_p);
- if (mp_read_unsigned_bin(&dh_p, (unsigned char*)dh_p_val, DH_P_LEN)
- != MP_OKAY) {
- dropbear_exit("Diffie-Hellman error");
- }
+ bytes_to_mp(&dh_p, dh_p_val, DH_P_LEN);
/* Check that dh_pub_them (dh_e or dh_f) is in the range [1, p-1] */
if (mp_cmp(dh_pub_them, &dh_p) != MP_LT
@@ -683,7 +666,7 @@ static void read_kex_algos() {
buf_eatstring(ses.payload);
/* first_kex_packet_follows */
- if (buf_getbyte(ses.payload)) {
+ if (buf_getbool(ses.payload)) {
ses.kexstate.firstfollows = 1;
/* if the guess wasn't good, we ignore the packet sent */
if (!allgood) {