comparison common-kex.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 7e43f5e473b9
children 43bbe17d6ba0
comparison
equal deleted inserted replaced
499:f3ca5ebc319a 501:d58c478bd399
329 329
330 TRACE(("leave gen_new_keys")) 330 TRACE(("leave gen_new_keys"))
331 } 331 }
332 332
333 #ifndef DISABLE_ZLIB 333 #ifndef DISABLE_ZLIB
334
335 int is_compress_trans() {
336 return ses.keys->trans_algo_comp == DROPBEAR_COMP_ZLIB
337 || (ses.authstate.authdone
338 && ses.keys->trans_algo_comp == DROPBEAR_COMP_ZLIB_DELAY);
339 }
340
341 int is_compress_recv() {
342 return ses.keys->recv_algo_comp == DROPBEAR_COMP_ZLIB
343 || (ses.authstate.authdone
344 && ses.keys->recv_algo_comp == DROPBEAR_COMP_ZLIB_DELAY);
345 }
346
334 /* Set up new zlib compression streams, close the old ones. Only 347 /* Set up new zlib compression streams, close the old ones. Only
335 * called from gen_new_keys() */ 348 * called from gen_new_keys() */
336 static void gen_new_zstreams() { 349 static void gen_new_zstreams() {
337 350
338 /* create new zstreams */ 351 /* create new zstreams */
339 if (ses.newkeys->recv_algo_comp == DROPBEAR_COMP_ZLIB) { 352 if (ses.newkeys->recv_algo_comp == DROPBEAR_COMP_ZLIB
353 || ses.newkeys->recv_algo_comp == DROPBEAR_COMP_ZLIB_DELAY) {
340 ses.newkeys->recv_zstream = (z_streamp)m_malloc(sizeof(z_stream)); 354 ses.newkeys->recv_zstream = (z_streamp)m_malloc(sizeof(z_stream));
341 ses.newkeys->recv_zstream->zalloc = Z_NULL; 355 ses.newkeys->recv_zstream->zalloc = Z_NULL;
342 ses.newkeys->recv_zstream->zfree = Z_NULL; 356 ses.newkeys->recv_zstream->zfree = Z_NULL;
343 357
344 if (inflateInit(ses.newkeys->recv_zstream) != Z_OK) { 358 if (inflateInit(ses.newkeys->recv_zstream) != Z_OK) {
346 } 360 }
347 } else { 361 } else {
348 ses.newkeys->recv_zstream = NULL; 362 ses.newkeys->recv_zstream = NULL;
349 } 363 }
350 364
351 if (ses.newkeys->trans_algo_comp == DROPBEAR_COMP_ZLIB) { 365 if (ses.newkeys->trans_algo_comp == DROPBEAR_COMP_ZLIB
366 || ses.newkeys->trans_algo_comp == DROPBEAR_COMP_ZLIB_DELAY) {
352 ses.newkeys->trans_zstream = (z_streamp)m_malloc(sizeof(z_stream)); 367 ses.newkeys->trans_zstream = (z_streamp)m_malloc(sizeof(z_stream));
353 ses.newkeys->trans_zstream->zalloc = Z_NULL; 368 ses.newkeys->trans_zstream->zalloc = Z_NULL;
354 ses.newkeys->trans_zstream->zfree = Z_NULL; 369 ses.newkeys->trans_zstream->zfree = Z_NULL;
355 370
356 if (deflateInit(ses.newkeys->trans_zstream, Z_DEFAULT_COMPRESSION) 371 if (deflateInit(ses.newkeys->trans_zstream, Z_DEFAULT_COMPRESSION)
358 dropbear_exit("zlib error"); 373 dropbear_exit("zlib error");
359 } 374 }
360 } else { 375 } else {
361 ses.newkeys->trans_zstream = NULL; 376 ses.newkeys->trans_zstream = NULL;
362 } 377 }
363 378
364 /* clean up old keys */ 379 /* clean up old keys */
365 if (ses.keys->recv_zstream != NULL) { 380 if (ses.keys->recv_zstream != NULL) {
366 if (inflateEnd(ses.keys->recv_zstream) == Z_STREAM_ERROR) { 381 if (inflateEnd(ses.keys->recv_zstream) == Z_STREAM_ERROR) {
367 /* Z_DATA_ERROR is ok, just means that stream isn't ended */ 382 /* Z_DATA_ERROR is ok, just means that stream isn't ended */
368 dropbear_exit("crypto error"); 383 dropbear_exit("crypto error");
375 dropbear_exit("crypto error"); 390 dropbear_exit("crypto error");
376 } 391 }
377 m_free(ses.keys->trans_zstream); 392 m_free(ses.keys->trans_zstream);
378 } 393 }
379 } 394 }
380 #endif 395 #endif /* DISABLE_ZLIB */
381 396
382 397
383 /* Executed upon receiving a kexinit message from the client to initiate 398 /* Executed upon receiving a kexinit message from the client to initiate
384 * key exchange. If we haven't already done so, we send the list of our 399 * key exchange. If we haven't already done so, we send the list of our
385 * preferred algorithms. The client's requested algorithms are processed, 400 * preferred algorithms. The client's requested algorithms are processed,