Decryption using CCCrypt returns kCCSuccess with a bad buffer size

I have an encrypted data stream (AES 128, CBC, PKCS7), which I try to decrypt as it arrives. Sometimes I get a 334 packet, which I then try to decrypt. When I do this on iPhone 5, it returns kCCBufferTooSmall (which is expected for non-mod 16 data). However, when I have the same thing on the iPhone 3GS, it returns kCCSuccess and gives me a partially decrypted stream (the last ten bytes or so 333 that it gives me are dummy - null terminators and random data).

Both devices are iOS 6.1.2. The application is built with a basic SDK installed on the latest SDK (6.1) in order to deploy iOS 5.0.

I created the following test case that also shows this problem:

 + (void)decryptionTest { NSData *data = [NSMutableData dataWithLength:334]; // 334 % 16 = 14 NSData *key = [NSMutableData dataWithLength:kCCKeySizeAES128]; NSData *iv = [NSMutableData dataWithLength:kCCBlockSizeAES128]; size_t outLength = 0; NSMutableData *cipherData = [NSMutableData dataWithLength:data.length]; CCCryptorStatus result = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding, key.bytes, key.length, iv.bytes, data.bytes, data.length, cipherData.mutableBytes, cipherData.length, &outLength); NSLog(@"result = %d", result); } 

Why am I getting kCCSuccess when it should fail due to a block size mismatch?

+4
source share

All Articles