summary refs log tree commit diff
path: root/crypto/src/pqc/crypto/lms/LMOtsParameters.cs
blob: 60bf28d5023574b50d741139f67a68727d465900 (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
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;

using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Utilities.Collections;

namespace Org.BouncyCastle.Pqc.Crypto.Lms
{
    public sealed class LMOtsParameters
    {
        // TODO add all parameter sets

        //public static int reserved = 0;
        public static LMOtsParameters sha256_n32_w1 = new LMOtsParameters(1, 32, 1, 265, 7, 8516, NistObjectIdentifiers.IdSha256);
        public static LMOtsParameters sha256_n32_w2 = new LMOtsParameters(2, 32, 2, 133, 6, 4292, NistObjectIdentifiers.IdSha256);
        public static LMOtsParameters sha256_n32_w4 = new LMOtsParameters(3, 32, 4, 67, 4, 2180, NistObjectIdentifiers.IdSha256);
        public static LMOtsParameters sha256_n32_w8 = new LMOtsParameters(4, 32, 8, 34, 0, 1124, NistObjectIdentifiers.IdSha256);

        private static Dictionary<object, LMOtsParameters> Suppliers = new Dictionary<object, LMOtsParameters>
        {
            { sha256_n32_w1.ID, sha256_n32_w1 },
            { sha256_n32_w2.ID, sha256_n32_w2 },
            { sha256_n32_w4.ID, sha256_n32_w4 },
            { sha256_n32_w8.ID, sha256_n32_w8 }
        };

        private readonly int m_id;
        private readonly int m_n;
        private readonly int m_w;
        private readonly int m_p;
        private readonly int m_ls;
        private readonly uint m_sigLen;
        private readonly DerObjectIdentifier m_digestOid;

        internal LMOtsParameters(int id, int n, int w, int p, int ls, uint sigLen, DerObjectIdentifier digestOid)
        {
            m_id = id;
            m_n = n;
            m_w = w;
            m_p = p;
            m_ls = ls;
            m_sigLen = sigLen;
            m_digestOid = digestOid;
        }

        public int ID => m_id;

        public int N => m_n;

        public int W => m_w;

        public int P => m_p;

        public int Ls => m_ls;

        public int SigLen => Convert.ToInt32(m_sigLen);

        public DerObjectIdentifier DigestOid => m_digestOid;

        public static LMOtsParameters GetParametersByID(int id)
        {
            return CollectionUtilities.GetValueOrNull(Suppliers, id);
        }
    }
}