View Javadoc
1   /*
2    * GordianKnot: Security Suite
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.gordianknot.api.keypair;
18  
19  import org.bouncycastle.asn1.ASN1ObjectIdentifier;
20  import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
21  import org.bouncycastle.jcajce.spec.SLHDSAParameterSpec;
22  import org.bouncycastle.pqc.crypto.slhdsa.SLHDSAParameters;
23  
24  /**
25   * SphincsPlus KeySpecs.
26   */
27  public enum GordianSLHDSASpec {
28      /**
29       * SHA2 128f.
30       */
31      SHA128F,
32  
33      /**
34       * SHA2 128s.
35       */
36      SHA128S,
37  
38      /**
39       * SHA2 192f.
40       */
41      SHA192F,
42  
43      /**
44       * SHA2 192s.
45       */
46      SHA192S,
47  
48      /**
49       * SHA2 256f.
50       */
51      SHA256F,
52  
53      /**
54       * SHA2 256s.
55       */
56      SHA256S,
57  
58      /**
59       * SHAKE 128f.
60       */
61      SHAKE128F,
62  
63      /**
64       * SHAKE 128s.
65       */
66      SHAKE128S,
67  
68      /**
69       * SHAKE 192f.
70       */
71      SHAKE192F,
72  
73      /**
74       * SHAKE 192s.
75       */
76      SHAKE192S,
77  
78      /**
79       * SHAKE 256f.
80       */
81      SHAKE256F,
82  
83      /**
84       * SHAKE 256s.
85       */
86      SHAKE256S,
87  
88      /**
89       * SHA2 128f hash.
90       */
91      SHA128F_HASH,
92  
93      /**
94       * SHA2 128s hash.
95       */
96      SHA128S_HASH,
97  
98      /**
99       * SHA2 192f hash.
100      */
101     SHA192F_HASH,
102 
103     /**
104      * SHA2 192s hash.
105      */
106     SHA192S_HASH,
107 
108     /**
109      * SHA2 256f hash.
110      */
111     SHA256F_HASH,
112 
113     /**
114      * SHA2 256s hash.
115      */
116     SHA256S_HASH,
117 
118     /**
119      * SHAKE 128f hash.
120      */
121     SHAKE128F_HASH,
122 
123     /**
124      * SHAKE 128s hash.
125      */
126     SHAKE128S_HASH,
127 
128     /**
129      * SHAKE 192f hash.
130      */
131     SHAKE192F_HASH,
132 
133     /**
134      * SHAKE 192s hash.
135      */
136     SHAKE192S_HASH,
137 
138     /**
139      * SHAKE 256f hash.
140      */
141     SHAKE256F_HASH,
142 
143     /**
144      * SHAKE 256s hash.
145      */
146     SHAKE256S_HASH;
147 
148 
149     /**
150      * Is this a hash signer?
151      *
152      * @return true/false
153      */
154     public boolean isHash() {
155         switch (this) {
156             case SHA128F:
157             case SHA128S:
158             case SHA192F:
159             case SHA192S:
160             case SHA256F:
161             case SHA256S:
162             case SHAKE128F:
163             case SHAKE128S:
164             case SHAKE192F:
165             case SHAKE192S:
166             case SHAKE256F:
167             case SHAKE256S:
168                 return false;
169             case SHA128F_HASH:
170             case SHA128S_HASH:
171             case SHA192F_HASH:
172             case SHA192S_HASH:
173             case SHA256F_HASH:
174             case SHA256S_HASH:
175             case SHAKE128F_HASH:
176             case SHAKE128S_HASH:
177             case SHAKE192F_HASH:
178             case SHAKE192S_HASH:
179             case SHAKE256F_HASH:
180             case SHAKE256S_HASH:
181             default:
182                 return true;
183         }
184     }
185 
186     /**
187      * Obtain SLHDSA Parameters.
188      *
189      * @return the parameters.
190      */
191     public SLHDSAParameters getParameters() {
192         switch (this) {
193             case SHA128F:
194                 return SLHDSAParameters.sha2_128f;
195             case SHA128S:
196                 return SLHDSAParameters.sha2_128s;
197             case SHA192F:
198                 return SLHDSAParameters.sha2_192f;
199             case SHA192S:
200                 return SLHDSAParameters.sha2_192s;
201             case SHA256F:
202                 return SLHDSAParameters.sha2_256f;
203             case SHA256S:
204                 return SLHDSAParameters.sha2_256s;
205             case SHAKE128F:
206                 return SLHDSAParameters.shake_128f;
207             case SHAKE128S:
208                 return SLHDSAParameters.shake_128s;
209             case SHAKE192F:
210                 return SLHDSAParameters.shake_192f;
211             case SHAKE192S:
212                 return SLHDSAParameters.shake_192s;
213             case SHAKE256F:
214                 return SLHDSAParameters.shake_256f;
215             case SHAKE256S:
216                 return SLHDSAParameters.shake_256s;
217             case SHA128F_HASH:
218                 return SLHDSAParameters.sha2_128f_with_sha256;
219             case SHA128S_HASH:
220                 return SLHDSAParameters.sha2_128s_with_sha256;
221             case SHA192F_HASH:
222                 return SLHDSAParameters.sha2_192f_with_sha512;
223             case SHA192S_HASH:
224                 return SLHDSAParameters.sha2_192s_with_sha512;
225             case SHA256F_HASH:
226                 return SLHDSAParameters.sha2_256f_with_sha512;
227             case SHA256S_HASH:
228                 return SLHDSAParameters.sha2_256s_with_sha512;
229             case SHAKE128F_HASH:
230                 return SLHDSAParameters.shake_128f_with_shake128;
231             case SHAKE128S_HASH:
232                 return SLHDSAParameters.shake_128s_with_shake128;
233             case SHAKE192F_HASH:
234                 return SLHDSAParameters.shake_192f_with_shake256;
235             case SHAKE192S_HASH:
236                 return SLHDSAParameters.shake_192s_with_shake256;
237             case SHAKE256F_HASH:
238                 return SLHDSAParameters.shake_256f_with_shake256;
239             case SHAKE256S_HASH:
240                 return SLHDSAParameters.shake_256s_with_shake256;
241             default:
242                 throw new IllegalArgumentException();
243         }
244     }
245 
246     /**
247      * Obtain SPHINCSPlus ParameterSpec.
248      *
249      * @return the parameters.
250      */
251     public SLHDSAParameterSpec getParameterSpec() {
252         switch (this) {
253             case SHA128F:
254                 return SLHDSAParameterSpec.slh_dsa_sha2_128f;
255             case SHA128S:
256                 return SLHDSAParameterSpec.slh_dsa_sha2_128s;
257             case SHA192F:
258                 return SLHDSAParameterSpec.slh_dsa_sha2_192f;
259             case SHA192S:
260                 return SLHDSAParameterSpec.slh_dsa_sha2_192s;
261             case SHA256F:
262                 return SLHDSAParameterSpec.slh_dsa_sha2_256f;
263             case SHA256S:
264                 return SLHDSAParameterSpec.slh_dsa_sha2_256s;
265             case SHAKE128F:
266                 return SLHDSAParameterSpec.slh_dsa_shake_128f;
267             case SHAKE128S:
268                 return SLHDSAParameterSpec.slh_dsa_shake_128s;
269             case SHAKE192F:
270                 return SLHDSAParameterSpec.slh_dsa_shake_192f;
271             case SHAKE192S:
272                 return SLHDSAParameterSpec.slh_dsa_shake_192s;
273             case SHAKE256F:
274                 return SLHDSAParameterSpec.slh_dsa_shake_256f;
275             case SHAKE256S:
276                 return SLHDSAParameterSpec.slh_dsa_shake_256s;
277             case SHA128F_HASH:
278                 return SLHDSAParameterSpec.slh_dsa_sha2_128f_with_sha256;
279             case SHA128S_HASH:
280                 return SLHDSAParameterSpec.slh_dsa_sha2_128s_with_sha256;
281             case SHA192F_HASH:
282                 return SLHDSAParameterSpec.slh_dsa_sha2_192f_with_sha512;
283             case SHA192S_HASH:
284                 return SLHDSAParameterSpec.slh_dsa_sha2_192s_with_sha512;
285             case SHA256F_HASH:
286                 return SLHDSAParameterSpec.slh_dsa_sha2_256f_with_sha512;
287             case SHA256S_HASH:
288                 return SLHDSAParameterSpec.slh_dsa_sha2_256s_with_sha512;
289             case SHAKE128F_HASH:
290                 return SLHDSAParameterSpec.slh_dsa_shake_128f_with_shake128;
291             case SHAKE128S_HASH:
292                 return SLHDSAParameterSpec.slh_dsa_shake_128s_with_shake128;
293             case SHAKE192F_HASH:
294                 return SLHDSAParameterSpec.slh_dsa_shake_192f_with_shake256;
295             case SHAKE192S_HASH:
296                 return SLHDSAParameterSpec.slh_dsa_shake_192s_with_shake256;
297             case SHAKE256F_HASH:
298                 return SLHDSAParameterSpec.slh_dsa_shake_256f_with_shake256;
299             case SHAKE256S_HASH:
300                 return SLHDSAParameterSpec.slh_dsa_shake_256s_with_shake256;
301             default:
302                 throw new IllegalArgumentException();
303         }
304     }
305 
306     /**
307      * Obtain SLHDSA algorithm Identifier.
308      *
309      * @return the identifier.
310      */
311     public ASN1ObjectIdentifier getIdentifier() {
312         switch (this) {
313             case SHA128F:
314                 return NISTObjectIdentifiers.id_slh_dsa_sha2_128f;
315             case SHA128S:
316                 return NISTObjectIdentifiers.id_slh_dsa_sha2_128s;
317             case SHA192F:
318                 return NISTObjectIdentifiers.id_slh_dsa_sha2_192f;
319             case SHA192S:
320                 return NISTObjectIdentifiers.id_slh_dsa_sha2_192s;
321             case SHA256F:
322                 return NISTObjectIdentifiers.id_slh_dsa_sha2_256f;
323             case SHA256S:
324                 return NISTObjectIdentifiers.id_slh_dsa_sha2_256s;
325             case SHAKE128F:
326                 return NISTObjectIdentifiers.id_slh_dsa_shake_128f;
327             case SHAKE128S:
328                 return NISTObjectIdentifiers.id_slh_dsa_shake_128s;
329             case SHAKE192F:
330                 return NISTObjectIdentifiers.id_slh_dsa_shake_192f;
331             case SHAKE192S:
332                 return NISTObjectIdentifiers.id_slh_dsa_shake_192s;
333             case SHAKE256F:
334                 return NISTObjectIdentifiers.id_slh_dsa_shake_256f;
335             case SHAKE256S:
336                 return NISTObjectIdentifiers.id_slh_dsa_shake_256s;
337             case SHA128F_HASH:
338                 return NISTObjectIdentifiers.id_hash_slh_dsa_sha2_128f_with_sha256;
339             case SHA128S_HASH:
340                 return NISTObjectIdentifiers.id_hash_slh_dsa_sha2_128s_with_sha256;
341             case SHA192F_HASH:
342                 return NISTObjectIdentifiers.id_hash_slh_dsa_sha2_192f_with_sha512;
343             case SHA192S_HASH:
344                 return NISTObjectIdentifiers.id_hash_slh_dsa_sha2_192s_with_sha512;
345             case SHA256F_HASH:
346                 return NISTObjectIdentifiers.id_hash_slh_dsa_sha2_256f_with_sha512;
347             case SHA256S_HASH:
348                 return NISTObjectIdentifiers.id_hash_slh_dsa_sha2_256s_with_sha512;
349             case SHAKE128F_HASH:
350                 return NISTObjectIdentifiers.id_hash_slh_dsa_shake_128f_with_shake128;
351             case SHAKE128S_HASH:
352                 return NISTObjectIdentifiers.id_hash_slh_dsa_shake_128s_with_shake128;
353             case SHAKE192F_HASH:
354                 return NISTObjectIdentifiers.id_hash_slh_dsa_shake_192f_with_shake256;
355             case SHAKE192S_HASH:
356                 return NISTObjectIdentifiers.id_hash_slh_dsa_shake_192s_with_shake256;
357             case SHAKE256F_HASH:
358                 return NISTObjectIdentifiers.id_hash_slh_dsa_shake_256f_with_shake256;
359             case SHAKE256S_HASH:
360                 return NISTObjectIdentifiers.id_hash_slh_dsa_shake_256s_with_shake256;
361             default:
362                 throw new IllegalArgumentException();
363         }
364     }
365 }