# Common Crypto C api: Why both CCCryptorUpdate() and CCCryptorFinal()? [closed]

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.

## closed as off-topic by e-sushiNov 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.

• 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. – zaph Nov 13 '17 at 17:24
• Yes.... but why do we need both CCCryptorUpdate and CCCryptorFinal? What is the advantage to splitting the process up? – krisennay Nov 13 '17 at 17:27
• 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. – zaph Nov 13 '17 at 17:30
• Okay, gotcha! That makes sense! – krisennay Nov 13 '17 at 17:34

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.
Additionally there are encryption modes that are not supported by the one-shot CCCrypt which only supports ECB and CBC modes.