Mercurial > dropbear
comparison packet.c @ 534:0431915df79f
- Get rid of decryptreadbuf, just decrypt in-place with readbuf
- Share make_mac function for both packet creation and validation
- Split recv/trans parts of key_context into their own structures
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 01 Mar 2009 16:15:57 +0000 |
parents | 805ae74ec024 |
children | 21490eea261d |
comparison
equal
deleted
inserted
replaced
533:805ae74ec024 | 534:0431915df79f |
---|---|
33 #include "random.h" | 33 #include "random.h" |
34 #include "service.h" | 34 #include "service.h" |
35 #include "auth.h" | 35 #include "auth.h" |
36 #include "channel.h" | 36 #include "channel.h" |
37 | 37 |
38 static void read_packet_init(); | 38 static int read_packet_init(); |
39 static void make_mac(buffer * clearwritebuf, unsigned char *output_mac); | 39 static void make_mac(unsigned int seqno, const struct key_context_directional * key_state, |
40 static int checkmac(buffer* hashbuf, buffer* readbuf); | 40 buffer * clear_buf, unsigned int clear_len, |
41 unsigned char *output_mac); | |
42 static int checkmac(); | |
41 | 43 |
42 #define ZLIB_COMPRESS_INCR 20 /* this is 12 bytes + 0.1% of 8000 bytes */ | 44 #define ZLIB_COMPRESS_INCR 20 /* this is 12 bytes + 0.1% of 8000 bytes */ |
43 #define ZLIB_DECOMPRESS_INCR 100 | 45 #define ZLIB_DECOMPRESS_INCR 100 |
44 #ifndef DISABLE_ZLIB | 46 #ifndef DISABLE_ZLIB |
45 static buffer* buf_decompress(buffer* buf, unsigned int len); | 47 static buffer* buf_decompress(buffer* buf, unsigned int len); |
100 int len; | 102 int len; |
101 unsigned int maxlen; | 103 unsigned int maxlen; |
102 unsigned char blocksize; | 104 unsigned char blocksize; |
103 | 105 |
104 TRACE(("enter read_packet")) | 106 TRACE(("enter read_packet")) |
105 blocksize = ses.keys->recv_algo_crypt->blocksize; | 107 blocksize = ses.keys->recv.algo_crypt->blocksize; |
106 | 108 |
107 if (ses.readbuf == NULL || ses.readbuf->len < blocksize) { | 109 if (ses.readbuf == NULL || ses.readbuf->len < blocksize) { |
110 int ret; | |
108 /* In the first blocksize of a packet */ | 111 /* In the first blocksize of a packet */ |
109 | 112 |
110 /* Read the first blocksize of the packet, so we can decrypt it and | 113 /* Read the first blocksize of the packet, so we can decrypt it and |
111 * find the length of the whole packet */ | 114 * find the length of the whole packet */ |
112 read_packet_init(); | 115 ret = read_packet_init(); |
113 | 116 |
114 /* If we don't have the length of decryptreadbuf, we didn't read | 117 if (ret == DROPBEAR_FAILURE) { |
115 * a whole blocksize and should exit */ | 118 /* didn't read enough to determine the length */ |
116 if (ses.decryptreadbuf->len == 0) { | |
117 TRACE(("leave read_packet: packetinit done")) | 119 TRACE(("leave read_packet: packetinit done")) |
118 return; | 120 return; |
119 } | 121 } |
120 } | 122 } |
121 | 123 |
122 /* Attempt to read the remainder of the packet, note that there | 124 /* Attempt to read the remainder of the packet, note that there |
123 * mightn't be any available (EAGAIN) */ | 125 * mightn't be any available (EAGAIN) */ |
124 dropbear_assert(ses.readbuf != NULL); | |
125 maxlen = ses.readbuf->len - ses.readbuf->pos; | 126 maxlen = ses.readbuf->len - ses.readbuf->pos; |
126 len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen); | 127 len = read(ses.sock_in, buf_getptr(ses.readbuf, maxlen), maxlen); |
127 | 128 |
128 if (len == 0) { | 129 if (len == 0) { |
129 ses.remoteclosed(); | 130 ses.remoteclosed(); |
149 TRACE(("leave read_packet")) | 150 TRACE(("leave read_packet")) |
150 } | 151 } |
151 | 152 |
152 /* Function used to read the initial portion of a packet, and determine the | 153 /* Function used to read the initial portion of a packet, and determine the |
153 * length. Only called during the first BLOCKSIZE of a packet. */ | 154 * length. Only called during the first BLOCKSIZE of a packet. */ |
154 static void read_packet_init() { | 155 /* Returns DROPBEAR_SUCCESS if the length is determined, |
156 * DROPBEAR_FAILURE otherwise */ | |
157 static int read_packet_init() { | |
155 | 158 |
156 unsigned int maxlen; | 159 unsigned int maxlen; |
157 int len; | 160 int len; |
158 unsigned char blocksize; | 161 unsigned char blocksize; |
159 unsigned char macsize; | 162 unsigned char macsize; |
160 | 163 |
161 | 164 |
162 blocksize = ses.keys->recv_algo_crypt->blocksize; | 165 blocksize = ses.keys->recv.algo_crypt->blocksize; |
163 macsize = ses.keys->recv_algo_mac->hashsize; | 166 macsize = ses.keys->recv.algo_mac->hashsize; |
164 | 167 |
165 if (ses.readbuf == NULL) { | 168 if (ses.readbuf == NULL) { |
166 /* start of a new packet */ | 169 /* start of a new packet */ |
167 ses.readbuf = buf_new(INIT_READBUF); | 170 ses.readbuf = buf_new(INIT_READBUF); |
168 dropbear_assert(ses.decryptreadbuf == NULL); | |
169 ses.decryptreadbuf = buf_new(blocksize); | |
170 } | 171 } |
171 | 172 |
172 maxlen = blocksize - ses.readbuf->pos; | 173 maxlen = blocksize - ses.readbuf->pos; |
173 | 174 |
174 /* read the rest of the packet if possible */ | 175 /* read the rest of the packet if possible */ |
178 ses.remoteclosed(); | 179 ses.remoteclosed(); |
179 } | 180 } |
180 if (len < 0) { | 181 if (len < 0) { |
181 if (errno == EINTR) { | 182 if (errno == EINTR) { |
182 TRACE(("leave read_packet_init: EINTR")) | 183 TRACE(("leave read_packet_init: EINTR")) |
183 return; | 184 return DROPBEAR_FAILURE; |
184 } | 185 } |
185 dropbear_exit("error reading: %s", strerror(errno)); | 186 dropbear_exit("error reading: %s", strerror(errno)); |
186 } | 187 } |
187 | 188 |
188 buf_incrwritepos(ses.readbuf, len); | 189 buf_incrwritepos(ses.readbuf, len); |
189 | 190 |
190 if ((unsigned int)len != maxlen) { | 191 if ((unsigned int)len != maxlen) { |
191 /* don't have enough bytes to determine length, get next time */ | 192 /* don't have enough bytes to determine length, get next time */ |
192 return; | 193 return DROPBEAR_FAILURE; |
193 } | 194 } |
194 | 195 |
195 /* now we have the first block, need to get packet length, so we decrypt | 196 /* now we have the first block, need to get packet length, so we decrypt |
196 * the first block (only need first 4 bytes) */ | 197 * the first block (only need first 4 bytes) */ |
197 buf_setpos(ses.readbuf, 0); | 198 buf_setpos(ses.readbuf, 0); |
198 if (ses.keys->recv_crypt_mode->decrypt(buf_getptr(ses.readbuf, blocksize), | 199 if (ses.keys->recv.crypt_mode->decrypt(buf_getptr(ses.readbuf, blocksize), |
199 buf_getwriteptr(ses.decryptreadbuf,blocksize), | 200 buf_getwriteptr(ses.readbuf, blocksize), |
200 blocksize, | 201 blocksize, |
201 &ses.keys->recv_cipher_state) != CRYPT_OK) { | 202 &ses.keys->recv.cipher_state) != CRYPT_OK) { |
202 dropbear_exit("error decrypting"); | 203 dropbear_exit("error decrypting"); |
203 } | 204 } |
204 buf_setlen(ses.decryptreadbuf, blocksize); | 205 len = buf_getint(ses.readbuf) + 4 + macsize; |
205 len = buf_getint(ses.decryptreadbuf) + 4 + macsize; | 206 |
206 | 207 TRACE(("packet size is %d, block %d mac %d", len, blocksize, macsize)) |
207 buf_setpos(ses.readbuf, blocksize); | 208 |
208 | 209 |
209 /* check packet length */ | 210 /* check packet length */ |
210 if ((len > RECV_MAX_PACKET_LEN) || | 211 if ((len > RECV_MAX_PACKET_LEN) || |
211 (len < MIN_PACKET_LEN + macsize) || | 212 (len < MIN_PACKET_LEN + macsize) || |
212 ((len - macsize) % blocksize != 0)) { | 213 ((len - macsize) % blocksize != 0)) { |
213 dropbear_exit("bad packet size %d", len); | 214 dropbear_exit("bad packet size %d", len); |
214 } | 215 } |
215 | 216 |
216 buf_resize(ses.readbuf, len); | 217 if (len > ses.readbuf->size) { |
218 buf_resize(ses.readbuf, len); | |
219 } | |
217 buf_setlen(ses.readbuf, len); | 220 buf_setlen(ses.readbuf, len); |
218 | 221 buf_setpos(ses.readbuf, blocksize); |
222 return DROPBEAR_SUCCESS; | |
219 } | 223 } |
220 | 224 |
221 /* handle the received packet */ | 225 /* handle the received packet */ |
222 void decrypt_packet() { | 226 void decrypt_packet() { |
223 | 227 |
225 unsigned char macsize; | 229 unsigned char macsize; |
226 unsigned int padlen; | 230 unsigned int padlen; |
227 unsigned int len; | 231 unsigned int len; |
228 | 232 |
229 TRACE(("enter decrypt_packet")) | 233 TRACE(("enter decrypt_packet")) |
230 blocksize = ses.keys->recv_algo_crypt->blocksize; | 234 blocksize = ses.keys->recv.algo_crypt->blocksize; |
231 macsize = ses.keys->recv_algo_mac->hashsize; | 235 macsize = ses.keys->recv.algo_mac->hashsize; |
232 | 236 |
233 ses.kexstate.datarecv += ses.readbuf->len; | 237 ses.kexstate.datarecv += ses.readbuf->len; |
234 | 238 |
235 /* we've already decrypted the first blocksize in read_packet_init */ | 239 /* we've already decrypted the first blocksize in read_packet_init */ |
236 buf_setpos(ses.readbuf, blocksize); | 240 buf_setpos(ses.readbuf, blocksize); |
237 | 241 |
238 buf_resize(ses.decryptreadbuf, ses.readbuf->len - macsize); | 242 /* decrypt it in-place */ |
239 buf_setlen(ses.decryptreadbuf, ses.decryptreadbuf->size); | |
240 buf_setpos(ses.decryptreadbuf, blocksize); | |
241 | |
242 /* decrypt it */ | |
243 len = ses.readbuf->len - macsize - ses.readbuf->pos; | 243 len = ses.readbuf->len - macsize - ses.readbuf->pos; |
244 if (ses.keys->recv_crypt_mode->decrypt( | 244 if (ses.keys->recv.crypt_mode->decrypt( |
245 buf_getptr(ses.readbuf, len), | 245 buf_getptr(ses.readbuf, len), |
246 buf_getwriteptr(ses.decryptreadbuf, len), | 246 buf_getwriteptr(ses.readbuf, len), |
247 len, | 247 len, |
248 &ses.keys->recv_cipher_state) != CRYPT_OK) { | 248 &ses.keys->recv.cipher_state) != CRYPT_OK) { |
249 dropbear_exit("error decrypting"); | 249 dropbear_exit("error decrypting"); |
250 } | 250 } |
251 buf_incrpos(ses.readbuf, len); | 251 buf_incrpos(ses.readbuf, len); |
252 buf_incrwritepos(ses.decryptreadbuf, len); | 252 |
253 printhex("readbuf decrypted", ses.readbuf->data, ses.readbuf->len); | |
253 | 254 |
254 /* check the hmac */ | 255 /* check the hmac */ |
255 buf_setpos(ses.readbuf, ses.readbuf->len - macsize); | 256 if (checkmac() != DROPBEAR_SUCCESS) { |
256 if (checkmac(ses.readbuf, ses.decryptreadbuf) != DROPBEAR_SUCCESS) { | |
257 dropbear_exit("Integrity error"); | 257 dropbear_exit("Integrity error"); |
258 } | 258 } |
259 | 259 |
260 /* readbuf no longer required */ | |
261 buf_free(ses.readbuf); | |
262 ses.readbuf = NULL; | |
263 | |
264 /* get padding length */ | 260 /* get padding length */ |
265 buf_setpos(ses.decryptreadbuf, PACKET_PADDING_OFF); | 261 buf_setpos(ses.readbuf, PACKET_PADDING_OFF); |
266 padlen = buf_getbyte(ses.decryptreadbuf); | 262 padlen = buf_getbyte(ses.readbuf); |
267 | 263 |
268 /* payload length */ | 264 /* payload length */ |
269 /* - 4 - 1 is for LEN and PADLEN values */ | 265 /* - 4 - 1 is for LEN and PADLEN values */ |
270 len = ses.decryptreadbuf->len - padlen - 4 - 1; | 266 len = ses.readbuf->len - padlen - 4 - 1; |
271 if ((len > RECV_MAX_PAYLOAD_LEN) || (len < 1)) { | 267 if ((len > RECV_MAX_PAYLOAD_LEN) || (len < 1)) { |
272 dropbear_exit("bad packet size"); | 268 dropbear_exit("bad packet size"); |
273 } | 269 } |
274 | 270 |
275 buf_setpos(ses.decryptreadbuf, PACKET_PAYLOAD_OFF); | 271 buf_setpos(ses.readbuf, PACKET_PAYLOAD_OFF); |
276 | 272 |
277 #ifndef DISABLE_ZLIB | 273 #ifndef DISABLE_ZLIB |
278 if (is_compress_recv()) { | 274 if (is_compress_recv()) { |
279 /* decompress */ | 275 /* decompress */ |
280 ses.payload = buf_decompress(ses.decryptreadbuf, len); | 276 ses.payload = buf_decompress(ses.readbuf, len); |
281 } else | 277 } else |
282 #endif | 278 #endif |
283 { | 279 { |
284 /* copy payload */ | 280 /* copy payload */ |
285 ses.payload = buf_new(len); | 281 ses.payload = buf_new(len); |
286 memcpy(ses.payload->data, buf_getptr(ses.decryptreadbuf, len), len); | 282 memcpy(ses.payload->data, buf_getptr(ses.readbuf, len), len); |
287 buf_incrlen(ses.payload, len); | 283 buf_incrlen(ses.payload, len); |
288 } | 284 } |
289 | 285 |
290 buf_free(ses.decryptreadbuf); | 286 buf_free(ses.readbuf); |
291 ses.decryptreadbuf = NULL; | 287 ses.readbuf = NULL; |
292 buf_setpos(ses.payload, 0); | 288 buf_setpos(ses.payload, 0); |
293 | 289 |
294 ses.recvseq++; | 290 ses.recvseq++; |
295 | 291 |
296 TRACE(("leave decrypt_packet")) | 292 TRACE(("leave decrypt_packet")) |
297 } | 293 } |
298 | 294 |
299 /* Checks the mac in hashbuf, for the data in readbuf. | 295 /* Checks the mac at the end of a decrypted readbuf. |
300 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ | 296 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ |
301 static int checkmac(buffer* macbuf, buffer* sourcebuf) { | 297 static int checkmac() { |
302 | 298 |
303 unsigned int macsize; | 299 unsigned char mac_bytes[MAX_MAC_LEN]; |
304 hmac_state hmac; | 300 unsigned int mac_size, contents_len; |
305 unsigned char tempbuf[MAX_MAC_LEN]; | 301 |
306 unsigned long bufsize; | 302 mac_size = ses.keys->trans.algo_mac->hashsize; |
307 unsigned int len; | 303 contents_len = ses.readbuf->len - mac_size; |
308 | 304 |
309 macsize = ses.keys->recv_algo_mac->hashsize; | 305 buf_setpos(ses.readbuf, 0); |
310 if (macsize == 0) { | 306 make_mac(ses.recvseq, &ses.keys->recv, ses.readbuf, contents_len, mac_bytes); |
311 return DROPBEAR_SUCCESS; | |
312 } | |
313 | |
314 /* calculate the mac */ | |
315 if (hmac_init(&hmac, | |
316 find_hash(ses.keys->recv_algo_mac->hashdesc->name), | |
317 ses.keys->recvmackey, | |
318 ses.keys->recv_algo_mac->keysize) | |
319 != CRYPT_OK) { | |
320 dropbear_exit("HMAC error"); | |
321 } | |
322 | |
323 /* sequence number */ | |
324 STORE32H(ses.recvseq, tempbuf); | |
325 if (hmac_process(&hmac, tempbuf, 4) != CRYPT_OK) { | |
326 dropbear_exit("HMAC error"); | |
327 } | |
328 | |
329 buf_setpos(sourcebuf, 0); | |
330 len = sourcebuf->len; | |
331 if (hmac_process(&hmac, buf_getptr(sourcebuf, len), len) != CRYPT_OK) { | |
332 dropbear_exit("HMAC error"); | |
333 } | |
334 | |
335 bufsize = sizeof(tempbuf); | |
336 if (hmac_done(&hmac, tempbuf, &bufsize) != CRYPT_OK) { | |
337 dropbear_exit("HMAC error"); | |
338 } | |
339 | 307 |
340 /* compare the hash */ | 308 /* compare the hash */ |
341 if (memcmp(tempbuf, buf_getptr(macbuf, macsize), macsize) != 0) { | 309 buf_setpos(ses.readbuf, contents_len); |
310 if (memcmp(mac_bytes, buf_getptr(ses.readbuf, mac_size), mac_size) != 0) { | |
342 return DROPBEAR_FAILURE; | 311 return DROPBEAR_FAILURE; |
343 } else { | 312 } else { |
344 return DROPBEAR_SUCCESS; | 313 return DROPBEAR_SUCCESS; |
345 } | 314 } |
346 } | 315 } |
351 | 320 |
352 int result; | 321 int result; |
353 buffer * ret; | 322 buffer * ret; |
354 z_streamp zstream; | 323 z_streamp zstream; |
355 | 324 |
356 zstream = ses.keys->recv_zstream; | 325 zstream = ses.keys->recv.zstream; |
357 ret = buf_new(len); | 326 ret = buf_new(len); |
358 | 327 |
359 zstream->avail_in = len; | 328 zstream->avail_in = len; |
360 zstream->next_in = buf_getptr(buf, len); | 329 zstream->next_in = buf_getptr(buf, len); |
361 | 330 |
466 after the KEX, see maybe_flush_reply_queue */ | 435 after the KEX, see maybe_flush_reply_queue */ |
467 enqueue_reply_packet(); | 436 enqueue_reply_packet(); |
468 return; | 437 return; |
469 } | 438 } |
470 | 439 |
471 blocksize = ses.keys->trans_algo_crypt->blocksize; | 440 blocksize = ses.keys->trans.algo_crypt->blocksize; |
472 mac_size = ses.keys->trans_algo_mac->hashsize; | 441 mac_size = ses.keys->trans.algo_mac->hashsize; |
473 | 442 |
474 /* Encrypted packet len is payload+5, then worst case is if we are 3 away | 443 /* Encrypted packet len is payload+5, then worst case is if we are 3 away |
475 * from a blocksize multiple. In which case we need to pad to the | 444 * from a blocksize multiple. In which case we need to pad to the |
476 * multiple, then add another blocksize (or MIN_PACKET_LEN) */ | 445 * multiple, then add another blocksize (or MIN_PACKET_LEN) */ |
477 encrypt_buf_size = (ses.writepayload->len+4+1) + MIN_PACKET_LEN + 3; | 446 encrypt_buf_size = (ses.writepayload->len+4+1) + MIN_PACKET_LEN + 3; |
524 /* actual padding */ | 493 /* actual padding */ |
525 buf_setpos(writebuf, writebuf->len); | 494 buf_setpos(writebuf, writebuf->len); |
526 buf_incrlen(writebuf, padlen); | 495 buf_incrlen(writebuf, padlen); |
527 genrandom(buf_getptr(writebuf, padlen), padlen); | 496 genrandom(buf_getptr(writebuf, padlen), padlen); |
528 | 497 |
529 make_mac(writebuf, mac_bytes); | 498 make_mac(ses.transseq, &ses.keys->trans, writebuf, writebuf->len, mac_bytes); |
530 | 499 |
531 /* do the actual encryption, in-place */ | 500 /* do the actual encryption, in-place */ |
532 buf_setpos(writebuf, 0); | 501 buf_setpos(writebuf, 0); |
533 /* encrypt it in-place*/ | 502 /* encrypt it in-place*/ |
534 len = writebuf->len; | 503 len = writebuf->len; |
535 if (ses.keys->trans_crypt_mode->encrypt( | 504 if (ses.keys->trans.crypt_mode->encrypt( |
536 buf_getptr(writebuf, len), | 505 buf_getptr(writebuf, len), |
537 buf_getwriteptr(writebuf, len), | 506 buf_getwriteptr(writebuf, len), |
538 len, | 507 len, |
539 &ses.keys->trans_cipher_state) != CRYPT_OK) { | 508 &ses.keys->trans.cipher_state) != CRYPT_OK) { |
540 dropbear_exit("error encrypting"); | 509 dropbear_exit("error encrypting"); |
541 } | 510 } |
542 buf_incrpos(writebuf, len); | 511 buf_incrpos(writebuf, len); |
543 | 512 |
544 /* stick the MAC on it */ | 513 /* stick the MAC on it */ |
555 TRACE(("leave encrypt_packet()")) | 524 TRACE(("leave encrypt_packet()")) |
556 } | 525 } |
557 | 526 |
558 | 527 |
559 /* Create the packet mac, and append H(seqno|clearbuf) to the output */ | 528 /* Create the packet mac, and append H(seqno|clearbuf) to the output */ |
560 /* output_mac must have ses.keys->trans_algo_mac->hashsize bytes. */ | 529 /* output_mac must have ses.keys->trans.algo_mac->hashsize bytes. */ |
561 static void make_mac(buffer * clearwritebuf, unsigned char *output_mac) { | 530 static void make_mac(unsigned int seqno, const struct key_context_directional * key_state, |
531 buffer * clear_buf, unsigned int clear_len, | |
532 unsigned char *output_mac) { | |
562 unsigned char seqbuf[4]; | 533 unsigned char seqbuf[4]; |
563 unsigned long bufsize; | 534 unsigned long bufsize; |
564 hmac_state hmac; | 535 hmac_state hmac; |
565 | 536 |
566 TRACE(("enter writemac")) | 537 TRACE(("enter writemac")) |
567 | 538 |
568 if (ses.keys->trans_algo_mac->hashsize > 0) { | 539 if (key_state->algo_mac->hashsize > 0) { |
569 /* calculate the mac */ | 540 /* calculate the mac */ |
570 if (hmac_init(&hmac, | 541 if (hmac_init(&hmac, |
571 find_hash(ses.keys->trans_algo_mac->hashdesc->name), | 542 key_state->hash_index, |
572 ses.keys->transmackey, | 543 key_state->mackey, |
573 ses.keys->trans_algo_mac->keysize) != CRYPT_OK) { | 544 key_state->algo_mac->keysize) != CRYPT_OK) { |
574 dropbear_exit("HMAC error"); | 545 dropbear_exit("HMAC error"); |
575 } | 546 } |
576 | 547 |
577 /* sequence number */ | 548 /* sequence number */ |
578 STORE32H(ses.transseq, seqbuf); | 549 STORE32H(seqno, seqbuf); |
579 if (hmac_process(&hmac, seqbuf, 4) != CRYPT_OK) { | 550 if (hmac_process(&hmac, seqbuf, 4) != CRYPT_OK) { |
580 dropbear_exit("HMAC error"); | 551 dropbear_exit("HMAC error"); |
581 } | 552 } |
582 | 553 |
583 /* the actual contents */ | 554 /* the actual contents */ |
584 buf_setpos(clearwritebuf, 0); | 555 buf_setpos(clear_buf, 0); |
585 if (hmac_process(&hmac, | 556 if (hmac_process(&hmac, |
586 buf_getptr(clearwritebuf, | 557 buf_getptr(clear_buf, clear_len), |
587 clearwritebuf->len), | 558 clear_len) != CRYPT_OK) { |
588 clearwritebuf->len) != CRYPT_OK) { | |
589 dropbear_exit("HMAC error"); | 559 dropbear_exit("HMAC error"); |
590 } | 560 } |
591 | 561 |
592 bufsize = MAX_MAC_LEN; | 562 bufsize = MAX_MAC_LEN; |
593 if (hmac_done(&hmac, output_mac, &bufsize) != CRYPT_OK) { | 563 if (hmac_done(&hmac, output_mac, &bufsize) != CRYPT_OK) { |
607 | 577 |
608 TRACE(("enter buf_compress")) | 578 TRACE(("enter buf_compress")) |
609 | 579 |
610 while (1) { | 580 while (1) { |
611 | 581 |
612 ses.keys->trans_zstream->avail_in = endpos - src->pos; | 582 ses.keys->trans.zstream->avail_in = endpos - src->pos; |
613 ses.keys->trans_zstream->next_in = | 583 ses.keys->trans.zstream->next_in = |
614 buf_getptr(src, ses.keys->trans_zstream->avail_in); | 584 buf_getptr(src, ses.keys->trans.zstream->avail_in); |
615 | 585 |
616 ses.keys->trans_zstream->avail_out = dest->size - dest->pos; | 586 ses.keys->trans.zstream->avail_out = dest->size - dest->pos; |
617 ses.keys->trans_zstream->next_out = | 587 ses.keys->trans.zstream->next_out = |
618 buf_getwriteptr(dest, ses.keys->trans_zstream->avail_out); | 588 buf_getwriteptr(dest, ses.keys->trans.zstream->avail_out); |
619 | 589 |
620 result = deflate(ses.keys->trans_zstream, Z_SYNC_FLUSH); | 590 result = deflate(ses.keys->trans.zstream, Z_SYNC_FLUSH); |
621 | 591 |
622 buf_setpos(src, endpos - ses.keys->trans_zstream->avail_in); | 592 buf_setpos(src, endpos - ses.keys->trans.zstream->avail_in); |
623 buf_setlen(dest, dest->size - ses.keys->trans_zstream->avail_out); | 593 buf_setlen(dest, dest->size - ses.keys->trans.zstream->avail_out); |
624 buf_setpos(dest, dest->len); | 594 buf_setpos(dest, dest->len); |
625 | 595 |
626 if (result != Z_OK) { | 596 if (result != Z_OK) { |
627 dropbear_exit("zlib error"); | 597 dropbear_exit("zlib error"); |
628 } | 598 } |
629 | 599 |
630 if (ses.keys->trans_zstream->avail_in == 0) { | 600 if (ses.keys->trans.zstream->avail_in == 0) { |
631 break; | 601 break; |
632 } | 602 } |
633 | 603 |
634 dropbear_assert(ses.keys->trans_zstream->avail_out == 0); | 604 dropbear_assert(ses.keys->trans.zstream->avail_out == 0); |
635 | 605 |
636 /* the buffer has been filled, we must extend. This only happens in | 606 /* the buffer has been filled, we must extend. This only happens in |
637 * unusual circumstances where the data grows in size after deflate(), | 607 * unusual circumstances where the data grows in size after deflate(), |
638 * but it is possible */ | 608 * but it is possible */ |
639 buf_resize(dest, dest->size + ZLIB_COMPRESS_INCR); | 609 buf_resize(dest, dest->size + ZLIB_COMPRESS_INCR); |