comparison packet.c @ 501:d58c478bd399

Add support for [email protected] delayed compression. Are still advertising 'zlib' for the server, need to allow delayed-only as an option
author Matt Johnston <matt@ucc.asn.au>
date Mon, 29 Sep 2008 02:23:04 +0000
parents e3db1f7a2e43
children 43bbe17d6ba0
comparison
equal deleted inserted replaced
499:f3ca5ebc319a 501:d58c478bd399
288 } 288 }
289 289
290 buf_setpos(ses.decryptreadbuf, PACKET_PAYLOAD_OFF); 290 buf_setpos(ses.decryptreadbuf, PACKET_PAYLOAD_OFF);
291 291
292 #ifndef DISABLE_ZLIB 292 #ifndef DISABLE_ZLIB
293 if (ses.keys->recv_algo_comp == DROPBEAR_COMP_ZLIB) { 293 if (is_compress_recv()) {
294 /* decompress */ 294 /* decompress */
295 ses.payload = buf_decompress(ses.decryptreadbuf, len); 295 ses.payload = buf_decompress(ses.decryptreadbuf, len);
296
297 } else 296 } else
298 #endif 297 #endif
299 { 298 {
300 /* copy payload */ 299 /* copy payload */
301 ses.payload = buf_new(len); 300 ses.payload = buf_new(len);
467 unsigned char padlen; 466 unsigned char padlen;
468 unsigned char blocksize, macsize; 467 unsigned char blocksize, macsize;
469 buffer * writebuf; /* the packet which will go on the wire */ 468 buffer * writebuf; /* the packet which will go on the wire */
470 buffer * clearwritebuf; /* unencrypted, possibly compressed */ 469 buffer * clearwritebuf; /* unencrypted, possibly compressed */
471 unsigned char type; 470 unsigned char type;
471 unsigned int clear_len;
472 472
473 type = ses.writepayload->data[0]; 473 type = ses.writepayload->data[0];
474 TRACE(("enter encrypt_packet()")) 474 TRACE(("enter encrypt_packet()"))
475 TRACE(("encrypt_packet type is %d", type)) 475 TRACE(("encrypt_packet type is %d", type))
476 476
486 macsize = ses.keys->trans_algo_mac->hashsize; 486 macsize = ses.keys->trans_algo_mac->hashsize;
487 487
488 /* Encrypted packet len is payload+5, then worst case is if we are 3 away 488 /* Encrypted packet len is payload+5, then worst case is if we are 3 away
489 * from a blocksize multiple. In which case we need to pad to the 489 * from a blocksize multiple. In which case we need to pad to the
490 * multiple, then add another blocksize (or MIN_PACKET_LEN) */ 490 * multiple, then add another blocksize (or MIN_PACKET_LEN) */
491 clearwritebuf = buf_new((ses.writepayload->len+4+1) + MIN_PACKET_LEN + 3 491 clear_len = (ses.writepayload->len+4+1) + MIN_PACKET_LEN + 3;
492
492 #ifndef DISABLE_ZLIB 493 #ifndef DISABLE_ZLIB
493 + ZLIB_COMPRESS_INCR /* bit of a kludge, but we can't know len*/ 494 clear_len += ZLIB_COMPRESS_INCR; /* bit of a kludge, but we can't know len*/
494 #endif 495 #endif
495 ); 496 clearwritebuf = buf_new(clear_len);
496 buf_setlen(clearwritebuf, PACKET_PAYLOAD_OFF); 497 buf_setlen(clearwritebuf, PACKET_PAYLOAD_OFF);
497 buf_setpos(clearwritebuf, PACKET_PAYLOAD_OFF); 498 buf_setpos(clearwritebuf, PACKET_PAYLOAD_OFF);
498 499
499 buf_setpos(ses.writepayload, 0); 500 buf_setpos(ses.writepayload, 0);
500 501
501 #ifndef DISABLE_ZLIB 502 #ifndef DISABLE_ZLIB
502 /* compression */ 503 /* compression */
503 if (ses.keys->trans_algo_comp == DROPBEAR_COMP_ZLIB) { 504 if (is_compress_trans()) {
504 buf_compress(clearwritebuf, ses.writepayload, ses.writepayload->len); 505 buf_compress(clearwritebuf, ses.writepayload, ses.writepayload->len);
505 } else 506 } else
506 #endif 507 #endif
507 { 508 {
508 memcpy(buf_getwriteptr(clearwritebuf, ses.writepayload->len), 509 memcpy(buf_getwriteptr(clearwritebuf, ses.writepayload->len),