public void Digest(ReadOnlySpan <byte> data, Span <byte> result, params object[] extra) { Contract.RequiresNonNull(extra, nameof(extra)); Contract.Requires <ArgumentException>(extra.Length > 0, $"{nameof(extra)} must not be empty"); Contract.Requires <ArgumentException>(result.Length >= 32, $"{nameof(result)} must be greater or equal 32 bytes"); // concat nTime as hex string to data var nTime = (ulong)extra[0]; var nTimeHex = nTime.ToString("X").HexToByteArray(); Span <byte> dataEx = stackalloc byte[data.Length + nTimeHex.Length]; data.CopyTo(dataEx); if (nTimeHex.Length > 0) { var dest = dataEx.Slice(data.Length); nTimeHex.CopyTo(dest); } fixed(byte *input = dataEx) { fixed(byte *output = result) { LibMultihash.kezzak(input, output, (uint)data.Length); } } }
public byte[] Digest(byte[] data, params object[] extra) { Assertion.RequiresNonNull(data, nameof(data)); Assertion.RequiresNonNull(extra, nameof(extra)); Assertion.Requires <ArgumentException>(extra.Length > 0, $"{nameof(extra)} must not be empty"); var nTime = (ulong)extra[0]; var dataEx = data.Concat(nTime.ToString("X").HexToByteArray()).ToArray(); var result = new byte[32]; fixed(byte *input = dataEx) { fixed(byte *output = result) { LibMultihash.kezzak(input, output, (uint)data.Length); } } return(result); }