< Summary

Information
Class: Renci.SshNet.Security.Cryptography.Ciphers.SerpentCipher
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\Security\Cryptography\Ciphers\SerpentCipher.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 740
Coverable lines: 740
Total lines: 1119
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 22
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)0%80%
EncryptBlock(...)0%20%
DecryptBlock(...)0%20%
MakeWorkingKey(...)0%100%
RotateLeft(...)100%10%
RotateRight(...)100%10%
BytesToWord(...)100%10%
WordToBytes(...)100%10%
Sb0(...)100%10%
Ib0(...)100%10%
Sb1(...)100%10%
Ib1(...)100%10%
Sb2(...)100%10%
Ib2(...)100%10%
Sb3(...)100%10%
Ib3(...)100%10%
Sb4(...)100%10%
Ib4(...)100%10%
Sb5(...)100%10%
Ib5(...)100%10%
Sb6(...)100%10%
Ib6(...)100%10%
Sb7(...)100%10%
Ib7(...)100%10%
LT()100%10%
InverseLT()100%10%

File(s)

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

#LineLine coverage
 1using System;
 2
 3namespace Renci.SshNet.Security.Cryptography.Ciphers
 4{
 5    /// <summary>
 6    /// Implements Serpent cipher algorithm.
 7    /// </summary>
 8    public sealed class SerpentCipher : BlockCipher
 9    {
 10        private const int Rounds = 32;
 11        private const int Phi = unchecked((int)0x9E3779B9); // (Sqrt(5) - 1) * 2**31
 12
 13        private readonly int[] _workingKey;
 14
 15        // registers
 16        private int _x0;
 17        private int _x1;
 18        private int _x2;
 19        private int _x3;
 20
 21        /// <summary>
 22        /// Initializes a new instance of the <see cref="SerpentCipher"/> class.
 23        /// </summary>
 24        /// <param name="key">The key.</param>
 25        /// <param name="mode">The mode.</param>
 26        /// <param name="padding">The padding.</param>
 27        /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception>
 28        /// <exception cref="ArgumentException">Keysize is not valid for this algorithm.</exception>
 29        public SerpentCipher(byte[] key, CipherMode mode, CipherPadding padding)
 030            : base(key, 16, mode, padding)
 031        {
 032            var keySize = key.Length * 8;
 33
 034            if (keySize is not (128 or 192 or 256))
 035            {
 036                throw new ArgumentException(string.Format("KeySize '{0}' is not valid for this algorithm.", keySize));
 37            }
 38
 039            _workingKey = MakeWorkingKey(key);
 040        }
 41
 42        /// <summary>
 43        /// Encrypts the specified region of the input byte array and copies the encrypted data to the specified region 
 44        /// </summary>
 45        /// <param name="inputBuffer">The input data to encrypt.</param>
 46        /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>
 47        /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>
 48        /// <param name="outputBuffer">The output to which to write encrypted data.</param>
 49        /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>
 50        /// <returns>
 51        /// The number of bytes encrypted.
 52        /// </returns>
 53        public override int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o
 054        {
 055            if (inputCount != BlockSize)
 056            {
 057                throw new ArgumentException("inputCount");
 58            }
 59
 060            _x3 = BytesToWord(inputBuffer, inputOffset);
 061            _x2 = BytesToWord(inputBuffer, inputOffset + 4);
 062            _x1 = BytesToWord(inputBuffer, inputOffset + 8);
 063            _x0 = BytesToWord(inputBuffer, inputOffset + 12);
 64
 065            Sb0(_workingKey[0] ^ _x0, _workingKey[1] ^ _x1, _workingKey[2] ^ _x2, _workingKey[3] ^ _x3);
 066            LT();
 067            Sb1(_workingKey[4] ^ _x0, _workingKey[5] ^ _x1, _workingKey[6] ^ _x2, _workingKey[7] ^ _x3);
 068            LT();
 069            Sb2(_workingKey[8] ^ _x0, _workingKey[9] ^ _x1, _workingKey[10] ^ _x2, _workingKey[11] ^ _x3);
 070            LT();
 071            Sb3(_workingKey[12] ^ _x0, _workingKey[13] ^ _x1, _workingKey[14] ^ _x2, _workingKey[15] ^ _x3);
 072            LT();
 073            Sb4(_workingKey[16] ^ _x0, _workingKey[17] ^ _x1, _workingKey[18] ^ _x2, _workingKey[19] ^ _x3);
 074            LT();
 075            Sb5(_workingKey[20] ^ _x0, _workingKey[21] ^ _x1, _workingKey[22] ^ _x2, _workingKey[23] ^ _x3);
 076            LT();
 077            Sb6(_workingKey[24] ^ _x0, _workingKey[25] ^ _x1, _workingKey[26] ^ _x2, _workingKey[27] ^ _x3);
 078            LT();
 079            Sb7(_workingKey[28] ^ _x0, _workingKey[29] ^ _x1, _workingKey[30] ^ _x2, _workingKey[31] ^ _x3);
 080            LT();
 081            Sb0(_workingKey[32] ^ _x0, _workingKey[33] ^ _x1, _workingKey[34] ^ _x2, _workingKey[35] ^ _x3);
 082            LT();
 083            Sb1(_workingKey[36] ^ _x0, _workingKey[37] ^ _x1, _workingKey[38] ^ _x2, _workingKey[39] ^ _x3);
 084            LT();
 085            Sb2(_workingKey[40] ^ _x0, _workingKey[41] ^ _x1, _workingKey[42] ^ _x2, _workingKey[43] ^ _x3);
 086            LT();
 087            Sb3(_workingKey[44] ^ _x0, _workingKey[45] ^ _x1, _workingKey[46] ^ _x2, _workingKey[47] ^ _x3);
 088            LT();
 089            Sb4(_workingKey[48] ^ _x0, _workingKey[49] ^ _x1, _workingKey[50] ^ _x2, _workingKey[51] ^ _x3);
 090            LT();
 091            Sb5(_workingKey[52] ^ _x0, _workingKey[53] ^ _x1, _workingKey[54] ^ _x2, _workingKey[55] ^ _x3);
 092            LT();
 093            Sb6(_workingKey[56] ^ _x0, _workingKey[57] ^ _x1, _workingKey[58] ^ _x2, _workingKey[59] ^ _x3);
 094            LT();
 095            Sb7(_workingKey[60] ^ _x0, _workingKey[61] ^ _x1, _workingKey[62] ^ _x2, _workingKey[63] ^ _x3);
 096            LT();
 097            Sb0(_workingKey[64] ^ _x0, _workingKey[65] ^ _x1, _workingKey[66] ^ _x2, _workingKey[67] ^ _x3);
 098            LT();
 099            Sb1(_workingKey[68] ^ _x0, _workingKey[69] ^ _x1, _workingKey[70] ^ _x2, _workingKey[71] ^ _x3);
 0100            LT();
 0101            Sb2(_workingKey[72] ^ _x0, _workingKey[73] ^ _x1, _workingKey[74] ^ _x2, _workingKey[75] ^ _x3);
 0102            LT();
 0103            Sb3(_workingKey[76] ^ _x0, _workingKey[77] ^ _x1, _workingKey[78] ^ _x2, _workingKey[79] ^ _x3);
 0104            LT();
 0105            Sb4(_workingKey[80] ^ _x0, _workingKey[81] ^ _x1, _workingKey[82] ^ _x2, _workingKey[83] ^ _x3);
 0106            LT();
 0107            Sb5(_workingKey[84] ^ _x0, _workingKey[85] ^ _x1, _workingKey[86] ^ _x2, _workingKey[87] ^ _x3);
 0108            LT();
 0109            Sb6(_workingKey[88] ^ _x0, _workingKey[89] ^ _x1, _workingKey[90] ^ _x2, _workingKey[91] ^ _x3);
 0110            LT();
 0111            Sb7(_workingKey[92] ^ _x0, _workingKey[93] ^ _x1, _workingKey[94] ^ _x2, _workingKey[95] ^ _x3);
 0112            LT();
 0113            Sb0(_workingKey[96] ^ _x0, _workingKey[97] ^ _x1, _workingKey[98] ^ _x2, _workingKey[99] ^ _x3);
 0114            LT();
 0115            Sb1(_workingKey[100] ^ _x0, _workingKey[101] ^ _x1, _workingKey[102] ^ _x2, _workingKey[103] ^ _x3);
 0116            LT();
 0117            Sb2(_workingKey[104] ^ _x0, _workingKey[105] ^ _x1, _workingKey[106] ^ _x2, _workingKey[107] ^ _x3);
 0118            LT();
 0119            Sb3(_workingKey[108] ^ _x0, _workingKey[109] ^ _x1, _workingKey[110] ^ _x2, _workingKey[111] ^ _x3);
 0120            LT();
 0121            Sb4(_workingKey[112] ^ _x0, _workingKey[113] ^ _x1, _workingKey[114] ^ _x2, _workingKey[115] ^ _x3);
 0122            LT();
 0123            Sb5(_workingKey[116] ^ _x0, _workingKey[117] ^ _x1, _workingKey[118] ^ _x2, _workingKey[119] ^ _x3);
 0124            LT();
 0125            Sb6(_workingKey[120] ^ _x0, _workingKey[121] ^ _x1, _workingKey[122] ^ _x2, _workingKey[123] ^ _x3);
 0126            LT();
 0127            Sb7(_workingKey[124] ^ _x0, _workingKey[125] ^ _x1, _workingKey[126] ^ _x2, _workingKey[127] ^ _x3);
 128
 0129            WordToBytes(_workingKey[131] ^ _x3, outputBuffer, outputOffset);
 0130            WordToBytes(_workingKey[130] ^ _x2, outputBuffer, outputOffset + 4);
 0131            WordToBytes(_workingKey[129] ^ _x1, outputBuffer, outputOffset + 8);
 0132            WordToBytes(_workingKey[128] ^ _x0, outputBuffer, outputOffset + 12);
 133
 0134            return BlockSize;
 0135        }
 136
 137        /// <summary>
 138        /// Decrypts the specified region of the input byte array and copies the decrypted data to the specified region 
 139        /// </summary>
 140        /// <param name="inputBuffer">The input data to decrypt.</param>
 141        /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param>
 142        /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param>
 143        /// <param name="outputBuffer">The output to which to write decrypted data.</param>
 144        /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param>
 145        /// <returns>
 146        /// The number of bytes decrypted.
 147        /// </returns>
 148        public override int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o
 0149        {
 0150            if (inputCount != BlockSize)
 0151            {
 0152                throw new ArgumentException("inputCount");
 153            }
 154
 0155            _x3 = _workingKey[131] ^ BytesToWord(inputBuffer, inputOffset);
 0156            _x2 = _workingKey[130] ^ BytesToWord(inputBuffer, inputOffset + 4);
 0157            _x1 = _workingKey[129] ^ BytesToWord(inputBuffer, inputOffset + 8);
 0158            _x0 = _workingKey[128] ^ BytesToWord(inputBuffer, inputOffset + 12);
 159
 0160            Ib7(_x0, _x1, _x2, _x3);
 161
 0162            _x0 ^= _workingKey[124];
 0163            _x1 ^= _workingKey[125];
 0164            _x2 ^= _workingKey[126];
 0165            _x3 ^= _workingKey[127];
 166
 0167            InverseLT();
 0168            Ib6(_x0, _x1, _x2, _x3);
 169
 0170            _x0 ^= _workingKey[120];
 0171            _x1 ^= _workingKey[121];
 0172            _x2 ^= _workingKey[122];
 0173            _x3 ^= _workingKey[123];
 174
 0175            InverseLT();
 0176            Ib5(_x0, _x1, _x2, _x3);
 177
 0178            _x0 ^= _workingKey[116];
 0179            _x1 ^= _workingKey[117];
 0180            _x2 ^= _workingKey[118];
 0181            _x3 ^= _workingKey[119];
 182
 0183            InverseLT();
 0184            Ib4(_x0, _x1, _x2, _x3);
 185
 0186            _x0 ^= _workingKey[112];
 0187            _x1 ^= _workingKey[113];
 0188            _x2 ^= _workingKey[114];
 0189            _x3 ^= _workingKey[115];
 0190            InverseLT();
 0191            Ib3(_x0, _x1, _x2, _x3);
 192
 0193            _x0 ^= _workingKey[108];
 0194            _x1 ^= _workingKey[109];
 0195            _x2 ^= _workingKey[110];
 0196            _x3 ^= _workingKey[111];
 197
 0198            InverseLT();
 0199            Ib2(_x0, _x1, _x2, _x3);
 200
 0201            _x0 ^= _workingKey[104];
 0202            _x1 ^= _workingKey[105];
 0203            _x2 ^= _workingKey[106];
 0204            _x3 ^= _workingKey[107];
 205
 0206            InverseLT();
 0207            Ib1(_x0, _x1, _x2, _x3);
 208
 0209            _x0 ^= _workingKey[100];
 0210            _x1 ^= _workingKey[101];
 0211            _x2 ^= _workingKey[102];
 0212            _x3 ^= _workingKey[103];
 213
 0214            InverseLT();
 0215            Ib0(_x0, _x1, _x2, _x3);
 216
 0217            _x0 ^= _workingKey[96];
 0218            _x1 ^= _workingKey[97];
 0219            _x2 ^= _workingKey[98];
 0220            _x3 ^= _workingKey[99];
 221
 0222            InverseLT();
 0223            Ib7(_x0, _x1, _x2, _x3);
 224
 0225            _x0 ^= _workingKey[92];
 0226            _x1 ^= _workingKey[93];
 0227            _x2 ^= _workingKey[94];
 0228            _x3 ^= _workingKey[95];
 229
 0230            InverseLT();
 0231            Ib6(_x0, _x1, _x2, _x3);
 232
 0233            _x0 ^= _workingKey[88];
 0234            _x1 ^= _workingKey[89];
 0235            _x2 ^= _workingKey[90];
 0236            _x3 ^= _workingKey[91];
 237
 0238            InverseLT();
 0239            Ib5(_x0, _x1, _x2, _x3);
 240
 0241            _x0 ^= _workingKey[84];
 0242            _x1 ^= _workingKey[85];
 0243            _x2 ^= _workingKey[86];
 0244            _x3 ^= _workingKey[87];
 245
 0246            InverseLT();
 0247            Ib4(_x0, _x1, _x2, _x3);
 248
 0249            _x0 ^= _workingKey[80];
 0250            _x1 ^= _workingKey[81];
 0251            _x2 ^= _workingKey[82];
 0252            _x3 ^= _workingKey[83];
 253
 0254            InverseLT();
 0255            Ib3(_x0, _x1, _x2, _x3);
 256
 0257            _x0 ^= _workingKey[76];
 0258            _x1 ^= _workingKey[77];
 0259            _x2 ^= _workingKey[78];
 0260            _x3 ^= _workingKey[79];
 261
 0262            InverseLT();
 0263            Ib2(_x0, _x1, _x2, _x3);
 264
 0265            _x0 ^= _workingKey[72];
 0266            _x1 ^= _workingKey[73];
 0267            _x2 ^= _workingKey[74];
 0268            _x3 ^= _workingKey[75];
 269
 0270            InverseLT();
 0271            Ib1(_x0, _x1, _x2, _x3);
 272
 0273            _x0 ^= _workingKey[68];
 0274            _x1 ^= _workingKey[69];
 0275            _x2 ^= _workingKey[70];
 0276            _x3 ^= _workingKey[71];
 277
 0278            InverseLT();
 0279            Ib0(_x0, _x1, _x2, _x3);
 280
 0281            _x0 ^= _workingKey[64];
 0282            _x1 ^= _workingKey[65];
 0283            _x2 ^= _workingKey[66];
 0284            _x3 ^= _workingKey[67];
 285
 0286            InverseLT();
 0287            Ib7(_x0, _x1, _x2, _x3);
 288
 0289            _x0 ^= _workingKey[60];
 0290            _x1 ^= _workingKey[61];
 0291            _x2 ^= _workingKey[62];
 0292            _x3 ^= _workingKey[63];
 293
 0294            InverseLT();
 0295            Ib6(_x0, _x1, _x2, _x3);
 296
 0297            _x0 ^= _workingKey[56];
 0298            _x1 ^= _workingKey[57];
 0299            _x2 ^= _workingKey[58];
 0300            _x3 ^= _workingKey[59];
 301
 0302            InverseLT();
 0303            Ib5(_x0, _x1, _x2, _x3);
 304
 0305            _x0 ^= _workingKey[52];
 0306            _x1 ^= _workingKey[53];
 0307            _x2 ^= _workingKey[54];
 0308            _x3 ^= _workingKey[55];
 309
 0310            InverseLT();
 0311            Ib4(_x0, _x1, _x2, _x3);
 312
 0313            _x0 ^= _workingKey[48];
 0314            _x1 ^= _workingKey[49];
 0315            _x2 ^= _workingKey[50];
 0316            _x3 ^= _workingKey[51];
 317
 0318            InverseLT();
 0319            Ib3(_x0, _x1, _x2, _x3);
 320
 0321            _x0 ^= _workingKey[44];
 0322            _x1 ^= _workingKey[45];
 0323            _x2 ^= _workingKey[46];
 0324            _x3 ^= _workingKey[47];
 325
 0326            InverseLT();
 0327            Ib2(_x0, _x1, _x2, _x3);
 328
 0329            _x0 ^= _workingKey[40];
 0330            _x1 ^= _workingKey[41];
 0331            _x2 ^= _workingKey[42];
 0332            _x3 ^= _workingKey[43];
 333
 0334            InverseLT();
 0335            Ib1(_x0, _x1, _x2, _x3);
 336
 0337            _x0 ^= _workingKey[36];
 0338            _x1 ^= _workingKey[37];
 0339            _x2 ^= _workingKey[38];
 0340            _x3 ^= _workingKey[39];
 341
 0342            InverseLT();
 0343            Ib0(_x0, _x1, _x2, _x3);
 344
 0345            _x0 ^= _workingKey[32];
 0346            _x1 ^= _workingKey[33];
 0347            _x2 ^= _workingKey[34];
 0348            _x3 ^= _workingKey[35];
 349
 0350            InverseLT();
 0351            Ib7(_x0, _x1, _x2, _x3);
 352
 0353            _x0 ^= _workingKey[28];
 0354            _x1 ^= _workingKey[29];
 0355            _x2 ^= _workingKey[30];
 0356            _x3 ^= _workingKey[31];
 357
 0358            InverseLT();
 0359            Ib6(_x0, _x1, _x2, _x3);
 360
 0361            _x0 ^= _workingKey[24];
 0362            _x1 ^= _workingKey[25];
 0363            _x2 ^= _workingKey[26];
 0364            _x3 ^= _workingKey[27];
 365
 0366            InverseLT();
 0367            Ib5(_x0, _x1, _x2, _x3);
 368
 0369            _x0 ^= _workingKey[20];
 0370            _x1 ^= _workingKey[21];
 0371            _x2 ^= _workingKey[22];
 0372            _x3 ^= _workingKey[23];
 373
 0374            InverseLT();
 0375            Ib4(_x0, _x1, _x2, _x3);
 376
 0377            _x0 ^= _workingKey[16];
 0378            _x1 ^= _workingKey[17];
 0379            _x2 ^= _workingKey[18];
 0380            _x3 ^= _workingKey[19];
 381
 0382            InverseLT();
 0383            Ib3(_x0, _x1, _x2, _x3);
 384
 0385            _x0 ^= _workingKey[12];
 0386            _x1 ^= _workingKey[13];
 0387            _x2 ^= _workingKey[14];
 0388            _x3 ^= _workingKey[15];
 389
 0390            InverseLT();
 0391            Ib2(_x0, _x1, _x2, _x3);
 392
 0393            _x0 ^= _workingKey[8];
 0394            _x1 ^= _workingKey[9];
 0395            _x2 ^= _workingKey[10];
 0396            _x3 ^= _workingKey[11];
 397
 0398            InverseLT();
 0399            Ib1(_x0, _x1, _x2, _x3);
 400
 0401            _x0 ^= _workingKey[4];
 0402            _x1 ^= _workingKey[5];
 0403            _x2 ^= _workingKey[6];
 0404            _x3 ^= _workingKey[7];
 405
 0406            InverseLT();
 0407            Ib0(_x0, _x1, _x2, _x3);
 408
 0409            WordToBytes(_x3 ^ _workingKey[3], outputBuffer, outputOffset);
 0410            WordToBytes(_x2 ^ _workingKey[2], outputBuffer, outputOffset + 4);
 0411            WordToBytes(_x1 ^ _workingKey[1], outputBuffer, outputOffset + 8);
 0412            WordToBytes(_x0 ^ _workingKey[0], outputBuffer, outputOffset + 12);
 413
 0414            return BlockSize;
 0415        }
 416
 417        /// <summary>
 418        /// Expand a user-supplied key material into a session key.
 419        /// </summary>
 420        /// <param name="key">The user-key bytes to use.</param>
 421        /// <returns>
 422        /// A session key.
 423        /// </returns>
 424        /// <exception cref="ArgumentException"><paramref name="key"/> is not multiple of 4 bytes.</exception>
 425        private int[] MakeWorkingKey(byte[] key)
 0426        {
 427            // pad key to 256 bits
 0428            var kPad = new int[16];
 429            int off;
 0430            var length = 0;
 431
 0432            for (off = key.Length - 4; off > 0; off -= 4)
 0433            {
 0434                kPad[length++] = BytesToWord(key, off);
 0435            }
 436
 0437            if (off == 0)
 0438            {
 0439                kPad[length++] = BytesToWord(key, 0);
 0440                if (length < 8)
 0441                {
 0442                    kPad[length] = 1;
 0443                }
 0444            }
 445            else
 0446            {
 0447                throw new ArgumentException("key must be a multiple of 4 bytes");
 448            }
 449
 450            // expand the padded key up to 33 x 128 bits of key material
 451            const int amount = (Rounds + 1) * 4;
 0452            var w = new int[amount];
 453
 454            // compute w0 to w7 from w-8 to w-1
 0455            for (var i = 8; i < 16; i++)
 0456            {
 0457                kPad[i] = RotateLeft(kPad[i - 8] ^ kPad[i - 5] ^ kPad[i - 3] ^ kPad[i - 1] ^ Phi ^ (i - 8), 11);
 0458            }
 459
 0460            Buffer.BlockCopy(kPad, 8, w, 0, 8);
 461
 462            // compute w8 to w136
 0463            for (var i = 8; i < amount; i++)
 0464            {
 0465                w[i] = RotateLeft(w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ Phi ^ i, 11);
 0466            }
 467
 468            // create the working keys by processing w with the Sbox and IP
 0469            Sb3(w[0], w[1], w[2], w[3]);
 0470            w[0] = _x0;
 0471            w[1] = _x1;
 0472            w[2] = _x2;
 0473            w[3] = _x3;
 474
 0475            Sb2(w[4], w[5], w[6], w[7]);
 0476            w[4] = _x0;
 0477            w[5] = _x1;
 0478            w[6] = _x2;
 0479            w[7] = _x3;
 480
 0481            Sb1(w[8], w[9], w[10], w[11]);
 0482            w[8] = _x0;
 0483            w[9] = _x1;
 0484            w[10] = _x2;
 0485            w[11] = _x3;
 486
 0487            Sb0(w[12], w[13], w[14], w[15]);
 0488            w[12] = _x0;
 0489            w[13] = _x1;
 0490            w[14] = _x2;
 0491            w[15] = _x3;
 492
 0493            Sb7(w[16], w[17], w[18], w[19]);
 0494            w[16] = _x0;
 0495            w[17] = _x1;
 0496            w[18] = _x2;
 0497            w[19] = _x3;
 498
 0499            Sb6(w[20], w[21], w[22], w[23]);
 0500            w[20] = _x0;
 0501            w[21] = _x1;
 0502            w[22] = _x2;
 0503            w[23] = _x3;
 504
 0505            Sb5(w[24], w[25], w[26], w[27]);
 0506            w[24] = _x0;
 0507            w[25] = _x1;
 0508            w[26] = _x2;
 0509            w[27] = _x3;
 510
 0511            Sb4(w[28], w[29], w[30], w[31]);
 0512            w[28] = _x0;
 0513            w[29] = _x1;
 0514            w[30] = _x2;
 0515            w[31] = _x3;
 516
 0517            Sb3(w[32], w[33], w[34], w[35]);
 0518            w[32] = _x0;
 0519            w[33] = _x1;
 0520            w[34] = _x2;
 0521            w[35] = _x3;
 522
 0523            Sb2(w[36], w[37], w[38], w[39]);
 0524            w[36] = _x0;
 0525            w[37] = _x1;
 0526            w[38] = _x2;
 0527            w[39] = _x3;
 528
 0529            Sb1(w[40], w[41], w[42], w[43]);
 0530            w[40] = _x0;
 0531            w[41] = _x1;
 0532            w[42] = _x2;
 0533            w[43] = _x3;
 534
 0535            Sb0(w[44], w[45], w[46], w[47]);
 0536            w[44] = _x0;
 0537            w[45] = _x1;
 0538            w[46] = _x2;
 0539            w[47] = _x3;
 540
 0541            Sb7(w[48], w[49], w[50], w[51]);
 0542            w[48] = _x0;
 0543            w[49] = _x1;
 0544            w[50] = _x2;
 0545            w[51] = _x3;
 546
 0547            Sb6(w[52], w[53], w[54], w[55]);
 0548            w[52] = _x0;
 0549            w[53] = _x1;
 0550            w[54] = _x2;
 0551            w[55] = _x3;
 552
 0553            Sb5(w[56], w[57], w[58], w[59]);
 0554            w[56] = _x0;
 0555            w[57] = _x1;
 0556            w[58] = _x2;
 0557            w[59] = _x3;
 558
 0559            Sb4(w[60], w[61], w[62], w[63]);
 0560            w[60] = _x0;
 0561            w[61] = _x1;
 0562            w[62] = _x2;
 0563            w[63] = _x3;
 564
 0565            Sb3(w[64], w[65], w[66], w[67]);
 0566            w[64] = _x0;
 0567            w[65] = _x1;
 0568            w[66] = _x2;
 0569            w[67] = _x3;
 570
 0571            Sb2(w[68], w[69], w[70], w[71]);
 0572            w[68] = _x0;
 0573            w[69] = _x1;
 0574            w[70] = _x2;
 0575            w[71] = _x3;
 576
 0577            Sb1(w[72], w[73], w[74], w[75]);
 0578            w[72] = _x0;
 0579            w[73] = _x1;
 0580            w[74] = _x2;
 0581            w[75] = _x3;
 582
 0583            Sb0(w[76], w[77], w[78], w[79]);
 0584            w[76] = _x0;
 0585            w[77] = _x1;
 0586            w[78] = _x2;
 0587            w[79] = _x3;
 588
 0589            Sb7(w[80], w[81], w[82], w[83]);
 0590            w[80] = _x0;
 0591            w[81] = _x1;
 0592            w[82] = _x2;
 0593            w[83] = _x3;
 594
 0595            Sb6(w[84], w[85], w[86], w[87]);
 0596            w[84] = _x0;
 0597            w[85] = _x1;
 0598            w[86] = _x2;
 0599            w[87] = _x3;
 600
 0601            Sb5(w[88], w[89], w[90], w[91]);
 0602            w[88] = _x0;
 0603            w[89] = _x1;
 0604            w[90] = _x2;
 0605            w[91] = _x3;
 606
 0607            Sb4(w[92], w[93], w[94], w[95]);
 0608            w[92] = _x0;
 0609            w[93] = _x1;
 0610            w[94] = _x2;
 0611            w[95] = _x3;
 612
 0613            Sb3(w[96], w[97], w[98], w[99]);
 0614            w[96] = _x0;
 0615            w[97] = _x1;
 0616            w[98] = _x2;
 0617            w[99] = _x3;
 618
 0619            Sb2(w[100], w[101], w[102], w[103]);
 0620            w[100] = _x0;
 0621            w[101] = _x1;
 0622            w[102] = _x2;
 0623            w[103] = _x3;
 624
 0625            Sb1(w[104], w[105], w[106], w[107]);
 0626            w[104] = _x0;
 0627            w[105] = _x1;
 0628            w[106] = _x2;
 0629            w[107] = _x3;
 630
 0631            Sb0(w[108], w[109], w[110], w[111]);
 0632            w[108] = _x0;
 0633            w[109] = _x1;
 0634            w[110] = _x2;
 0635            w[111] = _x3;
 636
 0637            Sb7(w[112], w[113], w[114], w[115]);
 0638            w[112] = _x0;
 0639            w[113] = _x1;
 0640            w[114] = _x2;
 0641            w[115] = _x3;
 642
 0643            Sb6(w[116], w[117], w[118], w[119]);
 0644            w[116] = _x0;
 0645            w[117] = _x1;
 0646            w[118] = _x2;
 0647            w[119] = _x3;
 648
 0649            Sb5(w[120], w[121], w[122], w[123]);
 0650            w[120] = _x0;
 0651            w[121] = _x1;
 0652            w[122] = _x2;
 0653            w[123] = _x3;
 654
 0655            Sb4(w[124], w[125], w[126], w[127]);
 0656            w[124] = _x0;
 0657            w[125] = _x1;
 0658            w[126] = _x2;
 0659            w[127] = _x3;
 660
 0661            Sb3(w[128], w[129], w[130], w[131]);
 0662            w[128] = _x0;
 0663            w[129] = _x1;
 0664            w[130] = _x2;
 0665            w[131] = _x3;
 666
 0667            return w;
 0668        }
 669
 670        private static int RotateLeft(int x, int bits)
 0671        {
 0672            return (x << bits) | (int) ((uint) x >> (32 - bits));
 0673        }
 674
 675        private static int RotateRight(int x, int bits)
 0676        {
 0677            return (int) ((uint) x >> bits) | (x << (32 - bits));
 0678        }
 679
 680        private static int BytesToWord(byte[] src, int srcOff)
 0681        {
 0682            return ((src[srcOff] & 0xff) << 24) | ((src[srcOff + 1] & 0xff) << 16) |
 0683                   ((src[srcOff + 2] & 0xff) << 8) | (src[srcOff + 3] & 0xff);
 0684        }
 685
 686        private static void WordToBytes(int word, byte[] dst, int dstOff)
 0687        {
 0688            dst[dstOff + 3] = (byte) word;
 0689            dst[dstOff + 2] = (byte) ((uint)word >> 8);
 0690            dst[dstOff + 1] = (byte) ((uint)word >> 16);
 0691            dst[dstOff] = (byte) ((uint)word >> 24);
 0692        }
 693
 694        /*
 695         * The sboxes below are based on the work of Brian Gladman and
 696         * Sam Simpson, whose original notice appears below.
 697         *
 698         * For further details see:
 699         *      http://fp.gladman.plus.com/cryptography_technology/serpent/
 700         *
 701         */
 702
 703        /*
 704         * Partially optimised Serpent S Box bool functions derived
 705         * using a recursive descent analyser but without a full search
 706         * of all subtrees. This set of S boxes is the result of work
 707         * by Sam Simpson and Brian Gladman using the spare time on a
 708         * cluster of high capacity servers to search for S boxes with
 709         * this customised search engine. There are now an average of
 710         * 15.375 terms per S box.
 711         *
 712         * Copyright:   Dr B. R Gladman (gladman@seven77.demon.co.uk)
 713         *              and Sam Simpson (s.simpson@mia.co.uk)
 714         *              17th December 1998
 715         *
 716         * We hereby give permission for information in this file to be
 717         * used freely subject only to acknowledgement of its origin.
 718         */
 719
 720        /// <summary>
 721        /// S0 - { 3, 8,15, 1,10, 6, 5,11,14,13, 4, 2, 7, 0, 9,12 } - 15 terms.
 722        /// </summary>
 723        /// <param name="a">A.</param>
 724        /// <param name="b">The b.</param>
 725        /// <param name="c">The c.</param>
 726        /// <param name="d">The d.</param>
 727        private void Sb0(int a, int b, int c, int d)
 0728        {
 0729            var t1 = a ^ d;
 0730            var t3 = c ^ t1;
 0731            var t4 = b ^ t3;
 0732            _x3 = (a & d) ^ t4;
 0733            var t7 = a ^ (b & t1);
 0734            _x2 = t4 ^ (c | t7);
 0735            var t12 = _x3 & (t3 ^ t7);
 0736            _x1 = (~t3) ^ t12;
 0737            _x0 = t12 ^ (~t7);
 0738        }
 739
 740        /// <summary>
 741        /// InvSO - {13, 3,11, 0,10, 6, 5,12, 1,14, 4, 7,15, 9, 8, 2 } - 15 terms.
 742        /// </summary>
 743        /// <param name="a">A.</param>
 744        /// <param name="b">The b.</param>
 745        /// <param name="c">The c.</param>
 746        /// <param name="d">The d.</param>
 747        private void Ib0(int a, int b, int c, int d)
 0748        {
 0749            var t1 = ~a;
 0750            var t2 = a ^ b;
 0751            var t4 = d ^ (t1 | t2);
 0752            var t5 = c ^ t4;
 0753            _x2 = t2 ^ t5;
 0754            var t8 = t1 ^ (d & t2);
 0755            _x1 = t4 ^ (_x2 & t8);
 0756            _x3 = (a & t4) ^ (t5 | _x1);
 0757            _x0 = _x3 ^ (t5 ^ t8);
 0758        }
 759
 760        /// <summary>
 761        /// S1 - {15,12, 2, 7, 9, 0, 5,10, 1,11,14, 8, 6,13, 3, 4 } - 14 terms.
 762        /// </summary>
 763        /// <param name="a">A.</param>
 764        /// <param name="b">The b.</param>
 765        /// <param name="c">The c.</param>
 766        /// <param name="d">The d.</param>
 767        private void Sb1(int a, int b, int c, int d)
 0768        {
 0769            var t2 = b ^ (~a);
 0770            var t5 = c ^ (a | t2);
 0771            _x2 = d ^ t5;
 0772            var t7 = b ^ (d | t2);
 0773            var t8 = t2 ^ _x2;
 0774            _x3 = t8 ^ (t5 & t7);
 0775            var t11 = t5 ^ t7;
 0776            _x1 = _x3 ^ t11;
 0777            _x0 = t5 ^ (t8 & t11);
 0778        }
 779
 780        /// <summary>
 781        /// InvS1 - { 5, 8, 2,14,15, 6,12, 3,11, 4, 7, 9, 1,13,10, 0 } - 14 steps.
 782        /// </summary>
 783        /// <param name="a">A.</param>
 784        /// <param name="b">The b.</param>
 785        /// <param name="c">The c.</param>
 786        /// <param name="d">The d.</param>
 787        private void Ib1(int a, int b, int c, int d)
 0788        {
 0789            var t1 = b ^ d;
 0790            var t3 = a ^ (b & t1);
 0791            var t4 = t1 ^ t3;
 0792            _x3 = c ^ t4;
 0793            var t7 = b ^ (t1 & t3);
 0794            var t8 = _x3 | t7;
 0795            _x1 = t3 ^ t8;
 0796            var t10 = ~_x1;
 0797            var t11 = _x3 ^ t7;
 0798            _x0 = t10 ^ t11;
 0799            _x2 = t4 ^ (t10 | t11);
 0800        }
 801
 802        /// <summary>
 803        /// S2 - { 8, 6, 7, 9, 3,12,10,15,13, 1,14, 4, 0,11, 5, 2 } - 16 terms.
 804        /// </summary>
 805        /// <param name="a">A.</param>
 806        /// <param name="b">The b.</param>
 807        /// <param name="c">The c.</param>
 808        /// <param name="d">The d.</param>
 809        private void Sb2(int a, int b, int c, int d)
 0810        {
 0811            var t1 = ~a;
 0812            var t2 = b ^ d;
 0813            var t3 = c & t1;
 0814            _x0 = t2 ^ t3;
 0815            var t5 = c ^ t1;
 0816            var t6 = c ^ _x0;
 0817            var t7 = b & t6;
 0818            _x3 = t5 ^ t7;
 0819            _x2 = a ^ ((d | t7) & (_x0 | t5));
 0820            _x1 = (t2 ^ _x3) ^ (_x2 ^ (d | t1));
 0821        }
 822
 823        /// <summary>
 824        /// InvS2 - {12, 9,15, 4,11,14, 1, 2, 0, 3, 6,13, 5, 8,10, 7 } - 16 steps.
 825        /// </summary>
 826        /// <param name="a">A.</param>
 827        /// <param name="b">The b.</param>
 828        /// <param name="c">The c.</param>
 829        /// <param name="d">The d.</param>
 830        private void Ib2(int a, int b, int c, int d)
 0831        {
 0832            var t1 = b ^ d;
 0833            var t2 = ~t1;
 0834            var t3 = a ^ c;
 0835            var t4 = c ^ t1;
 0836            var t5 = b & t4;
 0837            _x0 = t3 ^ t5;
 0838            var t7 = a | t2;
 0839            var t8 = d ^ t7;
 0840            var t9 = t3 | t8;
 0841            _x3 = t1 ^ t9;
 0842            var t11 = ~t4;
 0843            var t12 = _x0 | _x3;
 0844            _x1 = t11 ^ t12;
 0845            _x2 = (d & t11) ^ (t3 ^ t12);
 0846        }
 847
 848        /// <summary>
 849        /// S3 - { 0,15,11, 8,12, 9, 6, 3,13, 1, 2, 4,10, 7, 5,14 } - 16 terms.
 850        /// </summary>
 851        /// <param name="a">A.</param>
 852        /// <param name="b">The b.</param>
 853        /// <param name="c">The c.</param>
 854        /// <param name="d">The d.</param>
 855        private void Sb3(int a, int b, int c, int d)
 0856        {
 0857            var t1 = a ^ b;
 0858            var t2 = a & c;
 0859            var t3 = a | d;
 0860            var t4 = c ^ d;
 0861            var t5 = t1 & t3;
 0862            var t6 = t2 | t5;
 0863            _x2 = t4 ^ t6;
 0864            var t8 = b ^ t3;
 0865            var t9 = t6 ^ t8;
 0866            var t10 = t4 & t9;
 0867            _x0 = t1 ^ t10;
 0868            var t12 = _x2 & _x0;
 0869            _x1 = t9 ^ t12;
 0870            _x3 = (b | d) ^ (t4 ^ t12);
 0871        }
 872
 873        /// <summary>
 874        /// InvS3 - { 0, 9,10, 7,11,14, 6,13, 3, 5,12, 2, 4, 8,15, 1 } - 15 terms.
 875        /// </summary>
 876        /// <param name="a">A.</param>
 877        /// <param name="b">The b.</param>
 878        /// <param name="c">The c.</param>
 879        /// <param name="d">The d.</param>
 880        private void Ib3(int a, int b, int c, int d)
 0881        {
 0882            var t1 = a | b;
 0883            var t2 = b ^ c;
 0884            var t3 = b & t2;
 0885            var t4 = a ^ t3;
 0886            var t5 = c ^ t4;
 0887            var t6 = d | t4;
 0888            _x0 = t2 ^ t6;
 0889            var t8 = t2 | t6;
 0890            var t9 = d ^ t8;
 0891            _x2 = t5 ^ t9;
 0892            var t11 = t1 ^ t9;
 0893            var t12 = _x0 & t11;
 0894            _x3 = t4 ^ t12;
 0895            _x1 = _x3 ^ (_x0 ^ t11);
 0896        }
 897
 898        /// <summary>
 899        /// S4 - { 1,15, 8, 3,12, 0,11, 6, 2, 5, 4,10, 9,14, 7,13 } - 15 terms.
 900        /// </summary>
 901        /// <param name="a">A.</param>
 902        /// <param name="b">The b.</param>
 903        /// <param name="c">The c.</param>
 904        /// <param name="d">The d.</param>
 905        private void Sb4(int a, int b, int c, int d)
 0906        {
 0907            var t1 = a ^ d;
 0908            var t2 = d & t1;
 0909            var t3 = c ^ t2;
 0910            var t4 = b | t3;
 0911            _x3 = t1 ^ t4;
 0912            var t6 = ~b;
 0913            var t7 = t1 | t6;
 0914            _x0 = t3 ^ t7;
 0915            var t9 = a & _x0;
 0916            var t10 = t1 ^ t6;
 0917            var t11 = t4 & t10;
 0918            _x2 = t9 ^ t11;
 0919            _x1 = (a ^ t3) ^ (t10 & _x2);
 0920        }
 921
 922        /// <summary>
 923        /// InvS4 - { 5, 0, 8, 3,10, 9, 7,14, 2,12,11, 6, 4,15,13, 1 } - 15 terms.
 924        /// </summary>
 925        /// <param name="a">A.</param>
 926        /// <param name="b">The b.</param>
 927        /// <param name="c">The c.</param>
 928        /// <param name="d">The d.</param>
 929        private void Ib4(int a, int b, int c, int d)
 0930        {
 0931            var t1 = c | d;
 0932            var t2 = a & t1;
 0933            var t3 = b ^ t2;
 0934            var t4 = a & t3;
 0935            var t5 = c ^ t4;
 0936            _x1 = d ^ t5;
 0937            var t7 = ~a;
 0938            var t8 = t5 & _x1;
 0939            _x3 = t3 ^ t8;
 0940            var t10 = _x1 | t7;
 0941            var t11 = d ^ t10;
 0942            _x0 = _x3 ^ t11;
 0943            _x2 = (t3 & t11) ^ (_x1 ^ t7);
 0944        }
 945
 946        /// <summary>
 947        /// S5 - {15, 5, 2,11, 4,10, 9,12, 0, 3,14, 8,13, 6, 7, 1 } - 16 terms.
 948        /// </summary>
 949        /// <param name="a">A.</param>
 950        /// <param name="b">The b.</param>
 951        /// <param name="c">The c.</param>
 952        /// <param name="d">The d.</param>
 953        private void Sb5(int a, int b, int c, int d)
 0954        {
 0955            var t1 = ~a;
 0956            var t2 = a ^ b;
 0957            var t3 = a ^ d;
 0958            var t4 = c ^ t1;
 0959            var t5 = t2 | t3;
 0960            _x0 = t4 ^ t5;
 0961            var t7 = d & _x0;
 0962            var t8 = t2 ^ _x0;
 0963            _x1 = t7 ^ t8;
 0964            var t10 = t1 | _x0;
 0965            var t11 = t2 | t7;
 0966            var t12 = t3 ^ t10;
 0967            _x2 = t11 ^ t12;
 0968            _x3 = (b ^ t7) ^ (_x1 & t12);
 0969        }
 970
 971        /// <summary>
 972        /// InvS5 - { 8,15, 2, 9, 4, 1,13,14,11, 6, 5, 3, 7,12,10, 0 } - 16 terms.
 973        /// </summary>
 974        /// <param name="a">A.</param>
 975        /// <param name="b">The b.</param>
 976        /// <param name="c">The c.</param>
 977        /// <param name="d">The d.</param>
 978        private void Ib5(int a, int b, int c, int d)
 0979        {
 0980            var t1 = ~c;
 0981            var t2 = b & t1;
 0982            var t3 = d ^ t2;
 0983            var t4 = a & t3;
 0984            var t5 = b ^ t1;
 0985            _x3 = t4 ^ t5;
 0986            var t7 = b | _x3;
 0987            var t8 = a & t7;
 0988            _x1 = t3 ^ t8;
 0989            var t10 = a | d;
 0990            var t11 = t1 ^ t7;
 0991            _x0 = t10 ^ t11;
 0992            _x2 = (b & t10) ^ (t4 | (a ^ c));
 0993        }
 994
 995        /// <summary>
 996        /// S6 - { 7, 2,12, 5, 8, 4, 6,11,14, 9, 1,15,13, 3,10, 0 } - 15 terms.
 997        /// </summary>
 998        /// <param name="a">A.</param>
 999        /// <param name="b">The b.</param>
 1000        /// <param name="c">The c.</param>
 1001        /// <param name="d">The d.</param>
 1002        private void Sb6(int a, int b, int c, int d)
 01003        {
 01004            var t1 = ~a;
 01005            var t2 = a ^ d;
 01006            var t3 = b ^ t2;
 01007            var t4 = t1 | t2;
 01008            var t5 = c ^ t4;
 01009            _x1 = b ^ t5;
 01010            var t7 = t2 | _x1;
 01011            var t8 = d ^ t7;
 01012            var t9 = t5 & t8;
 01013            _x2 = t3 ^ t9;
 01014            var t11 = t5 ^ t8;
 01015            _x0 = _x2 ^ t11;
 01016            _x3 = (~t5) ^ (t3 & t11);
 01017        }
 1018
 1019        /// <summary>
 1020        /// InvS6 - {15,10, 1,13, 5, 3, 6, 0, 4, 9,14, 7, 2,12, 8,11 } - 15 terms.
 1021        /// </summary>
 1022        /// <param name="a">A.</param>
 1023        /// <param name="b">The b.</param>
 1024        /// <param name="c">The c.</param>
 1025        /// <param name="d">The d.</param>
 1026        private void Ib6(int a, int b, int c, int d)
 01027        {
 01028            var t1 = ~a;
 01029            var t2 = a ^ b;
 01030            var t3 = c ^ t2;
 01031            var t4 = c | t1;
 01032            var t5 = d ^ t4;
 01033            _x1 = t3 ^ t5;
 01034            var t7 = t3 & t5;
 01035            var t8 = t2 ^ t7;
 01036            var t9 = b | t8;
 01037            _x3 = t5 ^ t9;
 01038            var t11 = b | _x3;
 01039            _x0 = t8 ^ t11;
 01040            _x2 = (d & t1) ^ (t3 ^ t11);
 01041        }
 1042
 1043        /// <summary>
 1044        /// S7 - { 1,13,15, 0,14, 8, 2,11, 7, 4,12,10, 9, 3, 5, 6 } - 16 terms.
 1045        /// </summary>
 1046        /// <param name="a">A.</param>
 1047        /// <param name="b">The b.</param>
 1048        /// <param name="c">The c.</param>
 1049        /// <param name="d">The d.</param>
 1050        private void Sb7(int a, int b, int c, int d)
 01051        {
 01052            var t1 = b ^ c;
 01053            var t2 = c & t1;
 01054            var t3 = d ^ t2;
 01055            var t4 = a ^ t3;
 01056            var t5 = d | t1;
 01057            var t6 = t4 & t5;
 01058            _x1 = b ^ t6;
 01059            var t8 = t3 | _x1;
 01060            var t9 = a & t4;
 01061            _x3 = t1 ^ t9;
 01062            var t11 = t4 ^ t8;
 01063            var t12 = _x3 & t11;
 01064            _x2 = t3 ^ t12;
 01065            _x0 = (~t11) ^ (_x3 & _x2);
 01066        }
 1067
 1068        /// <summary>
 1069        /// InvS7 - { 3, 0, 6,13, 9,14,15, 8, 5,12,11, 7,10, 1, 4, 2 } - 17 terms.
 1070        /// </summary>
 1071        /// <param name="a">A.</param>
 1072        /// <param name="b">The b.</param>
 1073        /// <param name="c">The c.</param>
 1074        /// <param name="d">The d.</param>
 1075        private void Ib7(int a, int b, int c, int d)
 01076        {
 01077            var t3 = c | (a & b);
 01078            var t4 = d & (a | b);
 01079            _x3 = t3 ^ t4;
 01080            var t6 = ~d;
 01081            var t7 = b ^ t4;
 01082            var t9 = t7 | (_x3 ^ t6);
 01083            _x1 = a ^ t9;
 01084            _x0 = (c ^ t7) ^ (d | _x1);
 01085            _x2 = (t3 ^ _x1) ^ (_x0 ^ (a & _x3));
 01086        }
 1087
 1088        /// <summary>
 1089        /// Apply the linear transformation to the register set.
 1090        /// </summary>
 1091        private void LT()
 01092        {
 01093            var x0 = RotateLeft(_x0, 13);
 01094            var x2 = RotateLeft(_x2, 3);
 01095            var x1 = _x1 ^ x0 ^ x2;
 01096            var x3 = _x3 ^ x2 ^ x0 << 3;
 1097
 01098            _x1 = RotateLeft(x1, 1);
 01099            _x3 = RotateLeft(x3, 7);
 01100            _x0 = RotateLeft(x0 ^ _x1 ^ _x3, 5);
 01101            _x2 = RotateLeft(x2 ^ _x3 ^ (_x1 << 7), 22);
 01102        }
 1103
 1104        /// <summary>
 1105        /// Apply the inverse of the linear transformation to the register set.
 1106        /// </summary>
 1107        private void InverseLT()
 01108        {
 01109            var x2 = RotateRight(_x2, 22) ^ _x3 ^ (_x1 << 7);
 01110            var x0 = RotateRight(_x0, 5) ^ _x1 ^ _x3;
 01111            var x3 = RotateRight(_x3, 7);
 01112            var x1 = RotateRight(_x1, 1);
 01113            _x3 = x3 ^ x2 ^ x0 << 3;
 01114            _x1 = x1 ^ x0 ^ x2;
 01115            _x2 = RotateRight(x2, 3);
 01116            _x0 = RotateRight(x0, 13);
 01117        }
 1118    }
 1119}