# < Summary

Information

Class: | Renci.SshNet.Security.Cryptography.Ciphers.AesCipher
Assembly: | Renci.SshNet
File(s): | File 1: \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\AesCipher.BclImpl.cs File 2: \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\AesCipher.BlockImpl.cs File 3: \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\AesCipher.cs File 4: \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\AesCipher.CtrImpl.cs

Line coverage
82%

Covered lines: | 202
Uncovered lines: | 42
Coverable lines: | 244
Total lines: | 480
Line coverage: | 82.7%

Branch coverage
79%

Covered branches: | 43
Total branches: | 54
Branch coverage: | 79.6%

Method coverage

Feature is only available for sponsors

Upgrade to PRO version

# Metrics

Method | Branch coverage | Cyclomatic complexity | Line coverage
--- | --- | --- | ---
File 1: .ctor(...) | 75% | 4 | 88.88%
File 1: Encrypt(...) | 50% | 2 | 75%
File 1: Decrypt(...) | 100% | 2 | 100%
File 1: EncryptBlock(...) | 100% | 1 | 0%
File 1: DecryptBlock(...) | 100% | 1 | 0%
File 1: Dispose(...) | 100% | 2 | 100%
File 1: Dispose() | 100% | 1 | 100%
File 2: .ctor(...) | 100% | 1 | 100%
File 2: EncryptBlock(...) | 100% | 1 | 100%
File 2: DecryptBlock(...) | 100% | 1 | 0%
File 2: Dispose(...) | 0% | 2 | 0%
File 2: Dispose() | 100% | 1 | 0%
File 3: .ctor(...) | 87.5% | 8 | 100%
File 3: EncryptBlock(...) | 100% | 1 | 0%
File 3: DecryptBlock(...) | 100% | 1 | 0%
File 3: Encrypt(...) | 100% | 1 | 100%
File 3: Decrypt(...) | 100% | 1 | 100%
File 3: Dispose(...) | 75% | 4 | 100%
File 3: Dispose() | 100% | 1 | 100%
File 4: .ctor(...) | 100% | 1 | 100%
File 4: Encrypt(...) | 100% | 1 | 100%
File 4: Decrypt(...) | 100% | 1 | 100%
File 4: DecryptBlock(...) | 100% | 1 | 0%
File 4: EncryptBlock(...) | 100% | 1 | 0%
File 4: CTREncryptDecrypt(...) | 50% | 4 | 62.5%
File 4: CTRCreateCounterArray(...) | 100% | 4 | 100%
File 4: ArrayXOR(...) | 100% | 4 | 100%
File 4: CTRCreateCounterArray(...) | 87.5% | 8 | 100%
File 4: ArrayXOR(...) | 75% | 4 | 81.25%
File 4: GetPackedIV(...) | 100% | 1 | 100%
File 4: SwapEndianness(...) | 100% | 1 | 100%
File 4: Dispose(...) | 100% | 2 | 100%
File 4: Dispose() | 100% | 1 | 100%

# File(s)

## \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\AesCipher.BclImpl.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Security.Cryptography;`
|  | `3` |  | ``
|  | `4` |  | `using Renci.SshNet.Common;`
|  | `5` |  | ``
|  | `6` |  | `namespace Renci.SshNet.Security.Cryptography.Ciphers`
|  | `7` |  | `{`
|  | `8` |  | `public partial class AesCipher`
|  | `9` |  | `{`
|  | `10` |  | `private sealed class BclImpl : BlockCipher, IDisposable`
|  | `11` |  | `{`
|  | `12` |  | `private readonly Aes _aes;`
|  | `13` |  | `private readonly ICryptoTransform _encryptor;`
|  | `14` |  | `private readonly ICryptoTransform _decryptor;`
|  | `15` |  | ``
|  | `16` |  | `public BclImpl(`
|  | `17` |  | `byte[] key,`
|  | `18` |  | `byte[] iv,`
|  | `19` |  | `System.Security.Cryptography.CipherMode cipherMode,`
|  | `20` |  | `PaddingMode paddingMode)`
| 197 | `21` |  | `: base(key, 16, mode: null, padding: null)`
| 197 | `22` |  | `{`
| 197 | `23` |  | `var aes = Aes.Create();`
| 197 | `24` |  | `aes.Key = key;`
|  | `25` |  | ``
| 197 | `26` |  | `if (cipherMode != System.Security.Cryptography.CipherMode.ECB)`
| 143 | `27` |  | `{`
| 143 | `28` |  | `if (iv is null)`
| 0 | `29` |  | `{`
| 0 | `30` |  | `throw new ArgumentNullException(nameof(iv));`
|  | `31` |  | `}`
|  | `32` |  | ``
| 143 | `33` |  | `aes.IV = iv.Take(16);`
| 143 | `34` |  | `}`
|  | `35` |  | ``
| 197 | `36` |  | `aes.Mode = cipherMode;`
| 197 | `37` |  | `aes.Padding = paddingMode;`
| 197 | `38` |  | `aes.FeedbackSize = 128; // We use CFB128`
| 197 | `39` |  | `_aes = aes;`
| 197 | `40` |  | `_encryptor = aes.CreateEncryptor();`
| 197 | `41` |  | `_decryptor = aes.CreateDecryptor();`
| 197 | `42` |  | `}`
|  | `43` |  | ``
|  | `44` |  | `public override byte[] Encrypt(byte[] input, int offset, int length)`
| 153 | `45` |  | `{`
| 153 | `46` |  | `if (_aes.Padding != PaddingMode.None)`
| 0 | `47` |  | `{`
|  | `48` |  | `// If padding has been specified, call TransformFinalBlock to apply`
|  | `49` |  | `// the padding and reset the state.`
| 0 | `50` |  | `return _encryptor.TransformFinalBlock(input, offset, length);`
|  | `51` |  | `}`
|  | `52` |  | ``
|  | `53` |  | `// Otherwise, (the most important case) assume this instance is`
|  | `54` |  | `// used for one direction of an SSH connection, whereby the`
|  | `55` |  | `// encrypted data in all packets are considered a single data`
|  | `56` |  | `// stream i.e. we do not want to reset the state between calls to Encrypt.`
| 153 | `57` |  | `var output = new byte[length];`
| 153 | `58` |  | `_ = _encryptor.TransformBlock(input, offset, length, output, 0);`
| 153 | `59` |  | `return output;`
| 153 | `60` |  | `}`
|  | `61` |  | ``
|  | `62` |  | `public override byte[] Decrypt(byte[] input, int offset, int length)`
| 263 | `63` |  | `{`
| 263 | `64` |  | `if (_aes.Padding != PaddingMode.None)`
| 32 | `65` |  | `{`
|  | `66` |  | `// If padding has been specified, call TransformFinalBlock to apply`
|  | `67` |  | `// the padding and reset the state.`
| 32 | `68` |  | `return _decryptor.TransformFinalBlock(input, offset, length);`
|  | `69` |  | `}`
|  | `70` |  | ``
|  | `71` |  | `// Otherwise, (the most important case) assume this instance is`
|  | `72` |  | `// used for one direction of an SSH connection, whereby the`
|  | `73` |  | `// encrypted data in all packets are considered a single data`
|  | `74` |  | `// stream i.e. we do not want to reset the state between calls to Decrypt.`
| 231 | `75` |  | `var output = new byte[length];`
| 231 | `76` |  | `_ = _decryptor.TransformBlock(input, offset, length, output, 0);`
| 231 | `77` |  | `return output;`
| 263 | `78` |  | `}`
|  | `79` |  | ``
|  | `80` |  | `public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, i`
| 0 | `81` |  | `{`
| 0 | `82` |  | `throw new NotImplementedException($"Invalid usage of {nameof(EncryptBlock)}.");`
|  | `83` |  | `}`
|  | `84` |  | ``
|  | `85` |  | `public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, i`
| 0 | `86` |  | `{`
| 0 | `87` |  | `throw new NotImplementedException($"Invalid usage of {nameof(DecryptBlock)}.");`
|  | `88` |  | `}`
|  | `89` |  | ``
|  | `90` |  | `private void Dispose(bool disposing)`
| 18 | `91` |  | `{`
| 18 | `92` |  | `if (disposing)`
| 18 | `93` |  | `{`
| 18 | `94` |  | `_aes.Dispose();`
| 18 | `95` |  | `_encryptor.Dispose();`
| 18 | `96` |  | `_decryptor.Dispose();`
| 18 | `97` |  | `}`
| 18 | `98` |  | `}`
|  | `99` |  | ``
|  | `100` |  | `public void Dispose()`
| 18 | `101` |  | `{`
|  | `102` |  | `// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method`
| 18 | `103` |  | `Dispose(disposing: true);`
| 18 | `104` |  | `GC.SuppressFinalize(this);`
| 18 | `105` |  | `}`
|  | `106` |  | `}`
|  | `107` |  | `}`
|  | `108` |  | `}`

## \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\AesCipher.BlockImpl.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Security.Cryptography;`
|  | `3` |  | ``
|  | `4` |  | `namespace Renci.SshNet.Security.Cryptography.Ciphers`
|  | `5` |  | `{`
|  | `6` |  | `public partial class AesCipher`
|  | `7` |  | `{`
|  | `8` |  | `private sealed class BlockImpl : BlockCipher, IDisposable`
|  | `9` |  | `{`
|  | `10` |  | `private readonly Aes _aes;`
|  | `11` |  | `private readonly ICryptoTransform _encryptor;`
|  | `12` |  | `private readonly ICryptoTransform _decryptor;`
|  | `13` |  | ``
|  | `14` |  | `public BlockImpl(byte[] key, CipherMode mode, CipherPadding padding)`
| 72 | `15` |  | `: base(key, 16, mode, padding)`
| 72 | `16` |  | `{`
| 72 | `17` |  | `var aes = Aes.Create();`
| 72 | `18` |  | `aes.Key = key;`
| 72 | `19` |  | `aes.Mode = System.Security.Cryptography.CipherMode.ECB;`
| 72 | `20` |  | `aes.Padding = PaddingMode.None;`
| 72 | `21` |  | `_aes = aes;`
| 72 | `22` |  | `_encryptor = aes.CreateEncryptor();`
| 72 | `23` |  | `_decryptor = aes.CreateDecryptor();`
| 72 | `24` |  | `}`
|  | `25` |  | ``
|  | `26` |  | `public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, i`
| 168 | `27` |  | `{`
| 168 | `28` |  | `return _encryptor.TransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);`
| 168 | `29` |  | `}`
|  | `30` |  | ``
|  | `31` |  | `public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, i`
| 0 | `32` |  | `{`
| 0 | `33` |  | `return _decryptor.TransformBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);`
| 0 | `34` |  | `}`
|  | `35` |  | ``
|  | `36` |  | `private void Dispose(bool disposing)`
| 0 | `37` |  | `{`
| 0 | `38` |  | `if (disposing)`
| 0 | `39` |  | `{`
| 0 | `40` |  | `_aes.Dispose();`
| 0 | `41` |  | `_encryptor.Dispose();`
| 0 | `42` |  | `_decryptor.Dispose();`
| 0 | `43` |  | `}`
| 0 | `44` |  | `}`
|  | `45` |  | ``
|  | `46` |  | `public void Dispose()`
| 0 | `47` |  | `{`
|  | `48` |  | `// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method`
| 0 | `49` |  | `Dispose(disposing: true);`
| 0 | `50` |  | `GC.SuppressFinalize(this);`
| 0 | `51` |  | `}`
|  | `52` |  | `}`
|  | `53` |  | `}`
|  | `54` |  | `}`

## \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\AesCipher.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Security.Cryptography;`
|  | `3` |  | ``
|  | `4` |  | `using Renci.SshNet.Security.Cryptography.Ciphers.Modes;`
|  | `5` |  | `using Renci.SshNet.Security.Cryptography.Ciphers.Paddings;`
|  | `6` |  | ``
|  | `7` |  | `namespace Renci.SshNet.Security.Cryptography.Ciphers`
|  | `8` |  | `{`
|  | `9` |  | `/// <summary>`
|  | `10` |  | `/// AES cipher implementation.`
|  | `11` |  | `/// </summary>`
|  | `12` |  | `public sealed partial class AesCipher : BlockCipher, IDisposable`
|  | `13` |  | `{`
|  | `14` |  | `private readonly BlockCipher _impl;`
|  | `15` |  | ``
|  | `16` |  | `/// <summary>`
|  | `17` |  | `/// Initializes a new instance of the <see cref="AesCipher"/> class.`
|  | `18` |  | `/// </summary>`
|  | `19` |  | `/// <param name="key">The key.</param>`
|  | `20` |  | `/// <param name="mode">The mode.</param>`
|  | `21` |  | `/// <param name="iv">The IV.</param>`
|  | `22` |  | `/// <param name="pkcs7Padding">Enable PKCS7 padding.</param>`
|  | `23` |  | `/// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>`
|  | `24` |  | `/// <exception cref="ArgumentException">Keysize is not valid for this algorithm.</exception>`
|  | `25` |  | `public AesCipher(byte[] key, byte[] iv, AesCipherMode mode, bool pkcs7Padding = false)`
| 2734 | `26` |  | `: base(key, 16, mode: null, padding: null)`
| 2734 | `27` |  | `{`
| 2734 | `28` |  | `if (mode == AesCipherMode.OFB)`
| 54 | `29` |  | `{`
|  | `30` |  | `// OFB is not supported on modern .NET`
| 54 | `31` |  | `_impl = new BlockImpl(key, new OfbCipherMode(iv), pkcs7Padding ? new PKCS7Padding() : null);`
| 54 | `32` |  | `}`
|  | `33` |  | `#if !NET6_0_OR_GREATER`
| 95 | `34` |  | `else if (mode == AesCipherMode.CFB)`
| 18 | `35` |  | `{`
|  | `36` |  | `// CFB not supported on NetStandard 2.1`
| 18 | `37` |  | `_impl = new BlockImpl(key, new CfbCipherMode(iv), pkcs7Padding ? new PKCS7Padding() : null);`
| 18 | `38` |  | `}`
|  | `39` |  | `#endif`
| 2662 | `40` |  | `else if (mode == AesCipherMode.CTR)`
| 2465 | `41` |  | `{`
|  | `42` |  | `// CTR not supported by the BCL, use an optimized implementation`
| 2465 | `43` |  | `_impl = new CtrImpl(key, iv);`
| 2465 | `44` |  | `}`
|  | `45` |  | `else`
| 197 | `46` |  | `{`
| 197 | `47` |  | `_impl = new BclImpl(`
| 197 | `48` |  | `key,`
| 197 | `49` |  | `iv,`
| 197 | `50` |  | `(System.Security.Cryptography.CipherMode) mode,`
| 197 | `51` |  | `pkcs7Padding ? PaddingMode.PKCS7 : PaddingMode.None);`
| 197 | `52` |  | `}`
| 2734 | `53` |  | `}`
|  | `54` |  | ``
|  | `55` |  | `/// <inheritdoc/>`
|  | `56` |  | `public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o`
| 0 | `57` |  | `{`
| 0 | `58` |  | `return _impl.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);`
| 0 | `59` |  | `}`
|  | `60` |  | ``
|  | `61` |  | `/// <inheritdoc/>`
|  | `62` |  | `public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o`
| 0 | `63` |  | `{`
| 0 | `64` |  | `return _impl.EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);`
| 0 | `65` |  | `}`
|  | `66` |  | ``
|  | `67` |  | `/// <inheritdoc/>`
|  | `68` |  | `public override byte[] Encrypt(byte[] input, int offset, int length)`
| 48687 | `69` |  | `{`
| 48687 | `70` |  | `return _impl.Encrypt(input, offset, length);`
| 48687 | `71` |  | `}`
|  | `72` |  | ``
|  | `73` |  | `/// <inheritdoc/>`
|  | `74` |  | `public override byte[] Decrypt(byte[] input, int offset, int length)`
| 99828 | `75` |  | `{`
| 99828 | `76` |  | `return _impl.Decrypt(input, offset, length);`
| 99828 | `77` |  | `}`
|  | `78` |  | ``
|  | `79` |  | `/// <summary>`
|  | `80` |  | `/// Dispose the instance.`
|  | `81` |  | `/// </summary>`
|  | `82` |  | `/// <param name="disposing">Set to True to dispose of resouces.</param>`
|  | `83` |  | `public void Dispose(bool disposing)`
| 2408 | `84` |  | `{`
| 2408 | `85` |  | `if (disposing && _impl is IDisposable disposableImpl)`
| 2408 | `86` |  | `{`
| 2408 | `87` |  | `disposableImpl.Dispose();`
| 2408 | `88` |  | `}`
| 2408 | `89` |  | `}`
|  | `90` |  | ``
|  | `91` |  | `/// <inheritdoc/>`
|  | `92` |  | `public void Dispose()`
| 2408 | `93` |  | `{`
|  | `94` |  | `// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method`
| 2408 | `95` |  | `Dispose(disposing: true);`
| 2408 | `96` |  | `GC.SuppressFinalize(this);`
| 2408 | `97` |  | `}`
|  | `98` |  | `}`
|  | `99` |  | `}`

## \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\AesCipher.CtrImpl.cs

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER`
|  | `3` |  | `using System.Buffers.Binary;`
|  | `4` |  | `using System.Numerics;`
|  | `5` |  | `#endif`
|  | `6` |  | `using System.Security.Cryptography;`
|  | `7` |  | ``
|  | `8` |  | `namespace Renci.SshNet.Security.Cryptography.Ciphers`
|  | `9` |  | `{`
|  | `10` |  | `public partial class AesCipher`
|  | `11` |  | `{`
|  | `12` |  | `private sealed class CtrImpl : BlockCipher, IDisposable`
|  | `13` |  | `{`
|  | `14` |  | `private readonly Aes _aes;`
|  | `15` |  | ``
|  | `16` |  | `private readonly ICryptoTransform _encryptor;`
|  | `17` |  | ``
|  | `18` |  | `#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER`
|  | `19` |  | `private ulong _ivUpper; // The upper 64 bits of the IV`
|  | `20` |  | `private ulong _ivLower; // The lower 64 bits of the IV`
|  | `21` |  | `#else`
|  | `22` |  | `// The same on netfx`
|  | `23` |  | `private readonly uint[] _packedIV;`
|  | `24` |  | `#endif`
|  | `25` |  | ``
|  | `26` |  | `public CtrImpl(`
|  | `27` |  | `byte[] key,`
|  | `28` |  | `byte[] iv)`
| 2465 | `29` |  | `: base(key, 16, mode: null, padding: null)`
| 2465 | `30` |  | `{`
| 2465 | `31` |  | `var aes = Aes.Create();`
| 2465 | `32` |  | `aes.Key = key;`
| 2465 | `33` |  | `aes.Mode = System.Security.Cryptography.CipherMode.ECB;`
| 2465 | `34` |  | `aes.Padding = PaddingMode.None;`
| 2465 | `35` |  | `_aes = aes;`
| 2465 | `36` |  | `_encryptor = aes.CreateEncryptor();`
|  | `37` |  | ``
|  | `38` |  | `#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER`
| 2435 | `39` |  | `_ivLower = BinaryPrimitives.ReadUInt64BigEndian(iv.AsSpan(8));`
| 2435 | `40` |  | `_ivUpper = BinaryPrimitives.ReadUInt64BigEndian(iv);`
|  | `41` |  | `#else`
| 30 | `42` |  | `_packedIV = GetPackedIV(iv);`
|  | `43` |  | `#endif`
| 2465 | `44` |  | `}`
|  | `45` |  | ``
|  | `46` |  | `public override byte[] Encrypt(byte[] input, int offset, int length)`
| 48498 | `47` |  | `{`
| 48498 | `48` |  | `return CTREncryptDecrypt(input, offset, length);`
| 48498 | `49` |  | `}`
|  | `50` |  | ``
|  | `51` |  | `public override byte[] Decrypt(byte[] input, int offset, int length)`
| 99529 | `52` |  | `{`
| 99529 | `53` |  | `return CTREncryptDecrypt(input, offset, length);`
| 99529 | `54` |  | `}`
|  | `55` |  | ``
|  | `56` |  | `public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, i`
| 0 | `57` |  | `{`
| 0 | `58` |  | `throw new NotImplementedException($"Invalid usage of {nameof(DecryptBlock)}.");`
|  | `59` |  | `}`
|  | `60` |  | ``
|  | `61` |  | `public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, i`
| 0 | `62` |  | `{`
| 0 | `63` |  | `throw new NotImplementedException($"Invalid usage of {nameof(EncryptBlock)}.");`
|  | `64` |  | `}`
|  | `65` |  | ``
|  | `66` |  | `private byte[] CTREncryptDecrypt(byte[] data, int offset, int length)`
| 148027 | `67` |  | `{`
| 148027 | `68` |  | `var count = length / BlockSize;`
| 148027 | `69` |  | `if (length % BlockSize != 0)`
| 0 | `70` |  | `{`
| 0 | `71` |  | `count++;`
| 0 | `72` |  | `}`
|  | `73` |  | ``
| 148027 | `74` |  | `var buffer = new byte[count * BlockSize];`
| 148027 | `75` |  | `CTRCreateCounterArray(buffer);`
| 148027 | `76` |  | `_ = _encryptor.TransformBlock(buffer, 0, buffer.Length, buffer, 0);`
| 148027 | `77` |  | `ArrayXOR(buffer, data, offset, length);`
|  | `78` |  | ``
|  | `79` |  | `// adjust output for non-blocksized lengths`
| 148027 | `80` |  | `if (buffer.Length > length)`
| 0 | `81` |  | `{`
| 0 | `82` |  | `Array.Resize(ref buffer, length);`
| 0 | `83` |  | `}`
|  | `84` |  | ``
| 148027 | `85` |  | `return buffer;`
| 148027 | `86` |  | `}`
|  | `87` |  | ``
|  | `88` |  | `#if NETSTANDARD2_1_OR_GREATER || NET6_0_OR_GREATER`
|  | `89` |  | ``
|  | `90` |  | `// creates the Counter array filled with incrementing copies of IV`
|  | `91` |  | `private void CTRCreateCounterArray(byte[] buffer)`
| 147995 | `92` |  | `{`
| 46453302 | `93` |  | `for (var i = 0; i < buffer.Length; i += 16)`
| 23078656 | `94` |  | `{`
| 23078656 | `95` |  | `BinaryPrimitives.WriteUInt64BigEndian(buffer.AsSpan(i + 8), _ivLower);`
| 23078656 | `96` |  | `BinaryPrimitives.WriteUInt64BigEndian(buffer.AsSpan(i), _ivUpper);`
|  | `97` |  | ``
| 23078656 | `98` |  | `_ivLower += 1;`
| 23078656 | `99` |  | `_ivUpper += (_ivLower == 0) ? 1UL : 0UL;`
| 23078656 | `100` |  | `}`
| 147995 | `101` |  | `}`
|  | `102` |  | ``
|  | `103` |  | `// XOR 2 arrays using Vector<byte>`
|  | `104` |  | `private static void ArrayXOR(byte[] buffer, byte[] data, int offset, int length)`
| 147995 | `105` |  | `{`
| 147995 | `106` |  | `var i = 0;`
|  | `107` |  | ``
| 147995 | `108` |  | `var oneVectorFromEnd = length - Vector<byte>.Count;`
| 23118317 | `109` |  | `for (; i <= oneVectorFromEnd; i += Vector<byte>.Count)`
| 11485161 | `110` |  | `{`
| 11485161 | `111` |  | `var v = new Vector<byte>(buffer, i) ^ new Vector<byte>(data, offset + i);`
| 11485161 | `112` |  | `v.CopyTo(buffer, i);`
| 11485161 | `113` |  | `}`
|  | `114` |  | ``
| 3614683 | `115` |  | `for (; i < length; i++)`
| 1733344 | `116` |  | `{`
| 1733344 | `117` |  | `buffer[i] ^= data[offset + i];`
| 1733344 | `118` |  | `}`
| 147995 | `119` |  | `}`
|  | `120` |  | ``
|  | `121` |  | `#else`
|  | `122` |  | `// creates the Counter array filled with incrementing copies of IV`
|  | `123` |  | `private void CTRCreateCounterArray(byte[] buffer)`
| 32 | `124` |  | `{`
|  | `125` |  | `// fill array with IV, increment by 1 for each copy`
| 32 | `126` |  | `var words = buffer.Length / 4;`
| 32 | `127` |  | `var counter = new uint[words];`
| 432 | `128` |  | `for (var i = 0; i < words; i += 4)`
| 184 | `129` |  | `{`
|  | `130` |  | `// write IV to buffer (big endian)`
| 184 | `131` |  | `counter[i] = _packedIV[0];`
| 184 | `132` |  | `counter[i + 1] = _packedIV[1];`
| 184 | `133` |  | `counter[i + 2] = _packedIV[2];`
| 184 | `134` |  | `counter[i + 3] = _packedIV[3];`
|  | `135` |  | ``
|  | `136` |  | `// increment IV (little endian)`
| 184 | `137` |  | `if (_packedIV[3] < 0xFF000000u)`
| 182 | `138` |  | `{`
| 182 | `139` |  | `_packedIV[3] += 0x01000000u;`
| 182 | `140` |  | `}`
|  | `141` |  | `else`
| 2 | `142` |  | `{`
| 2 | `143` |  | `var j = 3;`
|  | `144` |  | `do`
| 8 | `145` |  | `{`
| 8 | `146` |  | `_packedIV[j] = SwapEndianness(SwapEndianness(_packedIV[j]) + 1);`
| 8 | `147` |  | `}`
| 8 | `148` |  | `while (_packedIV[j] == 0 && --j >= 0);`
| 2 | `149` |  | `}`
| 184 | `150` |  | `}`
|  | `151` |  | ``
|  | `152` |  | `// copy uint[] to byte[]`
| 32 | `153` |  | `Buffer.BlockCopy(counter, 0, buffer, 0, buffer.Length);`
| 32 | `154` |  | `}`
|  | `155` |  | ``
|  | `156` |  | `// XOR 2 arrays using Uint[] and blockcopy`
|  | `157` |  | `private static void ArrayXOR(byte[] buffer, byte[] data, int offset, int length)`
| 32 | `158` |  | `{`
| 32 | `159` |  | `var words = length / 4;`
| 32 | `160` |  | `if (length % 4 != 0)`
| 0 | `161` |  | `{`
| 0 | `162` |  | `words++;`
| 0 | `163` |  | `}`
|  | `164` |  | ``
|  | `165` |  | `// convert original data to words`
| 32 | `166` |  | `var datawords = new uint[words];`
| 32 | `167` |  | `Buffer.BlockCopy(data, offset, datawords, 0, length);`
|  | `168` |  | ``
|  | `169` |  | `// convert encrypted IV counter to words`
| 32 | `170` |  | `var bufferwords = new uint[words];`
| 32 | `171` |  | `Buffer.BlockCopy(buffer, 0, bufferwords, 0, length);`
|  | `172` |  | ``
|  | `173` |  | `// XOR encrypted Counter with input data`
| 1536 | `174` |  | `for (var i = 0; i < words; i++)`
| 736 | `175` |  | `{`
| 736 | `176` |  | `bufferwords[i] = bufferwords[i] ^ datawords[i];`
| 736 | `177` |  | `}`
|  | `178` |  | ``
|  | `179` |  | `// copy uint[] to byte[]`
| 32 | `180` |  | `Buffer.BlockCopy(bufferwords, 0, buffer, 0, length);`
| 32 | `181` |  | `}`
|  | `182` |  | ``
|  | `183` |  | `// pack the IV into an array of uint[4]`
|  | `184` |  | `private static uint[] GetPackedIV(byte[] iv)`
| 30 | `185` |  | `{`
| 30 | `186` |  | `var packedIV = new uint[4];`
| 30 | `187` |  | `packedIV[0] = BitConverter.ToUInt32(iv, 0);`
| 30 | `188` |  | `packedIV[1] = BitConverter.ToUInt32(iv, 4);`
| 30 | `189` |  | `packedIV[2] = BitConverter.ToUInt32(iv, 8);`
| 30 | `190` |  | `packedIV[3] = BitConverter.ToUInt32(iv, 12);`
|  | `191` |  | ``
| 30 | `192` |  | `return packedIV;`
| 30 | `193` |  | `}`
|  | `194` |  | ``
|  | `195` |  | `private static uint SwapEndianness(uint x)`
| 16 | `196` |  | `{`
| 16 | `197` |  | `x = (x >> 16) | (x << 16);`
| 16 | `198` |  | `return ((x & 0xFF00FF00) >> 8) | ((x & 0x00FF00FF) << 8);`
| 16 | `199` |  | `}`
|  | `200` |  | `#endif`
|  | `201` |  | ``
|  | `202` |  | `private void Dispose(bool disposing)`
| 2390 | `203` |  | `{`
| 2390 | `204` |  | `if (disposing)`
| 2390 | `205` |  | `{`
| 2390 | `206` |  | `_aes.Dispose();`
| 2390 | `207` |  | `_encryptor.Dispose();`
| 2390 | `208` |  | `}`
| 2390 | `209` |  | `}`
|  | `210` |  | ``
|  | `211` |  | `public void Dispose()`
| 2390 | `212` |  | `{`
|  | `213` |  | `// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method`
| 2390 | `214` |  | `Dispose(disposing: true);`
| 2390 | `215` |  | `GC.SuppressFinalize(this);`
| 2390 | `216` |  | `}`
|  | `217` |  | `}`
|  | `218` |  | `}`
|  | `219` |  | `}`

# Methods/Properties

.ctor(System.Byte[],System.Byte[],System.Security.Cryptography.CipherMode,System.Security.Cryptography.PaddingMode)
Encrypt(System.Byte[],System.Int32,System.Int32)
Decrypt(System.Byte[],System.Int32,System.Int32)
EncryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
DecryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
Dispose(System.Boolean)
Dispose()
.ctor(System.Byte[],Renci.SshNet.Security.Cryptography.Ciphers.CipherMode,Renci.SshNet.Security.Cryptography.Ciphers.CipherPadding)
EncryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
DecryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
Dispose(System.Boolean)
Dispose()
.ctor(System.Byte[],System.Byte[],Renci.SshNet.Security.Cryptography.Ciphers.AesCipherMode,System.Boolean)
EncryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
DecryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
Encrypt(System.Byte[],System.Int32,System.Int32)
Decrypt(System.Byte[],System.Int32,System.Int32)
Dispose(System.Boolean)
Dispose()
.ctor(System.Byte[],System.Byte[])
Encrypt(System.Byte[],System.Int32,System.Int32)
Decrypt(System.Byte[],System.Int32,System.Int32)
DecryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
EncryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
CTREncryptDecrypt(System.Byte[],System.Int32,System.Int32)
CTRCreateCounterArray(System.Byte[])
ArrayXOR(System.Byte[],System.Byte[],System.Int32,System.Int32)
CTRCreateCounterArray(System.Byte[])
ArrayXOR(System.Byte[],System.Byte[],System.Int32,System.Int32)
GetPackedIV(System.Byte[])
SwapEndianness(System.UInt32)
Dispose(System.Boolean)
Dispose()