1

The signature of one-shot crypto method CCCrypt is this (from CommonCryptor.h):

CCCryptorStatus CCCrypt(
    CCOperation op,         /* kCCEncrypt, etc. */
    CCAlgorithm alg,        /* kCCAlgorithmAES128, etc. */
    CCOptions options,      /* kCCOptionPKCS7Padding, etc. */
    const void *key,
    size_t keyLength,
    const void *iv,         /* optional initialization vector */
    const void *dataIn,     /* optional per op and alg */
    size_t dataInLength,
    void *dataOut,          /* data RETURNED here */
    size_t dataOutAvailable,
    size_t *dataOutMoved)

None of the parameter seems to accept a CCMode value (maybe sneakily, since all the enums are integers?). I have tried around combining it with the CCOptions parameter, but to no avail; the two enums are not options, and don't combine unambiguously.

It's not explicitly documented there, but I surmise from what I find around the web that the mode used with kCCAlgorithmAES is CBC.

How can I change the AES mode CCCrypt uses?

Raphael
  • 9,779
  • 5
  • 63
  • 94
  • It's pretty easy to implement other modes if you have access to ECB or CBC. The only challenge is to correctly implement the counter which is encrypted for each block. – Artjom B. Jul 12 '17 at 16:37
  • @ArtjomB. Yea, no, I won't go around and implement crypto methods myself. That way only doom and madness lie. – Raphael Jul 12 '17 at 17:51
  • @zaph - I expected to see you answer this one. Don't you have a crypto library based on Apple Common Crypto? – jww Jul 14 '17 at 19:40

1 Answers1

1

The documentation says:

CCCrypt Stateless, one-shot encrypt or decrypt operation. This basically performs a sequence of CCCrytorCreate() [sic], CCCryptorUpdate(), CCCryptorFinal(), and CCCryptorRelease().

Now, CCCryptorCreate does not seem to accept a mode parameter, either; in fact, we see that CBC is indeed hardcoded (aside from the one, somewhat arbitrary that allows us to use ECB):

/* Determine mode from options - old call only supported ECB and CBC 
   we treat RC4 as a "mode" in that it's the only streaming cipher
   currently supported 
*/
if(alg == kCCAlgorithmRC4) mode = kCCModeRC4;
else if(options & kCCOptionECBMode) mode = kCCModeECB;
else mode = kCCModeCBC;

If we want to use another mode we have to use CCCryptorCreateWithMode. So, unfortunately, it does not appear to be possible to change the mode of CCCrypt.

Raphael
  • 9,779
  • 5
  • 63
  • 94