-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix up Aes CCM/GCM support #48728
Fix up Aes CCM/GCM support #48728
Conversation
Fixes dotnet#48471 This gets 49 more tests passing (split between Ccm and Gcm tests and sadly no full test suites).
…pl has a lot of special cases that we don't need to handle (and handling them makes the code significantly harder to read).
…he shim. This fixes cases where the ciphertext returned from doFinal is either part or all of the tag (and no ciphertext).
Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq, @GrabYourPitchforks Issue DetailsFixes #48471 This gets all the tests passing in the AES/CCM and AES/GCM test suites. This PR splits the managed implementation for AES/CCM and AES/GCM from OpenSSL for Android since the authentication tag handling required for Android is different enough from OpenSSL to make the code to correctly handle it with the OpenSSL shim surface area extremely confusing.
|
...s/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesGcm.Android.cs
Show resolved
Hide resolved
...s/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesGcm.Android.cs
Outdated
Show resolved
Hide resolved
...ries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesCcm.Unix.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesCcm.Android.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesGcm.Android.cs
Outdated
Show resolved
Hide resolved
...Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.EVP.Cipher.cs
Outdated
Show resolved
Hide resolved
...Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.EVP.Cipher.cs
Outdated
Show resolved
Hide resolved
src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_evp_cipher.c
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesCcm.Android.cs
Outdated
Show resolved
Hide resolved
…hicExceptions. Check for overflow.
src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_cipher.c
Outdated
Show resolved
Hide resolved
src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_cipher.c
Outdated
Show resolved
Hide resolved
if(tagLength > TAG_MAX_LENGTH) | ||
return FAIL; | ||
|
||
ctx->tagLength = tagLength; |
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.
Does this permit resetting? Perhaps there is some invariant we should assert prior.
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.
Yes, this can be reset when the cipher is reused.
…nter-sized values.
src/libraries/Native/Unix/System.Security.Cryptography.Native.Android/pal_cipher.c
Show resolved
Hide resolved
return ReinitializeCipher(ctx); | ||
} | ||
|
||
CipherCtx* AndroidCryptoNative_CipherCreate2(CipherInfo* type, uint8_t* key, int32_t keyLength, int32_t effectiveKeyLength, uint8_t* iv, int32_t enc) |
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.
"CipherCreate2", already? 😄. If our OpenSSL shim has CIpherCreate2 it's because we created it during complex SxS upgrade time and didn't want to change CipherCreate.
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.
I’ll remove the 2 suffix.
...s/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesCcm.Android.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesCcm.Android.cs
Outdated
Show resolved
Hide resolved
...ies/Common/src/Interop/Android/System.Security.Cryptography.Native.Android/Interop.Cipher.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/AesGcm.Android.cs
Outdated
Show resolved
Hide resolved
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.
Some oddness around the exceptions/messages when CipherUpdate fails, and I'd always love to see less name reuse from the OpenSSL interop code, but otherwise LGTM.
Hello @jkoritzinsky! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Fixes #48471
This gets all the tests passing in the AES/CCM and AES/GCM test suites.
This PR splits the managed implementation for AES/CCM and AES/GCM from OpenSSL for Android since the authentication tag handling required for Android is different enough from OpenSSL to make the code to correctly handle it with the OpenSSL shim surface area extremely confusing.