/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <param name="size"></param> /// <returns></returns> public byte[] FileCheckSum(string fileName, int size) { var mdFour = new MdFour(_options); using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { var buf = new MapFile(fileStream, size, Options.MaxMapSize, CsumChunk); mdFour.Begin(); int i; for (i = 0; i + CsumChunk <= size; i += CsumChunk) { var offset = buf.MapPtr(i, CsumChunk); mdFour.Update(buf.P, offset, CsumChunk); } if (size - i > 0 || _options.ProtocolVersion >= 27) { var offset = buf.MapPtr(i, size - i); mdFour.Update(buf.P, offset, (UInt32)(size - i)); } fileStream.Close(); return(mdFour.Result()); } }
/// <summary> /// /// </summary> /// <param name="buf"></param> /// <param name="pos"></param> /// <param name="len"></param> /// <returns></returns> public byte[] GetChecksum2(byte[] buf, int pos, int len) { var buf1 = new byte[len + 4]; for (var j = 0; j < len; j++) { buf1[j] = buf[pos + j]; } var mdFour = new MdFour(_options); mdFour.Begin(); if (_options.ChecksumSeed != 0) { Sival(ref buf1, len, (UInt32)_options.ChecksumSeed); len += 4; } int i; for (i = 0; i + CsumChunk <= len; i += CsumChunk) { mdFour.Update(buf1, i, CsumChunk); } if (len - i > 0 || _options.ProtocolVersion >= 27) { mdFour.Update(buf1, i, (UInt32)(len - i)); } return(mdFour.Result()); }
public void Init(int seed) { var s = new byte[4]; Md.Begin(); SumResidue = 0; CheckSum.Sival(ref s, 0, (UInt32)seed); Update(s, 0, 4); }