Re: [RFC] CryptoAPI & Compression

Artem B. Bityuckiy
2005-04-03T10:25:57Z

Herbert Xu wrote:
> You might be right. But I'm not sure yet.
>
> If we use the current code and supply zlib_deflate with 1048576-12 bytes
> of (incompressible) input and 1048576 bytes of output buffer, wouldn't
> zlib keep writing incompressible blocks and return when it can't do that
> anymore because the output buffer has been exhausted?
It must not. Look at the algoritm closer.

stream->next_in = (u8 *)src;
stream->next_out = dst;

while (stream->total_in < *slen
&& stream->total_out < *dlen - DEFLATE_PCOMPR_RESERVE) {

stream->avail_out = *dlen - DEFLATE_PCOMPR_RESERVE -
stream->total_out;
stream->avail_in = min((unsigned int)(*slen -
stream->total_in), stream->avail_out);

ret = zlib_deflate(stream, Z_SYNC_FLUSH);
if (ret != Z_OK)
return -EINVAL;
}

stream->avail_out += DEFLATE_PCOMPR_RESERVE;
stream->avail_in = 0; /* <------ no more input ! ---------- */

ret = zlib_deflate(stream, Z_FINISH);
if (ret != Z_STREAM_END)
return -EINVAL;

>
> When it does return it has to finish writing the last block it's on.
No, it must only put EOB and adler32, we won't give it more input.