public void FIPS186_b(string testName, SHA384 hash, byte[] input, byte[] result)
 {
     byte[] output = hash.ComputeHash(input, 0, input.Length);
     Assert.AreEqual(result, output, testName + ".b.1");
     Assert.AreEqual(result, hash.Hash, testName + ".b.2");
     // required or next operation will still return old hash
     hash.Initialize();
 }
 public void FIPS186_d(string testName, SHA384 hash, byte[] input, byte[] result)
 {
     byte[] output = hash.TransformFinalBlock(input, 0, input.Length);
     // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
     // AssertEquals( testName + ".d.1", result, output );
     Assert.IsNotNull(output, testName + ".d.1");
     Assert.AreEqual(result, hash.Hash, testName + ".d.2");
     // required or next operation will still return old hash
     hash.Initialize();
 }
        public void FIPS186_c(string testName, SHA384 hash, byte[] input, byte[] result)
        {
            MemoryStream ms = new MemoryStream(input);

            byte[] output = hash.ComputeHash(ms);
            Assert.AreEqual(result, output, testName + ".c.1");
            Assert.AreEqual(result, hash.Hash, testName + ".c.2");
            // required or next operation will still return old hash
            hash.Initialize();
        }
        public static string HashExecutable(string path)
        {
            WindowsBinaryData r = ExecutableParser(path);

            byte[] selfHash;
            int    checkSumIndex = r.checkSumPos;
            int    tableIndex    = r.CertificateTableSizePos - 4;
            int    endIndex      = 0;

            if (r.CertificateTableAddress != 0)
            {
                endIndex = r.CertificateTableAddress;
            }

            if (endIndex == 0)
            {
                // Hash the entire file except the .msh at the end if .msh is present
                int mshLen = GetMshLengthFromExecutable(path);
                if (mshLen > 0)
                {
                    mshLen += 20;
                }
                using (SHA384 sha384 = SHA384Managed.Create())
                {
                    sha384.Initialize();
                    using (FileStream stream = File.OpenRead(path))
                    {
                        hashPortionOfStream(sha384, stream, 0, (int)stream.Length - mshLen); // Start --> end - (mshLen + 20)
                        sha384.TransformFinalBlock(new byte[0], 0, 0);
                        selfHash = sha384.Hash;
                    }
                }
                return(BitConverter.ToString(selfHash).Replace("-", string.Empty).ToLower());
            }

            using (SHA384 sha384 = SHA384Managed.Create())
            {
                sha384.Initialize();
                using (FileStream stream = File.OpenRead(path))
                {
                    hashPortionOfStream(sha384, stream, 0, checkSumIndex);              // Start --> checkSumIndex
                    sha384.TransformBlock(new byte[4], 0, 4, null, 0);                  // 4 zero bytes
                    hashPortionOfStream(sha384, stream, checkSumIndex + 4, tableIndex); // checkSumIndex + 4 --> tableIndex
                    sha384.TransformBlock(new byte[8], 0, 8, null, 0);                  // 8 zero bytes
                    hashPortionOfStream(sha384, stream, tableIndex + 8, endIndex);      // tableIndex + 8 --> endIndex
                    sha384.TransformFinalBlock(new byte[0], 0, 0);
                    selfHash = sha384.Hash;
                }
            }
            return(BitConverter.ToString(selfHash).Replace("-", string.Empty).ToLower());
        }
 public void FIPS186_e(string testName, SHA384 hash, byte[] input, byte[] result)
 {
     byte[] copy = new byte [input.Length];
     for (int i = 0; i < input.Length - 1; i++)
     {
         hash.TransformBlock(input, i, 1, copy, i);
     }
     byte[] output = hash.TransformFinalBlock(input, input.Length - 1, 1);
     // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
     // AssertEquals (testName + ".e.1", result, output);
     Assert.IsNotNull(output, testName + ".e.1");
     Assert.AreEqual(result, hash.Hash, testName + ".e.2");
     // required or next operation will still return old hash
     hash.Initialize();
 }
Beispiel #6
0
 public override void Initialize()
 {
     hash.Initialize();
 }
Beispiel #7
0
 public SHA384Hash()
 {
     _sha384 = SHA384.Create();
     _sha384.Initialize();
 }
 public override void Initialize()
 {
     _implementation.Initialize();
 }