-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question about AES/CBC speed #173
Comments
Hello, you’re not alone :) I use a similar implementation as you do and I also get similar results. I’m getting around ~9 mb/s on my laptop (AES/CBC, 256 bits key, running flutter app in release mode, encryption itself in separate isolate), less than that on some slower phones, meanwhile AES/CBC in Java/Kotlin (same modes, same params, same devices) encrypts at 200-300+ mb/s (desktop) and 80+ mb/s (phones). I have also tested the deprecated AESFastEngine engine. It can encrypt at ~20 mb/s on my machine. Do we know what is the bottleneck in the current implementation of AESEngine? |
Ah, I think I get it now after digging into the source code. aes.dart uses only one T-table, Check out section 5 Implementation aspects of the rijndael block cipher for more info. (this is a pdf) edit: |
How did you get aes_fast.dart to work? I can't seem to get it to work. Also, what package are you using for Java/Kotlin? BouncyCastle or something else? I have created gist for the "cryptography" package example if you want to try it. It will encrypt 100mb the same way as the gist provided in the original post for pointycastle (https://gist.github.com/hootyjeremy/97ccfe7b1203ac5160b4544a237b9b5a). I can't seem to get aes_fast.dart to work right now so I can't compare it to this other package. "cryptography" package by dint.dev... Does that package provide faster results than aes_fast.dart for you? |
I’ve modified your AES/CBC gist to run with AESFastEngine: it gives me following results: For comparison, same test, but with standard AESEngine, from Pointy Castle: with your cryptography test: With java/kotlin I use javax.crypto API. I guess I will end up writing native code for AES encryption / decryption (java / swift / other) and keep Pointy Castle as a fallback for platforms where I don’t have native implementation. |
Thanks for the benchmarks. I'm not yet sure why pointycastle's implementation is slower than I would like to be able to use aesni first and then fallback to a software implementation but I haven't found any packages that use CBC with aesni. Sodium will do aesni but only uses GCM which is fine except that it doesn't have a software fallback. But I've only found that the software implementations for GCM are even slower than CBC so I don't even want to use GCM. If you don't mind my asking, what is the difference in writing it natively vs. with dart? Why is that faster if flutter/dart is said to compile to native code? |
I guess it’s about code optimization itself. I mean just compiling to native code doesn’t mean it’s optimal. I’m not sure what speed you require in your implementation, but for my use cases, javax.crypto + “whatever is selected by default” is usually enough.
For CBC vs GCM, check this post: |
Thanks for the info. I'll give these a read. |
I am interested in using this package but when I test encrypting 100mb with AES/CBC, it takes about 7 seconds in release mode on my machine. I know that speed on machines are relative so I have a gist of the example code here which will print elapsed time:
https://gist.github.com/hootyjeremy/97ccfe7b1203ac5160b4544a237b9b5a
I can understand that this is software implemented AES and not aesni, but does this seem extremely slow for anybody else? Even that it is a software implementation, I wouldn't expect more than 0.5 to 1 seconds to encrypt 100mb.
Can anybody verify if I am getting acceptable speeds with this package or if this is an anomaly?
The text was updated successfully, but these errors were encountered: