summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--compress.c24
-rw-r--r--compress.h5
-rw-r--r--packet.c29
4 files changed, 47 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 9a9b7f5b7..3d1f8e012 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
4 - markus@cvs.openbsd.org 2001/04/05 10:00:06 4 - markus@cvs.openbsd.org 2001/04/05 10:00:06
5 [compat.c] 5 [compat.c]
6 2.3.x does old GEX, too; report jakob@ 6 2.3.x does old GEX, too; report jakob@
7 - markus@cvs.openbsd.org 2001/04/05 10:39:03
8 [compress.c compress.h packet.c]
9 reset compress state per direction when rekeying.
7 10
820010405 1120010405
9 - OpenBSD CVS Sync 12 - OpenBSD CVS Sync
@@ -4876,4 +4879,4 @@
4876 - Wrote replacements for strlcpy and mkdtemp 4879 - Wrote replacements for strlcpy and mkdtemp
4877 - Released 1.0pre1 4880 - Released 1.0pre1
4878 4881
4879$Id: ChangeLog,v 1.1064 2001/04/05 23:19:21 mouring Exp $ 4882$Id: ChangeLog,v 1.1065 2001/04/05 23:20:46 mouring Exp $
diff --git a/compress.c b/compress.c
index e8539baf0..3e41b3d82 100644
--- a/compress.c
+++ b/compress.c
@@ -12,7 +12,7 @@
12 */ 12 */
13 13
14#include "includes.h" 14#include "includes.h"
15RCSID("$OpenBSD: compress.c,v 1.13 2001/02/08 19:30:51 itojun Exp $"); 15RCSID("$OpenBSD: compress.c,v 1.14 2001/04/05 10:39:01 markus Exp $");
16 16
17#include "log.h" 17#include "log.h"
18#include "buffer.h" 18#include "buffer.h"
@@ -21,6 +21,8 @@ RCSID("$OpenBSD: compress.c,v 1.13 2001/02/08 19:30:51 itojun Exp $");
21 21
22static z_stream incoming_stream; 22static z_stream incoming_stream;
23static z_stream outgoing_stream; 23static z_stream outgoing_stream;
24static int compress_init_send_called = 0;
25static int compress_init_recv_called = 0;
24 26
25/* 27/*
26 * Initializes compression; level is compression level from 1 to 9 28 * Initializes compression; level is compression level from 1 to 9
@@ -28,14 +30,24 @@ static z_stream outgoing_stream;
28 */ 30 */
29 31
30void 32void
31buffer_compress_init(int level) 33buffer_compress_init_send(int level)
32{ 34{
35 if (compress_init_send_called == 1)
36 deflateEnd(&incoming_stream);
37 compress_init_send_called = 1;
33 debug("Enabling compression at level %d.", level); 38 debug("Enabling compression at level %d.", level);
34 if (level < 1 || level > 9) 39 if (level < 1 || level > 9)
35 fatal("Bad compression level %d.", level); 40 fatal("Bad compression level %d.", level);
36 inflateInit(&incoming_stream);
37 deflateInit(&outgoing_stream, level); 41 deflateInit(&outgoing_stream, level);
38} 42}
43void
44buffer_compress_init_recv(void)
45{
46 if (compress_init_recv_called == 1)
47 inflateEnd(&incoming_stream);
48 compress_init_recv_called = 1;
49 inflateInit(&incoming_stream);
50}
39 51
40/* Frees any data structures allocated for compression. */ 52/* Frees any data structures allocated for compression. */
41 53
@@ -50,8 +62,10 @@ buffer_compress_uninit(void)
50 incoming_stream.total_out, incoming_stream.total_in, 62 incoming_stream.total_out, incoming_stream.total_in,
51 incoming_stream.total_out == 0 ? 0.0 : 63 incoming_stream.total_out == 0 ? 0.0 :
52 (double) incoming_stream.total_in / incoming_stream.total_out); 64 (double) incoming_stream.total_in / incoming_stream.total_out);
53 inflateEnd(&incoming_stream); 65 if (compress_init_recv_called == 1)
54 deflateEnd(&outgoing_stream); 66 inflateEnd(&incoming_stream);
67 if (compress_init_send_called == 1)
68 deflateEnd(&outgoing_stream);
55} 69}
56 70
57/* 71/*
diff --git a/compress.h b/compress.h
index 87d592fe9..f90932a6f 100644
--- a/compress.h
+++ b/compress.h
@@ -11,7 +11,7 @@
11 * called by a name other than "ssh" or "Secure Shell". 11 * called by a name other than "ssh" or "Secure Shell".
12 */ 12 */
13 13
14/* RCSID("$OpenBSD: compress.h,v 1.7 2000/12/20 19:37:22 markus Exp $"); */ 14/* RCSID("$OpenBSD: compress.h,v 1.8 2001/04/05 10:39:02 markus Exp $"); */
15 15
16#ifndef COMPRESS_H 16#ifndef COMPRESS_H
17#define COMPRESS_H 17#define COMPRESS_H
@@ -20,7 +20,8 @@
20 * Initializes compression; level is compression level from 1 to 9 (as in 20 * Initializes compression; level is compression level from 1 to 9 (as in
21 * gzip). 21 * gzip).
22 */ 22 */
23void buffer_compress_init(int level); 23void buffer_compress_init_send(int level);
24void buffer_compress_init_recv(void);
24 25
25/* Frees any data structures allocated by buffer_compress_init. */ 26/* Frees any data structures allocated by buffer_compress_init. */
26void buffer_compress_uninit(void); 27void buffer_compress_uninit(void);
diff --git a/packet.c b/packet.c
index 5b5fa08d2..d518d0e0e 100644
--- a/packet.c
+++ b/packet.c
@@ -37,7 +37,7 @@
37 */ 37 */
38 38
39#include "includes.h" 39#include "includes.h"
40RCSID("$OpenBSD: packet.c,v 1.59 2001/04/04 23:09:18 markus Exp $"); 40RCSID("$OpenBSD: packet.c,v 1.60 2001/04/05 10:39:03 markus Exp $");
41 41
42#include "xmalloc.h" 42#include "xmalloc.h"
43#include "buffer.h" 43#include "buffer.h"
@@ -104,6 +104,7 @@ static Buffer incoming_packet;
104 104
105/* Scratch buffer for packet compression/decompression. */ 105/* Scratch buffer for packet compression/decompression. */
106static Buffer compression_buffer; 106static Buffer compression_buffer;
107static int compression_buffer_ready = 0;
107 108
108/* Flag indicating whether packet compression/decompression is enabled. */ 109/* Flag indicating whether packet compression/decompression is enabled. */
109static int packet_compression = 0; 110static int packet_compression = 0;
@@ -249,7 +250,7 @@ packet_close()
249 buffer_free(&output); 250 buffer_free(&output);
250 buffer_free(&outgoing_packet); 251 buffer_free(&outgoing_packet);
251 buffer_free(&incoming_packet); 252 buffer_free(&incoming_packet);
252 if (packet_compression) { 253 if (compression_buffer_ready) {
253 buffer_free(&compression_buffer); 254 buffer_free(&compression_buffer);
254 buffer_compress_uninit(); 255 buffer_compress_uninit();
255 } 256 }
@@ -277,15 +278,24 @@ packet_get_protocol_flags()
277 * Level is compression level 1 (fastest) - 9 (slow, best) as in gzip. 278 * Level is compression level 1 (fastest) - 9 (slow, best) as in gzip.
278 */ 279 */
279 280
280/*** XXXXX todo: kex means re-init */ 281void
282packet_init_compression()
283{
284 if (compression_buffer_ready == 1)
285 return;
286 compression_buffer_ready = 1;
287 buffer_init(&compression_buffer);
288}
289
281void 290void
282packet_start_compression(int level) 291packet_start_compression(int level)
283{ 292{
284 if (packet_compression) 293 if (packet_compression && !use_ssh2_packet_format)
285 fatal("Compression already enabled."); 294 fatal("Compression already enabled.");
286 packet_compression = 1; 295 packet_compression = 1;
287 buffer_init(&compression_buffer); 296 packet_init_compression();
288 buffer_compress_init(level); 297 buffer_compress_init_send(level);
298 buffer_compress_init_recv();
289} 299}
290 300
291/* 301/*
@@ -542,9 +552,12 @@ set_newkeys(int mode)
542 memset(enc->iv, 0, enc->cipher->block_size); 552 memset(enc->iv, 0, enc->cipher->block_size);
543 memset(enc->key, 0, enc->cipher->key_len); 553 memset(enc->key, 0, enc->cipher->key_len);
544 if (comp->type != 0 && comp->enabled == 0) { 554 if (comp->type != 0 && comp->enabled == 0) {
555 packet_init_compression();
556 if (mode == MODE_OUT)
557 buffer_compress_init_send(6);
558 else
559 buffer_compress_init_recv();
545 comp->enabled = 1; 560 comp->enabled = 1;
546 if (! packet_compression)
547 packet_start_compression(6);
548 } 561 }
549} 562}
550 563