comparison cli-kex.c @ 745:15999b098cc9 kexguess

Don't usually need to recalculate dh_e for the repeated kexdh_init packet
author Matt Johnston <matt@ucc.asn.au>
date Wed, 03 Apr 2013 00:32:55 +0800
parents 09c5eb71ec96
children d63ef1e211ea
comparison
equal deleted inserted replaced
744:504f33c684b5 745:15999b098cc9
41 static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen); 41 static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen);
42 #define MAX_KNOWNHOSTS_LINE 4500 42 #define MAX_KNOWNHOSTS_LINE 4500
43 43
44 void send_msg_kexdh_init() { 44 void send_msg_kexdh_init() {
45 TRACE(("send_msg_kexdh_init()")) 45 TRACE(("send_msg_kexdh_init()"))
46 cli_ses.dh_e = (mp_int*)m_malloc(sizeof(mp_int)); 46 if ((cli_ses.dh_e && cli_ses.dh_x
47 cli_ses.dh_x = (mp_int*)m_malloc(sizeof(mp_int)); 47 && cli_ses.dh_val_algo == ses.newkeys->algo_kex)) {
48 m_mp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); 48 TRACE(("reusing existing dh_e from first_kex_packet_follows"))
49 49 } else {
50 gen_kexdh_vals(cli_ses.dh_e, cli_ses.dh_x); 50 if (!cli_ses.dh_e || !cli_ses.dh_e) {
51 cli_ses.dh_e = (mp_int*)m_malloc(sizeof(mp_int));
52 cli_ses.dh_x = (mp_int*)m_malloc(sizeof(mp_int));
53 m_mp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL);
54 }
55
56 gen_kexdh_vals(cli_ses.dh_e, cli_ses.dh_x);
57 cli_ses.dh_val_algo = ses.newkeys->algo_kex;
58 }
51 59
52 CHECKCLEARTOWRITE(); 60 CHECKCLEARTOWRITE();
53 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_INIT); 61 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_INIT);
54 buf_putmpint(ses.writepayload, cli_ses.dh_e); 62 buf_putmpint(ses.writepayload, cli_ses.dh_e);
55 encrypt_packet(); 63 encrypt_packet();
97 kexdh_comb_key(cli_ses.dh_e, cli_ses.dh_x, &dh_f, hostkey); 105 kexdh_comb_key(cli_ses.dh_e, cli_ses.dh_x, &dh_f, hostkey);
98 mp_clear(&dh_f); 106 mp_clear(&dh_f);
99 mp_clear_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); 107 mp_clear_multi(cli_ses.dh_e, cli_ses.dh_x, NULL);
100 m_free(cli_ses.dh_e); 108 m_free(cli_ses.dh_e);
101 m_free(cli_ses.dh_x); 109 m_free(cli_ses.dh_x);
110 cli_ses.dh_val_algo = DROPBEAR_KEX_NONE;
102 111
103 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE) 112 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE)
104 != DROPBEAR_SUCCESS) { 113 != DROPBEAR_SUCCESS) {
105 dropbear_exit("Bad hostkey signature"); 114 dropbear_exit("Bad hostkey signature");
106 } 115 }