コード例 #1
0
        private void DoInit(Argon2Parameters parameters)
        {
            // 2. Align memory size
            // Minimum memoryBlocks = 8L blocks, where L is the number of lanes */
            var memoryBlocks = parameters.Memory;

            memoryBlocks = Math.Max(memoryBlocks, 2 * ARGON2_SYNC_POINTS * parameters.Lanes);

            _segmentLength = memoryBlocks / (_parameters.Lanes * ARGON2_SYNC_POINTS);
            _laneLength    = _segmentLength * ARGON2_SYNC_POINTS;

            // Ensure that all segments have equal length
            memoryBlocks = _segmentLength * parameters.Lanes * ARGON2_SYNC_POINTS;

            InitializeMemory(memoryBlocks);
        }
コード例 #2
0
        private static byte[] InitialHash(Argon2Parameters parameters, int outputLength,
                                          byte[] password)
        {
            var blake2B = MakeBlake2BInstanceAndInitialize(ARGON2_PREHASH_DIGEST_LENGTH);

            AddIntToLittleEndian(blake2B, parameters.Lanes);
            AddIntToLittleEndian(blake2B, outputLength);
            AddIntToLittleEndian(blake2B, parameters.Memory);
            AddIntToLittleEndian(blake2B, parameters.Iterations);
            AddIntToLittleEndian(blake2B, (int)parameters.Version);
            AddIntToLittleEndian(blake2B, (int)parameters.Type);

            AddByteString(blake2B, password);
            AddByteString(blake2B, parameters.Salt);

            AddByteString(blake2B, parameters.Secret);
            AddByteString(blake2B, parameters.Additional);

            return(blake2B.TransformFinal().GetBytes());
        }
コード例 #3
0
        /// <summary>
        /// Initialise the <see cref="PBKDFArgon2NotBuiltIn" />
        /// from the octets and parameter object.
        /// </summary>
        /// <param name="password">
        /// the octets to use.
        /// </param>
        /// <param name="parameters">
        /// Argon2 configuration.
        /// </param>
        internal PBKDFArgon2NotBuiltIn(byte[] password, Argon2Parameters parameters)
        {
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            _password   = ArrayUtils.Clone(password);
            _parameters = parameters.Clone();

            if (_parameters.Lanes < MIN_PARALLELISM)
            {
                throw new ArgumentException(string.Format(LanesTooSmall, MIN_PARALLELISM));
            }

            if (_parameters.Lanes > MAX_PARALLELISM)
            {
                throw new ArgumentException(string.Format(LanesTooBig, MAX_PARALLELISM));
            }

            if (_parameters.Memory < 8 * _parameters.Lanes)
            {
                throw new ArgumentException(string.Format(MemoryTooSmall, _parameters.Memory,
                                                          8 * _parameters.Lanes));
            }

            if (_parameters.Iterations < MIN_ITERATIONS)
            {
                throw new ArgumentException(string.Format(IterationsTooSmall, MIN_ITERATIONS));
            }

            DoInit(parameters);
        }