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.crypto.agreement.DHStandardGroups;
20  import org.bouncycastle.crypto.params.DHParameters;
21  
22  /**
23   * DH Groups.
24   */
25  public enum GordianDHGroup {
26      /**
27       * ffdhe 2048.
28       */
29      FFDHE2048(DHStandardGroups.rfc7919_ffdhe2048),
30  
31      /**
32       * std 2048.
33       */
34      STD2048(DHStandardGroups.rfc3526_2048),
35  
36      /**
37       * std 1024.
38       */
39      STD1024(DHStandardGroups.rfc2409_1024),
40  
41      /**
42       * std 2048.
43       */
44      STD1536(DHStandardGroups.rfc3526_1536),
45  
46      /**
47       * std 3072.
48       */
49      STD3072(DHStandardGroups.rfc3526_3072),
50  
51      /**
52       * ffdhe 3072.
53       */
54      FFDHE3072(DHStandardGroups.rfc7919_ffdhe3072),
55  
56      /**
57       * std 4096.
58       */
59      STD4096(DHStandardGroups.rfc3526_4096),
60  
61      /**
62       * ffdhe 4096.
63       */
64      FFDHE4096(DHStandardGroups.rfc7919_ffdhe4096),
65  
66      /**
67       * std 6144.
68       */
69      STD6144(DHStandardGroups.rfc3526_6144),
70  
71      /**
72       * ffdhe 6144.
73       */
74      FFDHE6144(DHStandardGroups.rfc7919_ffdhe6144),
75  
76      /**
77       * std 8192.
78       */
79      STD8192(DHStandardGroups.rfc3526_8192),
80  
81      /**
82       * ffdhe 8192.
83       */
84      FFDHE8192(DHStandardGroups.rfc7919_ffdhe8192);
85  
86      /**
87       * The DH Group.
88       */
89      private final DHParameters theParameters;
90  
91      /**
92       * Constructor.
93       *
94       * @param pParams the parameters
95       */
96      GordianDHGroup(final DHParameters pParams) {
97          theParameters = pParams;
98      }
99  
100     /**
101      * Obtain the parameters.
102      *
103      * @return the parameters
104      */
105     public DHParameters getParameters() {
106         return theParameters;
107     }
108 
109     /**
110      * Obtain the group for parameters.
111      *
112      * @param pParams the parameters
113      * @return the group
114      */
115     public static GordianDHGroup getGroupForParams(final DHParameters pParams) {
116         /* Loop through the values */
117         for (GordianDHGroup myGroup : values()) {
118             if (myGroup.getParameters().equals(pParams)) {
119                 return myGroup;
120             }
121         }
122         return null;
123     }
124 }