1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
4 using Internal.Cryptography;
6 namespace System.Security.Cryptography
8 internal sealed partial class DesImplementation
10 private static UniversalCryptoTransform CreateTransformCore(
11 CipherMode cipherMode,
12 PaddingMode paddingMode,
20 // The algorithm pointer is a static pointer, so not having any cleanup code is correct.
21 IntPtr algorithm = GetAlgorithm(cipherMode, feedbackSize);
23 Interop.Crypto.EnsureLegacyAlgorithmsRegistered();
25 BasicSymmetricCipher cipher = new OpenSslCipher(algorithm, cipherMode, blockSize, paddingSize, key, iv, encrypting);
26 return UniversalCryptoTransform.Create(paddingMode, cipher, encrypting);
29 private static ILiteSymmetricCipher CreateLiteCipher(
30 CipherMode cipherMode,
31 ReadOnlySpan<byte> key,
32 ReadOnlySpan<byte> iv,
38 // The algorithm pointer is a static pointer, so not having any cleanup code is correct.
39 IntPtr algorithm = GetAlgorithm(cipherMode, feedbackSize);
41 Interop.Crypto.EnsureLegacyAlgorithmsRegistered();
42 return new OpenSslCipherLite(algorithm, blockSize, paddingSize, key, iv, encrypting);
45 private static IntPtr GetAlgorithm(CipherMode cipherMode, int feedbackSize)
47 return cipherMode switch
49 CipherMode.CBC => Interop.Crypto.EvpDesCbc(),
50 CipherMode.ECB => Interop.Crypto.EvpDesEcb(),
51 CipherMode.CFB when feedbackSize == 1 => Interop.Crypto.EvpDesCfb8(),
52 _ => throw new NotSupportedException(),