Esempio n. 1
0
        /// <summary>
        /// Squeezes internal state until at least specified number of bits is produced, and returns these bits.
        /// </summary>
        /// <param name="outputLength">The number of desired output bits.</param>
        /// <returns>The byte array holding resulting bits.</returns>
        protected virtual byte[] Squeeze(int outputLength)
        {
            int       rate = State.Rate;
            Bitstring q    = new Bitstring();

            while (true)
            {
                q.Append(State.Bitstring.Truncate(rate));
                if (q.Length >= outputLength)
                {
                    return((q.Length == outputLength) ? q.Bytes : q.Truncate(outputLength).Bytes);
                }
                Function();
            }
        }
Esempio n. 2
0
        private static bool RoundConstant(int t)
        {
            t = Bin.Mod(t, 255);
            if (_roundConstants.ContainsKey(t))
            {
                return(_roundConstants[t]);
            }
            Bitstring r = new Bitstring("10000000", 8);

            for (int i = 0; i < t; i++)
            {
                r.Prepend(Bitstring.Zero);
                r[0] ^= r[8];
                r[4] ^= r[8];
                r[5] ^= r[8];
                r[6] ^= r[8];
                r     = r.Truncate(8);
            }
            bool bit = r[0];

            _roundConstants.Add(t, bit);
            return(bit);
        }