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.ntru.NTRUParameters;
22  import org.bouncycastle.pqc.jcajce.spec.NTRUParameterSpec;
23  
24  /**
25   * NTRU KeySpec.
26   */
27  public enum GordianNTRUSpec {
28      /**
29       * HPS 509 2048.
30       */
31      HPS509,
32  
33      /**
34       * HPS 677 2048.
35       */
36      HPS677,
37  
38      /**
39       * HPS 821 4096.
40       */
41      HPS821,
42  
43      /**
44       * HPS 1229 4096.
45       */
46      HPS1229,
47  
48      /**
49       * HRSS 701.
50       */
51      HRSS701,
52  
53      /**
54       * HRSS 1373.
55       */
56      HRSS1373;
57  
58      /**
59       * Obtain NTRU Parameters.
60       *
61       * @return the parameters.
62       */
63      public NTRUParameters getParameters() {
64          switch (this) {
65              case HPS509:
66                  return NTRUParameters.ntruhps2048509;
67              case HPS677:
68                  return NTRUParameters.ntruhps2048677;
69              case HPS821:
70                  return NTRUParameters.ntruhps4096821;
71              case HPS1229:
72                  return NTRUParameters.ntruhps40961229;
73              case HRSS701:
74                  return NTRUParameters.ntruhrss701;
75              case HRSS1373:
76                  return NTRUParameters.ntruhrss1373;
77              default:
78                  throw new IllegalArgumentException();
79          }
80      }
81  
82      /**
83       * Obtain NTRU ParameterSpec.
84       *
85       * @return the parameters.
86       */
87      public NTRUParameterSpec getParameterSpec() {
88          switch (this) {
89              case HPS509:
90                  return NTRUParameterSpec.ntruhps2048509;
91              case HPS677:
92                  return NTRUParameterSpec.ntruhps2048677;
93              case HPS821:
94                  return NTRUParameterSpec.ntruhps4096821;
95              case HPS1229:
96                  return NTRUParameterSpec.ntruhps40961229;
97              case HRSS701:
98                  return NTRUParameterSpec.ntruhrss701;
99              case HRSS1373:
100                 return NTRUParameterSpec.ntruhrss1373;
101             default:
102                 throw new IllegalArgumentException();
103         }
104     }
105 
106     /**
107      * Obtain NTRU algorithm Identifier.
108      *
109      * @return the identifier.
110      */
111     public ASN1ObjectIdentifier getIdentifier() {
112         switch (this) {
113             case HPS509:
114                 return BCObjectIdentifiers.ntruhps2048509;
115             case HPS677:
116                 return BCObjectIdentifiers.ntruhps2048677;
117             case HPS821:
118                 return BCObjectIdentifiers.ntruhps4096821;
119             case HPS1229:
120                 return BCObjectIdentifiers.ntruhps40961229;
121             case HRSS701:
122                 return BCObjectIdentifiers.ntruhrss701;
123             case HRSS1373:
124                 return BCObjectIdentifiers.ntruhrss1373;
125             default:
126                 throw new IllegalArgumentException();
127         }
128     }
129 }