-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Use OpenSSL implementation of AES Key Wrap with Padding on Linux #117256
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
Open
bartonjs
wants to merge
14
commits into
dotnet:main
Choose a base branch
from
bartonjs:aeskw_ossl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
cdcee07
Managed code to call OSSL AES-KW
bartonjs 770275e
Native code for OSSL AES-KW
bartonjs eeee023
Apply feedback
bartonjs 904163a
Set EVP_CIPHER_CTX_FLAG_WRAP_ALLOW for OpenSSL 1.1
vcsjones 52caa37
Add Dispose while we are here
vcsjones 65e1169
Protect portable with flag value assertion
bartonjs e2fb2fa
Set EVP_CIPHER_CTX_FLAG_WRAP_ALLOW for OpenSSL 1.1
bartonjs cd944cb
Merge branch 'main' into aeskw_ossl
bartonjs e7605b8
Merge branch 'main' into aeskw_ossl
bartonjs c28d629
Merge branch 'main' into aeskw_ossl
bartonjs f080022
Merge branch 'main' into aeskw_ossl
bartonjs f6d9563
Add OpenSSL version number to output
vcsjones 49a9c6c
Revert "Add OpenSSL version number to output"
vcsjones 19cfb1b
Merge branch 'main' into aeskw_ossl
bartonjs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ystem.Security.Cryptography/src/System/Security/Cryptography/AesImplementation.Android.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Security.Cryptography | ||
{ | ||
internal sealed partial class AesImplementation | ||
{ | ||
private static UniversalCryptoTransform CreateTransformCore( | ||
CipherMode cipherMode, | ||
PaddingMode paddingMode, | ||
ReadOnlySpan<byte> key, | ||
byte[]? iv, | ||
int blockSize, | ||
int paddingSize, | ||
int feedback, | ||
bool encrypting) | ||
{ | ||
// The algorithm pointer is a static pointer, so not having any cleanup code is correct. | ||
IntPtr algorithm = GetAlgorithm(key.Length * 8, feedback * 8, cipherMode); | ||
|
||
BasicSymmetricCipher cipher = new OpenSslCipher(algorithm, cipherMode, blockSize, paddingSize, key, iv, encrypting); | ||
return UniversalCryptoTransform.Create(paddingMode, cipher, encrypting); | ||
} | ||
|
||
private static OpenSslCipherLite CreateLiteCipher( | ||
CipherMode cipherMode, | ||
ReadOnlySpan<byte> key, | ||
ReadOnlySpan<byte> iv, | ||
int blockSize, | ||
int paddingSize, | ||
int feedback, | ||
bool encrypting) | ||
{ | ||
IntPtr algorithm = GetAlgorithm(key.Length * 8, feedback * 8, cipherMode); | ||
return new OpenSslCipherLite(algorithm, blockSize, paddingSize, key, iv, encrypting); | ||
} | ||
|
||
private static IntPtr GetAlgorithm(int keySize, int feedback, CipherMode cipherMode) => | ||
(keySize, cipherMode) switch | ||
{ | ||
// Neither OpenSSL nor Cng Aes support CTS mode. | ||
|
||
(128, CipherMode.CBC) => Interop.Crypto.EvpAes128Cbc(), | ||
(128, CipherMode.ECB) => Interop.Crypto.EvpAes128Ecb(), | ||
(128, CipherMode.CFB) when feedback == 8 => Interop.Crypto.EvpAes128Cfb8(), | ||
(128, CipherMode.CFB) when feedback == 128 => Interop.Crypto.EvpAes128Cfb128(), | ||
|
||
(192, CipherMode.CBC) => Interop.Crypto.EvpAes192Cbc(), | ||
(192, CipherMode.ECB) => Interop.Crypto.EvpAes192Ecb(), | ||
(192, CipherMode.CFB) when feedback == 8 => Interop.Crypto.EvpAes192Cfb8(), | ||
(192, CipherMode.CFB) when feedback == 128 => Interop.Crypto.EvpAes192Cfb128(), | ||
|
||
(256, CipherMode.CBC) => Interop.Crypto.EvpAes256Cbc(), | ||
(256, CipherMode.ECB) => Interop.Crypto.EvpAes256Ecb(), | ||
(256, CipherMode.CFB) when feedback == 8 => Interop.Crypto.EvpAes256Cfb8(), | ||
(256, CipherMode.CFB) when feedback == 128 => Interop.Crypto.EvpAes256Cfb128(), | ||
|
||
_ => throw (keySize == 128 || keySize == 192 || keySize == 256 ? (Exception) | ||
new NotSupportedException() : | ||
new CryptographicException(SR.Cryptography_InvalidKeySize)), | ||
}; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.