void IHashWorkManager.AddHashes(byte[] buffer, int start, int len, HASH.Platform.AsyncCancelCheck cancelCheck, HashFlags algos, HashFlags type, params HashFlags[] additionalTypes) { var allalgos = getAlgos(algos); if (allalgos.Count == 0) { throw new ArgumentException("Hash algorithm not specified."); } foreach (var algo in allalgos) { if (RomHash.IsHashRequired(Platform, algo | type)) { byte[] hash = null; if (cancelCheck == null || cancelCheck() == false) { switch (algo) { case HashFlags.MD5: hash = CalculateMD5(buffer, start, len); break; case HashFlags.SHA1: hash = CalculateSha1(buffer, start, len, cancelCheck); break; case HashFlags.SHA256: hash = CalculateSha256(buffer, start, len, cancelCheck); break; case HashFlags.CRC32: hash = CalculateCRC32(buffer, start, len); break; } } if (hash != null) { lock (HashesLock) { _Hashes.Add(new RomHash(hash, algo | type)); if (additionalTypes != null) { for (int i = 0; i < additionalTypes.Length; i++) { _Hashes.Add(new RomHash(hash, algo | additionalTypes[i])); } } } } } } }
private static byte[] CalculateSha256(byte[] rom, int start, int len, HASH.Platform.AsyncCancelCheck cancelChecker) { //byte[] copy = new byte[rom.Length]; var hash = SHA256.Create(); int size = 0x1000; int offset = 0; while (rom.Length - offset >= size) { if (cancelChecker != null && cancelChecker()) { return(null); } offset += hash.TransformBlock(rom, offset, size, rom, offset); } hash.TransformFinalBlock(rom, offset, rom.Length - offset); return(hash.Hash); }