comparison cli-kex.c @ 84:29a5c7c62350

default initialisers for mp_ints
author Matt Johnston <matt@ucc.asn.au>
date Tue, 17 Aug 2004 10:20:20 +0000
parents 07bcdccb3577
children e13f8a712a1c
comparison
equal deleted inserted replaced
83:6539c9480b23 84:29a5c7c62350
43 43
44 void send_msg_kexdh_init() { 44 void send_msg_kexdh_init() {
45 45
46 cli_ses.dh_e = (mp_int*)m_malloc(sizeof(mp_int)); 46 cli_ses.dh_e = (mp_int*)m_malloc(sizeof(mp_int));
47 cli_ses.dh_x = (mp_int*)m_malloc(sizeof(mp_int)); 47 cli_ses.dh_x = (mp_int*)m_malloc(sizeof(mp_int));
48
49 m_mp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); 48 m_mp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL);
49
50 gen_kexdh_vals(cli_ses.dh_e, cli_ses.dh_x); 50 gen_kexdh_vals(cli_ses.dh_e, cli_ses.dh_x);
51 51
52 CHECKCLEARTOWRITE(); 52 CHECKCLEARTOWRITE();
53 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_INIT); 53 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_INIT);
54 buf_putmpint(ses.writepayload, cli_ses.dh_e); 54 buf_putmpint(ses.writepayload, cli_ses.dh_e);
57 } 57 }
58 58
59 /* Handle a diffie-hellman key exchange reply. */ 59 /* Handle a diffie-hellman key exchange reply. */
60 void recv_msg_kexdh_reply() { 60 void recv_msg_kexdh_reply() {
61 61
62 mp_int dh_f; 62 DEF_MP_INT(dh_f);
63 sign_key *hostkey = NULL; 63 sign_key *hostkey = NULL;
64 unsigned int type, keybloblen; 64 unsigned int type, keybloblen;
65 unsigned char* keyblob = NULL; 65 unsigned char* keyblob = NULL;
66 66
67 67
68 TRACE(("enter recv_msg_kexdh_reply")); 68 TRACE(("enter recv_msg_kexdh_reply"));
69
70 if (cli_ses.kex_state != KEXDH_INIT_SENT) {
71 dropbear_exit("Received out-of-order kexdhreply");
72 }
73 m_mp_init(&dh_f);
69 type = ses.newkeys->algo_hostkey; 74 type = ses.newkeys->algo_hostkey;
70 TRACE(("type is %d", type)); 75 TRACE(("type is %d", type));
71 76
72 hostkey = new_sign_key(); 77 hostkey = new_sign_key();
73 keybloblen = buf_getint(ses.payload); 78 keybloblen = buf_getint(ses.payload);
81 if (buf_get_pub_key(ses.payload, hostkey, &type) != DROPBEAR_SUCCESS) { 86 if (buf_get_pub_key(ses.payload, hostkey, &type) != DROPBEAR_SUCCESS) {
82 TRACE(("failed getting pubkey")); 87 TRACE(("failed getting pubkey"));
83 dropbear_exit("Bad KEX packet"); 88 dropbear_exit("Bad KEX packet");
84 } 89 }
85 90
86 m_mp_init(&dh_f);
87 if (buf_getmpint(ses.payload, &dh_f) != DROPBEAR_SUCCESS) { 91 if (buf_getmpint(ses.payload, &dh_f) != DROPBEAR_SUCCESS) {
88 TRACE(("failed getting mpint")); 92 TRACE(("failed getting mpint"));
89 dropbear_exit("Bad KEX packet"); 93 dropbear_exit("Bad KEX packet");
90 } 94 }
91 95
92 kexdh_comb_key(cli_ses.dh_e, cli_ses.dh_x, &dh_f, hostkey); 96 kexdh_comb_key(cli_ses.dh_e, cli_ses.dh_x, &dh_f, hostkey);
93 mp_clear(&dh_f); 97 mp_clear(&dh_f);
98 mp_clear_multi(cli_ses.dh_e, cli_ses.dh_x, NULL);
99 m_free(cli_ses.dh_e);
100 m_free(cli_ses.dh_x);
94 101
95 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE) 102 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE)
96 != DROPBEAR_SUCCESS) { 103 != DROPBEAR_SUCCESS) {
97 dropbear_exit("Bad hostkey signature"); 104 dropbear_exit("Bad hostkey signature");
98 } 105 }