comparison common-kex.c @ 641:2b1bb792cd4d dropbear-tfm

- Update tfm changes to current default tip
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:52:28 +0800
parents 76097ec1a29a 3aa74a4d83ae
children 33fd2f3499d2
comparison
equal deleted inserted replaced
640:76097ec1a29a 641:2b1bb792cd4d
31 #include "kex.h" 31 #include "kex.h"
32 #include "ssh.h" 32 #include "ssh.h"
33 #include "packet.h" 33 #include "packet.h"
34 #include "bignum.h" 34 #include "bignum.h"
35 #include "random.h" 35 #include "random.h"
36 #include "runopts.h"
36 37
37 /* diffie-hellman-group1-sha1 value for p */ 38 /* diffie-hellman-group1-sha1 value for p */
38 static const unsigned char dh_p_val[] = { 39 #define DH_P_1_LEN 128
40 static const unsigned char dh_p_1[DH_P_1_LEN] = {
39 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 41 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
40 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 42 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
41 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 43 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
42 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 44 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
43 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 45 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
45 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9, 47 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
46 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 48 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
47 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 49 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
48 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81, 50 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81,
49 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 51 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
50 #define DH_P_LEN sizeof(dh_p_val) 52
51 53 /* diffie-hellman-group14-sha1 value for p */
54 #define DH_P_14_LEN 256
55 static const unsigned char dh_p_14[DH_P_14_LEN] = {
56 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
57 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
58 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
59 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
60 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
61 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
62 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
63 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
64 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
65 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
66 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36,
67 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
68 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56,
69 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
70 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08,
71 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
72 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2,
73 0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
74 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C,
75 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10,
76 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF,
77 0xFF, 0xFF, 0xFF, 0xFF};
78
79 /* Same for group1 and group14 */
52 static const int DH_G_VAL = 2; 80 static const int DH_G_VAL = 2;
53 81
54 static void kexinitialise(); 82 static void kexinitialise();
55 void gen_new_keys(); 83 void gen_new_keys();
56 #ifndef DISABLE_ZLIB 84 #ifndef DISABLE_ZLIB
89 117
90 /* mac_algorithms_server_to_client */ 118 /* mac_algorithms_server_to_client */
91 buf_put_algolist(ses.writepayload, sshhashes); 119 buf_put_algolist(ses.writepayload, sshhashes);
92 120
93 /* compression_algorithms_client_to_server */ 121 /* compression_algorithms_client_to_server */
94 buf_put_algolist(ses.writepayload, sshcompress); 122 buf_put_algolist(ses.writepayload, ses.compress_algos);
95 123
96 /* compression_algorithms_server_to_client */ 124 /* compression_algorithms_server_to_client */
97 buf_put_algolist(ses.writepayload, sshcompress); 125 buf_put_algolist(ses.writepayload, ses.compress_algos);
98 126
99 /* languages_client_to_server */ 127 /* languages_client_to_server */
100 buf_putstring(ses.writepayload, "", 0); 128 buf_putstring(ses.writepayload, "", 0);
101 129
102 /* languages_server_to_client */ 130 /* languages_server_to_client */
178 } 206 }
179 207
180 208
181 /* Set up the kex for the first time */ 209 /* Set up the kex for the first time */
182 void kexfirstinitialise() { 210 void kexfirstinitialise() {
183
184 ses.kexstate.donefirstkex = 0; 211 ses.kexstate.donefirstkex = 0;
212
213 #ifndef DISABLE_ZLIB
214 if (opts.enable_compress) {
215 ses.compress_algos = ssh_compress;
216 } else
217 #endif
218 {
219 ses.compress_algos = ssh_nocompress;
220 }
185 kexinitialise(); 221 kexinitialise();
186 } 222 }
187 223
188 /* Reset the kex state, ready for a new negotiation */ 224 /* Reset the kex state, ready for a new negotiation */
189 static void kexinitialise() { 225 static void kexinitialise() {
234 memcpy(&out[SHA1_HASH_SIZE], k2, outlen - SHA1_HASH_SIZE); 270 memcpy(&out[SHA1_HASH_SIZE], k2, outlen - SHA1_HASH_SIZE);
235 } 271 }
236 } 272 }
237 273
238 /* Generate the actual encryption/integrity keys, using the results of the 274 /* Generate the actual encryption/integrity keys, using the results of the
239 * key exchange, as specified in section 5.2 of the IETF secsh-transport 275 * key exchange, as specified in section 7.2 of the transport rfc 4253.
240 * draft. This occurs after the DH key-exchange. 276 * This occurs after the DH key-exchange.
241 * 277 *
242 * ses.newkeys is the new set of keys which are generated, these are only 278 * ses.newkeys is the new set of keys which are generated, these are only
243 * taken into use after both sides have sent a newkeys message */ 279 * taken into use after both sides have sent a newkeys message */
244 280
245 /* Originally from kex.c, generalized for cli/svr mode --mihnea */ 281 /* Originally from kex.c, generalized for cli/svr mode --mihnea */
270 if (IS_DROPBEAR_CLIENT) { 306 if (IS_DROPBEAR_CLIENT) {
271 trans_IV = C2S_IV; 307 trans_IV = C2S_IV;
272 recv_IV = S2C_IV; 308 recv_IV = S2C_IV;
273 trans_key = C2S_key; 309 trans_key = C2S_key;
274 recv_key = S2C_key; 310 recv_key = S2C_key;
275 C2S_keysize = ses.newkeys->trans_algo_crypt->keysize; 311 C2S_keysize = ses.newkeys->trans.algo_crypt->keysize;
276 S2C_keysize = ses.newkeys->recv_algo_crypt->keysize; 312 S2C_keysize = ses.newkeys->recv.algo_crypt->keysize;
277 mactransletter = 'E'; 313 mactransletter = 'E';
278 macrecvletter = 'F'; 314 macrecvletter = 'F';
279 } else { 315 } else {
280 trans_IV = S2C_IV; 316 trans_IV = S2C_IV;
281 recv_IV = C2S_IV; 317 recv_IV = C2S_IV;
282 trans_key = S2C_key; 318 trans_key = S2C_key;
283 recv_key = C2S_key; 319 recv_key = C2S_key;
284 C2S_keysize = ses.newkeys->recv_algo_crypt->keysize; 320 C2S_keysize = ses.newkeys->recv.algo_crypt->keysize;
285 S2C_keysize = ses.newkeys->trans_algo_crypt->keysize; 321 S2C_keysize = ses.newkeys->trans.algo_crypt->keysize;
286 mactransletter = 'F'; 322 mactransletter = 'F';
287 macrecvletter = 'E'; 323 macrecvletter = 'E';
288 } 324 }
289 325
290 hashkeys(C2S_IV, SHA1_HASH_SIZE, &hs, 'A'); 326 hashkeys(C2S_IV, SHA1_HASH_SIZE, &hs, 'A');
291 hashkeys(S2C_IV, SHA1_HASH_SIZE, &hs, 'B'); 327 hashkeys(S2C_IV, SHA1_HASH_SIZE, &hs, 'B');
292 hashkeys(C2S_key, C2S_keysize, &hs, 'C'); 328 hashkeys(C2S_key, C2S_keysize, &hs, 'C');
293 hashkeys(S2C_key, S2C_keysize, &hs, 'D'); 329 hashkeys(S2C_key, S2C_keysize, &hs, 'D');
294 330
295 recv_cipher = find_cipher(ses.newkeys->recv_algo_crypt->cipherdesc->name); 331 recv_cipher = find_cipher(ses.newkeys->recv.algo_crypt->cipherdesc->name);
296 if (recv_cipher < 0) 332 if (recv_cipher < 0)
297 dropbear_exit("crypto error"); 333 dropbear_exit("Crypto error");
298 if (ses.newkeys->recv_crypt_mode->start(recv_cipher, 334 if (ses.newkeys->recv.crypt_mode->start(recv_cipher,
299 recv_IV, recv_key, 335 recv_IV, recv_key,
300 ses.newkeys->recv_algo_crypt->keysize, 0, 336 ses.newkeys->recv.algo_crypt->keysize, 0,
301 &ses.newkeys->recv_cipher_state) != CRYPT_OK) { 337 &ses.newkeys->recv.cipher_state) != CRYPT_OK) {
302 dropbear_exit("crypto error"); 338 dropbear_exit("Crypto error");
303 } 339 }
304 340
305 trans_cipher = find_cipher(ses.newkeys->trans_algo_crypt->cipherdesc->name); 341 trans_cipher = find_cipher(ses.newkeys->trans.algo_crypt->cipherdesc->name);
306 if (trans_cipher < 0) 342 if (trans_cipher < 0)
307 dropbear_exit("crypto error"); 343 dropbear_exit("Crypto error");
308 if (ses.newkeys->trans_crypt_mode->start(trans_cipher, 344 if (ses.newkeys->trans.crypt_mode->start(trans_cipher,
309 trans_IV, trans_key, 345 trans_IV, trans_key,
310 ses.newkeys->trans_algo_crypt->keysize, 0, 346 ses.newkeys->trans.algo_crypt->keysize, 0,
311 &ses.newkeys->trans_cipher_state) != CRYPT_OK) { 347 &ses.newkeys->trans.cipher_state) != CRYPT_OK) {
312 dropbear_exit("crypto error"); 348 dropbear_exit("Crypto error");
313 } 349 }
314 350
315 /* MAC keys */ 351 /* MAC keys */
316 hashkeys(ses.newkeys->transmackey, 352 hashkeys(ses.newkeys->trans.mackey,
317 ses.newkeys->trans_algo_mac->keysize, &hs, mactransletter); 353 ses.newkeys->trans.algo_mac->keysize, &hs, mactransletter);
318 hashkeys(ses.newkeys->recvmackey, 354 hashkeys(ses.newkeys->recv.mackey,
319 ses.newkeys->recv_algo_mac->keysize, &hs, macrecvletter); 355 ses.newkeys->recv.algo_mac->keysize, &hs, macrecvletter);
356 ses.newkeys->trans.hash_index = find_hash(ses.newkeys->trans.algo_mac->hashdesc->name),
357 ses.newkeys->recv.hash_index = find_hash(ses.newkeys->recv.algo_mac->hashdesc->name),
320 358
321 #ifndef DISABLE_ZLIB 359 #ifndef DISABLE_ZLIB
322 gen_new_zstreams(); 360 gen_new_zstreams();
323 #endif 361 #endif
324 362
332 } 370 }
333 371
334 #ifndef DISABLE_ZLIB 372 #ifndef DISABLE_ZLIB
335 373
336 int is_compress_trans() { 374 int is_compress_trans() {
337 return ses.keys->trans_algo_comp == DROPBEAR_COMP_ZLIB 375 return ses.keys->trans.algo_comp == DROPBEAR_COMP_ZLIB
338 || (ses.authstate.authdone 376 || (ses.authstate.authdone
339 && ses.keys->trans_algo_comp == DROPBEAR_COMP_ZLIB_DELAY); 377 && ses.keys->trans.algo_comp == DROPBEAR_COMP_ZLIB_DELAY);
340 } 378 }
341 379
342 int is_compress_recv() { 380 int is_compress_recv() {
343 return ses.keys->recv_algo_comp == DROPBEAR_COMP_ZLIB 381 return ses.keys->recv.algo_comp == DROPBEAR_COMP_ZLIB
344 || (ses.authstate.authdone 382 || (ses.authstate.authdone
345 && ses.keys->recv_algo_comp == DROPBEAR_COMP_ZLIB_DELAY); 383 && ses.keys->recv.algo_comp == DROPBEAR_COMP_ZLIB_DELAY);
346 } 384 }
347 385
348 /* Set up new zlib compression streams, close the old ones. Only 386 /* Set up new zlib compression streams, close the old ones. Only
349 * called from gen_new_keys() */ 387 * called from gen_new_keys() */
350 static void gen_new_zstreams() { 388 static void gen_new_zstreams() {
351 389
352 /* create new zstreams */ 390 /* create new zstreams */
353 if (ses.newkeys->recv_algo_comp == DROPBEAR_COMP_ZLIB 391 if (ses.newkeys->recv.algo_comp == DROPBEAR_COMP_ZLIB
354 || ses.newkeys->recv_algo_comp == DROPBEAR_COMP_ZLIB_DELAY) { 392 || ses.newkeys->recv.algo_comp == DROPBEAR_COMP_ZLIB_DELAY) {
355 ses.newkeys->recv_zstream = (z_streamp)m_malloc(sizeof(z_stream)); 393 ses.newkeys->recv.zstream = (z_streamp)m_malloc(sizeof(z_stream));
356 ses.newkeys->recv_zstream->zalloc = Z_NULL; 394 ses.newkeys->recv.zstream->zalloc = Z_NULL;
357 ses.newkeys->recv_zstream->zfree = Z_NULL; 395 ses.newkeys->recv.zstream->zfree = Z_NULL;
358 396
359 if (inflateInit(ses.newkeys->recv_zstream) != Z_OK) { 397 if (inflateInit(ses.newkeys->recv.zstream) != Z_OK) {
360 dropbear_exit("zlib error"); 398 dropbear_exit("zlib error");
361 } 399 }
362 } else { 400 } else {
363 ses.newkeys->recv_zstream = NULL; 401 ses.newkeys->recv.zstream = NULL;
364 } 402 }
365 403
366 if (ses.newkeys->trans_algo_comp == DROPBEAR_COMP_ZLIB 404 if (ses.newkeys->trans.algo_comp == DROPBEAR_COMP_ZLIB
367 || ses.newkeys->trans_algo_comp == DROPBEAR_COMP_ZLIB_DELAY) { 405 || ses.newkeys->trans.algo_comp == DROPBEAR_COMP_ZLIB_DELAY) {
368 ses.newkeys->trans_zstream = (z_streamp)m_malloc(sizeof(z_stream)); 406 ses.newkeys->trans.zstream = (z_streamp)m_malloc(sizeof(z_stream));
369 ses.newkeys->trans_zstream->zalloc = Z_NULL; 407 ses.newkeys->trans.zstream->zalloc = Z_NULL;
370 ses.newkeys->trans_zstream->zfree = Z_NULL; 408 ses.newkeys->trans.zstream->zfree = Z_NULL;
371 409
372 if (deflateInit(ses.newkeys->trans_zstream, Z_DEFAULT_COMPRESSION) 410 if (deflateInit2(ses.newkeys->trans.zstream, Z_DEFAULT_COMPRESSION,
411 Z_DEFLATED, DROPBEAR_ZLIB_WINDOW_BITS,
412 DROPBEAR_ZLIB_MEM_LEVEL, Z_DEFAULT_STRATEGY)
373 != Z_OK) { 413 != Z_OK) {
374 dropbear_exit("zlib error"); 414 dropbear_exit("zlib error");
375 } 415 }
376 } else { 416 } else {
377 ses.newkeys->trans_zstream = NULL; 417 ses.newkeys->trans.zstream = NULL;
378 } 418 }
379 419
380 /* clean up old keys */ 420 /* clean up old keys */
381 if (ses.keys->recv_zstream != NULL) { 421 if (ses.keys->recv.zstream != NULL) {
382 if (inflateEnd(ses.keys->recv_zstream) == Z_STREAM_ERROR) { 422 if (inflateEnd(ses.keys->recv.zstream) == Z_STREAM_ERROR) {
383 /* Z_DATA_ERROR is ok, just means that stream isn't ended */ 423 /* Z_DATA_ERROR is ok, just means that stream isn't ended */
384 dropbear_exit("crypto error"); 424 dropbear_exit("Crypto error");
385 } 425 }
386 m_free(ses.keys->recv_zstream); 426 m_free(ses.keys->recv.zstream);
387 } 427 }
388 if (ses.keys->trans_zstream != NULL) { 428 if (ses.keys->trans.zstream != NULL) {
389 if (deflateEnd(ses.keys->trans_zstream) == Z_STREAM_ERROR) { 429 if (deflateEnd(ses.keys->trans.zstream) == Z_STREAM_ERROR) {
390 /* Z_DATA_ERROR is ok, just means that stream isn't ended */ 430 /* Z_DATA_ERROR is ok, just means that stream isn't ended */
391 dropbear_exit("crypto error"); 431 dropbear_exit("Crypto error");
392 } 432 }
393 m_free(ses.keys->trans_zstream); 433 m_free(ses.keys->trans.zstream);
394 } 434 }
395 } 435 }
396 #endif /* DISABLE_ZLIB */ 436 #endif /* DISABLE_ZLIB */
397 437
398 438
477 ses.kexstate.recvkexinit = 1; 517 ses.kexstate.recvkexinit = 1;
478 518
479 TRACE(("leave recv_msg_kexinit")) 519 TRACE(("leave recv_msg_kexinit"))
480 } 520 }
481 521
522 static void load_dh_p(mp_int * dh_p)
523 {
524 switch (ses.newkeys->algo_kex) {
525 case DROPBEAR_KEX_DH_GROUP1:
526 bytes_to_fp(dh_p, dh_p_1, DH_P_1_LEN);
527 break;
528 case DROPBEAR_KEX_DH_GROUP14:
529 bytes_to_fp(dh_p, dh_p_14, DH_P_14_LEN);
530 break;
531 }
532 }
533
482 /* Initialises and generate one side of the diffie-hellman key exchange values. 534 /* Initialises and generate one side of the diffie-hellman key exchange values.
483 * See the ietf-secsh-transport draft, section 6, for details */ 535 * See the transport rfc 4253 section 8 for details */
484 /* dh_pub and dh_priv MUST be already initialised */ 536 /* dh_pub and dh_priv MUST be already initialised */
485 void gen_kexdh_vals(fp_int *dh_pub, fp_int *dh_priv) { 537 void gen_kexdh_vals(fp_int *dh_pub, fp_int *dh_priv) {
486 538
487 DEF_FP_INT(dh_p); 539 DEF_FP_INT(dh_p);
488 DEF_FP_INT(dh_q); 540 DEF_FP_INT(dh_q);
491 TRACE(("enter send_msg_kexdh_reply")) 543 TRACE(("enter send_msg_kexdh_reply"))
492 544
493 m_fp_init_multi(&dh_g, &dh_p, &dh_q, NULL); 545 m_fp_init_multi(&dh_g, &dh_p, &dh_q, NULL);
494 546
495 /* read the prime and generator*/ 547 /* read the prime and generator*/
496 bytes_to_fp(&dh_p, (unsigned char*)dh_p_val, DH_P_LEN); 548 load_dh_p(&dh_p);
497 549
498 fp_set(&dh_g, DH_G_VAL); 550 fp_set(&dh_g, DH_G_VAL);
499 551
500 /* calculate q = (p-1)/2 */ 552 /* calculate q = (p-1)/2 */
501 /* dh_priv is just a temp var here */ 553 /* dh_priv is just a temp var here */
524 fp_int *dh_e = NULL, *dh_f = NULL; 576 fp_int *dh_e = NULL, *dh_f = NULL;
525 hash_state hs; 577 hash_state hs;
526 578
527 /* read the prime and generator*/ 579 /* read the prime and generator*/
528 m_fp_init(&dh_p); 580 m_fp_init(&dh_p);
529 bytes_to_fp(&dh_p, dh_p_val, DH_P_LEN); 581 load_dh_p(&dh_p);
530 582
531 /* Check that dh_pub_them (dh_e or dh_f) is in the range [1, p-1] */ 583 /* Check that dh_pub_them (dh_e or dh_f) is in the range [1, p-1] */
532 if (fp_cmp(dh_pub_them, &dh_p) != FP_LT 584 if (fp_cmp(dh_pub_them, &dh_p) != FP_LT
533 || fp_cmp_d(dh_pub_them, 0) != FP_GT) { 585 || fp_cmp_d(dh_pub_them, 0) != FP_GT) {
534 dropbear_exit("Diffie-Hellman error"); 586 dropbear_exit("Diffie-Hellman error");
659 goto error; 711 goto error;
660 } 712 }
661 TRACE(("hash s2c is %s", s2c_hash_algo->name)) 713 TRACE(("hash s2c is %s", s2c_hash_algo->name))
662 714
663 /* compression_algorithms_client_to_server */ 715 /* compression_algorithms_client_to_server */
716 <<<<<<< mine
664 c2s_cofp_algo = ses.buf_match_algo(ses.payload, sshcompress, &goodguess); 717 c2s_cofp_algo = ses.buf_match_algo(ses.payload, sshcompress, &goodguess);
665 if (c2s_cofp_algo == NULL) { 718 if (c2s_cofp_algo == NULL) {
719 =======
720 c2s_comp_algo = ses.buf_match_algo(ses.payload, ses.compress_algos, &goodguess);
721 if (c2s_comp_algo == NULL) {
722 >>>>>>> theirs
666 erralgo = "comp c->s"; 723 erralgo = "comp c->s";
667 goto error; 724 goto error;
668 } 725 }
669 TRACE(("hash c2s is %s", c2s_cofp_algo->name)) 726 TRACE(("hash c2s is %s", c2s_cofp_algo->name))
670 727
671 /* compression_algorithms_server_to_client */ 728 /* compression_algorithms_server_to_client */
729 <<<<<<< mine
672 s2c_cofp_algo = ses.buf_match_algo(ses.payload, sshcompress, &goodguess); 730 s2c_cofp_algo = ses.buf_match_algo(ses.payload, sshcompress, &goodguess);
673 if (s2c_cofp_algo == NULL) { 731 if (s2c_cofp_algo == NULL) {
732 =======
733 s2c_comp_algo = ses.buf_match_algo(ses.payload, ses.compress_algos, &goodguess);
734 if (s2c_comp_algo == NULL) {
735 >>>>>>> theirs
674 erralgo = "comp s->c"; 736 erralgo = "comp s->c";
675 goto error; 737 goto error;
676 } 738 }
677 TRACE(("hash s2c is %s", s2c_cofp_algo->name)) 739 TRACE(("hash s2c is %s", s2c_cofp_algo->name))
678 740
691 } 753 }
692 } 754 }
693 755
694 /* Handle the asymmetry */ 756 /* Handle the asymmetry */
695 if (IS_DROPBEAR_CLIENT) { 757 if (IS_DROPBEAR_CLIENT) {
696 ses.newkeys->recv_algo_crypt = 758 ses.newkeys->recv.algo_crypt =
697 (struct dropbear_cipher*)s2c_cipher_algo->data; 759 (struct dropbear_cipher*)s2c_cipher_algo->data;
698 ses.newkeys->trans_algo_crypt = 760 ses.newkeys->trans.algo_crypt =
699 (struct dropbear_cipher*)c2s_cipher_algo->data; 761 (struct dropbear_cipher*)c2s_cipher_algo->data;
700 ses.newkeys->recv_crypt_mode = 762 ses.newkeys->recv.crypt_mode =
701 (struct dropbear_cipher_mode*)s2c_cipher_algo->mode; 763 (struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
702 ses.newkeys->trans_crypt_mode = 764 ses.newkeys->trans.crypt_mode =
703 (struct dropbear_cipher_mode*)c2s_cipher_algo->mode; 765 (struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
704 ses.newkeys->recv_algo_mac = 766 ses.newkeys->recv.algo_mac =
705 (struct dropbear_hash*)s2c_hash_algo->data; 767 (struct dropbear_hash*)s2c_hash_algo->data;
706 ses.newkeys->trans_algo_mac = 768 ses.newkeys->trans.algo_mac =
707 (struct dropbear_hash*)c2s_hash_algo->data; 769 (struct dropbear_hash*)c2s_hash_algo->data;
770 <<<<<<< mine
708 ses.newkeys->recv_algo_comp = s2c_cofp_algo->val; 771 ses.newkeys->recv_algo_comp = s2c_cofp_algo->val;
709 ses.newkeys->trans_algo_comp = c2s_cofp_algo->val; 772 ses.newkeys->trans_algo_comp = c2s_cofp_algo->val;
773 =======
774 ses.newkeys->recv.algo_comp = s2c_comp_algo->val;
775 ses.newkeys->trans.algo_comp = c2s_comp_algo->val;
776 >>>>>>> theirs
710 } else { 777 } else {
711 /* SERVER */ 778 /* SERVER */
712 ses.newkeys->recv_algo_crypt = 779 ses.newkeys->recv.algo_crypt =
713 (struct dropbear_cipher*)c2s_cipher_algo->data; 780 (struct dropbear_cipher*)c2s_cipher_algo->data;
714 ses.newkeys->trans_algo_crypt = 781 ses.newkeys->trans.algo_crypt =
715 (struct dropbear_cipher*)s2c_cipher_algo->data; 782 (struct dropbear_cipher*)s2c_cipher_algo->data;
716 ses.newkeys->recv_crypt_mode = 783 ses.newkeys->recv.crypt_mode =
717 (struct dropbear_cipher_mode*)c2s_cipher_algo->mode; 784 (struct dropbear_cipher_mode*)c2s_cipher_algo->mode;
718 ses.newkeys->trans_crypt_mode = 785 ses.newkeys->trans.crypt_mode =
719 (struct dropbear_cipher_mode*)s2c_cipher_algo->mode; 786 (struct dropbear_cipher_mode*)s2c_cipher_algo->mode;
720 ses.newkeys->recv_algo_mac = 787 ses.newkeys->recv.algo_mac =
721 (struct dropbear_hash*)c2s_hash_algo->data; 788 (struct dropbear_hash*)c2s_hash_algo->data;
722 ses.newkeys->trans_algo_mac = 789 ses.newkeys->trans.algo_mac =
723 (struct dropbear_hash*)s2c_hash_algo->data; 790 (struct dropbear_hash*)s2c_hash_algo->data;
791 <<<<<<< mine
724 ses.newkeys->recv_algo_comp = c2s_cofp_algo->val; 792 ses.newkeys->recv_algo_comp = c2s_cofp_algo->val;
725 ses.newkeys->trans_algo_comp = s2c_cofp_algo->val; 793 ses.newkeys->trans_algo_comp = s2c_cofp_algo->val;
794 =======
795 ses.newkeys->recv.algo_comp = c2s_comp_algo->val;
796 ses.newkeys->trans.algo_comp = s2c_comp_algo->val;
797 >>>>>>> theirs
726 } 798 }
727 799
728 /* reserved for future extensions */ 800 /* reserved for future extensions */
729 buf_getint(ses.payload); 801 buf_getint(ses.payload);
730 return; 802 return;
731 803
732 error: 804 error:
733 dropbear_exit("no matching algo %s", erralgo); 805 dropbear_exit("No matching algo %s", erralgo);
734 } 806 }