cryptography icon indicating copy to clipboard operation
cryptography copied to clipboard

Slow AES-GCM decryption for initial runs

Open dv30fps opened this issue 4 years ago • 2 comments

I am developing an app on the Android simulator in debug mode. The user sets a configuration and the app begins solving a problem. The app needs to do the following for 16 iterations: Read a file from local storage with size 154 KB to 177 KB; Decrypt the file encoded with AES-GCM-128; Check the SHA256; Inflate the GZIP file; Reformat the data in memory for consumption by the app.

All of the operations take on the order of 20-150 ms except the first run(s) of decryption. For the first three files, decryption with the Cryptography package takes 32.35, 0.408, 0.111 seconds. Thereafter, decryption takes 0.094 to 0.156 seconds.

The Cryptography Flutter package is worse. For the first six files, decryption takes 32.971, 37.251, 38.330, 38.853, 0.669, 0.128 seconds. Thereafter, decryption takes around 0.13 seconds.

Questions: Why is the Cryptography package so slow for decryption in the initial runs? Would this behavior occur on real devices when built for highest performance?

dv30fps avatar Dec 06 '21 04:12 dv30fps

I decided to boot Cryptography Flutter from my app because of its appallingly bad performance. I am replacing it with native-crypto-flutter. While native-crypto lacks the polish of a mature package, it can encrypt or decrypt a 170 KB file in 11 ms compared to Cryptography Flutter at 94 ms in the best case or 39 seconds in the worse case.

dv30fps avatar Dec 17 '21 05:12 dv30fps

any fix or infos on this issue yet ?

theogrillat avatar Apr 29 '22 22:04 theogrillat

Fixed in cryptography_flutter 2.1.0.

terrier989 avatar Mar 03 '23 19:03 terrier989