0
$\begingroup$

With the C api for Apple's Common Crypto, why is it sometimes necessary to call both CCCryptorUpdate and CCCryptorFinal?

I read in the documentation that CCCryptorFinal is not needed when: 1. Encrypting or decrypting with a block cipher with padding disabled, when the total amount of data provided to CCCryptorUpdate() is an integral multiple of the block size. 2. Encrypting or decrypting with a stream cipher.

So it seems like it has something to do specifically with dealing with the padding for block cipher encrypted data, but I was hoping for more information.

$\endgroup$

closed as off-topic by e-sushi Nov 14 '17 at 6:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions are off-topic even if you are writing or debugging cryptographic code. Unless your question is specifically about how the cryptographic algorithm, protocol or side-channel (mitigation) works, you should look into asking on Stack Overflow instead." – e-sushi
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ When padding is disabled in block mode the input must be a multiple of the block size or an encryption error will occur. Also note that there is a one-shot option CCCrypt. $\endgroup$ – zaph Nov 13 '17 at 17:24
  • $\begingroup$ Yes.... but why do we need both CCCryptorUpdate and CCCryptorFinal? What is the advantage to splitting the process up? $\endgroup$ – krisennay Nov 13 '17 at 17:27
  • $\begingroup$ CCCryptorFinal is necessary when CCCryptorUpdate is being used and padding is specified in order to know when the last block is being encrypted so the padding can be added. The advantage to splitting up the process might be to use smaller buffers, etc, Consider encrypting a multi-GB file. $\endgroup$ – zaph Nov 13 '17 at 17:30
  • $\begingroup$ Okay, gotcha! That makes sense! $\endgroup$ – krisennay Nov 13 '17 at 17:34
0
$\begingroup$

Re-phrasing the comments into an answer as the question changed during comments:

CCCryptorFinal is necessary when CCCryptorUpdate is being used and padding is specified in order to know when the last block is being encrypted so the padding can be added.

The advantage to splitting up the process might be to use smaller buffers, etc, Consider encrypting a multi-GB file.

Additionally there are encryption modes that are not supported by the one-shot CCCrypt which only supports ECB and CBC modes.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.