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.cmce.CMCEParameters;
22  import org.bouncycastle.pqc.jcajce.spec.CMCEParameterSpec;
23  
24  /**
25   * CMCE KeySpecs.
26   */
27  public enum GordianCMCESpec {
28      /**
29       * Base 3488.
30       */
31      BASE3488,
32  
33      /**
34       * Pivot 3488.
35       */
36      PIVOT3488,
37  
38      /**
39       * Base 4608.
40       */
41      BASE4608,
42  
43      /**
44       * Pivot 4608.
45       */
46      PIVOT4608,
47  
48      /**
49       * Base 6688.
50       */
51      BASE6688,
52  
53      /**
54       * Pivot 6688.
55       */
56      PIVOT6688,
57  
58      /**
59       * Base 6960.
60       */
61      BASE6960,
62  
63      /**
64       * Pivot 6960.
65       */
66      PIVOT6960,
67  
68      /**
69       * Base 8192.
70       */
71      BASE8192,
72  
73      /**
74       * Pivot 8192.
75       */
76      PIVOT8192;
77  
78      /**
79       * Obtain CMCE Parameters.
80       *
81       * @return the parameters.
82       */
83      public CMCEParameters getParameters() {
84          switch (this) {
85              case BASE3488:
86                  return CMCEParameters.mceliece348864r3;
87              case PIVOT3488:
88                  return CMCEParameters.mceliece348864fr3;
89              case BASE4608:
90                  return CMCEParameters.mceliece460896r3;
91              case PIVOT4608:
92                  return CMCEParameters.mceliece460896fr3;
93              case BASE6688:
94                  return CMCEParameters.mceliece6688128r3;
95              case PIVOT6688:
96                  return CMCEParameters.mceliece6688128fr3;
97              case BASE6960:
98                  return CMCEParameters.mceliece6960119r3;
99              case PIVOT6960:
100                 return CMCEParameters.mceliece6960119fr3;
101             case BASE8192:
102                 return CMCEParameters.mceliece8192128r3;
103             case PIVOT8192:
104                 return CMCEParameters.mceliece8192128fr3;
105             default:
106                 throw new IllegalArgumentException();
107         }
108     }
109 
110     /**
111      * Obtain CMCE ParameterSpec.
112      *
113      * @return the parameters.
114      */
115     public CMCEParameterSpec getParameterSpec() {
116         switch (this) {
117             case BASE3488:
118                 return CMCEParameterSpec.mceliece348864;
119             case PIVOT3488:
120                 return CMCEParameterSpec.mceliece348864f;
121             case BASE4608:
122                 return CMCEParameterSpec.mceliece460896;
123             case PIVOT4608:
124                 return CMCEParameterSpec.mceliece460896f;
125             case BASE6688:
126                 return CMCEParameterSpec.mceliece6688128;
127             case PIVOT6688:
128                 return CMCEParameterSpec.mceliece6688128f;
129             case BASE6960:
130                 return CMCEParameterSpec.mceliece6960119;
131             case PIVOT6960:
132                 return CMCEParameterSpec.mceliece6960119f;
133             case BASE8192:
134                 return CMCEParameterSpec.mceliece8192128;
135             case PIVOT8192:
136                 return CMCEParameterSpec.mceliece8192128f;
137             default:
138                 throw new IllegalArgumentException();
139         }
140     }
141 
142     /**
143      * Obtain CMCE algorithm Identifier.
144      *
145      * @return the identifier.
146      */
147     public ASN1ObjectIdentifier getIdentifier() {
148         switch (this) {
149             case BASE3488:
150                 return BCObjectIdentifiers.mceliece348864_r3;
151             case PIVOT3488:
152                 return BCObjectIdentifiers.mceliece348864f_r3;
153             case BASE4608:
154                 return BCObjectIdentifiers.mceliece460896_r3;
155             case PIVOT4608:
156                 return BCObjectIdentifiers.mceliece460896f_r3;
157             case BASE6688:
158                 return BCObjectIdentifiers.mceliece6688128_r3;
159             case PIVOT6688:
160                 return BCObjectIdentifiers.mceliece6688128f_r3;
161             case BASE6960:
162                 return BCObjectIdentifiers.mceliece6960119_r3;
163             case PIVOT6960:
164                 return BCObjectIdentifiers.mceliece6960119f_r3;
165             case BASE8192:
166                 return BCObjectIdentifiers.mceliece8192128_r3;
167             case PIVOT8192:
168                 return BCObjectIdentifiers.mceliece8192128f_r3;
169             default:
170                 throw new IllegalArgumentException();
171         }
172     }
173 }