diff --git a/src/Renci.SshNet/ConnectionInfo.cs b/src/Renci.SshNet/ConnectionInfo.cs index 3a60ad3ec..461730f62 100644 --- a/src/Renci.SshNet/ConnectionInfo.cs +++ b/src/Renci.SshNet/ConnectionInfo.cs @@ -364,15 +364,15 @@ public ConnectionInfo(string host, int port, string username, ProxyTypes proxyTy Encryptions = new Dictionary { - { "aes128-ctr", new CipherInfo(128, (key, iv) => new AesCipher(key, iv, AesCipherMode.CTR, pkcs7Padding: false)) }, - { "aes192-ctr", new CipherInfo(192, (key, iv) => new AesCipher(key, iv, AesCipherMode.CTR, pkcs7Padding: false)) }, - { "aes256-ctr", new CipherInfo(256, (key, iv) => new AesCipher(key, iv, AesCipherMode.CTR, pkcs7Padding: false)) }, + { "aes128-ctr", new CipherInfo(128, (key, iv) => new AesCtrCipher(key, iv)) }, + { "aes192-ctr", new CipherInfo(192, (key, iv) => new AesCtrCipher(key, iv)) }, + { "aes256-ctr", new CipherInfo(256, (key, iv) => new AesCtrCipher(key, iv)) }, { "aes128-gcm@openssh.com", new CipherInfo(128, (key, iv) => new AesGcmCipher(key, iv, aadLength: 4), isAead: true) }, { "aes256-gcm@openssh.com", new CipherInfo(256, (key, iv) => new AesGcmCipher(key, iv, aadLength: 4), isAead: true) }, { "chacha20-poly1305@openssh.com", new CipherInfo(512, (key, iv) => new ChaCha20Poly1305Cipher(key, aadLength: 4), isAead: true) }, - { "aes128-cbc", new CipherInfo(128, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: false)) }, - { "aes192-cbc", new CipherInfo(192, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: false)) }, - { "aes256-cbc", new CipherInfo(256, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: false)) }, + { "aes128-cbc", new CipherInfo(128, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: false)) }, + { "aes192-cbc", new CipherInfo(192, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: false)) }, + { "aes256-cbc", new CipherInfo(256, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: false)) }, { "3des-cbc", new CipherInfo(192, (key, iv) => new TripleDesCipher(key, iv, CipherMode.CBC, pkcs7Padding: false)) }, }; diff --git a/src/Renci.SshNet/PrivateKeyFile.OpenSSH.cs b/src/Renci.SshNet/PrivateKeyFile.OpenSSH.cs index a91635146..5c866af23 100644 --- a/src/Renci.SshNet/PrivateKeyFile.OpenSSH.cs +++ b/src/Renci.SshNet/PrivateKeyFile.OpenSSH.cs @@ -95,22 +95,22 @@ public Key Parse() cipherInfo = new CipherInfo(192, (key, iv) => new TripleDesCipher(key, iv, CipherMode.CBC, pkcs7Padding: false)); break; case "aes128-cbc": - cipherInfo = new CipherInfo(128, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: false)); + cipherInfo = new CipherInfo(128, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: false)); break; case "aes192-cbc": - cipherInfo = new CipherInfo(192, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: false)); + cipherInfo = new CipherInfo(192, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: false)); break; case "aes256-cbc": - cipherInfo = new CipherInfo(256, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: false)); + cipherInfo = new CipherInfo(256, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: false)); break; case "aes128-ctr": - cipherInfo = new CipherInfo(128, (key, iv) => new AesCipher(key, iv, AesCipherMode.CTR, pkcs7Padding: false)); + cipherInfo = new CipherInfo(128, (key, iv) => new AesCtrCipher(key, iv)); break; case "aes192-ctr": - cipherInfo = new CipherInfo(192, (key, iv) => new AesCipher(key, iv, AesCipherMode.CTR, pkcs7Padding: false)); + cipherInfo = new CipherInfo(192, (key, iv) => new AesCtrCipher(key, iv)); break; case "aes256-ctr": - cipherInfo = new CipherInfo(256, (key, iv) => new AesCipher(key, iv, AesCipherMode.CTR, pkcs7Padding: false)); + cipherInfo = new CipherInfo(256, (key, iv) => new AesCtrCipher(key, iv)); break; case "aes128-gcm@openssh.com": cipherInfo = new CipherInfo(128, (key, iv) => new AesGcmCipher(key, iv, aadLength: 0), isAead: true); diff --git a/src/Renci.SshNet/PrivateKeyFile.PKCS1.cs b/src/Renci.SshNet/PrivateKeyFile.PKCS1.cs index 606bb00fb..f57498db5 100644 --- a/src/Renci.SshNet/PrivateKeyFile.PKCS1.cs +++ b/src/Renci.SshNet/PrivateKeyFile.PKCS1.cs @@ -57,13 +57,13 @@ public Key Parse() cipher = new CipherInfo(192, (key, iv) => new TripleDesCipher(key, iv, CipherMode.CFB, pkcs7Padding: false)); break; case "AES-128-CBC": - cipher = new CipherInfo(128, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: true)); + cipher = new CipherInfo(128, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: true)); break; case "AES-192-CBC": - cipher = new CipherInfo(192, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: true)); + cipher = new CipherInfo(192, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: true)); break; case "AES-256-CBC": - cipher = new CipherInfo(256, (key, iv) => new AesCipher(key, iv, AesCipherMode.CBC, pkcs7Padding: true)); + cipher = new CipherInfo(256, (key, iv) => new AesCipher(key, iv, CipherMode.CBC, pkcs7Padding: true)); break; default: throw new SshException(string.Format(CultureInfo.InvariantCulture, "Private key cipher \"{0}\" is not supported.", _cipherName)); diff --git a/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs b/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs index 627fcb991..f772ba906 100644 --- a/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs +++ b/src/Renci.SshNet/PrivateKeyFile.PuTTY.cs @@ -14,6 +14,8 @@ using Renci.SshNet.Security; using Renci.SshNet.Security.Cryptography.Ciphers; +using CipherMode = System.Security.Cryptography.CipherMode; + namespace Renci.SshNet { public partial class PrivateKeyFile @@ -111,7 +113,7 @@ public Key Parse() throw new SshException("PuTTY key file version " + _version + " is not supported"); } - using (var cipher = new AesCipher(cipherKey, cipherIV, AesCipherMode.CBC, pkcs7Padding: false)) + using (var cipher = new AesCipher(cipherKey, cipherIV, CipherMode.CBC, pkcs7Padding: false)) { privateKey = cipher.Decrypt(_data); } diff --git a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.CtrImpl.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.CtrImpl.cs deleted file mode 100644 index 0d4dde5cd..000000000 --- a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.CtrImpl.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Buffers.Binary; -using System.Numerics; -using System.Security.Cryptography; - -namespace Renci.SshNet.Security.Cryptography.Ciphers -{ - public partial class AesCipher - { - private sealed class CtrImpl : BlockCipher, IDisposable - { - private readonly Aes _aes; - - private readonly ICryptoTransform _encryptor; - - private ulong _ivUpper; // The upper 64 bits of the IV - private ulong _ivLower; // The lower 64 bits of the IV - - public CtrImpl( - byte[] key, - byte[] iv) - : base(key, 16, mode: null, padding: null) - { - var aes = Aes.Create(); - aes.Key = key; - aes.Mode = System.Security.Cryptography.CipherMode.ECB; - aes.Padding = PaddingMode.None; - _aes = aes; - _encryptor = aes.CreateEncryptor(); - - _ivLower = BinaryPrimitives.ReadUInt64BigEndian(iv.AsSpan(8)); - _ivUpper = BinaryPrimitives.ReadUInt64BigEndian(iv); - } - - public override byte[] Encrypt(byte[] input, int offset, int length) - { - return CTREncryptDecrypt(input, offset, length); - } - - public override byte[] Decrypt(byte[] input, int offset, int length) - { - return CTREncryptDecrypt(input, offset, length); - } - - public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) - { - throw new NotImplementedException($"Invalid usage of {nameof(DecryptBlock)}."); - } - - public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) - { - throw new NotImplementedException($"Invalid usage of {nameof(EncryptBlock)}."); - } - - private byte[] CTREncryptDecrypt(byte[] data, int offset, int length) - { - var count = length / BlockSize; - if (length % BlockSize != 0) - { - count++; - } - - var buffer = new byte[count * BlockSize]; - CTRCreateCounterArray(buffer); - _ = _encryptor.TransformBlock(buffer, 0, buffer.Length, buffer, 0); - ArrayXOR(buffer, data, offset, length); - - // adjust output for non-blocksized lengths - if (buffer.Length > length) - { - Array.Resize(ref buffer, length); - } - - return buffer; - } - - // creates the Counter array filled with incrementing copies of IV - private void CTRCreateCounterArray(byte[] buffer) - { - for (var i = 0; i < buffer.Length; i += 16) - { - BinaryPrimitives.WriteUInt64BigEndian(buffer.AsSpan(i + 8), _ivLower); - BinaryPrimitives.WriteUInt64BigEndian(buffer.AsSpan(i), _ivUpper); - - _ivLower += 1; - _ivUpper += (_ivLower == 0) ? 1UL : 0UL; - } - } - - // XOR 2 arrays using Vector - private static void ArrayXOR(byte[] buffer, byte[] data, int offset, int length) - { - var i = 0; - - var oneVectorFromEnd = length - Vector.Count; - for (; i <= oneVectorFromEnd; i += Vector.Count) - { - var v = new Vector(buffer, i) ^ new Vector(data, offset + i); - v.CopyTo(buffer, i); - } - - for (; i < length; i++) - { - buffer[i] ^= data[offset + i]; - } - } - - public void Dispose() - { - _aes.Dispose(); - _encryptor.Dispose(); - } - } - } -} diff --git a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.cs index e92b66d13..ba2e4f495 100644 --- a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.cs +++ b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.cs @@ -23,32 +23,27 @@ public sealed partial class AesCipher : BlockCipher, IDisposable /// Enable PKCS7 padding. /// is . /// Keysize is not valid for this algorithm. - public AesCipher(byte[] key, byte[] iv, AesCipherMode mode, bool pkcs7Padding = false) + public AesCipher(byte[] key, byte[] iv, System.Security.Cryptography.CipherMode mode, bool pkcs7Padding = false) : base(key, 16, mode: null, padding: null) { - if (mode == AesCipherMode.OFB) + if (mode == System.Security.Cryptography.CipherMode.OFB) { // OFB is not supported on modern .NET _impl = new BlockImpl(key, new OfbCipherMode(iv), pkcs7Padding ? new Pkcs7Padding() : null); } #if !NET6_0_OR_GREATER - else if (mode == AesCipherMode.CFB) + else if (mode == System.Security.Cryptography.CipherMode.CFB) { // CFB not supported on NetStandard 2.1 _impl = new BlockImpl(key, new CfbCipherMode(iv), pkcs7Padding ? new Pkcs7Padding() : null); } #endif - else if (mode == AesCipherMode.CTR) - { - // CTR not supported by the BCL, use an optimized implementation - _impl = new CtrImpl(key, iv); - } else { _impl = new BclImpl( key, iv, - (System.Security.Cryptography.CipherMode)mode, + mode, pkcs7Padding ? PaddingMode.PKCS7 : PaddingMode.None); } } diff --git a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipherMode.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipherMode.cs deleted file mode 100644 index 9f948b3cf..000000000 --- a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipherMode.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Renci.SshNet.Security.Cryptography.Ciphers -{ - /// - /// Custom AES Cipher Mode, follows System.Security.Cryptography.CipherMode. - /// - public enum AesCipherMode - { - /// Cipher Block Chain Mode. - CBC = 1, - - /// Electronic Codebook Mode. - ECB = 2, - - /// Output Feedback Mode. - OFB = 3, - - /// Cipher Feedback Mode. - CFB = 4, - - /// Cipher Text Stealing Mode. - CTS = 5, - - /// Counter Mode. - CTR = 6 - } -} diff --git a/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCtrCipher.cs b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCtrCipher.cs new file mode 100644 index 000000000..d6b4c3f23 --- /dev/null +++ b/src/Renci.SshNet/Security/Cryptography/Ciphers/AesCtrCipher.cs @@ -0,0 +1,109 @@ +using System; +using System.Buffers.Binary; +using System.Numerics; +using System.Security.Cryptography; + +namespace Renci.SshNet.Security.Cryptography.Ciphers +{ + internal sealed class AesCtrCipher : BlockCipher, IDisposable + { + private readonly Aes _aes; + private readonly ICryptoTransform _encryptor; + + private ulong _ivUpper; // The upper 64 bits of the IV + private ulong _ivLower; // The lower 64 bits of the IV + + public AesCtrCipher(byte[] key, byte[] iv) + : base(key, 16, mode: null, padding: null) + { + var aes = Aes.Create(); + aes.Key = key; + aes.Mode = System.Security.Cryptography.CipherMode.ECB; + aes.Padding = PaddingMode.None; + _aes = aes; + _encryptor = aes.CreateEncryptor(); + + _ivLower = BinaryPrimitives.ReadUInt64BigEndian(iv.AsSpan(8)); + _ivUpper = BinaryPrimitives.ReadUInt64BigEndian(iv); + } + + public override byte[] Encrypt(byte[] input, int offset, int length) + { + return CTREncryptDecrypt(input, offset, length); + } + + public override byte[] Decrypt(byte[] input, int offset, int length) + { + return CTREncryptDecrypt(input, offset, length); + } + + public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) + { + throw new NotImplementedException($"Invalid usage of {nameof(EncryptBlock)}."); + } + + public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset) + { + throw new NotImplementedException($"Invalid usage of {nameof(DecryptBlock)}."); + } + + private byte[] CTREncryptDecrypt(byte[] data, int offset, int length) + { + var count = length / BlockSize; + if (length % BlockSize != 0) + { + count++; + } + + var buffer = new byte[count * BlockSize]; + CTRCreateCounterArray(buffer); + _ = _encryptor.TransformBlock(buffer, 0, buffer.Length, buffer, 0); + ArrayXOR(buffer, data, offset, length); + + // adjust output for non-blocksized lengths + if (buffer.Length > length) + { + Array.Resize(ref buffer, length); + } + + return buffer; + } + + // creates the Counter array filled with incrementing copies of IV + private void CTRCreateCounterArray(byte[] buffer) + { + for (var i = 0; i < buffer.Length; i += 16) + { + BinaryPrimitives.WriteUInt64BigEndian(buffer.AsSpan(i + 8), _ivLower); + BinaryPrimitives.WriteUInt64BigEndian(buffer.AsSpan(i), _ivUpper); + + _ivLower += 1; + _ivUpper += (_ivLower == 0) ? 1UL : 0UL; + } + } + + // XOR 2 arrays using Vector + private static void ArrayXOR(byte[] buffer, byte[] data, int offset, int length) + { + var i = 0; + + var oneVectorFromEnd = length - Vector.Count; + for (; i <= oneVectorFromEnd; i += Vector.Count) + { + var v = new Vector(buffer, i) ^ new Vector(data, offset + i); + v.CopyTo(buffer, i); + } + + for (; i < length; i++) + { + buffer[i] ^= data[offset + i]; + } + } + + public void Dispose() + { + _aes.Dispose(); + _encryptor.Dispose(); + } + } +} diff --git a/test/Renci.SshNet.Benchmarks/Security/Cryptography/Ciphers/AesCipherBenchmarks.cs b/test/Renci.SshNet.Benchmarks/Security/Cryptography/Ciphers/AesCipherBenchmarks.cs index 9cecc0855..806467763 100644 --- a/test/Renci.SshNet.Benchmarks/Security/Cryptography/Ciphers/AesCipherBenchmarks.cs +++ b/test/Renci.SshNet.Benchmarks/Security/Cryptography/Ciphers/AesCipherBenchmarks.cs @@ -2,6 +2,8 @@ using Renci.SshNet.Security.Cryptography.Ciphers; +using CipherMode = System.Security.Cryptography.CipherMode; + namespace Renci.SshNet.Benchmarks.Security.Cryptography.Ciphers { [MemoryDiagnoser] @@ -26,49 +28,49 @@ public AesCipherBenchmarks() [Benchmark] public byte[] Encrypt_CBC() { - return new AesCipher(_key, _iv, AesCipherMode.CBC, false).Encrypt(_data); + return new AesCipher(_key, _iv, CipherMode.CBC, false).Encrypt(_data); } [Benchmark] public byte[] Decrypt_CBC() { - return new AesCipher(_key, _iv, AesCipherMode.CBC, false).Decrypt(_data); + return new AesCipher(_key, _iv, CipherMode.CBC, false).Decrypt(_data); } [Benchmark] public byte[] Encrypt_CFB() { - return new AesCipher(_key, _iv, AesCipherMode.CFB, false).Encrypt(_data); + return new AesCipher(_key, _iv, CipherMode.CFB, false).Encrypt(_data); } [Benchmark] public byte[] Decrypt_CFB() { - return new AesCipher(_key, _iv, AesCipherMode.CFB, false).Decrypt(_data); + return new AesCipher(_key, _iv, CipherMode.CFB, false).Decrypt(_data); } [Benchmark] public byte[] Encrypt_CTR() { - return new AesCipher(_key, _iv, AesCipherMode.CTR, false).Encrypt(_data); + return new AesCtrCipher(_key, _iv).Encrypt(_data); } [Benchmark] public byte[] Decrypt_CTR() { - return new AesCipher(_key, _iv, AesCipherMode.CTR, false).Decrypt(_data); + return new AesCtrCipher(_key, _iv).Decrypt(_data); } [Benchmark] public byte[] Encrypt_ECB() { - return new AesCipher(_key, null, AesCipherMode.ECB, false).Encrypt(_data); + return new AesCipher(_key, null, CipherMode.ECB, false).Encrypt(_data); } [Benchmark] public byte[] Decrypt_ECB() { - return new AesCipher(_key, null, AesCipherMode.ECB, false).Decrypt(_data); + return new AesCipher(_key, null, CipherMode.ECB, false).Decrypt(_data); } } } diff --git a/test/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.Gen.cs.txt b/test/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.Gen.cs.txt index 066c80ed5..88eec793f 100644 --- a/test/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.Gen.cs.txt +++ b/test/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.Gen.cs.txt @@ -4,20 +4,20 @@ // expected encrypted values, and also verifies those values against the .NET // BCL implementation as an extra validation before generating the tests. -Dictionary modes = new() +Dictionary modes = new() { - ["ecb"] = ("iv: null, AesCipherMode.ECB", CipherMode.ECB), - ["cbc"] = ("(byte[])iv.Clone(), AesCipherMode.CBC", CipherMode.CBC), - ["cfb"] = ("(byte[])iv.Clone(), AesCipherMode.CFB", CipherMode.CFB), - ["ctr"] = ("(byte[])iv.Clone(), AesCipherMode.CTR", null), - ["ofb"] = ("(byte[])iv.Clone(), AesCipherMode.OFB", CipherMode.OFB), + ["ecb"] = ("iv: null", "CipherMode.ECB", CipherMode.ECB), + ["cbc"] = ("(byte[])iv.Clone()", "CipherMode.CBC", CipherMode.CBC), + ["cfb"] = ("(byte[])iv.Clone()", "CipherMode.CFB", CipherMode.CFB), + ["ctr"] = ("(byte[])iv.Clone()", string.Empty, null), + ["ofb"] = ("(byte[])iv.Clone()", "CipherMode.OFB", CipherMode.OFB), }; Random random = new(123); using IndentedTextWriter tw = new(Console.Out); -foreach ((string mode, (string modeCode, CipherMode? bclMode)) in modes) +foreach ((string mode, (string ivCode, string modeCode, CipherMode? bclMode)) in modes) { foreach (int keySize in new int[] { 128, 192, 256 }) { @@ -110,7 +110,15 @@ foreach ((string mode, (string modeCode, CipherMode? bclMode)) in modes) tw.WriteLine($"// {openSslCmd} | hd"); // pipe to hexdump WriteBytes(expected); tw.WriteLine(); - tw.WriteLine($"var actual = new AesCipher(key, {modeCode}, pkcs7Padding: {(pad ? "true" : "false")}).Encrypt(input);"); + if (mode == "ctr") + { + tw.WriteLine($"var actual = new AesCtrCipher(key, {ivCode}).Encrypt(input);"); + } + else + { + tw.WriteLine($"var actual = new AesCipher(key, {ivCode}, {modeCode}, pkcs7Padding: {(pad ? "true" : "false")}).Encrypt(input);"); + } + tw.WriteLine(); tw.WriteLine($"CollectionAssert.AreEqual(expected, actual);"); @@ -137,7 +145,15 @@ foreach ((string mode, (string modeCode, CipherMode? bclMode)) in modes) } tw.WriteLine(); - tw.WriteLine($"var decrypted = new AesCipher(key, {modeCode}, pkcs7Padding: {(pad ? "true" : "false")}).Decrypt(actual);"); + if (mode == "ctr") + { + tw.WriteLine($"var decrypted = new AesCtrCipher(key, {ivCode}).Decrypt(actual);"); + } + else + { + tw.WriteLine($"var decrypted = new AesCipher(key, {ivCode}, {modeCode}, pkcs7Padding: {(pad ? "true" : "false")}).Decrypt(actual);"); + } + tw.WriteLine(); tw.WriteLine($"CollectionAssert.AreEqual(input, decrypted);"); diff --git a/test/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs b/test/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs index ee738b8a9..effd9528b 100644 --- a/test/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs +++ b/test/Renci.SshNet.Tests/Classes/Security/Cryptography/Ciphers/AesCipherTest.cs @@ -6,6 +6,8 @@ using Renci.SshNet.Security.Cryptography.Ciphers; using Renci.SshNet.Tests.Common; +using CipherMode = System.Security.Cryptography.CipherMode; + namespace Renci.SshNet.Tests.Classes.Security.Cryptography.Ciphers { /// @@ -42,7 +44,7 @@ public void AES_CTR_Encrypt_Should_Preserve_Cipher_Stream_State() 0xec, 0x47, 0x81, 0x82, 0x89, 0x24, 0x76, 0xe2, 0x20, 0x6a, 0x99, 0xe2, 0xa7, 0x5a, 0xb0, 0x40, }; - var cipher = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false); + var cipher = new AesCtrCipher(key, (byte[])iv.Clone()); var actual1 = cipher.Encrypt(input.Take(32)); var actual2 = cipher.Encrypt(input.Take(32, 32)); @@ -78,7 +80,7 @@ public void AES_CTR_Decrypt_Should_Preserve_Cipher_Stream_State() 0xbc, 0x89, 0x7a, 0x22, 0x42, 0x2c, 0xba, 0x8e, 0xd7, 0x15, 0x22, 0x41, 0xe4, 0xb5, 0x0b, 0xad, }; - var cipher = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false); + var cipher = new AesCtrCipher(key, (byte[])iv.Clone()); var actual1 = cipher.Decrypt(input.Take(32)); var actual2 = cipher.Decrypt(input.Take(32, 32)); @@ -115,11 +117,11 @@ public void AES_CTR_IV_Overflow() 0xfd, 0x34, 0xc5, 0x81, 0xfa, 0xb9, 0xe3, 0xc4, 0x10, 0xed, 0x06, 0x6e, 0x91, 0x5e, 0xfc, 0x47, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -133,7 +135,7 @@ public void Encrypt_InputAndOffsetAndLength_128_CBC() var key = new byte[] { 0xe4, 0x94, 0xf9, 0xb1, 0x00, 0x4f, 0x16, 0x2a, 0x80, 0x11, 0xea, 0x73, 0x0d, 0xb9, 0xbf, 0x64 }; var iv = new byte[] { 0x74, 0x8b, 0x4f, 0xe6, 0xc1, 0x29, 0xb3, 0x54, 0xec, 0x77, 0x92, 0xf3, 0x15, 0xa0, 0x41, 0xa8 }; var expected = new byte[] { 0x19, 0x7f, 0x80, 0xd8, 0xc9, 0x89, 0xc4, 0xa7, 0xc6, 0xc6, 0x3f, 0x9f, 0x1e, 0x00, 0x1f, 0x72, 0xa7, 0x5e, 0xde, 0x40, 0x88, 0xa2, 0x72, 0xf2, 0xed, 0x3f, 0x81, 0x45, 0xb6, 0xbd, 0x45, 0x87, 0x15, 0xa5, 0x10, 0x92, 0x4a, 0x37, 0x9e, 0xa9, 0x80, 0x1c, 0x14, 0x83, 0xa3, 0x39, 0x45, 0x28 }; - var testCipher = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false); + var testCipher = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false); var actual = testCipher.Encrypt(input, 2, input.Length - 5); @@ -147,7 +149,7 @@ public void Encrypt_Input_128_CTR() var key = new byte[] { 0x17, 0x78, 0x56, 0xe1, 0x3e, 0xbd, 0x3e, 0x50, 0x1d, 0x79, 0x3f, 0x0f, 0x55, 0x37, 0x45, 0x54 }; var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; var expected = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; - var testCipher = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false); + var testCipher = new AesCtrCipher(key, (byte[])iv.Clone()); var actual = testCipher.Encrypt(input); @@ -161,7 +163,7 @@ public void Decrypt_Input_128_CTR() var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; var input = new byte[] { 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d }; var expected = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; - var testCipher = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false); + var testCipher = new AesCtrCipher(key, (byte[])iv.Clone()); var actual = testCipher.Decrypt(input); @@ -175,7 +177,7 @@ public void Decrypt_InputAndOffsetAndLength_128_CTR() var iv = new byte[] { 0xe6, 0x65, 0x36, 0x0d, 0xdd, 0xd7, 0x50, 0xc3, 0x48, 0xdb, 0x48, 0x07, 0xa1, 0x30, 0xd2, 0x38 }; var input = new byte[] { 0x0a, 0xca, 0xfb, 0x1c, 0x49, 0xbf, 0x82, 0x2a, 0xbb, 0x1c, 0x52, 0xc7, 0x86, 0x22, 0x8a, 0xe5, 0xa4, 0xf3, 0xda, 0x4e, 0x1c, 0x3a, 0x87, 0x41, 0x1c, 0xd2, 0x6e, 0x76, 0xdc, 0xc2, 0xe9, 0xc2, 0x0e, 0xf5, 0xc7, 0xbd, 0x12, 0x85, 0xfa, 0x0e, 0xda, 0xee, 0x50, 0xd7, 0xfd, 0x81, 0x34, 0x25, 0x6d, 0x0a, 0x05 }; var expected = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0xb0, 0x74, 0x21, 0x87, 0x16, 0xb9, 0x69, 0x48, 0x33, 0xce, 0xb3, 0xe7, 0xdc, 0x3f, 0x50, 0xdc, 0xcc, 0xd5, 0x27, 0xb7, 0xfe, 0x7a, 0x78, 0x22, 0xae, 0xc8 }; - var testCipher = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false); + var testCipher = new AesCtrCipher(key, (byte[])iv.Clone()); var actual = testCipher.Decrypt(input, 1, input.Length - 3); @@ -201,11 +203,11 @@ public void AES_ECB_128_Length16_NoPad() 0x9d, 0x55, 0x05, 0x4e, 0xe9, 0x50, 0xb5, 0x93, 0x50, 0x93, 0x69, 0x96, 0xa6, 0xdd, 0x1e, 0x15, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -229,11 +231,11 @@ public void AES_ECB_128_Length16_Pad() 0x5b, 0x27, 0x39, 0x52, 0x46, 0x1d, 0x16, 0x28, 0xc7, 0xec, 0x1f, 0x65, 0x7f, 0x67, 0x76, 0x70, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -260,11 +262,11 @@ public void AES_ECB_128_Length35_Pad() 0xb1, 0xe2, 0x80, 0xcc, 0x21, 0x98, 0xa1, 0x26, 0x28, 0xac, 0x0b, 0x61, 0x19, 0x9d, 0xda, 0xaa, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -293,11 +295,11 @@ public void AES_ECB_128_Length64_NoPad() 0x5a, 0xf4, 0xf8, 0x16, 0xc6, 0xf2, 0xdd, 0x6d, 0x51, 0x4d, 0x42, 0xa9, 0x59, 0xdc, 0xb2, 0x01, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -327,11 +329,11 @@ public void AES_ECB_128_Length64_Pad() 0x3d, 0xc3, 0x0b, 0x2e, 0x7b, 0xd4, 0x20, 0x23, 0xb4, 0xb9, 0x2e, 0x07, 0x73, 0x37, 0x92, 0x80, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -355,11 +357,11 @@ public void AES_ECB_192_Length16_NoPad() 0x6b, 0x19, 0xbc, 0x1a, 0xe8, 0xf5, 0x3c, 0x9a, 0xbb, 0xaf, 0xb2, 0x28, 0xe1, 0x99, 0xd4, 0x81, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -384,11 +386,11 @@ public void AES_ECB_192_Length16_Pad() 0x95, 0x9a, 0x5d, 0x23, 0x23, 0x58, 0x25, 0x2d, 0x5f, 0x33, 0xc1, 0x9e, 0x6b, 0x68, 0xa2, 0x1e, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -416,11 +418,11 @@ public void AES_ECB_192_Length35_Pad() 0x40, 0xae, 0x13, 0xd6, 0xc1, 0xfc, 0x2b, 0xc0, 0xa0, 0x90, 0x9a, 0xfb, 0x96, 0xc7, 0xa0, 0x16, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -450,11 +452,11 @@ public void AES_ECB_192_Length64_NoPad() 0xa5, 0xd7, 0x6e, 0x76, 0x4f, 0x45, 0xef, 0xfe, 0xb2, 0x9f, 0xbc, 0x96, 0xd5, 0x49, 0x55, 0x31, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -485,11 +487,11 @@ public void AES_ECB_192_Length64_Pad() 0xa0, 0xec, 0xa8, 0x7e, 0x68, 0xb7, 0x63, 0x7b, 0xc2, 0x5e, 0xc4, 0x33, 0xfa, 0xf2, 0x76, 0x83, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -513,11 +515,11 @@ public void AES_ECB_256_Length16_NoPad() 0xf5, 0x94, 0x26, 0x13, 0x73, 0x7c, 0x20, 0xc4, 0xc4, 0xd3, 0x46, 0xb6, 0x0c, 0xd4, 0x29, 0xf2, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -542,11 +544,11 @@ public void AES_ECB_256_Length16_Pad() 0xbb, 0x89, 0x9c, 0xcb, 0x62, 0x32, 0x82, 0xb2, 0x58, 0xe2, 0x69, 0xd5, 0xce, 0x1d, 0xd0, 0xa9, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -574,11 +576,11 @@ public void AES_ECB_256_Length35_Pad() 0xe4, 0xd5, 0x5d, 0x03, 0x40, 0x5a, 0xd8, 0x91, 0x30, 0x89, 0xdf, 0xcf, 0x74, 0x54, 0x43, 0x31, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -608,11 +610,11 @@ public void AES_ECB_256_Length64_NoPad() 0x4e, 0xd4, 0xc2, 0x5d, 0x32, 0x33, 0x1a, 0xb0, 0x12, 0xa7, 0x60, 0x31, 0x6a, 0xed, 0xa2, 0x2b, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -643,11 +645,11 @@ public void AES_ECB_256_Length64_Pad() 0x62, 0xa7, 0x55, 0xf1, 0xc7, 0x6a, 0x0d, 0xb6, 0x67, 0xee, 0x09, 0xcc, 0xae, 0xe8, 0x13, 0x0f, }; - var actual = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, iv: null, AesCipherMode.ECB, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, iv: null, CipherMode.ECB, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -674,11 +676,11 @@ public void AES_CBC_128_Length16_NoPad() 0xbd, 0x17, 0x7d, 0x43, 0xf9, 0x66, 0x21, 0xf3, 0x3f, 0xc1, 0x89, 0xd7, 0x8d, 0x11, 0xf0, 0x52, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -706,11 +708,11 @@ public void AES_CBC_128_Length16_Pad() 0x97, 0xb2, 0xf2, 0xbf, 0xde, 0x3e, 0x6b, 0xee, 0x78, 0xf5, 0x77, 0xc9, 0x1a, 0x56, 0x01, 0x56, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -741,11 +743,11 @@ public void AES_CBC_128_Length35_Pad() 0xc8, 0x60, 0x05, 0xde, 0x81, 0xe4, 0xc6, 0xcd, 0x31, 0x7f, 0x9e, 0x5d, 0x4b, 0x03, 0x5f, 0x71, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -778,11 +780,11 @@ public void AES_CBC_128_Length64_NoPad() 0xe9, 0x40, 0x33, 0xc1, 0x3f, 0xb8, 0xf6, 0x69, 0x6b, 0x78, 0xaf, 0x4f, 0x58, 0x4c, 0xe6, 0x74, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -816,11 +818,11 @@ public void AES_CBC_128_Length64_Pad() 0xb4, 0x20, 0xcb, 0xb8, 0xb1, 0x7f, 0x0c, 0xf6, 0x17, 0x00, 0x0d, 0xde, 0x41, 0x46, 0x14, 0xae, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -848,11 +850,11 @@ public void AES_CBC_192_Length16_NoPad() 0x1f, 0x5a, 0xe4, 0x2d, 0x8b, 0x65, 0x70, 0x71, 0x26, 0x25, 0x3e, 0x46, 0x54, 0x3a, 0x99, 0x93, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -881,11 +883,11 @@ public void AES_CBC_192_Length16_Pad() 0x26, 0xac, 0x95, 0x24, 0xb5, 0x20, 0x37, 0x0b, 0x38, 0x72, 0x02, 0x19, 0x46, 0xfc, 0x63, 0xc7, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -917,11 +919,11 @@ public void AES_CBC_192_Length35_Pad() 0x10, 0x33, 0xf9, 0xe5, 0x3c, 0x5e, 0x35, 0x63, 0x5f, 0xbd, 0x35, 0x30, 0xbf, 0x9d, 0x1f, 0x9f, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -955,11 +957,11 @@ public void AES_CBC_192_Length64_NoPad() 0x8a, 0x64, 0x2a, 0x96, 0x82, 0xaa, 0xac, 0x8e, 0x88, 0x63, 0x28, 0x52, 0x5a, 0xfa, 0x8a, 0x5d, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -994,11 +996,11 @@ public void AES_CBC_192_Length64_Pad() 0xe5, 0xa1, 0x39, 0x09, 0x9c, 0xdd, 0xea, 0x04, 0xb9, 0x60, 0x34, 0xbe, 0x65, 0x9c, 0x15, 0x98, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1026,11 +1028,11 @@ public void AES_CBC_256_Length16_NoPad() 0x3e, 0x7c, 0xdd, 0x13, 0x85, 0x57, 0x34, 0x61, 0xe6, 0x6e, 0xcd, 0x87, 0xd9, 0xaa, 0xf8, 0xe3, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1059,11 +1061,11 @@ public void AES_CBC_256_Length16_Pad() 0x3e, 0x08, 0x87, 0x8c, 0xae, 0x30, 0xbc, 0x4f, 0x89, 0x16, 0x30, 0x42, 0x2a, 0xd9, 0xe6, 0xac, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1095,11 +1097,11 @@ public void AES_CBC_256_Length35_Pad() 0x88, 0x46, 0x53, 0x42, 0x98, 0x69, 0x4b, 0x91, 0x9e, 0x5f, 0x69, 0x22, 0x58, 0xff, 0x48, 0xca, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1133,11 +1135,11 @@ public void AES_CBC_256_Length64_NoPad() 0xfe, 0xa4, 0x71, 0xef, 0x33, 0x6b, 0x4f, 0x86, 0xe1, 0xa9, 0xf8, 0xc3, 0x40, 0xa4, 0x56, 0xc4, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1172,11 +1174,11 @@ public void AES_CBC_256_Length64_Pad() 0xbc, 0xcc, 0x5a, 0x91, 0x8a, 0xbb, 0xe9, 0x70, 0x39, 0x42, 0x8d, 0xb1, 0x02, 0x53, 0xa7, 0x88, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CBC, pkcs7Padding: true).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CBC, pkcs7Padding: true).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1203,11 +1205,11 @@ public void AES_CFB_128_Length16_NoPad() 0x8c, 0x75, 0xf1, 0xba, 0xf9, 0xe6, 0x66, 0x7d, 0x14, 0x4a, 0x9f, 0xfc, 0x31, 0xf7, 0x98, 0xcb, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1238,11 +1240,11 @@ public void AES_CFB_128_Length35_NoPad() 0xfc, 0x42, 0x49, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1275,11 +1277,11 @@ public void AES_CFB_128_Length64_NoPad() 0xd7, 0x15, 0xa4, 0x00, 0x33, 0xe6, 0x07, 0x1a, 0x6c, 0xc7, 0x95, 0x95, 0xb2, 0x52, 0x51, 0xc8, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1307,11 +1309,11 @@ public void AES_CFB_192_Length16_NoPad() 0x57, 0x7a, 0x4f, 0x03, 0x6e, 0x76, 0x43, 0x2d, 0xc0, 0x23, 0x26, 0x19, 0x58, 0x2e, 0x77, 0x83, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1343,11 +1345,11 @@ public void AES_CFB_192_Length35_NoPad() 0x05, 0xcb, 0xad, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1381,11 +1383,11 @@ public void AES_CFB_192_Length64_NoPad() 0x08, 0x4e, 0x2b, 0xbd, 0xbb, 0x0a, 0xdc, 0x25, 0xe5, 0x10, 0x6c, 0x3c, 0x89, 0x03, 0xa7, 0x63, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1413,11 +1415,11 @@ public void AES_CFB_256_Length16_NoPad() 0xd4, 0x21, 0xc2, 0xf2, 0x06, 0xcf, 0xa6, 0x65, 0x5d, 0xb0, 0x13, 0x3c, 0x87, 0x04, 0x5c, 0x59, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1449,11 +1451,11 @@ public void AES_CFB_256_Length35_NoPad() 0xb5, 0xcb, 0x97, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1487,11 +1489,11 @@ public void AES_CFB_256_Length64_NoPad() 0xbe, 0x24, 0x47, 0xeb, 0xe5, 0x0a, 0x24, 0x6d, 0xc2, 0x1e, 0xca, 0x52, 0x8d, 0x9a, 0xe7, 0x49, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.CFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1518,11 +1520,11 @@ public void AES_CTR_128_Length16_NoPad() 0xee, 0x28, 0x3f, 0x2e, 0xd9, 0xac, 0x08, 0x36, 0x8a, 0xc0, 0x44, 0x90, 0x4d, 0x1f, 0x35, 0x06, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1553,11 +1555,11 @@ public void AES_CTR_128_Length35_NoPad() 0x17, 0xf1, 0x16, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1590,11 +1592,11 @@ public void AES_CTR_128_Length64_NoPad() 0x0d, 0x1a, 0x30, 0x6d, 0xa7, 0xbd, 0x2b, 0x9b, 0x05, 0x05, 0xad, 0x92, 0x9a, 0xd6, 0x8e, 0x28, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1622,11 +1624,11 @@ public void AES_CTR_192_Length16_NoPad() 0x27, 0x94, 0x39, 0x4c, 0xab, 0x94, 0xd5, 0xfe, 0x0a, 0xc4, 0xf6, 0x33, 0x4c, 0x8c, 0xa5, 0xe1, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1658,11 +1660,11 @@ public void AES_CTR_192_Length35_NoPad() 0xf4, 0xfc, 0x58, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1696,11 +1698,11 @@ public void AES_CTR_192_Length64_NoPad() 0xe3, 0x39, 0xd5, 0xb8, 0x18, 0xe7, 0x1b, 0x0a, 0xdc, 0x63, 0xee, 0x3f, 0x59, 0xad, 0x76, 0xc1, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1728,11 +1730,11 @@ public void AES_CTR_256_Length16_NoPad() 0xc8, 0x8a, 0x9b, 0xd7, 0x03, 0xfa, 0x95, 0x61, 0x95, 0x69, 0x81, 0xa8, 0x2d, 0x0d, 0xfe, 0x4a, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1764,11 +1766,11 @@ public void AES_CTR_256_Length35_NoPad() 0x46, 0xd7, 0x46, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1802,11 +1804,11 @@ public void AES_CTR_256_Length64_NoPad() 0x8e, 0x53, 0xc7, 0x0a, 0xf9, 0x9f, 0x3c, 0xbe, 0x37, 0x6f, 0xd7, 0xd6, 0x5e, 0x94, 0x6a, 0x22, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Encrypt(input); + var actual = new AesCtrCipher(key, (byte[])iv.Clone()).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.CTR, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCtrCipher(key, (byte[])iv.Clone()).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1833,11 +1835,11 @@ public void AES_OFB_128_Length16_NoPad() 0xf4, 0x71, 0xef, 0x7a, 0xa2, 0xef, 0x90, 0x25, 0x18, 0x3e, 0x24, 0xc1, 0x40, 0xe4, 0xff, 0xb6, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1868,11 +1870,11 @@ public void AES_OFB_128_Length35_NoPad() 0x33, 0xf5, 0xcd, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1905,11 +1907,11 @@ public void AES_OFB_128_Length64_NoPad() 0x43, 0xe2, 0x0c, 0x6f, 0x22, 0x31, 0xcb, 0x7d, 0x4d, 0xd7, 0xa1, 0xa4, 0xd9, 0x7e, 0x55, 0xd2, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1937,11 +1939,11 @@ public void AES_OFB_192_Length16_NoPad() 0x49, 0xc5, 0x2c, 0x55, 0x4c, 0x74, 0xb0, 0x3e, 0xba, 0xd0, 0xcf, 0xdc, 0xd2, 0x44, 0xcb, 0x04, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -1973,11 +1975,11 @@ public void AES_OFB_192_Length35_NoPad() 0x09, 0x88, 0x44, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -2011,11 +2013,11 @@ public void AES_OFB_192_Length64_NoPad() 0xb8, 0xa8, 0x9d, 0x3b, 0x4d, 0x82, 0x9b, 0x8c, 0x96, 0xeb, 0x4e, 0x9d, 0x91, 0xda, 0x6e, 0x9e, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -2043,11 +2045,11 @@ public void AES_OFB_256_Length16_NoPad() 0xd4, 0xef, 0xb1, 0x5d, 0x7c, 0x7e, 0x36, 0x89, 0xd2, 0x18, 0xbb, 0x8c, 0x1f, 0x07, 0x1d, 0x49, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -2079,11 +2081,11 @@ public void AES_OFB_256_Length35_NoPad() 0x15, 0x7a, 0xce, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); } @@ -2117,11 +2119,11 @@ public void AES_OFB_256_Length64_NoPad() 0xf0, 0x1e, 0x04, 0x78, 0x6a, 0x90, 0x95, 0x80, 0x16, 0x8c, 0x7c, 0x86, 0xca, 0x26, 0x78, 0xab, }; - var actual = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Encrypt(input); + var actual = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Encrypt(input); CollectionAssert.AreEqual(expected, actual); - var decrypted = new AesCipher(key, (byte[])iv.Clone(), AesCipherMode.OFB, pkcs7Padding: false).Decrypt(actual); + var decrypted = new AesCipher(key, (byte[])iv.Clone(), CipherMode.OFB, pkcs7Padding: false).Decrypt(actual); CollectionAssert.AreEqual(input, decrypted); }