public static void Update( ref IncrementalMac state, ReadOnlySpan <byte> data) { if (state._algorithm == null) { throw Error.InvalidOperation_UninitializedState(); } state._algorithm.UpdateCore(ref Unsafe.AsRef(in state._state), data); }
public static void Initialize( Key key, out IncrementalMac state) { if (key == null) { throw Error.ArgumentNull_Key(nameof(key)); } if (!(key.Algorithm is MacAlgorithm algorithm)) { throw Error.Argument_MacKeyRequired(nameof(key)); } state = default; algorithm.InitializeCore(key.Handle, out Unsafe.AsRef(in state._state)); Unsafe.AsRef(in state._algorithm) = algorithm; }
public static void Initialize( Key key, out IncrementalMac state) { if (key == null) { throw Error.ArgumentNull_Key(nameof(key)); } if (!(key.Algorithm is MacAlgorithm algorithm)) { throw Error.Argument_MacKey(nameof(key), key.Algorithm.GetType().FullName, typeof(MacAlgorithm).FullName); } state = default; algorithm.InitializeCore(key.Span, out Unsafe.AsRef(in state._state)); Unsafe.AsRef(in state._algorithm) = algorithm; }
public static bool FinalizeAndVerify( ref IncrementalMac state, ReadOnlySpan <byte> mac) { if (state._algorithm == null) { throw Error.InvalidOperation_UninitializedState(); } try { return(mac.Length == state._algorithm.MacSize && state._algorithm.FinalizeAndVerifyCore(ref Unsafe.AsRef(in state._state), mac)); } finally { Unsafe.AsRef <MacAlgorithm?>(in state._algorithm) = null; } }
public static byte[] Finalize( ref IncrementalMac state) { if (state._algorithm == null) { throw Error.InvalidOperation_UninitializedState(); } try { byte[] mac = new byte[state._algorithm.MacSize]; state._algorithm.FinalizeCore(ref Unsafe.AsRef(in state._state), mac); return(mac); } finally { Unsafe.AsRef <MacAlgorithm?>(in state._algorithm) = null; } }
public static void Finalize( ref IncrementalMac state, Span <byte> mac) { if (state._algorithm == null) { throw Error.InvalidOperation_UninitializedState(); } if (mac.Length != state._algorithm.MacSize) { throw Error.Argument_MacLength(nameof(mac), state._algorithm.MacSize); } try { state._algorithm.FinalizeCore(ref Unsafe.AsRef(in state._state), mac); } finally { Unsafe.AsRef <MacAlgorithm?>(in state._algorithm) = null; } }