Skip to content

Use System.Security.Cryptography for TripleDesCipher - #1546

Merged
Rob-Hague merged 5 commits into
sshnet:developfrom
scott-xu:des
Dec 27, 2024
Merged

Use System.Security.Cryptography for TripleDesCipher#1546
Rob-Hague merged 5 commits into
sshnet:developfrom
scott-xu:des

Conversation

@scott-xu

@scott-xuscott-xu commented Nov 30, 2024

Copy link
Copy Markdown
Collaborator

This PR

  • changes TripleDesCipher to use BCL's TripleDES.
  • drops support for DesCipher. It is only used to decrypt OpenSSL legacy private key format (aka PKCS1). Suggest switching to newer encryption method.
  • changes PKCS7Padding to use BouncyCaslte's implementation.
  • renames AesCipherMode to BlockCipherMode. Some previous discussion: Use hardware-accelerated AES CryptoServiceProvider #865 (comment)

Benchmarks based on .NET 9.0.0 (9.0.24.52809), X64 RyuJIT AVX2

Before:

MethodMeanErrorStdDevGen0Gen1Allocated
Encrypt_CBC1.379 ms0.0268 ms0.0402 ms39.06251.9531161.19 KB
Decrypt_CBC1.333 ms0.0202 ms0.0189 ms39.06251.9531161.19 KB
Encrypt_CFB1.371 ms0.0263 ms0.0281 ms39.06251.9531161.23 KB
Decrypt_CFB1.379 ms0.0164 ms0.0146 ms39.06251.9531161.23 KB

After:

MethodMeanErrorStdDevGen0Allocated
Encrypt_CBC1,018.1 us20.33 us28.50 us7.812533.18 KB
Decrypt_CBC966.5 us19.25 us20.60 us7.812533.18 KB
Encrypt_CFB1,016.6 us15.57 us14.57 us7.812533.18 KB
Decrypt_CFB970.4 us13.38 us12.52 us7.812533.18 KB

@Rob-Hague

Copy link
Copy Markdown
Collaborator

We could consider dropping DesCipher

@scott-xu

Copy link
Copy Markdown
CollaboratorAuthor

Agree

@scott-xuscott-xu changed the title Use System.Security.Cryptography for DesCipher and TripleDesCipher and falls back to use BouncyCastle if BCL doesn't supportUse System.Security.Cryptography for TripleDesCipher and falls back to use BouncyCastle if BCL doesn't supportDec 22, 2024
@scott-xu
scott-xu marked this pull request as ready for review December 22, 2024 16:02
@scott-xuscott-xu changed the title Use System.Security.Cryptography for TripleDesCipher and falls back to use BouncyCastle if BCL doesn't supportUse System.Security.Cryptography for TripleDesCipher and fall back to use BouncyCastle if BCL doesn't supportDec 22, 2024
@scott-xu

scott-xu commented Dec 24, 2024

Copy link
Copy Markdown
CollaboratorAuthor

Might also be a good chance to drop home-made CfbCipherMode and OfbCipherMode.

  • CfbCipherMode is only used for PKCS1 private key encrypted byDES-EDE3-CFB.
  • OfbCipherMode is not used anywhere inside the library.

Further more, we can consider changing all Renci.SshNet.Security.Cryptography.* internal.

@Rob-Hague

Copy link
Copy Markdown
Collaborator

possibly yes, but I would prefer to think about that separately. Can you restore CbcCipherMode here?

@scott-xu

Copy link
Copy Markdown
CollaboratorAuthor

CbcCipherMode is restored.

@scott-xuscott-xu changed the title Use System.Security.Cryptography for TripleDesCipher and fall back to use BouncyCastle if BCL doesn't supportUse System.Security.Cryptography for TripleDesCipherDec 27, 2024
This was referenced Aug 12, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@scott-xu@Rob-Hague