public int Build(byte[] output, int outputOffset) { if (bufferLength > 0) { ProcessBuffer(); } h1 += (h0 >> 26); h0 &= 0x3ffffff; h2 += (h1 >> 26); h1 &= 0x3ffffff; h3 += (h2 >> 26); h2 &= 0x3ffffff; h4 += (h3 >> 26); h3 &= 0x3ffffff; h0 += (h4 >> 26) * 5; h4 &= 0x3ffffff; h1 += (h0 >> 26); h0 &= 0x3ffffff; uint g0, g1, g2, g3, g4, b; g0 = h0 + 5; b = g0 >> 26; g0 &= 0x3ffffff; g1 = h1 + b; b = g1 >> 26; g1 &= 0x3ffffff; g2 = h2 + b; b = g2 >> 26; g2 &= 0x3ffffff; g3 = h3 + b; b = g3 >> 26; g3 &= 0x3ffffff; g4 = h4 + b - (1 << 26); b = (g4 >> 31) - 1; uint nb = ~b; h0 = (h0 & nb) | (g0 & b); h1 = (h1 & nb) | (g1 & b); h2 = (h2 & nb) | (g2 & b); h3 = (h3 & nb) | (g3 & b); h4 = (h4 & nb) | (g4 & b); ulong f0, f1, f2, f3; f0 = ((h0) | (h1 << 26)) + (ulong)k0; f1 = ((h1 >> 6) | (h2 << 20)) + (ulong)k1; f2 = ((h2 >> 12) | (h3 << 14)) + (ulong)k2; f3 = ((h3 >> 18) | (h4 << 8)) + (ulong)k3; Lend.Unpack32((uint)f0, output, outputOffset); f1 += (f0 >> 32); Lend.Unpack32((uint)f1, output, outputOffset + 4); f2 += (f1 >> 32); Lend.Unpack32((uint)f2, output, outputOffset + 8); f3 += (f2 >> 32); Lend.Unpack32((uint)f3, output, outputOffset + 12); return(BLOCK_SIZE); }
private static void StateGamma(uint[] state, uint[] buffer, byte[] gamma) { RotateChaCha(state, buffer, 20); Lend.Unpack32(buffer, gamma, 0); }