Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="SpongeState"/> specifying its size and rate.
        /// </summary>
        /// <param name="size">The size of the sponge state.</param>
        /// <param name="rate">The rate of the sponge state, i.e. the number of bits which are impacted while absorbing
        /// messages.</param>
        /// <exception cref="ArgumentException"><paramref name="rate"/> is lower than one, or <paramref name="rate"/> is
        /// greater than or equal to <paramref name="size"/>'s <see cref="SpongeSize.B"/>.</exception>
        /// <remarks>
        /// <para>The capacity of the state, i.e. the number of bits which are not impacted while absorbing messages, will
        /// be <paramref name="size"/>.B - <paramref name="rate"/>.</para>
        /// </remarks>
        public SpongeState(SpongeSize size, int rate)
        {
            int b = size.B;

            if ((rate < 1) || (rate >= b))
            {
                throw new ArgumentException($"Invalid rate {rate} for width {b}.", nameof(rate));
            }
            _size      = size;
            _rate      = rate;
            _bitstring = Bitstring.Zeroes(b);
        }
Exemplo n.º 2
0
        private static SpongeState Iota(SpongeState state, int round)
        {
            int       w  = state.Size.W;
            int       l  = state.Size.L;
            Bitstring rc = Bitstring.Zeroes(w);
            RoundT    roundT;
            int       t;
            int       rnd = 7 * round;

            for (int j = 0; j <= l; j++)
            {
                t      = j + rnd;
                roundT = new RoundT(round, t);
                if (!_roundTConstants.ContainsKey(roundT))
                {
                    _roundTConstants.Add(roundT, RoundConstant(t));
                }
                rc[(1 << j) - 1] = _roundTConstants[roundT];
            }
            state.XorLane(state.GetLane(0, 0), rc);
            return(state);
        }