diff options
author | Colin Watson <cjwatson@debian.org> | 2005-01-04 13:07:27 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2005-01-04 13:07:27 +0000 |
commit | fd0f611b70a83d80fe8793af785542ee5541b7cd (patch) | |
tree | bededd22bb7eeec52e20083237ab7e4113445a16 /packet.c | |
parent | c44fe9a5b9d3db96a7249b04d915f17e4a3a3b04 (diff) | |
parent | ebd2ce335af5861020c79fddb1ae35c03bf036cf (diff) |
Merge 3.9p1 to the trunk.
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 53 |
1 files changed, 26 insertions, 27 deletions
@@ -37,7 +37,7 @@ | |||
37 | */ | 37 | */ |
38 | 38 | ||
39 | #include "includes.h" | 39 | #include "includes.h" |
40 | RCSID("$OpenBSD: packet.c,v 1.112 2003/09/23 20:17:11 markus Exp $"); | 40 | RCSID("$OpenBSD: packet.c,v 1.115 2004/06/21 17:36:31 avsm Exp $"); |
41 | 41 | ||
42 | #include "openbsd-compat/sys-queue.h" | 42 | #include "openbsd-compat/sys-queue.h" |
43 | 43 | ||
@@ -157,8 +157,10 @@ packet_set_connection(int fd_in, int fd_out, int new_setup_timeout) | |||
157 | connection_in = fd_in; | 157 | connection_in = fd_in; |
158 | connection_out = fd_out; | 158 | connection_out = fd_out; |
159 | setup_timeout = new_setup_timeout; | 159 | setup_timeout = new_setup_timeout; |
160 | cipher_init(&send_context, none, "", 0, NULL, 0, CIPHER_ENCRYPT); | 160 | cipher_init(&send_context, none, (const u_char *)"", |
161 | cipher_init(&receive_context, none, "", 0, NULL, 0, CIPHER_DECRYPT); | 161 | 0, NULL, 0, CIPHER_ENCRYPT); |
162 | cipher_init(&receive_context, none, (const u_char *)"", | ||
163 | 0, NULL, 0, CIPHER_DECRYPT); | ||
162 | newkeys[MODE_IN] = newkeys[MODE_OUT] = NULL; | 164 | newkeys[MODE_IN] = newkeys[MODE_OUT] = NULL; |
163 | if (!initialized) { | 165 | if (!initialized) { |
164 | initialized = 1; | 166 | initialized = 1; |
@@ -320,13 +322,10 @@ void | |||
320 | packet_set_nonblocking(void) | 322 | packet_set_nonblocking(void) |
321 | { | 323 | { |
322 | /* Set the socket into non-blocking mode. */ | 324 | /* Set the socket into non-blocking mode. */ |
323 | if (fcntl(connection_in, F_SETFL, O_NONBLOCK) < 0) | 325 | set_nonblock(connection_in); |
324 | error("fcntl O_NONBLOCK: %.100s", strerror(errno)); | ||
325 | 326 | ||
326 | if (connection_out != connection_in) { | 327 | if (connection_out != connection_in) |
327 | if (fcntl(connection_out, F_SETFL, O_NONBLOCK) < 0) | 328 | set_nonblock(connection_out); |
328 | error("fcntl O_NONBLOCK: %.100s", strerror(errno)); | ||
329 | } | ||
330 | } | 329 | } |
331 | 330 | ||
332 | /* Returns the socket used for reading. */ | 331 | /* Returns the socket used for reading. */ |
@@ -511,7 +510,7 @@ packet_send1(void) | |||
511 | u_char buf[8], *cp; | 510 | u_char buf[8], *cp; |
512 | int i, padding, len; | 511 | int i, padding, len; |
513 | u_int checksum; | 512 | u_int checksum; |
514 | u_int32_t rand = 0; | 513 | u_int32_t rnd = 0; |
515 | 514 | ||
516 | /* | 515 | /* |
517 | * If using packet compression, compress the payload of the outgoing | 516 | * If using packet compression, compress the payload of the outgoing |
@@ -537,9 +536,9 @@ packet_send1(void) | |||
537 | cp = buffer_ptr(&outgoing_packet); | 536 | cp = buffer_ptr(&outgoing_packet); |
538 | for (i = 0; i < padding; i++) { | 537 | for (i = 0; i < padding; i++) { |
539 | if (i % 4 == 0) | 538 | if (i % 4 == 0) |
540 | rand = arc4random(); | 539 | rnd = arc4random(); |
541 | cp[7 - i] = rand & 0xff; | 540 | cp[7 - i] = rnd & 0xff; |
542 | rand >>= 8; | 541 | rnd >>= 8; |
543 | } | 542 | } |
544 | } | 543 | } |
545 | buffer_consume(&outgoing_packet, 8 - padding); | 544 | buffer_consume(&outgoing_packet, 8 - padding); |
@@ -584,18 +583,18 @@ set_newkeys(int mode) | |||
584 | Comp *comp; | 583 | Comp *comp; |
585 | CipherContext *cc; | 584 | CipherContext *cc; |
586 | u_int64_t *max_blocks; | 585 | u_int64_t *max_blocks; |
587 | int encrypt; | 586 | int crypt_type; |
588 | 587 | ||
589 | debug2("set_newkeys: mode %d", mode); | 588 | debug2("set_newkeys: mode %d", mode); |
590 | 589 | ||
591 | if (mode == MODE_OUT) { | 590 | if (mode == MODE_OUT) { |
592 | cc = &send_context; | 591 | cc = &send_context; |
593 | encrypt = CIPHER_ENCRYPT; | 592 | crypt_type = CIPHER_ENCRYPT; |
594 | p_send.packets = p_send.blocks = 0; | 593 | p_send.packets = p_send.blocks = 0; |
595 | max_blocks = &max_blocks_out; | 594 | max_blocks = &max_blocks_out; |
596 | } else { | 595 | } else { |
597 | cc = &receive_context; | 596 | cc = &receive_context; |
598 | encrypt = CIPHER_DECRYPT; | 597 | crypt_type = CIPHER_DECRYPT; |
599 | p_read.packets = p_read.blocks = 0; | 598 | p_read.packets = p_read.blocks = 0; |
600 | max_blocks = &max_blocks_in; | 599 | max_blocks = &max_blocks_in; |
601 | } | 600 | } |
@@ -624,7 +623,7 @@ set_newkeys(int mode) | |||
624 | mac->enabled = 1; | 623 | mac->enabled = 1; |
625 | DBG(debug("cipher_init_context: %d", mode)); | 624 | DBG(debug("cipher_init_context: %d", mode)); |
626 | cipher_init(cc, enc->cipher, enc->key, enc->key_len, | 625 | cipher_init(cc, enc->cipher, enc->key, enc->key_len, |
627 | enc->iv, enc->block_size, encrypt); | 626 | enc->iv, enc->block_size, crypt_type); |
628 | /* Deleting the keys does not gain extra security */ | 627 | /* Deleting the keys does not gain extra security */ |
629 | /* memset(enc->iv, 0, enc->block_size); | 628 | /* memset(enc->iv, 0, enc->block_size); |
630 | memset(enc->key, 0, enc->key_len); */ | 629 | memset(enc->key, 0, enc->key_len); */ |
@@ -658,7 +657,7 @@ packet_send2_wrapped(void) | |||
658 | u_char padlen, pad; | 657 | u_char padlen, pad; |
659 | u_int packet_length = 0; | 658 | u_int packet_length = 0; |
660 | u_int i, len; | 659 | u_int i, len; |
661 | u_int32_t rand = 0; | 660 | u_int32_t rnd = 0; |
662 | Enc *enc = NULL; | 661 | Enc *enc = NULL; |
663 | Mac *mac = NULL; | 662 | Mac *mac = NULL; |
664 | Comp *comp = NULL; | 663 | Comp *comp = NULL; |
@@ -717,9 +716,9 @@ packet_send2_wrapped(void) | |||
717 | /* random padding */ | 716 | /* random padding */ |
718 | for (i = 0; i < padlen; i++) { | 717 | for (i = 0; i < padlen; i++) { |
719 | if (i % 4 == 0) | 718 | if (i % 4 == 0) |
720 | rand = arc4random(); | 719 | rnd = arc4random(); |
721 | cp[i] = rand & 0xff; | 720 | cp[i] = rnd & 0xff; |
722 | rand >>= 8; | 721 | rnd >>= 8; |
723 | } | 722 | } |
724 | } else { | 723 | } else { |
725 | /* clear padding */ | 724 | /* clear padding */ |
@@ -1463,7 +1462,7 @@ packet_is_interactive(void) | |||
1463 | return interactive_mode; | 1462 | return interactive_mode; |
1464 | } | 1463 | } |
1465 | 1464 | ||
1466 | u_int | 1465 | int |
1467 | packet_set_maxsize(u_int s) | 1466 | packet_set_maxsize(u_int s) |
1468 | { | 1467 | { |
1469 | static int called = 0; | 1468 | static int called = 0; |
@@ -1504,20 +1503,20 @@ packet_add_padding(u_char pad) | |||
1504 | void | 1503 | void |
1505 | packet_send_ignore(int nbytes) | 1504 | packet_send_ignore(int nbytes) |
1506 | { | 1505 | { |
1507 | u_int32_t rand = 0; | 1506 | u_int32_t rnd = 0; |
1508 | int i; | 1507 | int i; |
1509 | 1508 | ||
1510 | packet_start(compat20 ? SSH2_MSG_IGNORE : SSH_MSG_IGNORE); | 1509 | packet_start(compat20 ? SSH2_MSG_IGNORE : SSH_MSG_IGNORE); |
1511 | packet_put_int(nbytes); | 1510 | packet_put_int(nbytes); |
1512 | for (i = 0; i < nbytes; i++) { | 1511 | for (i = 0; i < nbytes; i++) { |
1513 | if (i % 4 == 0) | 1512 | if (i % 4 == 0) |
1514 | rand = arc4random(); | 1513 | rnd = arc4random(); |
1515 | packet_put_char(rand & 0xff); | 1514 | packet_put_char(rnd & 0xff); |
1516 | rand >>= 8; | 1515 | rnd >>= 8; |
1517 | } | 1516 | } |
1518 | } | 1517 | } |
1519 | 1518 | ||
1520 | #define MAX_PACKETS (1<<31) | 1519 | #define MAX_PACKETS (1U<<31) |
1521 | int | 1520 | int |
1522 | packet_need_rekeying(void) | 1521 | packet_need_rekeying(void) |
1523 | { | 1522 | { |