/// <summary> /// The MAC key is the first 32 bytes of the first key stream block. /// </summary> /// <param name="nonce">The nonce.</param> /// <returns>System.Byte[].</returns> private Span <byte> GetMacKey(ReadOnlySpan <byte> nonce) { Span <byte> firstBlock = new byte[_macKeySnuffle.BlockSizeInBytes]; _macKeySnuffle.ProcessKeyStreamBlock(nonce, 0, firstBlock); return(firstBlock[..Poly1305.MAC_KEY_SIZE_IN_BYTES]);
/// <summary> /// The MAC key is the first 32 bytes of the first key stream block. /// </summary> /// <param name="nonce">The nonce.</param> /// <returns>System.Byte[].</returns> private Span <byte> GetMacKey(ReadOnlySpan <byte> nonce) { Span <byte> firstBlock = new byte[Snuffle.BLOCK_SIZE_IN_BYTES]; _macKeySnuffle.ProcessKeyStreamBlock(nonce, 0, firstBlock); return(firstBlock.Slice(0, Poly1305.MAC_KEY_SIZE_IN_BYTES)); }
/// <summary> /// The MAC key is the first 32 bytes of the first key stream block. /// </summary> /// <param name="nonce">The nonce.</param> /// <returns>System.Byte[].</returns> private SpanOwner <byte> GetMacKey(ReadOnlySpan <byte> nonce) { //var firstBlock = new byte[Snuffle.BLOCK_SIZE_IN_BYTES]; //_macKeySnuffle.ProcessKeyStreamBlock(nonce, 0, firstBlock); //var result = new byte[Poly1305.MAC_KEY_SIZE_IN_BYTES]; //Array.Copy(firstBlock, result, result.Length); //return result; using (var firstBlock = SpanOwner <byte> .Allocate(Snuffle.BLOCK_SIZE_IN_BYTES, AllocationMode.Clear)) { //Span<byte> firstBlock = new byte[Snuffle.BLOCK_SIZE_IN_BYTES]; _macKeySnuffle.ProcessKeyStreamBlock(nonce, 0, firstBlock.Span); var macKey = SpanOwner <byte> .Allocate(Poly1305.MAC_KEY_SIZE_IN_BYTES, AllocationMode.Clear); firstBlock.Span.Slice(0, Poly1305.MAC_KEY_SIZE_IN_BYTES).CopyTo(macKey.Span); firstBlock.Span.Clear(); return(macKey); } }