<div dir="ltr"><div>Hello Paul, </div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 19, 2018 at 6:02 AM Paul Smith <<a href="mailto:paul@mad-scientist.net">paul@mad-scientist.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all; I'm working with OpenSSL 1.1.1a, using the EVP interface to<br>
encrypt/decrypt with various ciphers/modes.<br>
<br>
I had a couple of questions:<br>
<br>
<br>
First, the encrypt update docs say:<br>
<br>
> the amount of data written may be anything from zero bytes to<br>
> (inl + cipher_block_size - 1)<br>
<br>
Is that really true?  For example if my block size is 16 and my input<br>
length is 4, could the encrypt step really write as many as 19 bytes<br>
(4 + 16 - 1)?<br>
<br>
I would have thought that the true maximum would be round-up(inl,<br>
cipher_block_size); that is, for inl values 1-15 you'd get 16 bytes,<br>
and for inl values 16-31 you'd get 32 bytes, etc. (I'm not actually<br>
sure whether inl of 16 gets you 16 or 32 bytes...)<br>
<br>
Am I wrong about that?  Would some ciphers/modes write beyond the end<br>
of the current "block" and into the next one?<br></blockquote><div><br></div><div>When you use a block cipher and pass data less than block size, it is stored in the internal buffer. </div><div>In this case you do not get encrypted data until there is enough plain text to encrypt the full block.</div><div><br></div><div>When you add more data, if you pass enough data to finalize a previously unfinished block, </div><div>you get more long ciphertext than plaintext passed in a particular call of CipherUpdate.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
Second, the type of the outl parameter on EVP encrypt update is "int",<br>
rather than (as I would have expected) "unsigned int".  Is there a<br>
possibility that EVP would set &outl to a negative value and if so,<br>
what would that mean?  Do I need to check for this in my code?  Same<br>
with inl; why isn't it "unsigned int"?  Is there ever a reason to pass<br>
in a negative value?<br></blockquote><div><br></div><div>I strongly suspect just historical reasons here.</div><div> </div></div>-- <br><div dir="ltr" class="gmail_signature">SY, Dmitry Belyavsky</div></div>