summary refs log tree commit diff
path: root/crypto/src/pqc/crypto/sphincsplus/HarakaS256Digest.cs
blob: 1e2ef67cfd46d9ed759a86d684d3a72d8583a142 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
namespace Org.BouncyCastle.pqc.crypto.sphincsplus
{
    class HarakaS256Digest : HarakaSBase
    {
        public HarakaS256Digest(HarakaSXof harakaSXof)
        {
            haraka256_rc = harakaSXof.haraka256_rc;
        }

        public String GetAlgorithmName()
        {
            return "HarakaS-256";
        }

        public int GetDigestSize()
        {
            return 32;
        }

        public void BlockUpdate(byte input)
        {
            if (off + 1 > 32)
            {
                throw new ArgumentException("total input cannot be more than 32 bytes");
            }

            buffer[off++] = input;
        }

        public void BlockUpdate(byte[] input, int inOff, int len)
        {
            if (off + len > 32)
            {
                throw new ArgumentException("total input cannot be more than 32 bytes");
            }

            Array.Copy(input, inOff, buffer, off, len);
            off += len;
        }

        public int DoFinal(byte[] output, int outOff)
        {
            byte[] s = new byte[64];
            Haraka256Perm(s);
            Array.Copy(s, 0, output, outOff, output.Length - outOff);

            Reset();

            return output.Length;
        }

    }

}