Exemplo n.º 1
0
        static Word64[] CreateMessageScheduleSha512(Block1024 block)
        {
            // The message schedule.
            Word64[] W = new Word64[80];

            // Prepare the message schedule W.
            // The first 16 words in W are the same as the words of the block.
            // The remaining 80-16 =64 words in W are functions of the previously defined words.
            for (int t = 0; t < 80; t++)
            {
                if (t < 16)
                {
                    W[t] = block.words[t];
                }
                else
                {
                    W[t] = sigma1_512(W[t - 2]) + W[t - 7] + sigma0_512(W[t - 15]) + W[t - 16];
                }
            }

            return(W);
        }
Exemplo n.º 2
0
        static Block1024[] ConvertPaddedMessageToBlock1024Array(byte[] M)
        {
            // We are assuming M is padded, so the number of bits in M is divisible by 1024
            int numberBlocks = (M.Length * 8) / 1024;  // same as: M.Length / 128

            Block1024[] blocks = new Block1024[numberBlocks];

            for (int i = 0; i < numberBlocks; i++)
            {
                // First extract the relavant subarray from M
                byte[] B = new byte[128]; // 128 * 8 = 1024

                for (int j = 0; j < 128; j++)
                {
                    B[j] = M[i * 128 + j];
                }

                Word64[] words = ShaUtilities.ByteArrayToWord64Array(B);
                blocks[i] = new Block1024(words);
            }

            return(blocks);
        }