/// <summary> /// Generate hash for passwords /// </summary> /// <param name="indata"></param> /// <param name="challenge"></param> /// <param name="options"></param> /// <returns></returns> public static string GenerateHash(string indata, string challenge, Options options) { Sum sum = new Sum(options); sum.Init(0); sum.Update(Encoding.ASCII.GetBytes(indata), 0, indata.Length); sum.Update(Encoding.ASCII.GetBytes(challenge), 0, challenge.Length); byte[] buf = sum.End(); string hash = Convert.ToBase64String(buf); return hash.Substring(0, (buf.Length * 8 + 5) / 6); }
/// <summary> /// Generate hash for passwords /// </summary> /// <param name="indata"></param> /// <param name="challenge"></param> /// <param name="options"></param> /// <returns></returns> public static string GenerateHash(string indata, string challenge, Options options) { var sum = new Sum(options); sum.Init(0); sum.Update(Encoding.ASCII.GetBytes(indata), 0, indata.Length); sum.Update(Encoding.ASCII.GetBytes(challenge), 0, challenge.Length); var buf = sum.End(); var hash = Convert.ToBase64String(buf); return(hash.Substring(0, (buf.Length * 8 + 5) / 6)); }
public void Matched(IOStream f, SumStruct s, MapFile buf, int offset, int i, Sum sum) { int n = offset - lastMatch; int j; if (options.verbose > 2 && i >= 0) { Log.WriteLine("match at " + offset + " last_match=" + lastMatch + " j=" + i + " len=" + s.sums[i].len + " n=" + n); } Token token = new Token(options); token.SendToken(f, i, buf, lastMatch, n, (int)(i < 0?0:s.sums[i].len)); dataTransfer += n; if (i >= 0) { Options.stats.matchedData += s.sums[i].len; n += (int)s.sums[i].len; } for (j = 0; j < n; j += CHUNK_SIZE) { int n1 = Math.Min(CHUNK_SIZE, n - j); int off = buf.MapPtr(lastMatch + j, n1); sum.Update(buf.p, off, n1); } if (i >= 0) { lastMatch = (int)(offset + s.sums[i].len); } else { lastMatch = offset; } if (buf != null && options.doProgress) { Progress.ShowProgress(lastMatch, buf.fileSize); if (i == -1) { Progress.EndProgress(buf.fileSize); } } }
public void Matched(IoStream f, SumStruct s, MapFile buf, int offset, int i, Sum sum) { var n = offset - _lastMatch; int j; if (_options.Verbose > 2 && i >= 0) { Log.WriteLine("match at " + offset + " last_match=" + _lastMatch + " j=" + i + " len=" + s.Sums[i].Len + " n=" + n); } var token = new Token(_options); token.SendToken(f, i, buf, _lastMatch, n, (int)(i < 0 ? 0 : s.Sums[i].Len)); _dataTransfer += n; if (i >= 0) { Options.Stats.MatchedData += s.Sums[i].Len; n += (int)s.Sums[i].Len; } for (j = 0; j < n; j += ChunkSize) { var n1 = Math.Min(ChunkSize, n - j); var off = buf.MapPtr(_lastMatch + j, n1); sum.Update(buf.P, off, n1); } if (i >= 0) { _lastMatch = (int)(offset + s.Sums[i].Len); } else { _lastMatch = offset; } if (buf != null && _options.DoProgress) { Progress.ShowProgress(_lastMatch, buf.FileSize); if (i == -1) { Progress.EndProgress(buf.FileSize); } } }
public static string gen_challenge(string addr, Options opt) { string challenge = ""; byte[] input = new byte[32]; DateTime tv = DateTime.Now; for(int i=0; i < addr.Length; i++) input[i] = Convert.ToByte(addr[i]); CheckSum.SIVAL(ref input, 16, (UInt32)tv.Second); CheckSum.SIVAL(ref input, 20, (UInt32)tv.Hour); CheckSum.SIVAL(ref input, 24, (UInt32)tv.Day); Sum sum = new Sum(opt); sum.Init(0); sum.Update(input,0,input.Length); challenge = Encoding.ASCII.GetString(sum.End()); return challenge; }
/// <summary> /// Generates challenge using time as vector /// </summary> /// <param name="addr"></param> /// <param name="opt"></param> /// <returns></returns> public static string GenerateChallenge(string addr, Options opt) { var challenge = String.Empty; var input = new byte[32]; var timeVector = DateTime.Now; for (var i = 0; i < addr.Length; i++) { input[i] = Convert.ToByte(addr[i]); } CheckSum.Sival(ref input, 16, (UInt32)timeVector.Second); CheckSum.Sival(ref input, 20, (UInt32)timeVector.Hour); CheckSum.Sival(ref input, 24, (UInt32)timeVector.Day); var sum = new Sum(opt); sum.Init(0); sum.Update(input, 0, input.Length); challenge = Encoding.ASCII.GetString(sum.End()); return(challenge); }
public static string gen_challenge(string addr, Options opt) { string challenge = ""; byte[] input = new byte[32]; DateTime tv = DateTime.Now; for (int i = 0; i < addr.Length; i++) { input[i] = Convert.ToByte(addr[i]); } CheckSum.SIVAL(ref input, 16, (UInt32)tv.Second); CheckSum.SIVAL(ref input, 20, (UInt32)tv.Hour); CheckSum.SIVAL(ref input, 24, (UInt32)tv.Day); Sum sum = new Sum(opt); sum.Init(0); sum.Update(input, 0, input.Length); challenge = Encoding.ASCII.GetString(sum.End()); return(challenge); }
public void Matched(IOStream f, SumStruct s, MapFile buf, int offset, int i, Sum sum) { int n = offset - lastMatch; int j; if (options.verbose > 2 && i >= 0) Log.WriteLine("match at " + offset +" last_match=" + lastMatch + " j=" + i + " len=" + s.sums[i].len + " n=" + n); Token token = new Token(options); token.SendToken(f,i,buf,lastMatch,n,(int)(i<0?0:s.sums[i].len)); dataTransfer += n; if (i >= 0) { Options.stats.matchedData += s.sums[i].len; n += (int)s.sums[i].len; } for (j = 0; j < n; j += CHUNK_SIZE) { int n1 = Math.Min(CHUNK_SIZE,n-j); int off = buf.MapPtr(lastMatch + j, n1); sum.Update(buf.p , off, n1); } if (i >= 0) lastMatch = (int)(offset + s.sums[i].len); else lastMatch = offset; if (buf != null && options.doProgress) { Progress.ShowProgress(lastMatch, buf.fileSize); if (i == -1) Progress.EndProgress(buf.fileSize); } }
public bool ReceiveData(ClientInfo clientInfo, string fileNameR, Stream fdR, long sizeR, string fileName, Stream fd, int totalSize) { IOStream f = clientInfo.IoStream; byte[] fileSum1 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] fileSum2 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] data = new byte[Match.CHUNK_SIZE]; SumStruct sumStruct = new SumStruct(); MapFile mapBuf = null; Sender sender = new Sender(options); sender.ReadSumHead(clientInfo, ref sumStruct); int offset = 0; UInt32 len; if (fdR != null && sizeR > 0) { int mapSize = (int)Math.Max(sumStruct.bLength * 2, 16 * 1024); mapBuf = new MapFile(fdR, (int)sizeR, mapSize, (int)sumStruct.bLength); if (options.verbose > 2) { Log.WriteLine("recv mapped " + fileNameR + " of size " + sizeR); } } Sum sum = new Sum(options); sum.Init(options.checksumSeed); int i; Token token = new Token(options); while ((i = token.ReceiveToken(f, ref data, 0)) != 0) { if (options.doProgress) { Progress.ShowProgress(offset, totalSize); } if (i > 0) { if (options.verbose > 3) { Log.WriteLine("data recv " + i + " at " + offset); } Options.stats.literalData += i; sum.Update(data, 0, i); if (fd != null && FileIO.WriteFile(fd, data, 0, i) != i) { goto report_write_error; } offset += i; continue; } i = -(i + 1); int offset2 = (int)(i * sumStruct.bLength); len = sumStruct.bLength; if (i == sumStruct.count - 1 && sumStruct.remainder != 0) { len = sumStruct.remainder; } Options.stats.matchedData += len; if (options.verbose > 3) { Log.WriteLine("chunk[" + i + "] of size " + len + " at " + offset2 + " offset=" + offset); } byte[] map = null; int off = 0; if (mapBuf != null) { off = mapBuf.MapPtr(offset2, (int)len); map = mapBuf.p; token.SeeToken(map, offset, (int)len); sum.Update(map, off, (int)len); } if (options.inplace) { if (offset == offset2 && fd != null) { offset += (int)len; if (fd.Seek(len, SeekOrigin.Current) != offset) { MainClass.Exit("seek failed on " + Util.fullFileName(fileName), clientInfo); } continue; } } if (fd != null && FileIO.WriteFile(fd, map, off, (int)len) != (int)len) { goto report_write_error; } offset += (int)len; } if (options.doProgress) { Progress.EndProgress(totalSize); } if (fd != null && offset > 0 && FileIO.SparseEnd(fd) != 0) { MainClass.Exit("write failed on " + Util.fullFileName(fileName), clientInfo); } fileSum1 = sum.End(); if (mapBuf != null) { mapBuf = null; } fileSum2 = f.ReadBuffer(CheckSum.MD4_SUM_LENGTH); if (options.verbose > 2) { Log.WriteLine("got fileSum"); } if (fd != null && Util.MemoryCompare(fileSum1, 0, fileSum2, 0, CheckSum.MD4_SUM_LENGTH) != 0) { return false; } return true; report_write_error: { MainClass.Exit("write failed on " + Util.fullFileName(fileName), clientInfo); } return true; }
public bool ReceiveData(ClientInfo clientInfo, string fileNameR, Stream fdR, long sizeR, string fileName, Stream fd, int totalSize) { var f = clientInfo.IoStream; var fileSum1 = new byte[CheckSum.Md4SumLength]; var fileSum2 = new byte[CheckSum.Md4SumLength]; var data = new byte[Match.ChunkSize]; var sumStruct = new SumStruct(); MapFile mapBuf = null; var sender = new Sender(_options); sender.ReadSumHead(clientInfo, ref sumStruct); var offset = 0; UInt32 len; if (fdR != null && sizeR > 0) { var mapSize = (int)Math.Max(sumStruct.BLength * 2, 16 * 1024); mapBuf = new MapFile(fdR, (int)sizeR, mapSize, (int)sumStruct.BLength); if (_options.Verbose > 2) { Log.WriteLine("recv mapped " + fileNameR + " of size " + sizeR); } } var sum = new Sum(_options); sum.Init(_options.ChecksumSeed); int i; var token = new Token(_options); while ((i = token.ReceiveToken(f, ref data, 0)) != 0) { if (_options.DoProgress) { Progress.ShowProgress(offset, totalSize); } if (i > 0) { if (_options.Verbose > 3) { Log.WriteLine("data recv " + i + " at " + offset); } Options.Stats.LiteralData += i; sum.Update(data, 0, i); if (fd != null && FileIo.WriteFile(fd, data, 0, i) != i) { goto report_write_error; } offset += i; continue; } i = -(i + 1); var offset2 = (int)(i * sumStruct.BLength); len = sumStruct.BLength; if (i == sumStruct.Count - 1 && sumStruct.Remainder != 0) { len = sumStruct.Remainder; } Options.Stats.MatchedData += len; if (_options.Verbose > 3) { Log.WriteLine("chunk[" + i + "] of size " + len + " at " + offset2 + " offset=" + offset); } byte[] map = null; var off = 0; if (mapBuf != null) { off = mapBuf.MapPtr(offset2, (int)len); map = mapBuf.P; token.SeeToken(map, offset, (int)len); sum.Update(map, off, (int)len); } if (_options.Inplace) { if (offset == offset2 && fd != null) { offset += (int)len; if (fd.Seek(len, SeekOrigin.Current) != offset) { WinRsync.Exit("seek failed on " + Util.FullFileName(fileName), clientInfo); } continue; } } if (fd != null && FileIo.WriteFile(fd, map, off, (int)len) != (int)len) { goto report_write_error; } offset += (int)len; } if (_options.DoProgress) { Progress.EndProgress(totalSize); } if (fd != null && offset > 0 && FileIo.SparseEnd(fd) != 0) { WinRsync.Exit("write failed on " + Util.FullFileName(fileName), clientInfo); } fileSum1 = sum.End(); if (mapBuf != null) { mapBuf = null; } fileSum2 = f.ReadBuffer(CheckSum.Md4SumLength); if (_options.Verbose > 2) { Log.WriteLine("got fileSum"); } if (fd != null && Util.MemoryCompare(fileSum1, 0, fileSum2, 0, CheckSum.Md4SumLength) != 0) { return(false); } return(true); report_write_error: { WinRsync.Exit("write failed on " + Util.FullFileName(fileName), clientInfo); } return(true); }
public bool ReceiveData(ClientInfo clientInfo, string fileNameR, Stream fdR, long sizeR, string fileName, Stream fd, int totalSize) { IOStream f = clientInfo.IoStream; byte[] fileSum1 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] fileSum2 = new byte[CheckSum.MD4_SUM_LENGTH]; byte[] data = new byte[Match.CHUNK_SIZE]; SumStruct sumStruct = new SumStruct(); MapFile mapBuf = null; Sender sender = new Sender(options); sender.ReadSumHead(clientInfo, ref sumStruct); int offset = 0; UInt32 len; if (fdR != null && sizeR > 0) { int mapSize = (int)Math.Max(sumStruct.bLength * 2, 16 * 1024); mapBuf = new MapFile(fdR, (int)sizeR, mapSize, (int)sumStruct.bLength); if (options.verbose > 2) { Log.WriteLine("recv mapped " + fileNameR + " of size " + sizeR); } } Sum sum = new Sum(options); sum.Init(options.checksumSeed); int i; Token token = new Token(options); while ((i = token.ReceiveToken(f, ref data, 0)) != 0) { if (options.doProgress) { Progress.ShowProgress(offset, totalSize); } if (i > 0) { if (options.verbose > 3) { Log.WriteLine("data recv " + i + " at " + offset); } Options.stats.literalData += i; sum.Update(data, 0, i); if (fd != null && FileIO.WriteFile(fd, data, 0, i) != i) { goto report_write_error; } offset += i; continue; } i = -(i + 1); int offset2 = (int)(i * sumStruct.bLength); len = sumStruct.bLength; if (i == sumStruct.count - 1 && sumStruct.remainder != 0) { len = sumStruct.remainder; } Options.stats.matchedData += len; if (options.verbose > 3) { Log.WriteLine("chunk[" + i + "] of size " + len + " at " + offset2 + " offset=" + offset); } byte[] map = null; int off = 0; if (mapBuf != null) { off = mapBuf.MapPtr(offset2, (int)len); map = mapBuf.p; token.SeeToken(map, offset, (int)len); sum.Update(map, off, (int)len); } if (options.inplace) { if (offset == offset2 && fd != null) { offset += (int)len; if (fd.Seek(len, SeekOrigin.Current) != offset) { MainClass.Exit("seek failed on " + Util.fullFileName(fileName), clientInfo); } continue; } } if (fd != null && FileIO.WriteFile(fd, map, off, (int)len) != (int)len) { goto report_write_error; } offset += (int)len; } if (options.doProgress) { Progress.EndProgress(totalSize); } if (fd != null && offset > 0 && FileIO.SparseEnd(fd) != 0) { MainClass.Exit("write failed on " + Util.fullFileName(fileName), clientInfo); } fileSum1 = sum.End(); if (mapBuf != null) { mapBuf = null; } fileSum2 = f.ReadBuffer(CheckSum.MD4_SUM_LENGTH); if (options.verbose > 2) { Log.WriteLine("got fileSum"); } if (fd != null && Util.MemoryCompare(fileSum1, 0, fileSum2, 0, CheckSum.MD4_SUM_LENGTH) != 0) { return(false); } return(true); report_write_error: { MainClass.Exit("write failed on " + Util.fullFileName(fileName), clientInfo); } return(true); }