Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GMSSParameters.java « gmss « crypto « pqc « bouncycastle « org « java « main « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa89f76ae38f4e586710b196d5e2e305c530304b (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package org.bouncycastle.pqc.crypto.gmss;

import org.bouncycastle.util.Arrays;

/**
 * This class provides a specification for the GMSS parameters that are used by
 * the GMSSKeyPairGenerator and GMSSSignature classes.
 *
 * @see org.bouncycastle.pqc.crypto.gmss.GMSSKeyPairGenerator
 */
public class GMSSParameters
{
    /**
     * The number of authentication tree layers.
     */
    private int numOfLayers;

    /**
     * The height of the authentication trees of each layer.
     */
    private int[] heightOfTrees;

    /**
     * The Winternitz Parameter 'w' of each layer.
     */
    private int[] winternitzParameter;

    /**
     * The parameter K needed for the authentication path computation
     */
    private int[] K;

    /**
     * The constructor for the parameters of the GMSSKeyPairGenerator.
     *
     * @param layers              the number of authentication tree layers
     * @param heightOfTrees       the height of the authentication trees
     * @param winternitzParameter the Winternitz Parameter 'w' of each layer
     * @param K                   parameter for authpath computation
     */
    public GMSSParameters(int layers, int[] heightOfTrees, int[] winternitzParameter, int[] K)
        throws IllegalArgumentException
    {
        init(layers, heightOfTrees, winternitzParameter, K);
    }

    private void init(int layers, int[] heightOfTrees,
                      int[] winternitzParameter, int[] K)
        throws IllegalArgumentException
    {
        boolean valid = true;
        String errMsg = "";
        this.numOfLayers = layers;
        if ((numOfLayers != winternitzParameter.length)
            || (numOfLayers != heightOfTrees.length)
            || (numOfLayers != K.length))
        {
            valid = false;
            errMsg = "Unexpected parameterset format";
        }
        for (int i = 0; i < numOfLayers; i++)
        {
            if ((K[i] < 2) || ((heightOfTrees[i] - K[i]) % 2 != 0))
            {
                valid = false;
                errMsg = "Wrong parameter K (K >= 2 and H-K even required)!";
            }

            if ((heightOfTrees[i] < 4) || (winternitzParameter[i] < 2))
            {
                valid = false;
                errMsg = "Wrong parameter H or w (H > 3 and w > 1 required)!";
            }
        }

        if (valid)
        {
            this.heightOfTrees = Arrays.clone(heightOfTrees);
            this.winternitzParameter = Arrays.clone(winternitzParameter);
            this.K = Arrays.clone(K);
        }
        else
        {
            throw new IllegalArgumentException(errMsg);
        }
    }

    public GMSSParameters(int keySize)
        throws IllegalArgumentException
    {
        if (keySize <= 10)
        { // create 2^10 keys
            int[] defh = {10};
            int[] defw = {3};
            int[] defk = {2};
            this.init(defh.length, defh, defw, defk);
        }
        else if (keySize <= 20)
        { // create 2^20 keys
            int[] defh = {10, 10};
            int[] defw = {5, 4};
            int[] defk = {2, 2};
            this.init(defh.length, defh, defw, defk);
        }
        else
        { // create 2^40 keys, keygen lasts around 80 seconds
            int[] defh = {10, 10, 10, 10};
            int[] defw = {9, 9, 9, 3};
            int[] defk = {2, 2, 2, 2};
            this.init(defh.length, defh, defw, defk);
        }
    }

    /**
     * Returns the number of levels of the authentication trees.
     *
     * @return The number of levels of the authentication trees.
     */
    public int getNumOfLayers()
    {
        return numOfLayers;
    }

    /**
     * Returns the array of height (for each layer) of the authentication trees
     *
     * @return The array of height (for each layer) of the authentication trees
     */
    public int[] getHeightOfTrees()
    {
        return Arrays.clone(heightOfTrees);
    }

    /**
     * Returns the array of WinternitzParameter (for each layer) of the
     * authentication trees
     *
     * @return The array of WinternitzParameter (for each layer) of the
     *         authentication trees
     */
    public int[] getWinternitzParameter()
    {
        return Arrays.clone(winternitzParameter);
    }

    /**
     * Returns the parameter K needed for authentication path computation
     *
     * @return The parameter K needed for authentication path computation
     */
    public int[] getK()
    {
        return Arrays.clone(K);
    }
}