Exemple #1
0
        /// <summary>
        /// Creates a ChaCha RNG using the given seed and number of double rounds.
        /// </summary>
        /// <param name="seed">A seed containing the key and stream.</param>
        /// <param name="doubleRounds">
        /// The number of double rounds to perform. Half the total number of rounds,
        /// ex. ChaCha20 has 10 double rounds and ChaCha8 has 4 double rounds.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Thrown if <paramref name="doubleRounds"/> is equal to 0.
        /// </exception>
        public static ChaCha Create(Seed seed, UInt32 doubleRounds)
        {
            if (doubleRounds == 0)
            {
                throw new ArgumentOutOfRangeException(nameof(doubleRounds));
            }

            var key = seed.Key.Length != 0 ? seed.Key.Span : stackalloc UInt32[KeyLength];

#if X86_INTRINSICS
            var core        = ChaChaIntrinsics.Create(key, UInt64.MaxValue, seed.Stream, doubleRounds);
            var blockBuffer = new BlockBuffer32 <ChaChaIntrinsics, UInt64>(core);
#else
            var core        = ChaChaSoftware.Create(key, UInt64.MaxValue, seed.Stream, doubleRounds);
            var blockBuffer = new BlockBuffer32 <ChaChaSoftware, UInt64>(core);
#endif
            return(new ChaCha(blockBuffer));
        }
Exemple #2
0
 private CryptoServiceProvider(RNGCryptoServiceProvider rng)
 {
     _buffer = new BlockBuffer32 <BlockCore>(new BlockCore(rng));
     _rng    = rng;
 }
Exemple #3
0
 private SystemCryptoRng(RandomNumberGenerator rng)
 {
     _buffer = new BlockBuffer32 <BlockCore>(new BlockCore(rng));
     _rng    = rng;
 }
Exemple #4
0
        private ChaCha(BlockBuffer32 <ChaChaSoftware, UInt64> blockBuffer)
#endif
        {
            _blockBuffer = blockBuffer;
        }
Exemple #5
0
 private ChaCha(BlockBuffer32 <ChaChaIntrinsics, UInt64> blockBuffer)