# < Summary

Information

Class: | Renci.SshNet.Security.Cryptography.Ciphers.Modes.CtrCipherMode
Assembly: | Renci.SshNet
File(s): | \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\Modes\CtrCipherMode.cs

Line coverage
0%

Covered lines: | 0
Uncovered lines: | 28
Coverable lines: | 28
Total lines: | 83
Line coverage: | 0%

Branch coverage
0%

Covered branches: | 0
Total branches: | 12
Branch coverage: | 0%

Method coverage

Feature is only available for sponsors

Upgrade to PRO version

# Metrics

Method | Branch coverage | Cyclomatic complexity | Line coverage
--- | --- | --- | ---
.ctor(...) | 100% | 1 | 0%
EncryptBlock(...) | 0% | 12 | 0%
DecryptBlock(...) | 100% | 1 | 0%

# File(s)

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

| # | Line |  | Line coverage
--- | --- | --- | --- | ---
|  | `1` |  | `using System;`
|  | `2` |  | `using System.Globalization;`
|  | `3` |  | ``
|  | `4` |  | `namespace Renci.SshNet.Security.Cryptography.Ciphers.Modes`
|  | `5` |  | `{`
|  | `6` |  | `/// <summary>`
|  | `7` |  | `/// Implements CTR cipher mode.`
|  | `8` |  | `/// </summary>`
|  | `9` |  | `public class CtrCipherMode : CipherMode`
|  | `10` |  | `{`
|  | `11` |  | `private readonly byte[] _ivOutput;`
|  | `12` |  | ``
|  | `13` |  | `/// <summary>`
|  | `14` |  | `/// Initializes a new instance of the <see cref="CtrCipherMode"/> class.`
|  | `15` |  | `/// </summary>`
|  | `16` |  | `/// <param name="iv">The iv.</param>`
|  | `17` |  | `public CtrCipherMode(byte[] iv)`
| 0 | `18` |  | `: base(iv)`
| 0 | `19` |  | `{`
| 0 | `20` |  | `_ivOutput = new byte[iv.Length];`
| 0 | `21` |  | `}`
|  | `22` |  | ``
|  | `23` |  | `/// <summary>`
|  | `24` |  | `/// Encrypts the specified region of the input byte array and copies the encrypted data to the specified region`
|  | `25` |  | `/// </summary>`
|  | `26` |  | `/// <param name="inputBuffer">The input data to encrypt.</param>`
|  | `27` |  | `/// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>`
|  | `28` |  | `/// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>`
|  | `29` |  | `/// <param name="outputBuffer">The output to which to write encrypted data.</param>`
|  | `30` |  | `/// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>`
|  | `31` |  | `/// <returns>`
|  | `32` |  | `/// The number of bytes encrypted.`
|  | `33` |  | `/// </returns>`
|  | `34` |  | `public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o`
| 0 | `35` |  | `{`
| 0 | `36` |  | `if (inputBuffer.Length - inputOffset < _blockSize)`
| 0 | `37` |  | `{`
| 0 | `38` |  | `throw new ArgumentException("Invalid input buffer");`
|  | `39` |  | `}`
|  | `40` |  | ``
| 0 | `41` |  | `if (outputBuffer.Length - outputOffset < _blockSize)`
| 0 | `42` |  | `{`
| 0 | `43` |  | `throw new ArgumentException("Invalid output buffer");`
|  | `44` |  | `}`
|  | `45` |  | ``
| 0 | `46` |  | `if (inputCount != _blockSize)`
| 0 | `47` |  | `{`
| 0 | `48` |  | `throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "inputCount must be {0}.", _blockS`
|  | `49` |  | `}`
|  | `50` |  | ``
| 0 | `51` |  | `_ = Cipher.EncryptBlock(IV, 0, IV.Length, _ivOutput, 0);`
|  | `52` |  | ``
| 0 | `53` |  | `for (var i = 0; i < _blockSize; i++)`
| 0 | `54` |  | `{`
| 0 | `55` |  | `outputBuffer[outputOffset + i] = (byte)(_ivOutput[i] ^ inputBuffer[inputOffset + i]);`
| 0 | `56` |  | `}`
|  | `57` |  | ``
| 0 | `58` |  | `var j = IV.Length;`
| 0 | `59` |  | `while (--j >= 0 && ++IV[j] == 0)`
| 0 | `60` |  | `{`
|  | `61` |  | `// Intentionally empty block`
| 0 | `62` |  | `}`
|  | `63` |  | ``
| 0 | `64` |  | `return _blockSize;`
| 0 | `65` |  | `}`
|  | `66` |  | ``
|  | `67` |  | `/// <summary>`
|  | `68` |  | `/// Decrypts the specified region of the input byte array and copies the decrypted data to the specified region`
|  | `69` |  | `/// </summary>`
|  | `70` |  | `/// <param name="inputBuffer">The input data to decrypt.</param>`
|  | `71` |  | `/// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>`
|  | `72` |  | `/// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>`
|  | `73` |  | `/// <param name="outputBuffer">The output to which to write decrypted data.</param>`
|  | `74` |  | `/// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>`
|  | `75` |  | `/// <returns>`
|  | `76` |  | `/// The number of bytes decrypted.`
|  | `77` |  | `/// </returns>`
|  | `78` |  | `public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o`
| 0 | `79` |  | `{`
| 0 | `80` |  | `return EncryptBlock(inputBuffer, inputOffset, inputCount, outputBuffer, outputOffset);`
| 0 | `81` |  | `}`
|  | `82` |  | `}`
|  | `83` |  | `}`

# Methods/Properties

.ctor(System.Byte[])
EncryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)
DecryptBlock(System.Byte[],System.Int32,System.Int32,System.Byte[],System.Int32)