static Word32[] CreateMessageScheduleSha256(Block512 block) { // The message schedule. Word32[] W = new Word32[64]; // Prepare the message schedule W. // The first 16 words in W are the same as the words of the block. // The remaining 64-16 = 48 words in W are functions of the previously defined words. for (int t = 0; t < 64; t++) { if (t < 16) { W[t] = block.words[t]; } else { W[t] = sigma1_256(W[t - 2]) + W[t - 7] + sigma0_256(W[t - 15]) + W[t - 16]; } } return(W); }
static Word32[] CreateMessageScheduleSha1(Block512 block) { // The message schedule. Word32[] W = new Word32[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] = RotL(1, W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16]); } } return(W); }
static Block512[] ConvertPaddedTextToBlock512Array(byte[] paddedtext) { // We are assuming M has been padded, so the number of bits in M is divisible by 512 int numberBlocks = (paddedtext.Length * 8) / 512; // same as: paddedtext.Length / 64 Block512[] blocks = new Block512[numberBlocks]; for (int i = 0; i < numberBlocks; i++) { // First extract the relavant subarray from paddedtext byte[] B = new byte[64]; // 64 * 8 = 512 for (int j = 0; j < 64; j++) { B[j] = paddedtext[i * 64 + j]; } Word32[] words = ShaUtilities.ByteArrayToWord32Array(B); blocks[i] = new Block512(words); } return(blocks); }