-
Notifications
You must be signed in to change notification settings - Fork 473
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
Use hardware accelerated Aes on x64 #5196
Conversation
Contributed the improvement upstream bcgit/bc-csharp#414 |
This looks great. On the other hand, I'm considering replacing the BouncyCastle implementation with .NET's own one. |
Aren't necessarily incompatible; as I assume switching implementation will be a longer and more involved process due to different abstractions? So could do this change as quick win; then follow up with implementation change? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested. No issues.
I'm surprised that this is way faster than the implementation of |
Glad to here, I did spend quite a while optimizing the inheritance chain and implementation to get it just so 😅 However everything else is just abstraction cruft; so if you can take this implementation (and the sealed implementation inherence; which the Jit can then switch to direct calls as only use one type size of key and either encryption or decryption but not both at each call site) and combine it with platform version (which will be better for Arm and fallback); rather than bouncy castle; should have a very fast implementation. |
What is the speedup? |
The implementation of Aes in OpenSsl and Windows side is very good; however for small payloads might pay in interop and abstractions to get there? |
Changes
System.Runtime.Intrinsics.X86.Aes
when supportedTypes of changes
Generates clean hardware accelerated asm for the encypt+decrypt methods compared to the software version. E.g. the encrypt 256 is below
What types of changes does your code introduce?
Testing
Confirmed all the Aes goes through the accelerated
IBlockCipher
on supported hardware (everything x64)Requires testing
If yes, did you write tests?