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.MLDSAParameterSpec;
22  import org.bouncycastle.pqc.crypto.mldsa.MLDSAParameters;
23  
24  /**
25   * MLDSA KeySpec.
26   */
27  public enum GordianMLDSASpec {
28      /**
29       * mldsa44.
30       */
31      MLDSA44,
32  
33      /**
34       * mldsa65.
35       */
36      MLDSA65,
37  
38      /**
39       * mldsa87.
40       */
41      MLDSA87,
42  
43      /**
44       * mldsa44sha2.
45       */
46      MLDSA44SHA,
47  
48      /**
49       * mldsa65sha2.
50       */
51      MLDSA65SHA,
52  
53      /**
54       * mldsa87sha2.
55       */
56      MLDSA87SHA;
57  
58      /**
59       * Is this a hash signer?
60       *
61       * @return true/false
62       */
63      public boolean isHash() {
64          switch (this) {
65              case MLDSA44SHA:
66              case MLDSA65SHA:
67              case MLDSA87SHA:
68                  return true;
69              case MLDSA44:
70              case MLDSA65:
71              case MLDSA87:
72              default:
73                  return false;
74          }
75      }
76  
77      /**
78       * Obtain MLDSA Parameters.
79       *
80       * @return the parameters.
81       */
82      public MLDSAParameters getParameters() {
83          switch (this) {
84              case MLDSA44:
85                  return MLDSAParameters.ml_dsa_44;
86              case MLDSA65:
87                  return MLDSAParameters.ml_dsa_65;
88              case MLDSA87:
89                  return MLDSAParameters.ml_dsa_87;
90              case MLDSA44SHA:
91                  return MLDSAParameters.ml_dsa_44_with_sha512;
92              case MLDSA65SHA:
93                  return MLDSAParameters.ml_dsa_65_with_sha512;
94              case MLDSA87SHA:
95                  return MLDSAParameters.ml_dsa_87_with_sha512;
96              default:
97                  throw new IllegalArgumentException();
98          }
99      }
100 
101     /**
102      * Obtain MLDSA ParameterSpec.
103      *
104      * @return the parameters.
105      */
106     public MLDSAParameterSpec getParameterSpec() {
107         switch (this) {
108             case MLDSA44:
109                 return MLDSAParameterSpec.ml_dsa_44;
110             case MLDSA65:
111                 return MLDSAParameterSpec.ml_dsa_65;
112             case MLDSA87:
113                 return MLDSAParameterSpec.ml_dsa_87;
114             case MLDSA44SHA:
115                 return MLDSAParameterSpec.ml_dsa_44_with_sha512;
116             case MLDSA65SHA:
117                 return MLDSAParameterSpec.ml_dsa_65_with_sha512;
118             case MLDSA87SHA:
119                 return MLDSAParameterSpec.ml_dsa_87_with_sha512;
120             default:
121                 throw new IllegalArgumentException();
122         }
123     }
124 
125     /**
126      * Obtain MLDSA algorithm Identifier.
127      *
128      * @return the identifier.
129      */
130     public ASN1ObjectIdentifier getIdentifier() {
131         switch (this) {
132             case MLDSA44:
133                 return NISTObjectIdentifiers.id_ml_dsa_44;
134             case MLDSA65:
135                 return NISTObjectIdentifiers.id_ml_dsa_65;
136             case MLDSA87:
137                 return NISTObjectIdentifiers.id_ml_dsa_87;
138             case MLDSA44SHA:
139                 return NISTObjectIdentifiers.id_hash_ml_dsa_44_with_sha512;
140             case MLDSA65SHA:
141                 return NISTObjectIdentifiers.id_hash_ml_dsa_65_with_sha512;
142             case MLDSA87SHA:
143                 return NISTObjectIdentifiers.id_hash_ml_dsa_87_with_sha512;
144             default:
145                 throw new IllegalArgumentException();
146         }
147     }
148 }