コード例 #1
0
        private static byte[] MFcrypt(byte[] P, byte[] S,
                                      int cost, int blockSize, int parallel, int?maxThreads)
        {
            int MFLen = blockSize * 128;

            if (maxThreads == null)
            {
                maxThreads = int.MaxValue;
            }

            if (cost <= 0 || (cost & (cost - 1)) != 0)
            {
                throw new ArgumentOutOfRangeException("cost", "Cost must be a positive power of 2.");
            }
            Helper.CheckRange("blockSize", blockSize, 1, int.MaxValue / 32);
            Helper.CheckRange("parallel", parallel, 1, int.MaxValue / MFLen);
            Helper.CheckRange("maxThreads", (int)maxThreads, 1, int.MaxValue);

            byte[] B = new byte[parallel * MFLen];
            Pbkdf2.ComputeKey(P, S, 1, HmacCallback, HLen, B);

            uint[] B0 = new uint[B.Length / 4];
            for (int i = 0; i < B0.Length; i++)
            {
                B0[i] = Helper.BytesToUInt32LE(B, i * 4);
            } // code is easier with uint[]
            ThreadSMixCalls(B0, MFLen, cost, blockSize, parallel, (int)maxThreads);
            for (int i = 0; i < B0.Length; i++)
            {
                Helper.UInt32ToBytesLE(B0[i], B, i * 4);
            }
            Clear(B0);

            return(B);
        }
コード例 #2
0
 public static void ComputeKey(byte[] key, byte[] salt,
                               int cost, int blockSize, int parallel, int?maxThreads, byte[] output)
 {
     using (Pbkdf2 kdf = GetStream(key, salt, cost, blockSize, parallel, maxThreads))
     {
         kdf.Read(output);
     }
 }
コード例 #3
0
 public static void ComputeKey(byte[] key, byte[] salt, int iterations,
                               ComputeHmacCallback computeHmacCallback, int hmacLength, byte[] output)
 {
     using (Pbkdf2 kdf = new Pbkdf2(key, salt, iterations, computeHmacCallback, hmacLength))
     {
         kdf.Read(output);
     }
 }
コード例 #4
0
        public static Pbkdf2 GetStream(byte[] key, byte[] salt,
                                       int cost, int blockSize, int parallel, int?maxThreads)
        {
            byte[] B   = GetEffectivePbkdf2Salt(key, salt, cost, blockSize, parallel, maxThreads);
            var    kdf = new Pbkdf2(key, B, 1, HmacCallback, HLen);

            Clear(B);
            return(kdf);
        }