Пример #1
0
        public override byte[] Transform(byte[] pbMsg, KdfParameters p)
        {
            if (pbMsg == null)
            {
                throw new ArgumentNullException("pbMsg");
            }
            if (p == null)
            {
                throw new ArgumentNullException("p");
            }

            Type tRounds = p.GetTypeOf(ParamRounds);

            if (tRounds == null)
            {
                throw new ArgumentNullException("p.Rounds");
            }
            if (tRounds != typeof(ulong))
            {
                throw new ArgumentOutOfRangeException("p.Rounds");
            }
            ulong uRounds = p.GetUInt64(ParamRounds, 0);

            byte[] pbSeed = p.GetByteArray(ParamSeed);
            if (pbSeed == null)
            {
                throw new ArgumentNullException("p.Seed");
            }

            if (pbMsg.Length != 32)
            {
                Debug.Assert(false);
                pbMsg = CryptoUtil.HashSha256(pbMsg);
            }

            if (pbSeed.Length != 32)
            {
                Debug.Assert(false);
                pbSeed = CryptoUtil.HashSha256(pbSeed);
            }

            return(TransformKey(pbMsg, pbSeed, uRounds));
        }
Пример #2
0
        public override byte[] Transform(byte[] pbMsg, KdfParameters p)
        {
            if (pbMsg == null)
            {
                throw new ArgumentNullException("pbMsg");
            }
            if (p == null)
            {
                throw new ArgumentNullException("p");
            }

            byte[] pbSalt = p.GetByteArray(ParamSalt);
            if (pbSalt == null)
            {
                throw new ArgumentNullException("p.Salt");
            }
            if ((pbSalt.Length < MinSalt) || (pbSalt.Length > MaxSalt))
            {
                throw new ArgumentOutOfRangeException("p.Salt");
            }

            uint uPar = p.GetUInt32(ParamParallelism, 0);

            if ((uPar < MinParallelism) || (uPar > MaxParallelism))
            {
                throw new ArgumentOutOfRangeException("p.Parallelism");
            }

            ulong uMem = p.GetUInt64(ParamMemory, 0);

            if ((uMem < MinMemory) || (uMem > MaxMemory))
            {
                throw new ArgumentOutOfRangeException("p.Memory");
            }

            ulong uIt = p.GetUInt64(ParamIterations, 0);

            if ((uIt < MinIterations) || (uIt > MaxIterations))
            {
                throw new ArgumentOutOfRangeException("p.Iterations");
            }

            uint v = p.GetUInt32(ParamVersion, 0);

            if ((v < MinVersion) || (v > MaxVersion))
            {
                throw new ArgumentOutOfRangeException("p.Version");
            }

            byte[] pbSecretKey = p.GetByteArray(ParamSecretKey);
            byte[] pbAssocData = p.GetByteArray(ParamAssocData);

            byte[] pbRet = Argon2d(pbMsg, pbSalt, uPar, uMem, uIt,
                                   32, v, pbSecretKey, pbAssocData);

            if (uMem > (100UL * 1024UL * 1024UL))
            {
                GC.Collect();
            }
            return(pbRet);
        }