Esempio 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);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a new <see cref="SpongeState"/> from an existing bitstring and specified rate.
        /// </summary>
        /// <param name="bitstring">The bitstring which holds the bits of the sponge state.</param>
        /// <param name="rate">The number of bits which are impacted while aborbing messages.</param>
        /// <exception cref="ArgumentNullException"><paramref name="bitstring"/> is null.</exception>
        /// <exception cref="ArgumentException"><paramref name="bitstring"/> is empty, or <paramref name="rate"/> is lower
        /// than one, or <paramref name="rate"/> is greater than or equal to <paramref>
        ///         <name>size</name>
        ///     </paramref>
        ///     '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 <see cref="bitstring"/>.Length - <paramref name="rate"/>.</para>
        /// </remarks>
        public SpongeState(Bitstring bitstring, int rate)
        {
            _bitstring = bitstring ?? throw new ArgumentNullException(nameof(bitstring));
            int length = _bitstring.Length;

            if (length < 1)
            {
                throw new ArgumentException("Bitstring cannot be empty.", nameof(bitstring));
            }
            _size = new SpongeSize(length);
            if ((rate < 1) || (rate >= _size.B))
            {
                throw new ArgumentException($"Invalid rate {rate} for width {_size.B}.", nameof(rate));
            }
            _rate = rate;
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new <see cref="SpongeState"/> from an existing one.
 /// </summary>
 /// <param name="state">The sponge state to copy.</param>
 public SpongeState(SpongeState state)
 {
     _size      = state._size;
     _rate      = state._rate;
     _bitstring = new Bitstring(state._bitstring);
 }
Esempio n. 4
0
 /// <summary>
 /// Creates a new <see cref="KeccakPermutation"/> specifying its size, rate and number of iterations of a single
 /// permutation.
 /// </summary>
 /// <param name="size">The size of the permutation.</param>
 /// <param name="rate">The rate of the permutation.</param>
 /// <param name="roundCount">The number of internal iterations of a single permutation.</param>
 protected KeccakPermutation(SpongeSize size, int rate, int roundCount)
     : base(size, rate)
 {
     _roundCount = roundCount;
 }
Esempio n. 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="size"></param>
 /// <param name="rate"></param>
 protected KeccakFunction(SpongeSize size, int rate)
     : base(size, rate, 12 + (size.L << 1))
 {
 }
Esempio n. 6
0
 /// <summary>
 /// Creates a new <see cref="SpongeConstruction"/>, specifying the size of the construction and its rate.
 /// </summary>
 /// <param name="size">The size of the sponge construction.</param>
 /// <param name="rate">The rate of the sponge construction.</param>
 protected SpongeConstruction(SpongeSize size, int rate)
 {
     State = new SpongeState(size, rate);
 }