Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Fonseca committed Nov 1, 2023
1 parent 5cc5d4a commit 086ad43
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/Renci.SshNet/Security/Cryptography/BlockCipher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override byte[] Encrypt(byte[] input, int offset, int length)
{
if (length % _blockSize > 0)
{
if (_padding is null)
if (_padding is null)
{
throw new ArgumentException("data");
}
Expand Down Expand Up @@ -135,17 +135,18 @@ public override byte[] Decrypt(byte[] input, int offset, int length)
{
if (length % _blockSize > 0)
{
if (_padding is null)
if (_padding is null)
{
throw new ArgumentException("data");
}

input = _padding.Pad(_blockSize, input, offset, length);
offset = 0;
length = input.Length;
input = _padding.Pad(_blockSize, input, offset, length);
offset = 0;
length = input.Length;
}

var output = new byte[length];

var writtenBytes = 0;
for (var i = 0; i < length / _blockSize; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ public override byte[] Decrypt(byte[] input, int offset, int length)
return _aesCSP.Decrypt(input, offset, length);
}

return base.Encrypt(input, offset, length);
return base.Decrypt(input, offset, length);
}

private uint[] GenerateWorkingKey(bool isEncryption, byte[] key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace Renci.SshNet.Security.Cryptography.Ciphers
{
// allow ECB in this class
#pragma warning disable CA5358

/// <summary>
/// AES cipher implementation using the accelerated AesCryptoServiceProvider
/// This CSP makes use of AES-NI instructions if available (faster, less CPU usage).
Expand Down Expand Up @@ -128,7 +125,9 @@ private bool InitCryptoServiceProvider(byte[] key, byte[] iv)
using var aesProvider = CSP.Aes.Create();
aesProvider.BlockSize = _blockSize * 8;
aesProvider.KeySize = key.Length * 8;
#pragma warning disable CA5358 // allow ECB
aesProvider.Mode = _isCTRMode ? CSP.CipherMode.ECB : CSP.CipherMode.CBC; // CTR uses ECB
#pragma warning restore CA5358
aesProvider.Padding = CSP.PaddingMode.None;
aesProvider.Key = key;
aesProvider.IV = iv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class CipherMode
/// <summary>
/// Gets the IV vector.
/// </summary>
internal byte[] IV {get; private set;}
internal byte[] IV;

/// <summary>
/// Holds block size of the cipher.
Expand Down

0 comments on commit 086ad43

Please sign in to comment.