Use BCL CipherMode enum for AesCipher class#1564
Use BCL CipherMode enum for AesCipher class#1564scott-xu wants to merge 3 commits intosshnet:developfrom
Conversation
166cd93 to
e02f749
Compare
|
Is there a benefit to this? |
|
FYI: some previous discussion: #865 (comment) |
|
The main purpose is to use BCL as possible as it can. |
|
Thanks, I remember the previous discussion, but I don't think it is worth changing the API right now. Maybe at a later time |
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the cipher implementation to use the BCL CipherMode enum instead of a custom AesCipherMode enum, and creates a dedicated AesCtrCipher class similar to the existing AesGcmCipher class. The changes remove support for DES-EDE3-CFB encryption and eliminate custom cipher mode implementations in favor of BCL-provided functionality.
- Replaced custom
AesCipherModeenum with BCL'sSystem.Security.Cryptography.CipherMode - Created dedicated
AesCtrCipherclass for CTR mode encryption - Removed DES-EDE3-CFB support and associated test data
- Simplified cipher implementations by removing custom mode classes (CFB, CTR, OFB, CBC)
Reviewed Changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.cs |
Refactored to use BCL CipherMode and simplified implementation |
src/Renci.SshNet/Security/Cryptography/Ciphers/AesCtrCipher.cs |
New dedicated class for AES-CTR mode |
src/Renci.SshNet/Security/Cryptography/Ciphers/TripleDesCipher.cs |
Refactored to use BCL CipherMode |
src/Renci.SshNet/PrivateKeyFile.*.cs |
Updated cipher instantiation to use BCL CipherMode |
src/Renci.SshNet/ConnectionInfo.cs |
Updated cipher configurations to use new class constructors |
test/**/*CipherTest*.cs |
Updated tests to use BCL CipherMode and new AesCtrCipher class |
| Multiple cipher mode files | Removed custom implementations (CFB, CTR, OFB, CBC, CipherMode base) |
test/Data/Key.RSA.Encrypted.Des.Ede3.CFB.* |
Removed test data for unsupported DES-EDE3-CFB |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/Renci.SshNet/Security/Cryptography/Ciphers/TripleDesCipher.cs
Outdated
Show resolved
Hide resolved
1b1c639 to
86d3a29
Compare
86d3a29 to
0a89a35
Compare
|
IMHO, SSH.NET should be the client of SSH but not a cryptography library. That's the reason why I hide |
0a89a35 to
2b4037b
Compare
|
Could you please have another review of this PR please? @Rob-Hague |
|
I am fine with dropping BlockCipher (and CipherMode), but I would rather not change AesCipher until there is a compelling reason, otherwise it is just churn. If you can put it back, I'll merge the rest |
|
The reason is
|
2b4037b to
98c45ed
Compare
| /// AES cipher implementation. | ||
| /// </summary> | ||
| public sealed partial class AesCipher : BlockCipher, IDisposable | ||
| internal sealed class AesCipher : SymmetricCipher, IDisposable |
There was a problem hiding this comment.
Note: this is a breaking change of public API
| /// Implements 3DES cipher algorithm. | ||
| /// </summary> | ||
| public sealed partial class TripleDesCipher : BlockCipher, IDisposable | ||
| internal sealed class TripleDesCipher : SymmetricCipher, IDisposable |
There was a problem hiding this comment.
This is a breaking change of public API
| if (mode == AesCipherMode.OFB) | ||
| { | ||
| // OFB is not supported on modern .NET | ||
| _impl = new BlockImpl(key, new OfbCipherMode(iv), pkcs7Padding ? new Pkcs7Padding() : null); | ||
| } |
There was a problem hiding this comment.
OFB is not used anywhere
| else if (mode == AesCipherMode.CFB) | ||
| { | ||
| // CFB not supported on NetStandard 2.1 | ||
| _impl = new BlockImpl(key, new CfbCipherMode(iv), pkcs7Padding ? new Pkcs7Padding() : null); | ||
| } |
There was a problem hiding this comment.
CFB is not used anywhere
| else if (mode == AesCipherMode.CTR) | ||
| { | ||
| // CTR not supported by the BCL, use an optimized implementation | ||
| _impl = new CtrImpl(key, iv); | ||
| } |
There was a problem hiding this comment.
BCL CipherMode does not have CTR mode
d4891a9 to
e0c4906
Compare
|
BTW, I would suggest renaming |
… class; Create a dedicated AesCtrCipher class just like AesGcmCipher class.
e0c4906 to
2ebb953
Compare
|
|
de35184 to
d8ffc06
Compare

Create a dedicated AesCtrCipher class just like AesGcmCipher class.
Relate to #1560