comparison svr-kex.c @ 640:76097ec1a29a dropbear-tfm

- Bring in original tomsfastmath patch against 0.52 from Peter Turczak in 2008
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:19:57 +0800
parents 454a34b2dfd1
children 2b1bb792cd4d
comparison
equal deleted inserted replaced
518:ce104c8b0be1 640:76097ec1a29a
34 #include "bignum.h" 34 #include "bignum.h"
35 #include "random.h" 35 #include "random.h"
36 #include "runopts.h" 36 #include "runopts.h"
37 37
38 38
39 static void send_msg_kexdh_reply(mp_int *dh_e); 39 static void send_msg_kexdh_reply(fp_int *dh_e);
40 40
41 /* Handle a diffie-hellman key exchange initialisation. This involves 41 /* Handle a diffie-hellman key exchange initialisation. This involves
42 * calculating a session key reply value, and corresponding hash. These 42 * calculating a session key reply value, and corresponding hash. These
43 * are carried out by send_msg_kexdh_reply(). recv_msg_kexdh_init() calls 43 * are carried out by send_msg_kexdh_reply(). recv_msg_kexdh_init() calls
44 * that function, then brings the new keys into use */ 44 * that function, then brings the new keys into use */
45 void recv_msg_kexdh_init() { 45 void recv_msg_kexdh_init() {
46 46
47 DEF_MP_INT(dh_e); 47 DEF_FP_INT(dh_e);
48 48
49 TRACE(("enter recv_msg_kexdh_init")) 49 TRACE(("enter recv_msg_kexdh_init"))
50 if (!ses.kexstate.recvkexinit) { 50 if (!ses.kexstate.recvkexinit) {
51 dropbear_exit("Premature kexdh_init message received"); 51 dropbear_exit("Premature kexdh_init message received");
52 } 52 }
53 53
54 m_mp_init(&dh_e); 54 m_fp_init(&dh_e);
55 if (buf_getmpint(ses.payload, &dh_e) != DROPBEAR_SUCCESS) { 55 if (buf_getfpint(ses.payload, &dh_e) != DROPBEAR_SUCCESS) {
56 dropbear_exit("Failed to get kex value"); 56 dropbear_exit("Failed to get kex value");
57 } 57 }
58 58
59 send_msg_kexdh_reply(&dh_e); 59 send_msg_kexdh_reply(&dh_e);
60 60
61 mp_clear(&dh_e); 61 fp_zero(&dh_e);
62 62
63 send_msg_newkeys(); 63 send_msg_newkeys();
64 ses.requirenext = SSH_MSG_NEWKEYS; 64 ses.requirenext = SSH_MSG_NEWKEYS;
65 TRACE(("leave recv_msg_kexdh_init")) 65 TRACE(("leave recv_msg_kexdh_init"))
66 } 66 }
69 * calculate the session key using the diffie-hellman algorithm. Following 69 * calculate the session key using the diffie-hellman algorithm. Following
70 * that, the session hash is calculated, and signed with RSA or DSS. The 70 * that, the session hash is calculated, and signed with RSA or DSS. The
71 * result is sent to the client. 71 * result is sent to the client.
72 * 72 *
73 * See the ietf-secsh-transport draft, section 6, for details */ 73 * See the ietf-secsh-transport draft, section 6, for details */
74 static void send_msg_kexdh_reply(mp_int *dh_e) { 74 static void send_msg_kexdh_reply(fp_int *dh_e) {
75 75
76 DEF_MP_INT(dh_y); 76 DEF_FP_INT(dh_y);
77 DEF_MP_INT(dh_f); 77 DEF_FP_INT(dh_f);
78 78
79 TRACE(("enter send_msg_kexdh_reply")) 79 TRACE(("enter send_msg_kexdh_reply"))
80 m_mp_init_multi(&dh_y, &dh_f, NULL); 80 m_fp_init_multi(&dh_y, &dh_f, NULL);
81 81
82 gen_kexdh_vals(&dh_f, &dh_y); 82 gen_kexdh_vals(&dh_f, &dh_y);
83 83
84 kexdh_comb_key(&dh_f, &dh_y, dh_e, svr_opts.hostkey); 84 kexdh_comb_key(&dh_f, &dh_y, dh_e, svr_opts.hostkey);
85 mp_clear(&dh_y); 85 fp_zero(&dh_y);
86 86
87 /* we can start creating the kexdh_reply packet */ 87 /* we can start creating the kexdh_reply packet */
88 CHECKCLEARTOWRITE(); 88 CHECKCLEARTOWRITE();
89 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY); 89 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY);
90 buf_put_pub_key(ses.writepayload, svr_opts.hostkey, 90 buf_put_pub_key(ses.writepayload, svr_opts.hostkey,
91 ses.newkeys->algo_hostkey); 91 ses.newkeys->algo_hostkey);
92 92
93 /* put f */ 93 /* put f */
94 buf_putmpint(ses.writepayload, &dh_f); 94 buf_putfpint(ses.writepayload, &dh_f);
95 mp_clear(&dh_f); 95 fp_zero(&dh_f);
96 96
97 /* calc the signature */ 97 /* calc the signature */
98 buf_put_sign(ses.writepayload, svr_opts.hostkey, 98 buf_put_sign(ses.writepayload, svr_opts.hostkey,
99 ses.newkeys->algo_hostkey, ses.hash, SHA1_HASH_SIZE); 99 ses.newkeys->algo_hostkey, ses.hash, SHA1_HASH_SIZE);
100 100