comparison common-kex.c @ 1256:506f7681d0f8 coverity

merge up to date
author Matt Johnston <matt@ucc.asn.au>
date Tue, 15 Mar 2016 22:45:43 +0800
parents 52a456a3add0
children 9169e4e7cbee
comparison
equal deleted inserted replaced
1219:84cf9062718d 1256:506f7681d0f8
27 #include "dbutil.h" 27 #include "dbutil.h"
28 #include "algo.h" 28 #include "algo.h"
29 #include "buffer.h" 29 #include "buffer.h"
30 #include "session.h" 30 #include "session.h"
31 #include "kex.h" 31 #include "kex.h"
32 #include "dh_groups.h"
32 #include "ssh.h" 33 #include "ssh.h"
33 #include "packet.h" 34 #include "packet.h"
34 #include "bignum.h" 35 #include "bignum.h"
35 #include "dbrandom.h" 36 #include "dbrandom.h"
36 #include "runopts.h" 37 #include "runopts.h"
37 #include "ecc.h" 38 #include "ecc.h"
38 #include "crypto_desc.h" 39 #include "crypto_desc.h"
39
40 /* diffie-hellman-group1-sha1 value for p */
41 const unsigned char dh_p_1[DH_P_1_LEN] = {
42 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2,
43 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
44 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
45 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
46 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D,
47 0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
48 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
49 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
50 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
51 0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE6, 0x53, 0x81,
52 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
53
54 /* diffie-hellman-group14-sha1 value for p */
55 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 */
80 static const int DH_G_VAL = 2;
81 40
82 static void kexinitialise(); 41 static void kexinitialise();
83 static void gen_new_keys(); 42 static void gen_new_keys();
84 #ifndef DISABLE_ZLIB 43 #ifndef DISABLE_ZLIB
85 static void gen_new_zstream_recv(); 44 static void gen_new_zstream_recv();
347 buf_burn(ses.hash); 306 buf_burn(ses.hash);
348 buf_free(ses.hash); 307 buf_free(ses.hash);
349 ses.hash = NULL; 308 ses.hash = NULL;
350 309
351 if (IS_DROPBEAR_CLIENT) { 310 if (IS_DROPBEAR_CLIENT) {
352 trans_IV = C2S_IV; 311 trans_IV = C2S_IV;
353 recv_IV = S2C_IV; 312 recv_IV = S2C_IV;
354 trans_key = C2S_key; 313 trans_key = C2S_key;
355 recv_key = S2C_key; 314 recv_key = S2C_key;
356 mactransletter = 'E'; 315 mactransletter = 'E';
357 macrecvletter = 'F'; 316 macrecvletter = 'F';
358 } else { 317 } else {
359 trans_IV = S2C_IV; 318 trans_IV = S2C_IV;
360 recv_IV = C2S_IV; 319 recv_IV = C2S_IV;
361 trans_key = S2C_key; 320 trans_key = S2C_key;
362 recv_key = C2S_key; 321 recv_key = C2S_key;
363 mactransletter = 'F'; 322 mactransletter = 'F';
364 macrecvletter = 'E'; 323 macrecvletter = 'E';
365 } 324 }
366 325
367 hashkeys(C2S_IV, sizeof(C2S_IV), &hs, 'A'); 326 hashkeys(C2S_IV, sizeof(C2S_IV), &hs, 'A');
523 482
524 /* read the peer's choice of algos */ 483 /* read the peer's choice of algos */
525 read_kex_algos(); 484 read_kex_algos();
526 485
527 /* V_C, the client's version string (CR and NL excluded) */ 486 /* V_C, the client's version string (CR and NL excluded) */
528 buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len); 487 buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
529 /* V_S, the server's version string (CR and NL excluded) */ 488 /* V_S, the server's version string (CR and NL excluded) */
530 buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); 489 buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
531 490
532 /* I_C, the payload of the client's SSH_MSG_KEXINIT */ 491 /* I_C, the payload of the client's SSH_MSG_KEXINIT */
533 buf_putstring(ses.kexhashbuf, 492 buf_putstring(ses.kexhashbuf,
534 (const char*)ses.transkexinit->data, ses.transkexinit->len); 493 (const char*)ses.transkexinit->data, ses.transkexinit->len);
535 /* I_S, the payload of the server's SSH_MSG_KEXINIT */ 494 /* I_S, the payload of the server's SSH_MSG_KEXINIT */
536 buf_setpos(ses.payload, ses.payload_beginning); 495 buf_setpos(ses.payload, ses.payload_beginning);
537 buf_putstring(ses.kexhashbuf, 496 buf_putstring(ses.kexhashbuf,
538 (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos), 497 (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
539 ses.payload->len-ses.payload->pos); 498 ses.payload->len-ses.payload->pos);
540 ses.requirenext = SSH_MSG_KEXDH_REPLY; 499 ses.requirenext = SSH_MSG_KEXDH_REPLY;
541 } else { 500 } else {
542 /* SERVER */ 501 /* SERVER */
543 502
544 /* read the peer's choice of algos */ 503 /* read the peer's choice of algos */
545 read_kex_algos(); 504 read_kex_algos();
546 /* V_C, the client's version string (CR and NL excluded) */ 505 /* V_C, the client's version string (CR and NL excluded) */
547 buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len); 506 buf_putstring(ses.kexhashbuf, ses.remoteident, remote_ident_len);
548 /* V_S, the server's version string (CR and NL excluded) */ 507 /* V_S, the server's version string (CR and NL excluded) */
549 buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len); 508 buf_putstring(ses.kexhashbuf, LOCAL_IDENT, local_ident_len);
550 509
551 /* I_C, the payload of the client's SSH_MSG_KEXINIT */ 510 /* I_C, the payload of the client's SSH_MSG_KEXINIT */
552 buf_setpos(ses.payload, ses.payload_beginning); 511 buf_setpos(ses.payload, ses.payload_beginning);
553 buf_putstring(ses.kexhashbuf, 512 buf_putstring(ses.kexhashbuf,
554 (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos), 513 (const char*)buf_getptr(ses.payload, ses.payload->len-ses.payload->pos),
555 ses.payload->len-ses.payload->pos); 514 ses.payload->len-ses.payload->pos);
556 515
557 /* I_S, the payload of the server's SSH_MSG_KEXINIT */ 516 /* I_S, the payload of the server's SSH_MSG_KEXINIT */
558 buf_putstring(ses.kexhashbuf, 517 buf_putstring(ses.kexhashbuf,
559 (const char*)ses.transkexinit->data, ses.transkexinit->len); 518 (const char*)ses.transkexinit->data, ses.transkexinit->len);
560 519
561 ses.requirenext = SSH_MSG_KEXDH_INIT; 520 ses.requirenext = SSH_MSG_KEXDH_INIT;
562 } 521 }
563 522