XCode 11: Using AES CBC 256 CommonCrypto/CryptoSwift 32 bit devices return unexpected result

Dear Apple Developer team,
We're using CryptoSwift to encrypt password:

private func encryptAESCBC(rawText: String,
                               key: String) -> String {
        let iv = Data(count: 16)
        do {
            let keyData = Data(hex: key)
            print("keyData: \(keyData.bytes)")
            let aes = try AES(key: keyData.bytes, blockMode: CBC(iv: iv.bytes), padding: .pkcs7)
            let cipherPassword = try aes.encrypt(Array(rawText.utf8)).toHexString()
            print("cipherPassword: \(cipherPassword)")
            return cipherPassword
        }
        catch {
            print(error.localizedDescription)
            return ""
        }
    }


Building with Xcode below 11, everything is good. But If we build it with XCode 11 cipherPassword returned an unexpected result in 32-bit devices.
Then we tried to convert to use CommonCrypto, It returned unexpected result in 32-bit devices also.

- (NSData *)makeCryptedVersionWithKeyData:(const void*)keyData ofLength:(int)keyLength decrypt:(bool)decrypt
{
    // Copy the key data, padding with zeroes if needed
    char key[kKeySize];
    bzero(key, sizeof(key));
    memcpy(key, keyData, keyLength > kKeySize ? kKeySize : keyLength);

    size_t bufferSize = [self length] + kCCBlockSizeAES128;
    void* buffer = malloc(bufferSize);

    size_t dataUsed;

    char cIv[kCCBlockSizeAES128];
    bzero(cIv, kCCBlockSizeAES128);
    CCCryptorStatus status = CCCrypt(decrypt ? kCCDecrypt : kCCEncrypt,
                                     kCCAlgorithmAES,
                                     kCCOptionPKCS7Padding,
                                     key, kKeySize,
                                     cIv,
                                     [self bytes], [self length],
                                     buffer, bufferSize,
                                     &dataUsed);

     return [NSData dataWithBytesNoCopy:buffer length:dataUsed];
}

But If we build it using XCode 10.2.1 everything is okay, However, we upload app into AppStore connect and download by TestFlight in 32-bit devices. It returned unexpected result in 32-bit devices also. We guest after Apple update AppStore connect at Sept 10, 12 that using XCode 11 to rebuild binary with uploaded bitcode. So if we upload a build (xcode 10.2.1) without bitcode into AppStore connect and download by TestFlight everything will okay.

Just happened on 32-bit iPhone devices, 64-bit iPhone devices are good.

Replies

I had a same problems, and my app has quite a lot of users still using 32 bit devices. This problem really caused a lot of difficulties for me. Hope it fixed soon!

https://www.jianshu.com/p/cc80b4891399