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.MLKEMParameterSpec;
22  import org.bouncycastle.pqc.crypto.mlkem.MLKEMParameters;
23  
24  /**
25   * Kyber KeySpec.
26   */
27  public enum GordianMLKEMSpec {
28      /**
29       * Kyber 512.
30       */
31      MLKEM512,
32  
33      /**
34       * Kyber 768.
35       */
36      MLKEM768,
37  
38      /**
39       * Kyber 1024.
40       */
41      MLKEM1024;
42  
43      /**
44       * Obtain KYBER Parameters.
45       *
46       * @return the parameters.
47       */
48      public MLKEMParameters getParameters() {
49          switch (this) {
50              case MLKEM512:
51                  return MLKEMParameters.ml_kem_512;
52              case MLKEM768:
53                  return MLKEMParameters.ml_kem_768;
54              case MLKEM1024:
55                  return MLKEMParameters.ml_kem_1024;
56              default:
57                  throw new IllegalArgumentException();
58          }
59      }
60  
61      /**
62       * Obtain Kyber ParameterSpec.
63       *
64       * @return the parameters.
65       */
66      public MLKEMParameterSpec getParameterSpec() {
67          switch (this) {
68              case MLKEM512:
69                  return MLKEMParameterSpec.ml_kem_512;
70              case MLKEM768:
71                  return MLKEMParameterSpec.ml_kem_768;
72              case MLKEM1024:
73                  return MLKEMParameterSpec.ml_kem_1024;
74              default:
75                  throw new IllegalArgumentException();
76          }
77      }
78  
79      /**
80       * Obtain MLKEM algorithm Identifier.
81       *
82       * @return the identifier.
83       */
84      public ASN1ObjectIdentifier getIdentifier() {
85          switch (this) {
86              case MLKEM512:
87                  return NISTObjectIdentifiers.id_alg_ml_kem_512;
88              case MLKEM768:
89                  return NISTObjectIdentifiers.id_alg_ml_kem_768;
90              case MLKEM1024:
91                  return NISTObjectIdentifiers.id_alg_ml_kem_1024;
92              default:
93                  throw new IllegalArgumentException();
94          }
95      }
96  }