Mercurial > dropbear
comparison cli-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 | 91939c8c2572 |
children | 2b1bb792cd4d |
comparison
equal
deleted
inserted
replaced
518:ce104c8b0be1 | 640:76097ec1a29a |
---|---|
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 | 45 |
46 cli_ses.dh_e = (mp_int*)m_malloc(sizeof(mp_int)); | 46 cli_ses.dh_e = (fp_int*)m_malloc(sizeof(fp_int)); |
47 cli_ses.dh_x = (mp_int*)m_malloc(sizeof(mp_int)); | 47 cli_ses.dh_x = (fp_int*)m_malloc(sizeof(fp_int)); |
48 m_mp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); | 48 m_fp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); |
49 | 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_putfpint(ses.writepayload, cli_ses.dh_e); |
55 encrypt_packet(); | 55 encrypt_packet(); |
56 ses.requirenext = SSH_MSG_KEXDH_REPLY; | 56 ses.requirenext = SSH_MSG_KEXDH_REPLY; |
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 DEF_MP_INT(dh_f); | 62 DEF_FP_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 | 69 |
70 if (cli_ses.kex_state != KEXDH_INIT_SENT) { | 70 if (cli_ses.kex_state != KEXDH_INIT_SENT) { |
71 dropbear_exit("Received out-of-order kexdhreply"); | 71 dropbear_exit("Received out-of-order kexdhreply"); |
72 } | 72 } |
73 m_mp_init(&dh_f); | 73 m_fp_init(&dh_f); |
74 type = ses.newkeys->algo_hostkey; | 74 type = ses.newkeys->algo_hostkey; |
75 TRACE(("type is %d", type)) | 75 TRACE(("type is %d", type)) |
76 | 76 |
77 hostkey = new_sign_key(); | 77 hostkey = new_sign_key(); |
78 keybloblen = buf_getint(ses.payload); | 78 keybloblen = buf_getint(ses.payload); |
86 if (buf_get_pub_key(ses.payload, hostkey, &type) != DROPBEAR_SUCCESS) { | 86 if (buf_get_pub_key(ses.payload, hostkey, &type) != DROPBEAR_SUCCESS) { |
87 TRACE(("failed getting pubkey")) | 87 TRACE(("failed getting pubkey")) |
88 dropbear_exit("Bad KEX packet"); | 88 dropbear_exit("Bad KEX packet"); |
89 } | 89 } |
90 | 90 |
91 if (buf_getmpint(ses.payload, &dh_f) != DROPBEAR_SUCCESS) { | 91 if (buf_getfpint(ses.payload, &dh_f) != DROPBEAR_SUCCESS) { |
92 TRACE(("failed getting mpint")) | 92 TRACE(("failed getting fpint")) |
93 dropbear_exit("Bad KEX packet"); | 93 dropbear_exit("Bad KEX packet"); |
94 } | 94 } |
95 | 95 |
96 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); |
97 mp_clear(&dh_f); | 97 fp_zero(&dh_f); |
98 mp_clear_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); | 98 fp_zero(cli_ses.dh_e); |
99 fp_zero(cli_ses.dh_x); | |
99 m_free(cli_ses.dh_e); | 100 m_free(cli_ses.dh_e); |
100 m_free(cli_ses.dh_x); | 101 m_free(cli_ses.dh_x); |
101 | 102 |
102 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE) | 103 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE) |
103 != DROPBEAR_SUCCESS) { | 104 != DROPBEAR_SUCCESS) { |