1

I'm using pointycastle (by BouncyCastle) in Flutter for encryption/decryption. I've got the following code for encryption:

Uint8List encrypt(Uint8List key, Uint8List iv, String encryptionMethod, Uint8List data) {
    if (key.isEmpty || iv.isEmpty || encryptionMethod == "" || data.isEmpty) return Uint8List(0);


    final paddedBlockCipher = PaddedBlockCipher("AES/CFB-64/PKCS7");

    //initialize paddedBlockCipher
    final parametersWithIV = ParametersWithIV<KeyParameter>(KeyParameter(key), iv);
    final paddedBlockCipherParameters = PaddedBlockCipherParameters(parametersWithIV,null);
    paddedBlockCipher.init(true, paddedBlockCipherParameters);

    final result = paddedBlockCipher.process(data);

    return result;
  }

PaddedBlockCipher is part of the framework. I've noticed that if I input Uint8Lists of 200KB or more, it takes way too long. So I analysed the line final result = paddedBlockCipher.process(data); using debug mode with different data sizes and it turns out it has at least a polynomial runtime. Here is what i found:

Input Size (KB) | time (s)
200 | 2
400 | 15
800 | 77
1600 | 330

How is that even possible? I mean "process" is just supposed to do AES on every block which should be linear shouldn't it? Does anyone have an idea how to fix this?

2
  • Is this only for CFB or also for other modes like CBC? By the way, CFB is a stream cipher mode and should not need padding.
    – Topaco
    Jan 7, 2022 at 16:50
  • You're right, it's a lot better with f.e. CBC. BUt nothing more than like 2-3 MB/s. What i found online is way above 10MB/s, some even well over 100MB/s. That just seems kinda fishy to me.
    – Sir Falk
    Jan 7, 2022 at 17:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.