Beispiel #1
0
        public override byte [] ComputeHash(byte [] buffer)
        {
            byte [] tempBa = (byte [])buffer.Clone();
            rgbInner = KeySetup(key, 0x36);
            rgbOuter = KeySetup(key, 0x5C);

            //SHA1CryptoServiceProvider scap = new SHA1CryptoServiceProvider();
            byte [] in1 = PSHA1.ConcatBa(rgbInner, tempBa);
            hash = mHashAlg.ComputeHash(in1);

            byte [] in2 = PSHA1.ConcatBa(rgbOuter, hash);
            hash = mHashAlg.ComputeHash(in2);

            return(hash);
        }
Beispiel #2
0
        /// <summary>
        /// Returns pseudo-random key bytes.
        /// </summary>
        /// <param name="cb">The number of pseudo-random key bytes to generate.</param>
        /// <returns>A byte array filled with pseudo-random key bytes.</returns>
        public override byte[] GetBytes(int cb)
        {
            //http://www.rsasecurity.com/rsalabs/node.asp?id=2127
            byte []       P  = Format.GetBytes(password);
            HashAlgorithm ha = new HMACSHA1(P);

            int hLen = 20;             //HMACSHA1 out is 20 bytes
            int L    = cb / hLen;
            int rem  = cb % hLen;

            if (rem != 0)
            {
                L = L + 1;                 //round up
            }
            int r = cb - (L - 1) * hLen;

            byte [] outL    = new byte[hLen * L];
            int     offsetL = 0;

            for (int k = 0; k < L; k++)
            {
                byte[] icb = BitConverter.GetBytes(internalCount);
                Array.Reverse(icb, 0, 4);
                byte [] salt_icb = PSHA1.ConcatBa(salt, icb);
                byte [] U        = ha.ComputeHash(salt_icb);
                byte[]  T        = U;
                for (int i = 2; i <= iterations; i++)
                {
                    U = ha.ComputeHash(U);
                    for (int j = 0; j < hLen; j++)
                    {
                        byte b1 = T[j];
                        byte b2 = U[j];
                        T[j] = (byte)(b1 ^ b2);
                    }
                }
                Array.Copy(T, 0, outL, offsetL, hLen);
                offsetL       = offsetL + hLen;
                internalCount = internalCount + 1;
            }

            byte[] key = new byte[cb];
            Array.Copy(outL, 0, key, 0, cb);
            return(key);
        }