Renci.SshNet.Security.Cryptography.Ciphers.BlowfishCipher.SetKey C# (CSharp) Method

SetKey() private method

private SetKey ( byte key ) : void
key byte
return void
        private void SetKey(byte[] key)
        {
            /*
             * - comments are from _Applied Crypto_, Schneier, p338
             * please be careful comparing the two, AC numbers the
             * arrays from 1, the enclosed code from 0.
             *
             * (1)
             * 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, SboxSk * sizeof(uint));
            Buffer.BlockCopy(KS1, 0, _s1, 0, SboxSk * sizeof(uint));
            Buffer.BlockCopy(KS2, 0, _s2, 0, SboxSk * sizeof(uint));
            Buffer.BlockCopy(KS3, 0, _s3, 0, SboxSk * sizeof(uint));
            Buffer.BlockCopy(KP, 0, _p, 0, PSize * sizeof(uint));

            /*
             * (2)
             * Now, XOR P[0] with the first 32 bits of the key, XOR P[1] with the
             * second 32-bits of the key, and so on for all bits of the key
             * (up to P[17]).  Repeatedly cycle through the key bits until the
             * entire P-array has been XOR-ed with the key bits
             */
            var keyLength = key.Length;
            var keyIndex = 0;

            for (var i = 0; i < PSize; i++)
            {
                // Get the 32 bits of the key, in 4 * 8 bit chunks
                uint data = 0x0000000;
                for (var j = 0; j < 4; j++)
                {
                    // create a 32 bit block
                    data = (data << 8) | key[keyIndex++];

                    // wrap when we get to the end of the key
                    if (keyIndex >= keyLength)
                    {
                        keyIndex = 0;
                    }
                }
                // XOR the newly created 32 bit chunk onto the P-array
                _p[i] ^= data;
            }

            /*
             * (3)
             * Encrypt the all-zero string with the Blowfish algorithm, using
             * the subkeys described in (1) and (2)
             *
             * (4)
             * Replace P1 and P2 with the output of step (3)
             *
             * (5)
             * Encrypt the output of step(3) using the Blowfish algorithm,
             * with the modified subkeys.
             *
             * (6)
             * Replace P3 and P4 with the output of step (5)
             *
             * (7)
             * Continue the process, replacing all elements of the P-array
             * and then all four S-boxes in order, with the output of the
             * continuously changing Blowfish algorithm
             */

            ProcessTable(0, 0, _p);
            ProcessTable(_p[PSize - 2], _p[PSize - 1], _s0);
            ProcessTable(_s0[SboxSk - 2], _s0[SboxSk - 1], _s1);
            ProcessTable(_s1[SboxSk - 2], _s1[SboxSk - 1], _s2);
            ProcessTable(_s2[SboxSk - 2], _s2[SboxSk - 1], _s3);
        }