HarakaS512Digest
using System;
namespace Org.BouncyCastle.Pqc.Crypto.SphincsPlus
{
internal sealed class HarakaS512Digest : HarakaSBase
{
public string AlgorithmName => "HarakaS-512";
public HarakaS512Digest(HarakaSBase harakaSBase)
{
haraka512_rc = harakaSBase.haraka512_rc;
}
public int GetDigestSize()
{
return 32;
}
public void Update(byte input)
{
if (off > 63)
throw new ArgumentException("total input cannot be more than 64 bytes");
buffer[off++] = input;
}
public void BlockUpdate(byte[] input, int inOff, int len)
{
if (off > 64 - len)
throw new ArgumentException("total input cannot be more than 64 bytes");
Array.Copy(input, inOff, buffer, off, len);
off += len;
}
public void BlockUpdate(ReadOnlySpan<byte> input)
{
if (off > 64 - input.Length)
throw new ArgumentException("total input cannot be more than 64 bytes");
input.CopyTo(buffer.AsSpan(off));
off += input.Length;
}
public int DoFinal(byte[] output, int outOff)
{
byte[] array = new byte[64];
Haraka512Perm(array);
HarakaSBase.Xor(array, 8, buffer, 8, output, outOff, 8);
HarakaSBase.Xor(array, 24, buffer, 24, output, outOff + 8, 16);
HarakaSBase.Xor(array, 48, buffer, 48, output, outOff + 24, 8);
Reset();
return 32;
}
public unsafe int DoFinal(Span<byte> output)
{
Span<byte> output2 = new Span<byte>(stackalloc byte[64], 64);
Haraka512Perm(output2);
HarakaSBase.Xor(output2.Slice(8, output2.Length - 8), buffer.AsSpan(8), output.Slice(0, 8));
HarakaSBase.Xor(output2.Slice(24, output2.Length - 24), buffer.AsSpan(24), output.Slice(8, 16));
HarakaSBase.Xor(output2.Slice(48, output2.Length - 48), buffer.AsSpan(48), output.Slice(24, 8));
Reset();
return 32;
}
}
}