using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using OpenSSL.Crypto; namespace Pithos.Network { public class SHA1OpenSSL : SHA1 { private MessageDigestContext _context; public SHA1OpenSSL() { _context = new MessageDigestContext(MessageDigest.CreateByName("SHA1")); _context.Init(); } public override void Initialize() { _context.Init(); } protected override void HashCore(byte[] array, int ibStart, int cbSize) { if (array.Length == cbSize) _context.Update(array); else { var block = new byte[cbSize]; Buffer.BlockCopy(array, ibStart, block, 0, cbSize); _context.Update(block); } } protected override byte[] HashFinal() { return _context.DigestFinal(); } protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { if (_context != null) _context.Dispose(); _context = null; } } } public class SHA256OpenSSL : SHA256 { private MessageDigestContext _context; public SHA256OpenSSL() { _context = new MessageDigestContext(MessageDigest.CreateByName("SHA256")); _context.Init(); } public override void Initialize() { _context.Init(); } protected override void HashCore(byte[] array, int ibStart, int cbSize) { if (array.Length == cbSize) _context.Update(array); else { var block = new byte[cbSize]; Buffer.BlockCopy(array, ibStart, block, 0, cbSize); _context.Update(block); } } protected override byte[] HashFinal() { return _context.DigestFinal(); } protected override void Dispose(bool disposing) { base.Dispose(disposing); if (disposing) { if (_context != null) _context.Dispose(); _context = null; } } } }