public void Test()
        {
            Environment.CurrentDirectory = DataFolder;

            bool exists = File.Exists(TestFile);

            Assert.True(exists, "Test file not found");

            var     filtersList = new FiltersList();
            IFilter inputFilter = filtersList.GetFilter(TestFile);

            Assert.IsNotNull(inputFilter, "Filter for test file is not detected");

            IMediaImage image = ImageFormat.Detect(inputFilter);

            Assert.IsNotNull(image, "Image format for test file is not detected");

            Assert.AreEqual(true, image.Open(inputFilter), "Cannot open image for test file");

            var opticalInput = image as IOpticalMediaImage;

            Assert.IsNotNull(opticalInput, "Image format for test file is not for an optical disc");

            var ctx = new Crc32Context();

            Checksum trackChecksum = null;

            ulong previousTrackEnd = 0;

            List <Track> inputTracks = opticalInput.Tracks;

            foreach (Track currentTrack in inputTracks)
            {
                ulong sectors     = currentTrack.TrackEndSector - currentTrack.TrackStartSector + 1;
                ulong doneSectors = 0;

                while (doneSectors < sectors)
                {
                    byte[] sector;

                    if (sectors - doneSectors >= SECTORS_TO_READ)
                    {
                        sector = opticalInput.ReadSectors(doneSectors, SECTORS_TO_READ, currentTrack.TrackSequence);

                        doneSectors += SECTORS_TO_READ;
                    }
                    else
                    {
                        sector = opticalInput.ReadSectors(doneSectors, (uint)(sectors - doneSectors),
                                                          currentTrack.TrackSequence);

                        doneSectors += sectors - doneSectors;
                    }

                    ctx.Update(sector);
                }

                previousTrackEnd = currentTrack.TrackEndSector;
            }
        }
예제 #2
0
        public void Crc32EmptyInstance()
        {
            byte[]     data = new byte[1048576];
            FileStream fs   = new FileStream(Path.Combine(Consts.TestFilesRoot, "checksums", "empty"), FileMode.Open,
                                             FileAccess.Read);

            fs.Read(data, 0, 1048576);
            fs.Close();
            fs.Dispose();
            IChecksum ctx = new Crc32Context();

            ctx.Update(data);
            byte[] result = ctx.Final();
            Assert.AreEqual(ExpectedEmpty, result);
        }
예제 #3
0
파일: CRC32.cs 프로젝트: paulyc/Aaru
        public void Crc32RandomInstance()
        {
            byte[] data = new byte[1048576];

            var fs = new FileStream(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "random"),
                                    FileMode.Open, FileAccess.Read);

            fs.Read(data, 0, 1048576);
            fs.Close();
            fs.Dispose();
            IChecksum ctx = new Crc32Context();

            ctx.Update(data);
            byte[] result = ctx.Final();
            Assert.AreEqual(_expectedRandom, result);
        }
예제 #4
0
파일: CRC32.cs 프로젝트: arrowsmith001/Aaru
        public void EmptyInstance()
        {
            byte[] data = new byte[1048576];

            var fs = new FileStream(Path.Combine(Consts.TEST_FILES_ROOT, "Checksum test files", "empty"), FileMode.Open,
                                    FileAccess.Read);

            fs.Read(data, 0, 1048576);
            fs.Close();
            fs.Dispose();
            IChecksum ctx = new Crc32Context();

            ctx.Update(data);
            byte[] result = ctx.Final();
            result.Should().BeEquivalentTo(_expectedEmpty);
        }
예제 #5
0
        public void Test()
        {
            Environment.CurrentDirectory = DataFolder;

            bool exists = File.Exists(TestFile);

            Assert.True(exists, "Test file not found");

            var     filtersList = new FiltersList();
            IFilter inputFilter = filtersList.GetFilter(TestFile);

            Assert.IsNotNull(inputFilter, "Filter for test file is not detected");

            IMediaImage image = ImageFormat.Detect(inputFilter);

            Assert.IsNotNull(image, "Image format for test file is not detected");

            Assert.AreEqual(true, image.Open(inputFilter), "Cannot open image for test file");

            ulong doneSectors = 0;
            var   ctx         = new Crc32Context();

            while (doneSectors < image.Info.Sectors)
            {
                byte[] sector;

                if (image.Info.Sectors - doneSectors >= SECTORS_TO_READ)
                {
                    sector       = image.ReadSectors(doneSectors, SECTORS_TO_READ);
                    doneSectors += SECTORS_TO_READ;
                }
                else
                {
                    sector       = image.ReadSectors(doneSectors, (uint)(image.Info.Sectors - doneSectors));
                    doneSectors += image.Info.Sectors - doneSectors;
                }

                ctx.Update(sector);
            }
        }
예제 #6
0
        public bool?VerifyMediaImage()
        {
            if (_discImage.DiscHashes.Count == 0)
            {
                return(null);
            }

            // Read up to 1 MiB at a time for verification
            const int verifySize = 1024 * 1024;
            long      readBytes;

            byte[] verifyBytes;

            IFilter[] filters = _discImage.Tracks.OrderBy(t => t.Sequence).Select(t => t.TrackFile.DataFilter).
                                Distinct().ToArray();

            if (_discImage.DiscHashes.TryGetValue("sha1", out string sha1))
            {
                var ctx = new Sha1Context();

                foreach (IFilter filter in filters)
                {
                    Stream stream = filter.GetDataForkStream();
                    readBytes   = 0;
                    verifyBytes = new byte[verifySize];

                    while (readBytes + verifySize < stream.Length)
                    {
                        stream.Read(verifyBytes, 0, verifyBytes.Length);
                        ctx.Update(verifyBytes);
                        readBytes += verifyBytes.LongLength;
                    }

                    verifyBytes = new byte[stream.Length - readBytes];
                    stream.Read(verifyBytes, 0, verifyBytes.Length);
                    ctx.Update(verifyBytes);
                }

                string verifySha1 = ctx.End();
                AaruConsole.DebugWriteLine("CDRWin plugin", "Calculated SHA1: {0}", verifySha1);
                AaruConsole.DebugWriteLine("CDRWin plugin", "Expected SHA1: {0}", sha1);

                return(verifySha1 == sha1);
            }

            if (_discImage.DiscHashes.TryGetValue("md5", out string md5))
            {
                var ctx = new Md5Context();

                foreach (IFilter filter in filters)
                {
                    Stream stream = filter.GetDataForkStream();
                    readBytes   = 0;
                    verifyBytes = new byte[verifySize];

                    while (readBytes + verifySize < stream.Length)
                    {
                        stream.Read(verifyBytes, 0, verifyBytes.Length);
                        ctx.Update(verifyBytes);
                        readBytes += verifyBytes.LongLength;
                    }

                    verifyBytes = new byte[stream.Length - readBytes];
                    stream.Read(verifyBytes, 0, verifyBytes.Length);
                    ctx.Update(verifyBytes);
                }

                string verifyMd5 = ctx.End();
                AaruConsole.DebugWriteLine("CDRWin plugin", "Calculated MD5: {0}", verifyMd5);
                AaruConsole.DebugWriteLine("CDRWin plugin", "Expected MD5: {0}", md5);

                return(verifyMd5 == md5);
            }

            if (_discImage.DiscHashes.TryGetValue("crc32", out string crc32))
            {
                var ctx = new Crc32Context();

                foreach (IFilter filter in filters)
                {
                    Stream stream = filter.GetDataForkStream();
                    readBytes   = 0;
                    verifyBytes = new byte[verifySize];

                    while (readBytes + verifySize < stream.Length)
                    {
                        stream.Read(verifyBytes, 0, verifyBytes.Length);
                        ctx.Update(verifyBytes);
                        readBytes += verifyBytes.LongLength;
                    }

                    verifyBytes = new byte[stream.Length - readBytes];
                    stream.Read(verifyBytes, 0, verifyBytes.Length);
                    ctx.Update(verifyBytes);
                }

                string verifyCrc = ctx.End();
                AaruConsole.DebugWriteLine("CDRWin plugin", "Calculated CRC32: {0}", verifyCrc);
                AaruConsole.DebugWriteLine("CDRWin plugin", "Expected CRC32: {0}", crc32);

                return(verifyCrc == crc32);
            }

            foreach (string hash in _discImage.DiscHashes.Keys)
            {
                AaruConsole.DebugWriteLine("CDRWin plugin", "Found unsupported hash {0}", hash);
            }

            return(null);
        }
예제 #7
0
        public static BenchmarkResults Do(int bufferSize, int blockSize)
        {
            BenchmarkResults results = new BenchmarkResults
            {
                Entries      = new Dictionary <string, BenchmarkEntry>(),
                MinMemory    = long.MaxValue,
                MaxMemory    = 0,
                SeparateTime = 0
            };
            MemoryStream ms  = new MemoryStream(bufferSize);
            Random       rnd = new Random();
            DateTime     start;
            DateTime     end;

            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Writing block {0} of {1} with random data.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                rnd.NextBytes(tmp);
                ms.Write(tmp, 0, blockSize);
            }

            EndProgress();
            end = DateTime.Now;

            results.FillTime  = (end - start).TotalSeconds;
            results.FillSpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds;

            ms.Seek(0, SeekOrigin.Begin);
            long mem = GC.GetTotalMemory(false);

            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Reading block {0} of {1}.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
            }

            EndProgress();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.ReadTime  = (end - start).TotalSeconds;
            results.ReadSpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds;

            #region Adler32
            IChecksum ctx = new Adler32Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with Adler32.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("Adler32",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion Adler32

            #region Fletcher16
            ctx = new Fletcher16Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with Fletcher-16.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("Fletcher16",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion Fletcher16

            #region Fletcher32
            ctx = new Fletcher32Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with Fletcher-32.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("Fletcher32",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion Fletcher32

            #region CRC16
            ctx = new Crc16Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with CRC16.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("CRC16",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion CRC16

            #region CRC32
            ctx = new Crc32Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with CRC32.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("CRC32",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion CRC32

            #region CRC64
            ctx = new Crc64Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with CRC64.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("CRC64",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion CRC64

            #region MD5
            ctx = new Md5Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with MD5.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("MD5",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion MD5

            #if !NETSTANDARD2_0
            #region RIPEMD160
            ctx = new Ripemd160Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with RIPEMD160.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("RIPEMD160",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion RIPEMD160
            #endif

            #region SHA1
            ctx = new Sha1Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with SHA1.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("SHA1",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion SHA1

            #region SHA256
            ctx = new Sha256Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with SHA256.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("SHA256",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion SHA256

            #region SHA384
            ctx = new Sha384Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with SHA384.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("SHA384",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion SHA384

            #region SHA512
            ctx = new Sha512Context();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with SHA512.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("SHA512",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion SHA512

            #region SpamSum
            ctx = new SpamSumContext();
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Checksumming block {0} of {1} with SpamSum.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                ctx.Update(tmp);
            }

            EndProgress();
            ctx.End();
            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.Entries.Add("SpamSum",
                                new BenchmarkEntry
            {
                TimeSpan = (end - start).TotalSeconds,
                Speed    = bufferSize / 1048576.0 / (end - start).TotalSeconds
            });
            results.SeparateTime += (end - start).TotalSeconds;
            #endregion SpamSum

            #region Entropy
            ulong[] entTable = new ulong[256];
            ms.Seek(0, SeekOrigin.Begin);
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }
            start = DateTime.Now;
            InitProgress();
            for (int i = 0; i < bufferSize / blockSize; i++)
            {
                UpdateProgress("Entropying block {0} of {1}.", i + 1, bufferSize / blockSize);
                byte[] tmp = new byte[blockSize];
                ms.Read(tmp, 0, blockSize);
                foreach (byte b in tmp)
                {
                    entTable[b]++;
                }
            }

            EndProgress();

            end = DateTime.Now;
            mem = GC.GetTotalMemory(false);
            if (mem > results.MaxMemory)
            {
                results.MaxMemory = mem;
            }
            if (mem < results.MinMemory)
            {
                results.MinMemory = mem;
            }

            results.EntropyTime  = (end - start).TotalSeconds;
            results.EntropySpeed = bufferSize / 1048576.0 / (end - start).TotalSeconds;
            #endregion Entropy

            /*
             #region Multitasking
             * start                 = DateTime.Now;
             * Checksum allChecksums = new Checksum();
             * InitProgress();
             * for(int i = 0; i < bufferSize / blockSize; i++)
             * {
             *  UpdateProgress("Checksumming block {0} of {1} with all algorithms at the same time.", i + 1,
             *                 bufferSize / blockSize);
             *  byte[] tmp = new byte[blockSize];
             *  ms.Read(tmp, 0, blockSize);
             *
             *  allChecksums.Update(tmp);
             * }
             *
             * EndProgress();
             *
             * allChecksums.End();
             * end                                           = DateTime.Now;
             * mem                                           = GC.GetTotalMemory(false);
             * if(mem > results.MaxMemory) results.MaxMemory = mem;
             * if(mem < results.MinMemory) results.MinMemory = mem;
             *
             * results.TotalTime  = (end - start).TotalSeconds;
             * results.TotalSpeed = bufferSize / 1048576.0 / results.TotalTime;
             #endregion
             */
            results.SeparateSpeed = bufferSize / 1048576.0 / results.SeparateTime;

            return(results);
        }