Преглед на файлове

Create Random function for BigInteger
Clean up minor TODO items

olegkap_cp преди 14 години
родител
ревизия
c301c940ce

+ 40 - 23
Renci.SshClient/Renci.SshNet.Tests/Security/Cryptography/Ciphers.cs

@@ -15,16 +15,12 @@ namespace Renci.SshNet.Tests.Security.Cryptography
             var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 };
             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 output = new[] { 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 output = 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 Renci.SshNet.Security.Cryptography.Ciphers.AesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
             var r = testCipher.Encrypt(input);
-            for (int i = 0; i < r.Length; i++)
-            {
-                if (r[i] != output[i])
-                {
-                    Assert.Fail("Invalid encryption");
-                }
-            }
+
+            if (!r.SequenceEqual(output))
+                Assert.Fail("Invalid encryption");
         }
 
         [TestMethod]
@@ -33,16 +29,12 @@ namespace Renci.SshNet.Tests.Security.Cryptography
             var input = new byte[] { 0x00, 0x00, 0x00, 0x1c, 0x0a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x72, 0x4e, 0x06, 0x08, 0x28, 0x2d, 0xaa, 0xe2, 0xb3, 0xd9 };
             var key = new byte[] { 0x78, 0xf6, 0xc6, 0xbb, 0x57, 0x03, 0x69, 0xca, 0xba, 0x31, 0x18, 0x2f, 0x2f, 0x4c, 0x35, 0x34, 0x64, 0x06, 0x85, 0x30, 0xbe, 0x78, 0x60, 0xb3 };
             var iv = new byte[] { 0xc0, 0x75, 0xf2, 0x26, 0x0a, 0x2a, 0x42, 0x96 };
-            var output = new[] { 0x28, 0x77, 0x2f, 0x07, 0x3e, 0xc2, 0x27, 0xa6, 0xdb, 0x36, 0x4d, 0xc6, 0x7a, 0x26, 0x7a, 0x38, 0xe6, 0x54, 0x0b, 0xab, 0x07, 0x87, 0xf0, 0xa4, 0x73, 0x1f, 0xde, 0xe6, 0x81, 0x1d, 0x4b, 0x4b };
+            var output = new byte[] { 0x28, 0x77, 0x2f, 0x07, 0x3e, 0xc2, 0x27, 0xa6, 0xdb, 0x36, 0x4d, 0xc6, 0x7a, 0x26, 0x7a, 0x38, 0xe6, 0x54, 0x0b, 0xab, 0x07, 0x87, 0xf0, 0xa4, 0x73, 0x1f, 0xde, 0xe6, 0x81, 0x1d, 0x4b, 0x4b };
             var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.TripleDesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
             var r = testCipher.Encrypt(input);
-            for (int i = 0; i < r.Length; i++)
-            {
-                if (r[i] != output[i])
-                {
-                    Assert.Fail("Invalid encryption");
-                }
-            }
+
+            if (!r.SequenceEqual(output))
+                Assert.Fail("Invalid encryption");
         }
 
         [TestMethod]
@@ -55,14 +47,39 @@ namespace Renci.SshNet.Tests.Security.Cryptography
             var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.AesCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CtrCipherMode(iv), null);
 
             var r = testCipher.Encrypt(input);
-            for (int i = 0; i < r.Length; i++)
-            {
-                if (r[i] != output[i])
-                {
-                    Assert.Fail("Invalid encryption");
-                }
-            }
+
+            if (!r.SequenceEqual(output))
+                Assert.Fail("Invalid encryption");
+        }
+
+        [TestMethod]
+        public void Test_Cipher_Blowfish_128_CBC()
+        {
+            var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 };
+            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 output = new byte[] { 0x50, 0x49, 0xe0, 0xce, 0x98, 0x93, 0x8b, 0xec, 0x82, 0x7d, 0x14, 0x1b, 0x3e, 0xdc, 0xca, 0x63, 0xef, 0x36, 0x20, 0x67, 0x58, 0x63, 0x1f, 0x9c, 0xd2, 0x12, 0x6b, 0xca, 0xea, 0xd0, 0x78, 0x8b, 0x61, 0x50, 0x4f, 0xc4, 0x5b, 0x32, 0x91, 0xd6, 0x65, 0xcb, 0x74, 0xe5, 0x6e, 0xf5, 0xde, 0x14 };
+            var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.BlowfishCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
+            var r = testCipher.Encrypt(input);
+
+            if (!r.SequenceEqual(output))
+                Assert.Fail("Invalid encryption");
+        }
+
+        [TestMethod]
+        public void Test_Cipher_CastCipher_128_CBC()
+        {
+            var input = new byte[] { 0x00, 0x00, 0x00, 0x2c, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x0c, 0x73, 0x73, 0x68, 0x2d, 0x75, 0x73, 0x65, 0x72, 0x61, 0x75, 0x74, 0x68, 0x30, 0x9e, 0xe0, 0x9c, 0x12, 0xee, 0x3a, 0x30, 0x03, 0x52, 0x1c, 0x1a, 0xe7, 0x3e, 0x0b, 0x9a, 0xcf, 0x9a, 0x57, 0x42, 0x0b, 0x4f, 0x4a, 0x15, 0xa0, 0xf5 };
+            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 output = new byte[] { 0x32, 0xef, 0xbd, 0xac, 0xb6, 0xfd, 0x1f, 0xae, 0x1b, 0x13, 0x5f, 0x31, 0x6d, 0x38, 0xcd, 0xb0, 0xe3, 0xca, 0xe1, 0xbc, 0xf8, 0xa7, 0xc2, 0x31, 0x62, 0x14, 0x3a, 0x9a, 0xda, 0xe3, 0xf8, 0xc8, 0x70, 0x87, 0x53, 0x21, 0x5d, 0xb7, 0x94, 0xb7, 0xe8, 0xc6, 0x9d, 0x46, 0x0c, 0x6d, 0x64, 0x6d };
+            var testCipher = new Renci.SshNet.Security.Cryptography.Ciphers.CastCipher(key, new Renci.SshNet.Security.Cryptography.Ciphers.Modes.CbcCipherMode(iv), null);
+            var r = testCipher.Encrypt(input);
+
+            if (!r.SequenceEqual(output))
+                Assert.Fail("Invalid encryption");
         }
 
+
     }
 }

+ 16 - 0
Renci.SshClient/Renci.SshNet/Common/BigInteger.cs

@@ -51,6 +51,7 @@ using System.Diagnostics.CodeAnalysis;
 using System.Globalization;
 using System.Text;
 using System.Threading;
+using System.Security.Cryptography;
 
 /*
 Optimization
@@ -69,6 +70,8 @@ namespace Renci.SshNet.Common
     /// </summary>
     public struct BigInteger : IComparable, IFormattable, IComparable<BigInteger>, IEquatable<BigInteger>
     {
+        private static RNGCryptoServiceProvider _randomizer = new System.Security.Cryptography.RNGCryptoServiceProvider();
+
         private const ulong _BASE = 0x100000000;
         private const Int32 _DECIMALSIGNMASK = unchecked((Int32)0x80000000);
         private const int _BIAS = 1075;
@@ -1960,6 +1963,19 @@ namespace Renci.SshNet.Common
             return LongCompare(low, high);
         }
 
+        /// <summary>
+        /// Generates random BigInteger number
+        /// </summary>
+        /// <param name="bitLength">Length of random number in bits.</param>
+        /// <returns></returns>
+        public static BigInteger Random(int bitLength)
+        {
+            var bytesArray = new byte[bitLength / 8 + (((bitLength % 8) > 0) ? 1 : 0)];
+            _randomizer.GetBytes(bytesArray);
+            bytesArray[bytesArray.Length - 1] = (byte)(bytesArray[bytesArray.Length - 1] & 0x7F);   //  Ensure not a negative value
+            return new BigInteger(bytesArray.ToArray());
+        }
+
         /// <summary>
         /// Divides one System.Numerics.BigInteger value by another and returns the result.
         /// </summary>

+ 70 - 64
Renci.SshClient/Renci.SshNet/Security/Cryptography/Ciphers/BlowfishCipher.cs

@@ -291,12 +291,15 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 
 		#endregion
 
-		private static readonly int ROUNDS = 16;
-		private static readonly int SBOX_SK = 256;
-		private static readonly int P_SZ = ROUNDS + 2;
+		private static readonly int _rounds = 16;
 
-		private readonly uint[] S0, S1, S2, S3;     // the s-boxes
-		private readonly uint[] P;                  // the p-array
+		private static readonly int _sboxSk = 256;
+
+		private static readonly int _pSize = _rounds + 2;
+
+		private readonly uint[] _s0, _s1, _s2, _s3;     // the s-boxes
+
+		private readonly uint[] _p;                  // the p-array
 
 		/// <summary>
 		/// Initializes a new instance of the <see cref="BlowfishCipher"/> class.
@@ -314,13 +317,15 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			if (keySize < 1 || keySize > 448)
 				throw new ArgumentException(string.Format("KeySize '{0}' is not valid for this algorithm.", keySize));
 
-			//  TODO:   Refactor this algorithm
+			this._s0 = new uint[_sboxSk];
+
+			this._s1 = new uint[_sboxSk];
 
-			S0 = new uint[SBOX_SK];
-			S1 = new uint[SBOX_SK];
-			S2 = new uint[SBOX_SK];
-			S3 = new uint[SBOX_SK];
-			P = new uint[P_SZ];
+			this._s2 = new uint[_sboxSk];
+
+			this._s3 = new uint[_sboxSk];
+
+			this._p = new uint[_pSize];
 
 			this.SetKey(key);
 		}
@@ -344,15 +349,15 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			uint xl = BigEndianToUInt32(inputBuffer, inputOffset);
 			uint xr = BigEndianToUInt32(inputBuffer, inputOffset + 4);
 
-			xl ^= P[0];
+			xl ^= this._p[0];
 
-			for (int i = 1; i < ROUNDS; i += 2)
+			for (int i = 1; i < _rounds; i += 2)
 			{
-				xr ^= F(xl) ^ P[i];
-				xl ^= F(xr) ^ P[i + 1];
+				xr ^= F(xl) ^ this._p[i];
+				xl ^= F(xr) ^ this._p[i + 1];
 			}
 
-			xr ^= P[ROUNDS + 1];
+			xr ^= this._p[_rounds + 1];
 
 			UInt32ToBigEndian(xr, outputBuffer, outputOffset);
 			UInt32ToBigEndian(xl, outputBuffer, outputOffset + 4);
@@ -379,15 +384,15 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			uint xl = BigEndianToUInt32(inputBuffer, inputOffset);
 			uint xr = BigEndianToUInt32(inputBuffer, inputOffset + 4);
 
-			xl ^= P[ROUNDS + 1];
+			xl ^= this._p[_rounds + 1];
 
-			for (int i = ROUNDS; i > 0; i -= 2)
+			for (int i = _rounds; i > 0; i -= 2)
 			{
-				xr ^= F(xl) ^ P[i];
-				xl ^= F(xr) ^ P[i - 1];
+				xr ^= F(xl) ^ this._p[i];
+				xl ^= F(xr) ^ this._p[i - 1];
 			}
 
-			xr ^= P[0];
+			xr ^= this._p[0];
 
 			UInt32ToBigEndian(xr, outputBuffer, outputOffset);
 			UInt32ToBigEndian(xl, outputBuffer, outputOffset + 4);
@@ -397,37 +402,7 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 
 		private uint F(uint x)
 		{
-			return (((S0[x >> 24] + S1[(x >> 16) & 0xff]) ^ S2[(x >> 8) & 0xff]) + S3[x & 0xff]);
-		}
-
-		/// <summary>
-		/// apply the encryption cycle to each value pair in the table.
-		/// </summary>
-		/// <param name="xl">The xl.</param>
-		/// <param name="xr">The xr.</param>
-		/// <param name="table">The table.</param>
-		private void ProcessTable(uint xl, uint xr, uint[] table)
-		{
-			int size = table.Length;
-
-			for (int s = 0; s < size; s += 2)
-			{
-				xl ^= P[0];
-
-				for (int i = 1; i < ROUNDS; i += 2)
-				{
-					xr ^= F(xl) ^ P[i];
-					xl ^= F(xr) ^ P[i + 1];
-				}
-
-				xr ^= P[ROUNDS + 1];
-
-				table[s] = xr;
-				table[s + 1] = xl;
-
-				xr = xl;            // end of cycle swap
-				xl = table[s];
-			}
+			return (((this._s0[x >> 24] + this._s1[(x >> 16) & 0xff]) ^ this._s2[(x >> 8) & 0xff]) + this._s3[x & 0xff]);
 		}
 
 		private void SetKey(byte[] key)
@@ -441,12 +416,12 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			* Initialise the S-boxes and the P-array, with a fixed string
 			* This string contains the hexadecimal digits of pi (3.141...)
 			*/
-			Buffer.BlockCopy(KS0, 0, S0, 0, SBOX_SK * sizeof(uint));
-			Buffer.BlockCopy(KS1, 0, S1, 0, SBOX_SK * sizeof(uint));
-			Buffer.BlockCopy(KS2, 0, S2, 0, SBOX_SK * sizeof(uint));
-			Buffer.BlockCopy(KS3, 0, S3, 0, SBOX_SK * sizeof(uint));
+			Buffer.BlockCopy(KS0, 0, this._s0, 0, _sboxSk * sizeof(uint));
+			Buffer.BlockCopy(KS1, 0, this._s1, 0, _sboxSk * sizeof(uint));
+			Buffer.BlockCopy(KS2, 0, this._s2, 0, _sboxSk * sizeof(uint));
+			Buffer.BlockCopy(KS3, 0, this._s3, 0, _sboxSk * sizeof(uint));
 
-			Buffer.BlockCopy(KP, 0, P, 0, P_SZ * sizeof(uint));
+			Buffer.BlockCopy(KP, 0, this._p, 0, _pSize * sizeof(uint));
 
 			/*
 			* (2)
@@ -458,7 +433,7 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int keyLength = key.Length;
 			int keyIndex = 0;
 
-			for (int i = 0; i < P_SZ; i++)
+			for (int i = 0; i < _pSize; i++)
 			{
 				// Get the 32 bits of the key, in 4 * 8 bit chunks
 				uint data = 0x0000000;
@@ -474,7 +449,7 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 					}
 				}
 				// XOR the newly created 32 bit chunk onto the P-array
-				P[i] ^= data;
+				this._p[i] ^= data;
 			}
 
 			/*
@@ -498,11 +473,42 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			* continuously changing Blowfish algorithm
 			*/
 
-			ProcessTable(0, 0, P);
-			ProcessTable(P[P_SZ - 2], P[P_SZ - 1], S0);
-			ProcessTable(S0[SBOX_SK - 2], S0[SBOX_SK - 1], S1);
-			ProcessTable(S1[SBOX_SK - 2], S1[SBOX_SK - 1], S2);
-			ProcessTable(S2[SBOX_SK - 2], S2[SBOX_SK - 1], S3);
+			ProcessTable(0, 0, this._p);
+			ProcessTable(this._p[_pSize - 2], this._p[_pSize - 1], this._s0);
+			ProcessTable(this._s0[_sboxSk - 2], this._s0[_sboxSk - 1], this._s1);
+			ProcessTable(this._s1[_sboxSk - 2], this._s1[_sboxSk - 1], this._s2);
+			ProcessTable(this._s2[_sboxSk - 2], this._s2[_sboxSk - 1], this._s3);
+		}
+
+		/// <summary>
+		/// apply the encryption cycle to each value pair in the table.
+		/// </summary>
+		/// <param name="xl">The xl.</param>
+		/// <param name="xr">The xr.</param>
+		/// <param name="table">The table.</param>
+		private void ProcessTable(uint xl, uint xr, uint[] table)
+		{
+			int size = table.Length;
+
+			for (int s = 0; s < size; s += 2)
+			{
+				xl ^= _p[0];
+
+				for (int i = 1; i < _rounds; i += 2)
+				{
+					xr ^= F(xl) ^ _p[i];
+					xl ^= F(xr) ^ _p[i + 1];
+				}
+
+				xr ^= _p[_rounds + 1];
+
+				table[s] = xr;
+				table[s + 1] = xl;
+
+				xr = xl;            // end of cycle swap
+				xl = table[s];
+			}
 		}
+
 	}
 }

+ 2 - 3
Renci.SshClient/Renci.SshNet/Security/Cryptography/Ciphers/CastCipher.cs

@@ -34,7 +34,6 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
             if (!(keySize >= 40 && keySize <= 128 && keySize % 8 == 0))
                 throw new ArgumentException(string.Format("KeySize '{0}' is not valid for this algorithm.", keySize));
 
-            //  TODO:   Refactor this algorithm
             this.SetKey(key);
         }
 
@@ -59,7 +58,7 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
             uint R0 = BigEndianToUInt32(inputBuffer, inputOffset + 4);
 
             uint[] result = new uint[2];
-            CastEncipher(L0, R0, result);
+            this.CastEncipher(L0, R0, result);
 
             // now stuff them into the destination block
             UInt32ToBigEndian(result[0], outputBuffer, outputOffset);
@@ -88,7 +87,7 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
             uint R16 = BigEndianToUInt32(inputBuffer, inputOffset + 4);
 
             uint[] result = new uint[2];
-            CastDecipher(L16, R16, result);
+            this.CastDecipher(L16, R16, result);
 
             // now stuff them into the destination block
             UInt32ToBigEndian(result[0], outputBuffer, outputOffset);

+ 1 - 6
Renci.SshClient/Renci.SshNet/Security/Cryptography/Ciphers/RsaCipher.cs

@@ -94,14 +94,9 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
                 
                 var bitLength = this._key.Modulus.BitLength;
 
-                var bytesArray = new byte[bitLength / 8 + (((bitLength % 8) > 0) ? 1 : 0)];
-
                 while (random <= BigInteger.One || random >= max)
                 {
-                    _randomizer.GetBytes(bytesArray);
-
-                    bytesArray[bytesArray.Length - 1] = (byte)(bytesArray[bytesArray.Length - 1] & 0x7F);   //  Ensure not a negative value
-                    random = new BigInteger(bytesArray.Reverse().ToArray());
+                    random = BigInteger.Random(bitLength);
                 }
 
                 BigInteger blindedInput = BigInteger.PositiveMod((BigInteger.ModPow(random, this._key.Exponent, this._key.Modulus) * input), this._key.Modulus);

+ 251 - 252
Renci.SshClient/Renci.SshNet/Security/Cryptography/Ciphers/SerpentCipher.cs

@@ -15,7 +15,7 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 
 		private int[] _workingKey;
 
-		private int X0, X1, X2, X3;    // registers
+		private int _x0, _x1, _x2, _x3;    // registers
 
 		/// <summary>
 		/// Initializes a new instance of the <see cref="SerpentCipher"/> class.
@@ -28,7 +28,6 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 		public SerpentCipher(byte[] key, CipherMode mode, CipherPadding padding)
 			: base(key, 16, mode, padding)
 		{
-			//  TODO:   Refactor this algorithm
 			var keySize = key.Length * 8;
 
 			if (!(keySize == 128 || keySize == 192 || keySize == 256))
@@ -53,48 +52,48 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			if (inputCount != this.BlockSize)
 				throw new ArgumentException("inputCount");
 
-			X3 = BytesToWord(inputBuffer, inputOffset);
-			X2 = BytesToWord(inputBuffer, inputOffset + 4);
-			X1 = BytesToWord(inputBuffer, inputOffset + 8);
-			X0 = BytesToWord(inputBuffer, inputOffset + 12);
-
-			Sb0(this._workingKey[0] ^ X0, this._workingKey[1] ^ X1, this._workingKey[2] ^ X2, this._workingKey[3] ^ X3); LT();
-			Sb1(this._workingKey[4] ^ X0, this._workingKey[5] ^ X1, this._workingKey[6] ^ X2, this._workingKey[7] ^ X3); LT();
-			Sb2(this._workingKey[8] ^ X0, this._workingKey[9] ^ X1, this._workingKey[10] ^ X2, this._workingKey[11] ^ X3); LT();
-			Sb3(this._workingKey[12] ^ X0, this._workingKey[13] ^ X1, this._workingKey[14] ^ X2, this._workingKey[15] ^ X3); LT();
-			Sb4(this._workingKey[16] ^ X0, this._workingKey[17] ^ X1, this._workingKey[18] ^ X2, this._workingKey[19] ^ X3); LT();
-			Sb5(this._workingKey[20] ^ X0, this._workingKey[21] ^ X1, this._workingKey[22] ^ X2, this._workingKey[23] ^ X3); LT();
-			Sb6(this._workingKey[24] ^ X0, this._workingKey[25] ^ X1, this._workingKey[26] ^ X2, this._workingKey[27] ^ X3); LT();
-			Sb7(this._workingKey[28] ^ X0, this._workingKey[29] ^ X1, this._workingKey[30] ^ X2, this._workingKey[31] ^ X3); LT();
-			Sb0(this._workingKey[32] ^ X0, this._workingKey[33] ^ X1, this._workingKey[34] ^ X2, this._workingKey[35] ^ X3); LT();
-			Sb1(this._workingKey[36] ^ X0, this._workingKey[37] ^ X1, this._workingKey[38] ^ X2, this._workingKey[39] ^ X3); LT();
-			Sb2(this._workingKey[40] ^ X0, this._workingKey[41] ^ X1, this._workingKey[42] ^ X2, this._workingKey[43] ^ X3); LT();
-			Sb3(this._workingKey[44] ^ X0, this._workingKey[45] ^ X1, this._workingKey[46] ^ X2, this._workingKey[47] ^ X3); LT();
-			Sb4(this._workingKey[48] ^ X0, this._workingKey[49] ^ X1, this._workingKey[50] ^ X2, this._workingKey[51] ^ X3); LT();
-			Sb5(this._workingKey[52] ^ X0, this._workingKey[53] ^ X1, this._workingKey[54] ^ X2, this._workingKey[55] ^ X3); LT();
-			Sb6(this._workingKey[56] ^ X0, this._workingKey[57] ^ X1, this._workingKey[58] ^ X2, this._workingKey[59] ^ X3); LT();
-			Sb7(this._workingKey[60] ^ X0, this._workingKey[61] ^ X1, this._workingKey[62] ^ X2, this._workingKey[63] ^ X3); LT();
-			Sb0(this._workingKey[64] ^ X0, this._workingKey[65] ^ X1, this._workingKey[66] ^ X2, this._workingKey[67] ^ X3); LT();
-			Sb1(this._workingKey[68] ^ X0, this._workingKey[69] ^ X1, this._workingKey[70] ^ X2, this._workingKey[71] ^ X3); LT();
-			Sb2(this._workingKey[72] ^ X0, this._workingKey[73] ^ X1, this._workingKey[74] ^ X2, this._workingKey[75] ^ X3); LT();
-			Sb3(this._workingKey[76] ^ X0, this._workingKey[77] ^ X1, this._workingKey[78] ^ X2, this._workingKey[79] ^ X3); LT();
-			Sb4(this._workingKey[80] ^ X0, this._workingKey[81] ^ X1, this._workingKey[82] ^ X2, this._workingKey[83] ^ X3); LT();
-			Sb5(this._workingKey[84] ^ X0, this._workingKey[85] ^ X1, this._workingKey[86] ^ X2, this._workingKey[87] ^ X3); LT();
-			Sb6(this._workingKey[88] ^ X0, this._workingKey[89] ^ X1, this._workingKey[90] ^ X2, this._workingKey[91] ^ X3); LT();
-			Sb7(this._workingKey[92] ^ X0, this._workingKey[93] ^ X1, this._workingKey[94] ^ X2, this._workingKey[95] ^ X3); LT();
-			Sb0(this._workingKey[96] ^ X0, this._workingKey[97] ^ X1, this._workingKey[98] ^ X2, this._workingKey[99] ^ X3); LT();
-			Sb1(this._workingKey[100] ^ X0, this._workingKey[101] ^ X1, this._workingKey[102] ^ X2, this._workingKey[103] ^ X3); LT();
-			Sb2(this._workingKey[104] ^ X0, this._workingKey[105] ^ X1, this._workingKey[106] ^ X2, this._workingKey[107] ^ X3); LT();
-			Sb3(this._workingKey[108] ^ X0, this._workingKey[109] ^ X1, this._workingKey[110] ^ X2, this._workingKey[111] ^ X3); LT();
-			Sb4(this._workingKey[112] ^ X0, this._workingKey[113] ^ X1, this._workingKey[114] ^ X2, this._workingKey[115] ^ X3); LT();
-			Sb5(this._workingKey[116] ^ X0, this._workingKey[117] ^ X1, this._workingKey[118] ^ X2, this._workingKey[119] ^ X3); LT();
-			Sb6(this._workingKey[120] ^ X0, this._workingKey[121] ^ X1, this._workingKey[122] ^ X2, this._workingKey[123] ^ X3); LT();
-			Sb7(this._workingKey[124] ^ X0, this._workingKey[125] ^ X1, this._workingKey[126] ^ X2, this._workingKey[127] ^ X3);
-
-			WordToBytes(this._workingKey[131] ^ X3, outputBuffer, outputOffset);
-			WordToBytes(this._workingKey[130] ^ X2, outputBuffer, outputOffset + 4);
-			WordToBytes(this._workingKey[129] ^ X1, outputBuffer, outputOffset + 8);
-			WordToBytes(this._workingKey[128] ^ X0, outputBuffer, outputOffset + 12);
+			this._x3 = BytesToWord(inputBuffer, inputOffset);
+			this._x2 = BytesToWord(inputBuffer, inputOffset + 4);
+			this._x1 = BytesToWord(inputBuffer, inputOffset + 8);
+			this._x0 = BytesToWord(inputBuffer, inputOffset + 12);
+
+			Sb0(this._workingKey[0] ^ this._x0, this._workingKey[1] ^ this._x1, this._workingKey[2] ^ this._x2, this._workingKey[3] ^ this._x3); LT();
+			Sb1(this._workingKey[4] ^ this._x0, this._workingKey[5] ^ this._x1, this._workingKey[6] ^ this._x2, this._workingKey[7] ^ this._x3); LT();
+			Sb2(this._workingKey[8] ^ this._x0, this._workingKey[9] ^ this._x1, this._workingKey[10] ^ this._x2, this._workingKey[11] ^ this._x3); LT();
+			Sb3(this._workingKey[12] ^ this._x0, this._workingKey[13] ^ this._x1, this._workingKey[14] ^ this._x2, this._workingKey[15] ^ this._x3); LT();
+			Sb4(this._workingKey[16] ^ this._x0, this._workingKey[17] ^ this._x1, this._workingKey[18] ^ this._x2, this._workingKey[19] ^ this._x3); LT();
+			Sb5(this._workingKey[20] ^ this._x0, this._workingKey[21] ^ this._x1, this._workingKey[22] ^ this._x2, this._workingKey[23] ^ this._x3); LT();
+			Sb6(this._workingKey[24] ^ this._x0, this._workingKey[25] ^ this._x1, this._workingKey[26] ^ this._x2, this._workingKey[27] ^ this._x3); LT();
+			Sb7(this._workingKey[28] ^ this._x0, this._workingKey[29] ^ this._x1, this._workingKey[30] ^ this._x2, this._workingKey[31] ^ this._x3); LT();
+			Sb0(this._workingKey[32] ^ this._x0, this._workingKey[33] ^ this._x1, this._workingKey[34] ^ this._x2, this._workingKey[35] ^ this._x3); LT();
+			Sb1(this._workingKey[36] ^ this._x0, this._workingKey[37] ^ this._x1, this._workingKey[38] ^ this._x2, this._workingKey[39] ^ this._x3); LT();
+			Sb2(this._workingKey[40] ^ this._x0, this._workingKey[41] ^ this._x1, this._workingKey[42] ^ this._x2, this._workingKey[43] ^ this._x3); LT();
+			Sb3(this._workingKey[44] ^ this._x0, this._workingKey[45] ^ this._x1, this._workingKey[46] ^ this._x2, this._workingKey[47] ^ this._x3); LT();
+			Sb4(this._workingKey[48] ^ this._x0, this._workingKey[49] ^ this._x1, this._workingKey[50] ^ this._x2, this._workingKey[51] ^ this._x3); LT();
+			Sb5(this._workingKey[52] ^ this._x0, this._workingKey[53] ^ this._x1, this._workingKey[54] ^ this._x2, this._workingKey[55] ^ this._x3); LT();
+			Sb6(this._workingKey[56] ^ this._x0, this._workingKey[57] ^ this._x1, this._workingKey[58] ^ this._x2, this._workingKey[59] ^ this._x3); LT();
+			Sb7(this._workingKey[60] ^ this._x0, this._workingKey[61] ^ this._x1, this._workingKey[62] ^ this._x2, this._workingKey[63] ^ this._x3); LT();
+			Sb0(this._workingKey[64] ^ this._x0, this._workingKey[65] ^ this._x1, this._workingKey[66] ^ this._x2, this._workingKey[67] ^ this._x3); LT();
+			Sb1(this._workingKey[68] ^ this._x0, this._workingKey[69] ^ this._x1, this._workingKey[70] ^ this._x2, this._workingKey[71] ^ this._x3); LT();
+			Sb2(this._workingKey[72] ^ this._x0, this._workingKey[73] ^ this._x1, this._workingKey[74] ^ this._x2, this._workingKey[75] ^ this._x3); LT();
+			Sb3(this._workingKey[76] ^ this._x0, this._workingKey[77] ^ this._x1, this._workingKey[78] ^ this._x2, this._workingKey[79] ^ this._x3); LT();
+			Sb4(this._workingKey[80] ^ this._x0, this._workingKey[81] ^ this._x1, this._workingKey[82] ^ this._x2, this._workingKey[83] ^ this._x3); LT();
+			Sb5(this._workingKey[84] ^ this._x0, this._workingKey[85] ^ this._x1, this._workingKey[86] ^ this._x2, this._workingKey[87] ^ this._x3); LT();
+			Sb6(this._workingKey[88] ^ this._x0, this._workingKey[89] ^ this._x1, this._workingKey[90] ^ this._x2, this._workingKey[91] ^ this._x3); LT();
+			Sb7(this._workingKey[92] ^ this._x0, this._workingKey[93] ^ this._x1, this._workingKey[94] ^ this._x2, this._workingKey[95] ^ this._x3); LT();
+			Sb0(this._workingKey[96] ^ this._x0, this._workingKey[97] ^ this._x1, this._workingKey[98] ^ this._x2, this._workingKey[99] ^ this._x3); LT();
+			Sb1(this._workingKey[100] ^ this._x0, this._workingKey[101] ^ this._x1, this._workingKey[102] ^ this._x2, this._workingKey[103] ^ this._x3); LT();
+			Sb2(this._workingKey[104] ^ this._x0, this._workingKey[105] ^ this._x1, this._workingKey[106] ^ this._x2, this._workingKey[107] ^ this._x3); LT();
+			Sb3(this._workingKey[108] ^ this._x0, this._workingKey[109] ^ this._x1, this._workingKey[110] ^ this._x2, this._workingKey[111] ^ this._x3); LT();
+			Sb4(this._workingKey[112] ^ this._x0, this._workingKey[113] ^ this._x1, this._workingKey[114] ^ this._x2, this._workingKey[115] ^ this._x3); LT();
+			Sb5(this._workingKey[116] ^ this._x0, this._workingKey[117] ^ this._x1, this._workingKey[118] ^ this._x2, this._workingKey[119] ^ this._x3); LT();
+			Sb6(this._workingKey[120] ^ this._x0, this._workingKey[121] ^ this._x1, this._workingKey[122] ^ this._x2, this._workingKey[123] ^ this._x3); LT();
+			Sb7(this._workingKey[124] ^ this._x0, this._workingKey[125] ^ this._x1, this._workingKey[126] ^ this._x2, this._workingKey[127] ^ this._x3);
+
+			WordToBytes(this._workingKey[131] ^ this._x3, outputBuffer, outputOffset);
+			WordToBytes(this._workingKey[130] ^ this._x2, outputBuffer, outputOffset + 4);
+			WordToBytes(this._workingKey[129] ^ this._x1, outputBuffer, outputOffset + 8);
+			WordToBytes(this._workingKey[128] ^ this._x0, outputBuffer, outputOffset + 12);
 
 			return this.BlockSize;
 		}
@@ -115,79 +114,79 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			if (inputCount != this.BlockSize)
 				throw new ArgumentException("inputCount");
 
-			X3 = this._workingKey[131] ^ BytesToWord(inputBuffer, inputOffset);
-			X2 = this._workingKey[130] ^ BytesToWord(inputBuffer, inputOffset + 4);
-			X1 = this._workingKey[129] ^ BytesToWord(inputBuffer, inputOffset + 8);
-			X0 = this._workingKey[128] ^ BytesToWord(inputBuffer, inputOffset + 12);
-
-			Ib7(X0, X1, X2, X3);
-			X0 ^= this._workingKey[124]; X1 ^= this._workingKey[125]; X2 ^= this._workingKey[126]; X3 ^= this._workingKey[127];
-			InverseLT(); Ib6(X0, X1, X2, X3);
-			X0 ^= this._workingKey[120]; X1 ^= this._workingKey[121]; X2 ^= this._workingKey[122]; X3 ^= this._workingKey[123];
-			InverseLT(); Ib5(X0, X1, X2, X3);
-			X0 ^= this._workingKey[116]; X1 ^= this._workingKey[117]; X2 ^= this._workingKey[118]; X3 ^= this._workingKey[119];
-			InverseLT(); Ib4(X0, X1, X2, X3);
-			X0 ^= this._workingKey[112]; X1 ^= this._workingKey[113]; X2 ^= this._workingKey[114]; X3 ^= this._workingKey[115];
-			InverseLT(); Ib3(X0, X1, X2, X3);
-			X0 ^= this._workingKey[108]; X1 ^= this._workingKey[109]; X2 ^= this._workingKey[110]; X3 ^= this._workingKey[111];
-			InverseLT(); Ib2(X0, X1, X2, X3);
-			X0 ^= this._workingKey[104]; X1 ^= this._workingKey[105]; X2 ^= this._workingKey[106]; X3 ^= this._workingKey[107];
-			InverseLT(); Ib1(X0, X1, X2, X3);
-			X0 ^= this._workingKey[100]; X1 ^= this._workingKey[101]; X2 ^= this._workingKey[102]; X3 ^= this._workingKey[103];
-			InverseLT(); Ib0(X0, X1, X2, X3);
-			X0 ^= this._workingKey[96]; X1 ^= this._workingKey[97]; X2 ^= this._workingKey[98]; X3 ^= this._workingKey[99];
-			InverseLT(); Ib7(X0, X1, X2, X3);
-			X0 ^= this._workingKey[92]; X1 ^= this._workingKey[93]; X2 ^= this._workingKey[94]; X3 ^= this._workingKey[95];
-			InverseLT(); Ib6(X0, X1, X2, X3);
-			X0 ^= this._workingKey[88]; X1 ^= this._workingKey[89]; X2 ^= this._workingKey[90]; X3 ^= this._workingKey[91];
-			InverseLT(); Ib5(X0, X1, X2, X3);
-			X0 ^= this._workingKey[84]; X1 ^= this._workingKey[85]; X2 ^= this._workingKey[86]; X3 ^= this._workingKey[87];
-			InverseLT(); Ib4(X0, X1, X2, X3);
-			X0 ^= this._workingKey[80]; X1 ^= this._workingKey[81]; X2 ^= this._workingKey[82]; X3 ^= this._workingKey[83];
-			InverseLT(); Ib3(X0, X1, X2, X3);
-			X0 ^= this._workingKey[76]; X1 ^= this._workingKey[77]; X2 ^= this._workingKey[78]; X3 ^= this._workingKey[79];
-			InverseLT(); Ib2(X0, X1, X2, X3);
-			X0 ^= this._workingKey[72]; X1 ^= this._workingKey[73]; X2 ^= this._workingKey[74]; X3 ^= this._workingKey[75];
-			InverseLT(); Ib1(X0, X1, X2, X3);
-			X0 ^= this._workingKey[68]; X1 ^= this._workingKey[69]; X2 ^= this._workingKey[70]; X3 ^= this._workingKey[71];
-			InverseLT(); Ib0(X0, X1, X2, X3);
-			X0 ^= this._workingKey[64]; X1 ^= this._workingKey[65]; X2 ^= this._workingKey[66]; X3 ^= this._workingKey[67];
-			InverseLT(); Ib7(X0, X1, X2, X3);
-			X0 ^= this._workingKey[60]; X1 ^= this._workingKey[61]; X2 ^= this._workingKey[62]; X3 ^= this._workingKey[63];
-			InverseLT(); Ib6(X0, X1, X2, X3);
-			X0 ^= this._workingKey[56]; X1 ^= this._workingKey[57]; X2 ^= this._workingKey[58]; X3 ^= this._workingKey[59];
-			InverseLT(); Ib5(X0, X1, X2, X3);
-			X0 ^= this._workingKey[52]; X1 ^= this._workingKey[53]; X2 ^= this._workingKey[54]; X3 ^= this._workingKey[55];
-			InverseLT(); Ib4(X0, X1, X2, X3);
-			X0 ^= this._workingKey[48]; X1 ^= this._workingKey[49]; X2 ^= this._workingKey[50]; X3 ^= this._workingKey[51];
-			InverseLT(); Ib3(X0, X1, X2, X3);
-			X0 ^= this._workingKey[44]; X1 ^= this._workingKey[45]; X2 ^= this._workingKey[46]; X3 ^= this._workingKey[47];
-			InverseLT(); Ib2(X0, X1, X2, X3);
-			X0 ^= this._workingKey[40]; X1 ^= this._workingKey[41]; X2 ^= this._workingKey[42]; X3 ^= this._workingKey[43];
-			InverseLT(); Ib1(X0, X1, X2, X3);
-			X0 ^= this._workingKey[36]; X1 ^= this._workingKey[37]; X2 ^= this._workingKey[38]; X3 ^= this._workingKey[39];
-			InverseLT(); Ib0(X0, X1, X2, X3);
-			X0 ^= this._workingKey[32]; X1 ^= this._workingKey[33]; X2 ^= this._workingKey[34]; X3 ^= this._workingKey[35];
-			InverseLT(); Ib7(X0, X1, X2, X3);
-			X0 ^= this._workingKey[28]; X1 ^= this._workingKey[29]; X2 ^= this._workingKey[30]; X3 ^= this._workingKey[31];
-			InverseLT(); Ib6(X0, X1, X2, X3);
-			X0 ^= this._workingKey[24]; X1 ^= this._workingKey[25]; X2 ^= this._workingKey[26]; X3 ^= this._workingKey[27];
-			InverseLT(); Ib5(X0, X1, X2, X3);
-			X0 ^= this._workingKey[20]; X1 ^= this._workingKey[21]; X2 ^= this._workingKey[22]; X3 ^= this._workingKey[23];
-			InverseLT(); Ib4(X0, X1, X2, X3);
-			X0 ^= this._workingKey[16]; X1 ^= this._workingKey[17]; X2 ^= this._workingKey[18]; X3 ^= this._workingKey[19];
-			InverseLT(); Ib3(X0, X1, X2, X3);
-			X0 ^= this._workingKey[12]; X1 ^= this._workingKey[13]; X2 ^= this._workingKey[14]; X3 ^= this._workingKey[15];
-			InverseLT(); Ib2(X0, X1, X2, X3);
-			X0 ^= this._workingKey[8]; X1 ^= this._workingKey[9]; X2 ^= this._workingKey[10]; X3 ^= this._workingKey[11];
-			InverseLT(); Ib1(X0, X1, X2, X3);
-			X0 ^= this._workingKey[4]; X1 ^= this._workingKey[5]; X2 ^= this._workingKey[6]; X3 ^= this._workingKey[7];
-			InverseLT(); Ib0(X0, X1, X2, X3);
-
-			WordToBytes(X3 ^ this._workingKey[3], outputBuffer, outputOffset);
-			WordToBytes(X2 ^ this._workingKey[2], outputBuffer, outputOffset + 4);
-			WordToBytes(X1 ^ this._workingKey[1], outputBuffer, outputOffset + 8);
-			WordToBytes(X0 ^ this._workingKey[0], outputBuffer, outputOffset + 12);
+			this._x3 = this._workingKey[131] ^ BytesToWord(inputBuffer, inputOffset);
+			this._x2 = this._workingKey[130] ^ BytesToWord(inputBuffer, inputOffset + 4);
+			this._x1 = this._workingKey[129] ^ BytesToWord(inputBuffer, inputOffset + 8);
+			this._x0 = this._workingKey[128] ^ BytesToWord(inputBuffer, inputOffset + 12);
+
+			Ib7(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[124]; this._x1 ^= this._workingKey[125]; this._x2 ^= this._workingKey[126]; this._x3 ^= this._workingKey[127];
+			InverseLT(); Ib6(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[120]; this._x1 ^= this._workingKey[121]; this._x2 ^= this._workingKey[122]; this._x3 ^= this._workingKey[123];
+			InverseLT(); Ib5(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[116]; this._x1 ^= this._workingKey[117]; this._x2 ^= this._workingKey[118]; this._x3 ^= this._workingKey[119];
+			InverseLT(); Ib4(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[112]; this._x1 ^= this._workingKey[113]; this._x2 ^= this._workingKey[114]; this._x3 ^= this._workingKey[115];
+			InverseLT(); Ib3(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[108]; this._x1 ^= this._workingKey[109]; this._x2 ^= this._workingKey[110]; this._x3 ^= this._workingKey[111];
+			InverseLT(); Ib2(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[104]; this._x1 ^= this._workingKey[105]; this._x2 ^= this._workingKey[106]; this._x3 ^= this._workingKey[107];
+			InverseLT(); Ib1(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[100]; this._x1 ^= this._workingKey[101]; this._x2 ^= this._workingKey[102]; this._x3 ^= this._workingKey[103];
+			InverseLT(); Ib0(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[96]; this._x1 ^= this._workingKey[97]; this._x2 ^= this._workingKey[98]; this._x3 ^= this._workingKey[99];
+			InverseLT(); Ib7(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[92]; this._x1 ^= this._workingKey[93]; this._x2 ^= this._workingKey[94]; this._x3 ^= this._workingKey[95];
+			InverseLT(); Ib6(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[88]; this._x1 ^= this._workingKey[89]; this._x2 ^= this._workingKey[90]; this._x3 ^= this._workingKey[91];
+			InverseLT(); Ib5(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[84]; this._x1 ^= this._workingKey[85]; this._x2 ^= this._workingKey[86]; this._x3 ^= this._workingKey[87];
+			InverseLT(); Ib4(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[80]; this._x1 ^= this._workingKey[81]; this._x2 ^= this._workingKey[82]; this._x3 ^= this._workingKey[83];
+			InverseLT(); Ib3(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[76]; this._x1 ^= this._workingKey[77]; this._x2 ^= this._workingKey[78]; this._x3 ^= this._workingKey[79];
+			InverseLT(); Ib2(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[72]; this._x1 ^= this._workingKey[73]; this._x2 ^= this._workingKey[74]; this._x3 ^= this._workingKey[75];
+			InverseLT(); Ib1(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[68]; this._x1 ^= this._workingKey[69]; this._x2 ^= this._workingKey[70]; this._x3 ^= this._workingKey[71];
+			InverseLT(); Ib0(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[64]; this._x1 ^= this._workingKey[65]; this._x2 ^= this._workingKey[66]; this._x3 ^= this._workingKey[67];
+			InverseLT(); Ib7(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[60]; this._x1 ^= this._workingKey[61]; this._x2 ^= this._workingKey[62]; this._x3 ^= this._workingKey[63];
+			InverseLT(); Ib6(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[56]; this._x1 ^= this._workingKey[57]; this._x2 ^= this._workingKey[58]; this._x3 ^= this._workingKey[59];
+			InverseLT(); Ib5(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[52]; this._x1 ^= this._workingKey[53]; this._x2 ^= this._workingKey[54]; this._x3 ^= this._workingKey[55];
+			InverseLT(); Ib4(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[48]; this._x1 ^= this._workingKey[49]; this._x2 ^= this._workingKey[50]; this._x3 ^= this._workingKey[51];
+			InverseLT(); Ib3(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[44]; this._x1 ^= this._workingKey[45]; this._x2 ^= this._workingKey[46]; this._x3 ^= this._workingKey[47];
+			InverseLT(); Ib2(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[40]; this._x1 ^= this._workingKey[41]; this._x2 ^= this._workingKey[42]; this._x3 ^= this._workingKey[43];
+			InverseLT(); Ib1(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[36]; this._x1 ^= this._workingKey[37]; this._x2 ^= this._workingKey[38]; this._x3 ^= this._workingKey[39];
+			InverseLT(); Ib0(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[32]; this._x1 ^= this._workingKey[33]; this._x2 ^= this._workingKey[34]; this._x3 ^= this._workingKey[35];
+			InverseLT(); Ib7(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[28]; this._x1 ^= this._workingKey[29]; this._x2 ^= this._workingKey[30]; this._x3 ^= this._workingKey[31];
+			InverseLT(); Ib6(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[24]; this._x1 ^= this._workingKey[25]; this._x2 ^= this._workingKey[26]; this._x3 ^= this._workingKey[27];
+			InverseLT(); Ib5(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[20]; this._x1 ^= this._workingKey[21]; this._x2 ^= this._workingKey[22]; this._x3 ^= this._workingKey[23];
+			InverseLT(); Ib4(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[16]; this._x1 ^= this._workingKey[17]; this._x2 ^= this._workingKey[18]; this._x3 ^= this._workingKey[19];
+			InverseLT(); Ib3(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[12]; this._x1 ^= this._workingKey[13]; this._x2 ^= this._workingKey[14]; this._x3 ^= this._workingKey[15];
+			InverseLT(); Ib2(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[8]; this._x1 ^= this._workingKey[9]; this._x2 ^= this._workingKey[10]; this._x3 ^= this._workingKey[11];
+			InverseLT(); Ib1(this._x0, this._x1, this._x2, this._x3);
+			this._x0 ^= this._workingKey[4]; this._x1 ^= this._workingKey[5]; this._x2 ^= this._workingKey[6]; this._x3 ^= this._workingKey[7];
+			InverseLT(); Ib0(this._x0, this._x1, this._x2, this._x3);
+
+			WordToBytes(this._x3 ^ this._workingKey[3], outputBuffer, outputOffset);
+			WordToBytes(this._x2 ^ this._workingKey[2], outputBuffer, outputOffset + 4);
+			WordToBytes(this._x1 ^ this._workingKey[1], outputBuffer, outputOffset + 8);
+			WordToBytes(this._x0 ^ this._workingKey[0], outputBuffer, outputOffset + 12);
 
 			return this.BlockSize;
 		}
@@ -253,71 +252,71 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			// create the working keys by processing w with the Sbox and IP
 			//
 			Sb3(w[0], w[1], w[2], w[3]);
-			w[0] = X0; w[1] = X1; w[2] = X2; w[3] = X3;
+			w[0] = this._x0; w[1] = this._x1; w[2] = this._x2; w[3] = this._x3;
 			Sb2(w[4], w[5], w[6], w[7]);
-			w[4] = X0; w[5] = X1; w[6] = X2; w[7] = X3;
+			w[4] = this._x0; w[5] = this._x1; w[6] = this._x2; w[7] = this._x3;
 			Sb1(w[8], w[9], w[10], w[11]);
-			w[8] = X0; w[9] = X1; w[10] = X2; w[11] = X3;
+			w[8] = this._x0; w[9] = this._x1; w[10] = this._x2; w[11] = this._x3;
 			Sb0(w[12], w[13], w[14], w[15]);
-			w[12] = X0; w[13] = X1; w[14] = X2; w[15] = X3;
+			w[12] = this._x0; w[13] = this._x1; w[14] = this._x2; w[15] = this._x3;
 			Sb7(w[16], w[17], w[18], w[19]);
-			w[16] = X0; w[17] = X1; w[18] = X2; w[19] = X3;
+			w[16] = this._x0; w[17] = this._x1; w[18] = this._x2; w[19] = this._x3;
 			Sb6(w[20], w[21], w[22], w[23]);
-			w[20] = X0; w[21] = X1; w[22] = X2; w[23] = X3;
+			w[20] = this._x0; w[21] = this._x1; w[22] = this._x2; w[23] = this._x3;
 			Sb5(w[24], w[25], w[26], w[27]);
-			w[24] = X0; w[25] = X1; w[26] = X2; w[27] = X3;
+			w[24] = this._x0; w[25] = this._x1; w[26] = this._x2; w[27] = this._x3;
 			Sb4(w[28], w[29], w[30], w[31]);
-			w[28] = X0; w[29] = X1; w[30] = X2; w[31] = X3;
+			w[28] = this._x0; w[29] = this._x1; w[30] = this._x2; w[31] = this._x3;
 			Sb3(w[32], w[33], w[34], w[35]);
-			w[32] = X0; w[33] = X1; w[34] = X2; w[35] = X3;
+			w[32] = this._x0; w[33] = this._x1; w[34] = this._x2; w[35] = this._x3;
 			Sb2(w[36], w[37], w[38], w[39]);
-			w[36] = X0; w[37] = X1; w[38] = X2; w[39] = X3;
+			w[36] = this._x0; w[37] = this._x1; w[38] = this._x2; w[39] = this._x3;
 			Sb1(w[40], w[41], w[42], w[43]);
-			w[40] = X0; w[41] = X1; w[42] = X2; w[43] = X3;
+			w[40] = this._x0; w[41] = this._x1; w[42] = this._x2; w[43] = this._x3;
 			Sb0(w[44], w[45], w[46], w[47]);
-			w[44] = X0; w[45] = X1; w[46] = X2; w[47] = X3;
+			w[44] = this._x0; w[45] = this._x1; w[46] = this._x2; w[47] = this._x3;
 			Sb7(w[48], w[49], w[50], w[51]);
-			w[48] = X0; w[49] = X1; w[50] = X2; w[51] = X3;
+			w[48] = this._x0; w[49] = this._x1; w[50] = this._x2; w[51] = this._x3;
 			Sb6(w[52], w[53], w[54], w[55]);
-			w[52] = X0; w[53] = X1; w[54] = X2; w[55] = X3;
+			w[52] = this._x0; w[53] = this._x1; w[54] = this._x2; w[55] = this._x3;
 			Sb5(w[56], w[57], w[58], w[59]);
-			w[56] = X0; w[57] = X1; w[58] = X2; w[59] = X3;
+			w[56] = this._x0; w[57] = this._x1; w[58] = this._x2; w[59] = this._x3;
 			Sb4(w[60], w[61], w[62], w[63]);
-			w[60] = X0; w[61] = X1; w[62] = X2; w[63] = X3;
+			w[60] = this._x0; w[61] = this._x1; w[62] = this._x2; w[63] = this._x3;
 			Sb3(w[64], w[65], w[66], w[67]);
-			w[64] = X0; w[65] = X1; w[66] = X2; w[67] = X3;
+			w[64] = this._x0; w[65] = this._x1; w[66] = this._x2; w[67] = this._x3;
 			Sb2(w[68], w[69], w[70], w[71]);
-			w[68] = X0; w[69] = X1; w[70] = X2; w[71] = X3;
+			w[68] = this._x0; w[69] = this._x1; w[70] = this._x2; w[71] = this._x3;
 			Sb1(w[72], w[73], w[74], w[75]);
-			w[72] = X0; w[73] = X1; w[74] = X2; w[75] = X3;
+			w[72] = this._x0; w[73] = this._x1; w[74] = this._x2; w[75] = this._x3;
 			Sb0(w[76], w[77], w[78], w[79]);
-			w[76] = X0; w[77] = X1; w[78] = X2; w[79] = X3;
+			w[76] = this._x0; w[77] = this._x1; w[78] = this._x2; w[79] = this._x3;
 			Sb7(w[80], w[81], w[82], w[83]);
-			w[80] = X0; w[81] = X1; w[82] = X2; w[83] = X3;
+			w[80] = this._x0; w[81] = this._x1; w[82] = this._x2; w[83] = this._x3;
 			Sb6(w[84], w[85], w[86], w[87]);
-			w[84] = X0; w[85] = X1; w[86] = X2; w[87] = X3;
+			w[84] = this._x0; w[85] = this._x1; w[86] = this._x2; w[87] = this._x3;
 			Sb5(w[88], w[89], w[90], w[91]);
-			w[88] = X0; w[89] = X1; w[90] = X2; w[91] = X3;
+			w[88] = this._x0; w[89] = this._x1; w[90] = this._x2; w[91] = this._x3;
 			Sb4(w[92], w[93], w[94], w[95]);
-			w[92] = X0; w[93] = X1; w[94] = X2; w[95] = X3;
+			w[92] = this._x0; w[93] = this._x1; w[94] = this._x2; w[95] = this._x3;
 			Sb3(w[96], w[97], w[98], w[99]);
-			w[96] = X0; w[97] = X1; w[98] = X2; w[99] = X3;
+			w[96] = this._x0; w[97] = this._x1; w[98] = this._x2; w[99] = this._x3;
 			Sb2(w[100], w[101], w[102], w[103]);
-			w[100] = X0; w[101] = X1; w[102] = X2; w[103] = X3;
+			w[100] = this._x0; w[101] = this._x1; w[102] = this._x2; w[103] = this._x3;
 			Sb1(w[104], w[105], w[106], w[107]);
-			w[104] = X0; w[105] = X1; w[106] = X2; w[107] = X3;
+			w[104] = this._x0; w[105] = this._x1; w[106] = this._x2; w[107] = this._x3;
 			Sb0(w[108], w[109], w[110], w[111]);
-			w[108] = X0; w[109] = X1; w[110] = X2; w[111] = X3;
+			w[108] = this._x0; w[109] = this._x1; w[110] = this._x2; w[111] = this._x3;
 			Sb7(w[112], w[113], w[114], w[115]);
-			w[112] = X0; w[113] = X1; w[114] = X2; w[115] = X3;
+			w[112] = this._x0; w[113] = this._x1; w[114] = this._x2; w[115] = this._x3;
 			Sb6(w[116], w[117], w[118], w[119]);
-			w[116] = X0; w[117] = X1; w[118] = X2; w[119] = X3;
+			w[116] = this._x0; w[117] = this._x1; w[118] = this._x2; w[119] = this._x3;
 			Sb5(w[120], w[121], w[122], w[123]);
-			w[120] = X0; w[121] = X1; w[122] = X2; w[123] = X3;
+			w[120] = this._x0; w[121] = this._x1; w[122] = this._x2; w[123] = this._x3;
 			Sb4(w[124], w[125], w[126], w[127]);
-			w[124] = X0; w[125] = X1; w[126] = X2; w[127] = X3;
+			w[124] = this._x0; w[125] = this._x1; w[126] = this._x2; w[127] = this._x3;
 			Sb3(w[128], w[129], w[130], w[131]);
-			w[128] = X0; w[129] = X1; w[130] = X2; w[131] = X3;
+			w[128] = this._x0; w[129] = this._x1; w[130] = this._x2; w[131] = this._x3;
 
 			return w;
 		}
@@ -378,12 +377,12 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t1 = a ^ d;
 			int t3 = c ^ t1;
 			int t4 = b ^ t3;
-			X3 = (a & d) ^ t4;
+			this._x3 = (a & d) ^ t4;
 			int t7 = a ^ (b & t1);
-			X2 = t4 ^ (c | t7);
-			int t12 = X3 & (t3 ^ t7);
-			X1 = (~t3) ^ t12;
-			X0 = t12 ^ (~t7);
+			this._x2 = t4 ^ (c | t7);
+			int t12 = this._x3 & (t3 ^ t7);
+			this._x1 = (~t3) ^ t12;
+			this._x0 = t12 ^ (~t7);
 		}
 
 		/**
@@ -395,11 +394,11 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t2 = a ^ b;
 			int t4 = d ^ (t1 | t2);
 			int t5 = c ^ t4;
-			X2 = t2 ^ t5;
+			this._x2 = t2 ^ t5;
 			int t8 = t1 ^ (d & t2);
-			X1 = t4 ^ (X2 & t8);
-			X3 = (a & t4) ^ (t5 | X1);
-			X0 = X3 ^ (t5 ^ t8);
+			this._x1 = t4 ^ (this._x2 & t8);
+			this._x3 = (a & t4) ^ (t5 | this._x1);
+			this._x0 = this._x3 ^ (t5 ^ t8);
 		}
 
 		/**
@@ -409,13 +408,13 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 		{
 			int t2 = b ^ (~a);
 			int t5 = c ^ (a | t2);
-			X2 = d ^ t5;
+			this._x2 = d ^ t5;
 			int t7 = b ^ (d | t2);
-			int t8 = t2 ^ X2;
-			X3 = t8 ^ (t5 & t7);
+			int t8 = t2 ^ this._x2;
+			this._x3 = t8 ^ (t5 & t7);
 			int t11 = t5 ^ t7;
-			X1 = X3 ^ t11;
-			X0 = t5 ^ (t8 & t11);
+			this._x1 = this._x3 ^ t11;
+			this._x0 = t5 ^ (t8 & t11);
 		}
 
 		/**
@@ -426,14 +425,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t1 = b ^ d;
 			int t3 = a ^ (b & t1);
 			int t4 = t1 ^ t3;
-			X3 = c ^ t4;
+			this._x3 = c ^ t4;
 			int t7 = b ^ (t1 & t3);
-			int t8 = X3 | t7;
-			X1 = t3 ^ t8;
-			int t10 = ~X1;
-			int t11 = X3 ^ t7;
-			X0 = t10 ^ t11;
-			X2 = t4 ^ (t10 | t11);
+			int t8 = this._x3 | t7;
+			this._x1 = t3 ^ t8;
+			int t10 = ~this._x1;
+			int t11 = this._x3 ^ t7;
+			this._x0 = t10 ^ t11;
+			this._x2 = t4 ^ (t10 | t11);
 		}
 
 		/**
@@ -444,13 +443,13 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t1 = ~a;
 			int t2 = b ^ d;
 			int t3 = c & t1;
-			X0 = t2 ^ t3;
+			this._x0 = t2 ^ t3;
 			int t5 = c ^ t1;
-			int t6 = c ^ X0;
+			int t6 = c ^ this._x0;
 			int t7 = b & t6;
-			X3 = t5 ^ t7;
-			X2 = a ^ ((d | t7) & (X0 | t5));
-			X1 = (t2 ^ X3) ^ (X2 ^ (d | t1));
+			this._x3 = t5 ^ t7;
+			this._x2 = a ^ ((d | t7) & (this._x0 | t5));
+			this._x1 = (t2 ^ this._x3) ^ (this._x2 ^ (d | t1));
 		}
 
 		/**
@@ -463,15 +462,15 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t3 = a ^ c;
 			int t4 = c ^ t1;
 			int t5 = b & t4;
-			X0 = t3 ^ t5;
+			this._x0 = t3 ^ t5;
 			int t7 = a | t2;
 			int t8 = d ^ t7;
 			int t9 = t3 | t8;
-			X3 = t1 ^ t9;
+			this._x3 = t1 ^ t9;
 			int t11 = ~t4;
-			int t12 = X0 | X3;
-			X1 = t11 ^ t12;
-			X2 = (d & t11) ^ (t3 ^ t12);
+			int t12 = this._x0 | this._x3;
+			this._x1 = t11 ^ t12;
+			this._x2 = (d & t11) ^ (t3 ^ t12);
 		}
 
 		/**
@@ -485,14 +484,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t4 = c ^ d;
 			int t5 = t1 & t3;
 			int t6 = t2 | t5;
-			X2 = t4 ^ t6;
+			this._x2 = t4 ^ t6;
 			int t8 = b ^ t3;
 			int t9 = t6 ^ t8;
 			int t10 = t4 & t9;
-			X0 = t1 ^ t10;
-			int t12 = X2 & X0;
-			X1 = t9 ^ t12;
-			X3 = (b | d) ^ (t4 ^ t12);
+			this._x0 = t1 ^ t10;
+			int t12 = this._x2 & this._x0;
+			this._x1 = t9 ^ t12;
+			this._x3 = (b | d) ^ (t4 ^ t12);
 		}
 
 		/**
@@ -506,14 +505,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t4 = a ^ t3;
 			int t5 = c ^ t4;
 			int t6 = d | t4;
-			X0 = t2 ^ t6;
+			this._x0 = t2 ^ t6;
 			int t8 = t2 | t6;
 			int t9 = d ^ t8;
-			X2 = t5 ^ t9;
+			this._x2 = t5 ^ t9;
 			int t11 = t1 ^ t9;
-			int t12 = X0 & t11;
-			X3 = t4 ^ t12;
-			X1 = X3 ^ (X0 ^ t11);
+			int t12 = this._x0 & t11;
+			this._x3 = t4 ^ t12;
+			this._x1 = this._x3 ^ (this._x0 ^ t11);
 		}
 
 		/**
@@ -525,15 +524,15 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t2 = d & t1;
 			int t3 = c ^ t2;
 			int t4 = b | t3;
-			X3 = t1 ^ t4;
+			this._x3 = t1 ^ t4;
 			int t6 = ~b;
 			int t7 = t1 | t6;
-			X0 = t3 ^ t7;
-			int t9 = a & X0;
+			this._x0 = t3 ^ t7;
+			int t9 = a & this._x0;
 			int t10 = t1 ^ t6;
 			int t11 = t4 & t10;
-			X2 = t9 ^ t11;
-			X1 = (a ^ t3) ^ (t10 & X2);
+			this._x2 = t9 ^ t11;
+			this._x1 = (a ^ t3) ^ (t10 & this._x2);
 		}
 
 		/**
@@ -546,14 +545,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t3 = b ^ t2;
 			int t4 = a & t3;
 			int t5 = c ^ t4;
-			X1 = d ^ t5;
+			this._x1 = d ^ t5;
 			int t7 = ~a;
-			int t8 = t5 & X1;
-			X3 = t3 ^ t8;
-			int t10 = X1 | t7;
+			int t8 = t5 & this._x1;
+			this._x3 = t3 ^ t8;
+			int t10 = this._x1 | t7;
 			int t11 = d ^ t10;
-			X0 = X3 ^ t11;
-			X2 = (t3 & t11) ^ (X1 ^ t7);
+			this._x0 = this._x3 ^ t11;
+			this._x2 = (t3 & t11) ^ (this._x1 ^ t7);
 		}
 
 		/**
@@ -566,15 +565,15 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t3 = a ^ d;
 			int t4 = c ^ t1;
 			int t5 = t2 | t3;
-			X0 = t4 ^ t5;
-			int t7 = d & X0;
-			int t8 = t2 ^ X0;
-			X1 = t7 ^ t8;
-			int t10 = t1 | X0;
+			this._x0 = t4 ^ t5;
+			int t7 = d & this._x0;
+			int t8 = t2 ^ this._x0;
+			this._x1 = t7 ^ t8;
+			int t10 = t1 | this._x0;
 			int t11 = t2 | t7;
 			int t12 = t3 ^ t10;
-			X2 = t11 ^ t12;
-			X3 = (b ^ t7) ^ (X1 & t12);
+			this._x2 = t11 ^ t12;
+			this._x3 = (b ^ t7) ^ (this._x1 & t12);
 		}
 
 		/**
@@ -587,14 +586,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t3 = d ^ t2;
 			int t4 = a & t3;
 			int t5 = b ^ t1;
-			X3 = t4 ^ t5;
-			int t7 = b | X3;
+			this._x3 = t4 ^ t5;
+			int t7 = b | this._x3;
 			int t8 = a & t7;
-			X1 = t3 ^ t8;
+			this._x1 = t3 ^ t8;
 			int t10 = a | d;
 			int t11 = t1 ^ t7;
-			X0 = t10 ^ t11;
-			X2 = (b & t10) ^ (t4 | (a ^ c));
+			this._x0 = t10 ^ t11;
+			this._x2 = (b & t10) ^ (t4 | (a ^ c));
 		}
 
 		/**
@@ -607,14 +606,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t3 = b ^ t2;
 			int t4 = t1 | t2;
 			int t5 = c ^ t4;
-			X1 = b ^ t5;
-			int t7 = t2 | X1;
+			this._x1 = b ^ t5;
+			int t7 = t2 | this._x1;
 			int t8 = d ^ t7;
 			int t9 = t5 & t8;
-			X2 = t3 ^ t9;
+			this._x2 = t3 ^ t9;
 			int t11 = t5 ^ t8;
-			X0 = X2 ^ t11;
-			X3 = (~t5) ^ (t3 & t11);
+			this._x0 = this._x2 ^ t11;
+			this._x3 = (~t5) ^ (t3 & t11);
 		}
 
 		/**
@@ -627,14 +626,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t3 = c ^ t2;
 			int t4 = c | t1;
 			int t5 = d ^ t4;
-			X1 = t3 ^ t5;
+			this._x1 = t3 ^ t5;
 			int t7 = t3 & t5;
 			int t8 = t2 ^ t7;
 			int t9 = b | t8;
-			X3 = t5 ^ t9;
-			int t11 = b | X3;
-			X0 = t8 ^ t11;
-			X2 = (d & t1) ^ (t3 ^ t11);
+			this._x3 = t5 ^ t9;
+			int t11 = b | this._x3;
+			this._x0 = t8 ^ t11;
+			this._x2 = (d & t1) ^ (t3 ^ t11);
 		}
 
 		/**
@@ -648,14 +647,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 			int t4 = a ^ t3;
 			int t5 = d | t1;
 			int t6 = t4 & t5;
-			X1 = b ^ t6;
-			int t8 = t3 | X1;
+			this._x1 = b ^ t6;
+			int t8 = t3 | this._x1;
 			int t9 = a & t4;
-			X3 = t1 ^ t9;
+			this._x3 = t1 ^ t9;
 			int t11 = t4 ^ t8;
-			int t12 = X3 & t11;
-			X2 = t3 ^ t12;
-			X0 = (~t11) ^ (X3 & X2);
+			int t12 = this._x3 & t11;
+			this._x2 = t3 ^ t12;
+			this._x0 = (~t11) ^ (this._x3 & this._x2);
 		}
 
 		/**
@@ -665,13 +664,13 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 		{
 			int t3 = c | (a & b);
 			int t4 = d & (a | b);
-			X3 = t3 ^ t4;
+			this._x3 = t3 ^ t4;
 			int t6 = ~d;
 			int t7 = b ^ t4;
-			int t9 = t7 | (X3 ^ t6);
-			X1 = a ^ t9;
-			X0 = (c ^ t7) ^ (d | X1);
-			X2 = (t3 ^ X1) ^ (X0 ^ (a & X3));
+			int t9 = t7 | (this._x3 ^ t6);
+			this._x1 = a ^ t9;
+			this._x0 = (c ^ t7) ^ (d | this._x1);
+			this._x2 = (t3 ^ this._x1) ^ (this._x0 ^ (a & this._x3));
 		}
 
 		/**
@@ -679,15 +678,15 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 		*/
 		private void LT()
 		{
-			int x0 = RotateLeft(X0, 13);
-			int x2 = RotateLeft(X2, 3);
-			int x1 = X1 ^ x0 ^ x2;
-			int x3 = X3 ^ x2 ^ x0 << 3;
-
-			X1 = RotateLeft(x1, 1);
-			X3 = RotateLeft(x3, 7);
-			X0 = RotateLeft(x0 ^ X1 ^ X3, 5);
-			X2 = RotateLeft(x2 ^ X3 ^ (X1 << 7), 22);
+			int x0 = RotateLeft(this._x0, 13);
+			int x2 = RotateLeft(this._x2, 3);
+			int x1 = this._x1 ^ x0 ^ x2;
+			int x3 = this._x3 ^ x2 ^ x0 << 3;
+
+			this._x1 = RotateLeft(x1, 1);
+			this._x3 = RotateLeft(x3, 7);
+			this._x0 = RotateLeft(x0 ^ this._x1 ^ this._x3, 5);
+			this._x2 = RotateLeft(x2 ^ this._x3 ^ (this._x1 << 7), 22);
 		}
 
 		/**
@@ -695,14 +694,14 @@ namespace Renci.SshNet.Security.Cryptography.Ciphers
 		*/
 		private void InverseLT()
 		{
-			int x2 = RotateRight(X2, 22) ^ X3 ^ (X1 << 7);
-			int x0 = RotateRight(X0, 5) ^ X1 ^ X3;
-			int x3 = RotateRight(X3, 7);
-			int x1 = RotateRight(X1, 1);
-			X3 = x3 ^ x2 ^ x0 << 3;
-			X1 = x1 ^ x0 ^ x2;
-			X2 = RotateRight(x2, 3);
-			X0 = RotateRight(x0, 13);
+			int x2 = RotateRight(this._x2, 22) ^ this._x3 ^ (this._x1 << 7);
+			int x0 = RotateRight(this._x0, 5) ^ this._x1 ^ this._x3;
+			int x3 = RotateRight(this._x3, 7);
+			int x1 = RotateRight(this._x1, 1);
+			this._x3 = x3 ^ x2 ^ x0 << 3;
+			this._x1 = x1 ^ x0 ^ x2;
+			this._x2 = RotateRight(x2, 3);
+			this._x0 = RotateRight(x0, 13);
 		}
 	}
 }

+ 3 - 11
Renci.SshClient/Renci.SshNet/Security/Cryptography/DsaDigitalSignature.cs

@@ -103,25 +103,17 @@ namespace Renci.SshNet.Security.Cryptography
 
             do
             {
-                BigInteger k;
+                BigInteger k = BigInteger.Zero;
 
                 do
                 {
-                    //  TODO:   Take random function to BigInteger
-
                     //  Generate a random per-message value k where 0 < k < q
                     var bitLength = this._key.Q.BitLength;
 
-                    var bytesArray = new byte[bitLength / 8 + (((bitLength % 8) > 0) ? 1 : 0)];
-                    
-                    do
+                    while (k <= 0 || k >= this._key.Q)
                     {
-                        _randomizer.GetBytes(bytesArray);
-
-                        bytesArray[bytesArray.Length - 1] = (byte)(bytesArray[bytesArray.Length - 1] & 0x7F);   //  Ensure not a negative value
-                        k = new BigInteger(bytesArray.Reverse().ToArray());
+                        k = BigInteger.Random(bitLength);
                     }
-                    while (k <= 0 || k >= this._key.Q);
 
                     //  Calculate r = ((g pow k) mod p) mod q
                     r = BigInteger.ModPow(this._key.G, k, this._key.P) % this._key.Q;

+ 2 - 5
Renci.SshClient/Renci.SshNet/Security/KeyExchangeDiffieHellman.cs

@@ -108,13 +108,10 @@ namespace Renci.SshNet.Security
 
             var bitLength = this._prime.BitLength;
 
-            var bytesArray = new byte[bitLength / 8 + (((bitLength % 8) > 0) ? 1 : 0)];
-
             do
             {
-                _randomizer.GetBytes(bytesArray);
-                bytesArray[bytesArray.Length - 1] = (byte)(bytesArray[bytesArray.Length - 1] & 0x7F);   //  Ensure not a negative value
-                this._randomValue = new BigInteger(bytesArray);
+                this._randomValue = BigInteger.Random(bitLength);
+
                 this._clientExchangeValue = BigInteger.ModPow(this._group, this._randomValue, this._prime);
 
             } while (this._clientExchangeValue < 1 || this._clientExchangeValue > ((this._prime - 1)));