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.bc.BCObjectIdentifiers;
21  import org.bouncycastle.pqc.crypto.saber.SABERParameters;
22  import org.bouncycastle.pqc.jcajce.spec.SABERParameterSpec;
23  
24  /**
25   * SABER KeySpec.
26   */
27  public enum GordianSABERSpec {
28      /**
29       * Light 128.
30       */
31      LIGHT128,
32  
33      /**
34       * Base 128.
35       */
36      BASE128,
37  
38      /**
39       * Fire 128.
40       */
41      FIRE128,
42  
43      /**
44       * Light 192.
45       */
46      LIGHT192,
47  
48      /**
49       * Base 192.
50       */
51      BASE192,
52  
53      /**
54       * Fire 192.
55       */
56      FIRE192,
57  
58      /**
59       * Light 256.
60       */
61      LIGHT256,
62  
63      /**
64       * Base 256.
65       */
66      BASE256,
67  
68      /**
69       * Fire 256.
70       */
71      FIRE256;
72  
73      /**
74       * Obtain SABER Parameters.
75       *
76       * @return the parameters.
77       */
78      public SABERParameters getParameters() {
79          switch (this) {
80              case LIGHT128:
81                  return SABERParameters.lightsaberkem128r3;
82              case BASE128:
83                  return SABERParameters.saberkem128r3;
84              case FIRE128:
85                  return SABERParameters.firesaberkem128r3;
86              case LIGHT192:
87                  return SABERParameters.lightsaberkem192r3;
88              case BASE192:
89                  return SABERParameters.saberkem192r3;
90              case FIRE192:
91                  return SABERParameters.firesaberkem192r3;
92              case LIGHT256:
93                  return SABERParameters.lightsaberkem256r3;
94              case BASE256:
95                  return SABERParameters.saberkem256r3;
96              case FIRE256:
97                  return SABERParameters.firesaberkem256r3;
98              default:
99                  throw new IllegalArgumentException();
100         }
101     }
102 
103     /**
104      * Obtain SABER ParameterSpec.
105      *
106      * @return the parameters.
107      */
108     public SABERParameterSpec getParameterSpec() {
109         switch (this) {
110             case LIGHT128:
111                 return SABERParameterSpec.lightsaberkem128r3;
112             case BASE128:
113                 return SABERParameterSpec.saberkem128r3;
114             case FIRE128:
115                 return SABERParameterSpec.firesaberkem128r3;
116             case LIGHT192:
117                 return SABERParameterSpec.lightsaberkem192r3;
118             case BASE192:
119                 return SABERParameterSpec.saberkem192r3;
120             case FIRE192:
121                 return SABERParameterSpec.firesaberkem192r3;
122             case LIGHT256:
123                 return SABERParameterSpec.lightsaberkem256r3;
124             case BASE256:
125                 return SABERParameterSpec.saberkem256r3;
126             case FIRE256:
127                 return SABERParameterSpec.firesaberkem256r3;
128             default:
129                 throw new IllegalArgumentException();
130         }
131     }
132 
133     /**
134      * Obtain Saber algorithm Identifier.
135      *
136      * @return the identifier.
137      */
138     public ASN1ObjectIdentifier getIdentifier() {
139         switch (this) {
140             case LIGHT128:
141                 return BCObjectIdentifiers.lightsaberkem128r3;
142             case BASE128:
143                 return BCObjectIdentifiers.saberkem128r3;
144             case FIRE128:
145                 return BCObjectIdentifiers.firesaberkem128r3;
146             case LIGHT192:
147                 return BCObjectIdentifiers.lightsaberkem192r3;
148             case BASE192:
149                 return BCObjectIdentifiers.saberkem192r3;
150             case FIRE192:
151                 return BCObjectIdentifiers.firesaberkem192r3;
152             case LIGHT256:
153                 return BCObjectIdentifiers.lightsaberkem256r3;
154             case BASE256:
155                 return BCObjectIdentifiers.saberkem256r3;
156             case FIRE256:
157                 return BCObjectIdentifiers.firesaberkem256r3;
158             default:
159                 throw new IllegalArgumentException();
160         }
161     }
162 }