示例#1
0
        private void PadAndSwitchToSqueezingPhase()
        {
            _dataQueue[_bitsInQueue >> 3] |= (byte)(1 << (_bitsInQueue & 7));

            if (++_bitsInQueue == _rate)
            {
                KeccakAbsorb(_dataQueue, 0);
            }
            else
            {
                int full = _bitsInQueue >> 6, partial = _bitsInQueue & 63;
                int off = 0;
                for (int i = 0; i < full; ++i)
                {
                    _state[i] ^= NativeFastShaUtils.LE_To_UInt64(_dataQueue, off);
                    off       += 8;
                }

                if (partial > 0)
                {
                    ulong mask = (1UL << partial) - 1UL;
                    _state[full] ^= NativeFastShaUtils.LE_To_UInt64(_dataQueue, off) & mask;
                }
            }

            _state[(_rate - 1) >> 6] ^= (1UL << 63);

            _bitsInQueue = 0;
            _squeezing   = true;
        }
示例#2
0
        private void KeccakExtract()
        {
            KeccakPermutation();

            NativeFastShaUtils.UInt64_To_LE(_state, 0, _rate >> 6, _dataQueue, 0);

            _bitsInQueue = _rate;
        }
示例#3
0
        private void ProcessWord(byte[] input, int inOff)
        {
            W[wOff] = NativeFastShaUtils.BE_To_UInt64(input, inOff);

            if (++wOff == 16)
            {
                ProcessBlock();
            }
        }
        protected override void ProcessWord(byte[] input, int inOff)
        {
            X[xOff] = NativeFastShaUtils.BE_To_UInt32(input, inOff);

            if (++xOff == 16)
            {
                ProcessBlock();
            }
        }
示例#5
0
        public void Final(byte[] output, int outputBitLength = 0)
        {
            Finish();

            NativeFastShaUtils.UInt64_To_BE(H1, output, 0);
            NativeFastShaUtils.UInt64_To_BE(H2, output, 8);
            NativeFastShaUtils.UInt64_To_BE(H3, output, 16);
            NativeFastShaUtils.UInt64_To_BE(H4, output, 24);
        }
示例#6
0
        private void KeccakAbsorb(byte[] data, int off)
        {
            int count = _rate >> 6;

            for (int i = 0; i < count; ++i)
            {
                _state[i] ^= NativeFastShaUtils.LE_To_UInt64(data, off);
                off       += 8;
            }

            KeccakPermutation();
        }
示例#7
0
        public void Final(byte[] output, int outputBitLength = 0)
        {
            Finish();

            NativeFastShaUtils.UInt64_To_BE(H1, output, 0);
            NativeFastShaUtils.UInt64_To_BE(H2, output, 8);
            NativeFastShaUtils.UInt64_To_BE(H3, output, 16);
            NativeFastShaUtils.UInt64_To_BE(H4, output, 24);

            // Extra stuff is given, so we clear out the unneeded parts
            Array.Clear(output, 28, output.Length - 28);
        }
示例#8
0
        public void Final(byte[] output, int outputBitLength = 0)
        {
            Finish();

            NativeFastShaUtils.UInt32_To_BE(H1, output, 0);
            NativeFastShaUtils.UInt32_To_BE(H2, output, 4);
            NativeFastShaUtils.UInt32_To_BE(H3, output, 8);
            NativeFastShaUtils.UInt32_To_BE(H4, output, 12);
            NativeFastShaUtils.UInt32_To_BE(H5, output, 16);
            NativeFastShaUtils.UInt32_To_BE(H6, output, 20);
            NativeFastShaUtils.UInt32_To_BE(H7, output, 24);
            NativeFastShaUtils.UInt32_To_BE(H8, output, 28);
        }