Mercurial > dropbear
comparison svr-kex.c @ 848:6c69e7df3621 ecc
curve25519
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 08 Nov 2013 23:11:43 +0800 |
parents | 7dcb46da72d9 |
children | 754d7bee1068 |
comparison
equal
deleted
inserted
replaced
845:774ad9b112ef | 848:6c69e7df3621 |
---|---|
50 TRACE(("enter recv_msg_kexdh_init")) | 50 TRACE(("enter recv_msg_kexdh_init")) |
51 if (!ses.kexstate.recvkexinit) { | 51 if (!ses.kexstate.recvkexinit) { |
52 dropbear_exit("Premature kexdh_init message received"); | 52 dropbear_exit("Premature kexdh_init message received"); |
53 } | 53 } |
54 | 54 |
55 if (IS_NORMAL_DH(ses.newkeys->algo_kex)) { | 55 switch (ses.newkeys->algo_kex->mode) { |
56 m_mp_init(&dh_e); | 56 case DROPBEAR_KEX_NORMAL_DH: |
57 if (buf_getmpint(ses.payload, &dh_e) != DROPBEAR_SUCCESS) { | 57 m_mp_init(&dh_e); |
58 dropbear_exit("Failed to get kex value"); | 58 if (buf_getmpint(ses.payload, &dh_e) != DROPBEAR_SUCCESS) { |
59 } | 59 dropbear_exit("Bad kex value"); |
60 } else { | 60 } |
61 #ifdef DROPBEAR_ECDH | 61 break; |
62 ecdh_qs = buf_getstringbuf(ses.payload); | 62 case DROPBEAR_KEX_ECDH: |
63 case DROPBEAR_KEX_CURVE25519: | |
64 #if defined(DROPBEAR_ECDH) || defined(DROPBEAR_CURVE25519) | |
65 ecdh_qs = buf_getstringbuf(ses.payload); | |
66 if (ses.payload->pos != ses.payload->len) { | |
67 dropbear_exit("Bad kex value"); | |
68 } | |
63 #endif | 69 #endif |
70 break; | |
64 } | 71 } |
65 | 72 |
66 send_msg_kexdh_reply(&dh_e, ecdh_qs); | 73 send_msg_kexdh_reply(&dh_e, ecdh_qs); |
67 | 74 |
68 mp_clear(&dh_e); | 75 mp_clear(&dh_e); |
90 CHECKCLEARTOWRITE(); | 97 CHECKCLEARTOWRITE(); |
91 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY); | 98 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY); |
92 buf_put_pub_key(ses.writepayload, svr_opts.hostkey, | 99 buf_put_pub_key(ses.writepayload, svr_opts.hostkey, |
93 ses.newkeys->algo_hostkey); | 100 ses.newkeys->algo_hostkey); |
94 | 101 |
95 if (IS_NORMAL_DH(ses.newkeys->algo_kex)) { | 102 switch (ses.newkeys->algo_kex->mode) { |
96 // Normal diffie-hellman | 103 case DROPBEAR_KEX_NORMAL_DH: |
97 struct kex_dh_param * dh_param = gen_kexdh_param(); | 104 { |
98 kexdh_comb_key(dh_param, dh_e, svr_opts.hostkey); | 105 struct kex_dh_param * dh_param = gen_kexdh_param(); |
106 kexdh_comb_key(dh_param, dh_e, svr_opts.hostkey); | |
99 | 107 |
100 /* put f */ | 108 /* put f */ |
101 buf_putmpint(ses.writepayload, &dh_param->pub); | 109 buf_putmpint(ses.writepayload, &dh_param->pub); |
102 free_kexdh_param(dh_param); | 110 free_kexdh_param(dh_param); |
103 } else { | 111 } |
112 break; | |
113 case DROPBEAR_KEX_ECDH: | |
104 #ifdef DROPBEAR_ECDH | 114 #ifdef DROPBEAR_ECDH |
105 struct kex_ecdh_param *ecdh_param = gen_kexecdh_param(); | 115 { |
106 kexecdh_comb_key(ecdh_param, ecdh_qs, svr_opts.hostkey); | 116 struct kex_ecdh_param *ecdh_param = gen_kexecdh_param(); |
117 kexecdh_comb_key(ecdh_param, ecdh_qs, svr_opts.hostkey); | |
107 | 118 |
108 buf_put_ecc_raw_pubkey_string(ses.writepayload, &ecdh_param->key); | 119 buf_put_ecc_raw_pubkey_string(ses.writepayload, &ecdh_param->key); |
109 free_kexecdh_param(ecdh_param); | 120 free_kexecdh_param(ecdh_param); |
121 } | |
110 #endif | 122 #endif |
123 break; | |
124 case DROPBEAR_KEX_CURVE25519: | |
125 #ifdef DROPBEAR_CURVE25519 | |
126 { | |
127 struct kex_curve25519_param *param = gen_kexecdh_param(); | |
128 kexcurve25519_comb_key(param, ecdh_qs, svr_opts.hostkey); | |
129 buf_putstring(ses.writepayload, param->priv, CURVE25519_LEN); | |
130 free_kexcurve25519_param(param); | |
131 } | |
132 #endif | |
133 break; | |
111 } | 134 } |
112 | 135 |
113 /* calc the signature */ | 136 /* calc the signature */ |
114 buf_put_sign(ses.writepayload, svr_opts.hostkey, | 137 buf_put_sign(ses.writepayload, svr_opts.hostkey, |
115 ses.newkeys->algo_hostkey, ses.hash); | 138 ses.newkeys->algo_hostkey, ses.hash); |