Example #1
0
        /// <summary>
        /// Hashes a list of byte arrays, prefixing each one with its length.
        /// </summary>
        public byte[] Sum(byte[] domain, params byte[][] datas)
        {
            using (var stream = new MemoryStream())
            {
                byte[] ulongBytes;

                foreach (var data in datas)
                {
                    ulongBytes = this.UInt64ToBytes((ulong)data.Length);

                    stream.Write(ulongBytes, 0, ulongBytes.Length);
                    stream.Write(data, 0, data.Length);
                }

                ulongBytes = this.UInt64ToBytes((ulong)domain.Length);

                stream.Write(ulongBytes, 0, ulongBytes.Length);
                stream.Write(domain, 0, domain.Length);

                var result = stream.ToArray();

                byte[] hash;
                var    sha = new Sha512tDigest(256);

                try
                {
                    sha.BlockUpdate(result, 0, result.Length);
                    hash = new byte[sha.GetDigestSize()];
                    sha.DoFinal(hash, 0);
                }
                finally
                {
                    sha.Finish();
                }

                return(hash);
            }
        }
Example #2
0
 public override void Initialize()
 {
     HashValue = new byte[_digest.GetDigestSize()];
 }