1 /*
2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package sun.security.provider;
27 
28 import java.util.*;
29 import java.util.concurrent.ConcurrentHashMap;
30 import java.math.BigInteger;
31 
32 import java.security.*;
33 import java.security.SecureRandom;
34 import java.security.spec.*;
35 
36 import javax.crypto.spec.DHParameterSpec;
37 
38 /**
39  * Cache for DSA and DH parameter specs. Used by the KeyPairGenerators
40  * in the Sun, SunJCE, and SunPKCS11 provider if no parameters have been
41  * explicitly specified by the application.
42  *
43  * @author  Andreas Sterbenz
44  * @since   1.5
45  */
46 public final class ParameterCache {
47 
ParameterCache()48     private ParameterCache() {
49         // empty
50     }
51 
52     // cache of DSA parameters
53     private static final Map<Integer,DSAParameterSpec> dsaCache;
54 
55     // cache of DH parameters
56     private static final Map<Integer,DHParameterSpec> dhCache;
57 
58     /**
59      * Return cached DSA parameters for the given length combination of
60      * prime and subprime, or null if none are available in the cache.
61      */
getCachedDSAParameterSpec(int primeLen, int subprimeLen)62     public static DSAParameterSpec getCachedDSAParameterSpec(int primeLen,
63             int subprimeLen) {
64         // ensure the sum is unique in all cases, i.e.
65         // case#1: (512 <= p <= 1024) AND q=160
66         // case#2: p=2048 AND q=224
67         // case#3: p=2048 AND q=256
68         // case#4: p=3072 AND q=256
69         return dsaCache.get(Integer.valueOf(primeLen+subprimeLen));
70     }
71 
72     /**
73      * Return cached DH parameters for the given keylength, or null if none
74      * are available in the cache.
75      */
getCachedDHParameterSpec(int keyLength)76     public static DHParameterSpec getCachedDHParameterSpec(int keyLength) {
77         return dhCache.get(Integer.valueOf(keyLength));
78     }
79 
80     /**
81      * Return DSA parameters for the given primeLen. Uses cache if
82      * possible, generates new parameters and adds them to the cache
83      * otherwise.
84      */
getDSAParameterSpec(int primeLen, SecureRandom random)85     public static DSAParameterSpec getDSAParameterSpec(int primeLen,
86             SecureRandom random)
87             throws NoSuchAlgorithmException, InvalidParameterSpecException,
88                    InvalidAlgorithmParameterException {
89         if (primeLen <= 1024) {
90             return getDSAParameterSpec(primeLen, 160, random);
91         } else if (primeLen == 2048) {
92             return getDSAParameterSpec(primeLen, 224, random);
93         } else if (primeLen == 3072) {
94             return getDSAParameterSpec(primeLen, 256, random);
95         } else {
96             return null;
97         }
98     }
99 
100     /**
101      * Return DSA parameters for the given primeLen and subprimeLen.
102      * Uses cache if possible, generates new parameters and adds them to the
103      * cache otherwise.
104      */
getDSAParameterSpec(int primeLen, int subprimeLen, SecureRandom random)105     public static DSAParameterSpec getDSAParameterSpec(int primeLen,
106             int subprimeLen, SecureRandom random)
107             throws NoSuchAlgorithmException, InvalidParameterSpecException,
108                    InvalidAlgorithmParameterException {
109         DSAParameterSpec spec =
110             getCachedDSAParameterSpec(primeLen, subprimeLen);
111         if (spec != null) {
112             return spec;
113         }
114         spec = getNewDSAParameterSpec(primeLen, subprimeLen, random);
115         dsaCache.put(Integer.valueOf(primeLen + subprimeLen), spec);
116         return spec;
117     }
118 
119     /**
120      * Return DH parameters for the given keylength. Uses cache if possible,
121      * generates new parameters and adds them to the cache otherwise.
122      */
getDHParameterSpec(int keyLength, SecureRandom random)123     public static DHParameterSpec getDHParameterSpec(int keyLength,
124             SecureRandom random)
125             throws NoSuchAlgorithmException, InvalidParameterSpecException {
126         DHParameterSpec spec = getCachedDHParameterSpec(keyLength);
127         if (spec != null) {
128             return spec;
129         }
130         AlgorithmParameterGenerator gen =
131                 AlgorithmParameterGenerator.getInstance("DH");
132         gen.init(keyLength, random);
133         AlgorithmParameters params = gen.generateParameters();
134         spec = params.getParameterSpec(DHParameterSpec.class);
135         dhCache.put(Integer.valueOf(keyLength), spec);
136         return spec;
137     }
138 
139     /**
140      * Return new DSA parameters for the given length combination of prime and
141      * sub prime. Do not lookup in cache and do not cache the newly generated
142      * parameters. This method really only exists for the legacy method
143      * DSAKeyPairGenerator.initialize(int, boolean, SecureRandom).
144      */
getNewDSAParameterSpec(int primeLen, int subprimeLen, SecureRandom random)145     public static DSAParameterSpec getNewDSAParameterSpec(int primeLen,
146             int subprimeLen, SecureRandom random)
147             throws NoSuchAlgorithmException, InvalidParameterSpecException,
148                    InvalidAlgorithmParameterException {
149         AlgorithmParameterGenerator gen =
150                 AlgorithmParameterGenerator.getInstance("DSA");
151         // Use init(int size, SecureRandom random) for legacy DSA key sizes
152         if (primeLen < 1024) {
153             gen.init(primeLen, random);
154         } else {
155             DSAGenParameterSpec genParams =
156                 new DSAGenParameterSpec(primeLen, subprimeLen);
157             gen.init(genParams, random);
158         }
159         AlgorithmParameters params = gen.generateParameters();
160         DSAParameterSpec spec = params.getParameterSpec(DSAParameterSpec.class);
161         return spec;
162     }
163 
164     static {
165         dhCache = new ConcurrentHashMap<Integer,DHParameterSpec>();
166         dsaCache = new ConcurrentHashMap<Integer,DSAParameterSpec>();
167 
168         /*
169          * We support precomputed parameter for legacy 512, 768 bit moduli,
170          * and (L, N) combinations of (1024, 160), (2048, 224), (2048, 256),
171          * (3072, 256). In this file we provide both the seed and counter
172          * value of the generation process for each of these seeds,
173          * for validation purposes. We also include the test vectors
174          * from the DSA specification, FIPS 186, and the FIPS 186
175          * Change No 1, which updates the test vector using SHA-1
176          * instead of SHA (for both the G function and the message
177          * hash.
178          */
179 
180         /*
181          * L = 512
182          * SEED = b869c82b35d70e1b1ff91b28e37a62ecdc34409b
183          * counter = 123
184          */
185         BigInteger p512 =
186             new BigInteger("fca682ce8e12caba26efccf7110e526db078b05edecb" +
187                            "cd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e1" +
188                            "2ed0899bcd132acd50d99151bdc43ee737592e17", 16);
189 
190         BigInteger q512 =
191             new BigInteger("962eddcc369cba8ebb260ee6b6a126d9346e38c5", 16);
192 
193         BigInteger g512 =
194             new BigInteger("678471b27a9cf44ee91a49c5147db1a9aaf244f05a43" +
195                            "4d6486931d2d14271b9e35030b71fd73da179069b32e" +
196                            "2935630e1c2062354d0da20a6c416e50be794ca4", 16);
197 
198         /*
199          * L = 768
200          * SEED = 77d0f8c4dad15eb8c4f2f8d6726cefd96d5bb399
201          * counter = 263
202          */
203         BigInteger p768 =
204             new BigInteger("e9e642599d355f37c97ffd3567120b8e25c9cd43e" +
205                            "927b3a9670fbec5d890141922d2c3b3ad24800937" +
206                            "99869d1e846aab49fab0ad26d2ce6a22219d470bc" +
207                            "e7d777d4a21fbe9c270b57f607002f3cef8393694" +
208                            "cf45ee3688c11a8c56ab127a3daf", 16);
209 
210         BigInteger q768 =
211             new BigInteger("9cdbd84c9f1ac2f38d0f80f42ab952e7338bf511",
212                            16);
213 
214         BigInteger g768 =
215             new BigInteger("30470ad5a005fb14ce2d9dcd87e38bc7d1b1c5fac" +
216                            "baecbe95f190aa7a31d23c4dbbcbe06174544401a" +
217                            "5b2c020965d8c2bd2171d3668445771f74ba084d2" +
218                            "029d83c1c158547f3a9f1a2715be23d51ae4d3e5a" +
219                            "1f6a7064f316933a346d3f529252", 16);
220 
221 
222         /*
223          * L = 1024
224          * SEED = 8d5155894229d5e689ee01e6018a237e2cae64cd
225          * counter = 92
226          */
227         BigInteger p1024 =
228             new BigInteger("fd7f53811d75122952df4a9c2eece4e7f611b7523c" +
229                            "ef4400c31e3f80b6512669455d402251fb593d8d58" +
230                            "fabfc5f5ba30f6cb9b556cd7813b801d346ff26660" +
231                            "b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c6" +
232                            "1bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554" +
233                            "135a169132f675f3ae2b61d72aeff22203199dd148" +
234                            "01c7", 16);
235 
236         BigInteger q1024 =
237             new BigInteger("9760508f15230bccb292b982a2eb840bf0581cf5",
238                            16);
239 
240         BigInteger g1024 =
241             new BigInteger("f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa" +
242                            "3aea82f9574c0b3d0782675159578ebad4594fe671" +
243                            "07108180b449167123e84c281613b7cf09328cc8a6" +
244                            "e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f" +
245                            "0bfa213562f1fb627a01243bcca4f1bea8519089a8" +
246                            "83dfe15ae59f06928b665e807b552564014c3bfecf" +
247                            "492a", 16);
248 
249         dsaCache.put(Integer.valueOf(512+160),
DSAParameterSpec(p512, q512, g512)250                                 new DSAParameterSpec(p512, q512, g512));
251         dsaCache.put(Integer.valueOf(768+160),
DSAParameterSpec(p768, q768, g768)252                                 new DSAParameterSpec(p768, q768, g768));
253         dsaCache.put(Integer.valueOf(1024+160),
DSAParameterSpec(p1024, q1024, g1024)254                                 new DSAParameterSpec(p1024, q1024, g1024));
255         /*
256          * L = 2048, N = 224
257          * SEED = 584236080cfa43c09b02354135f4cc5198a19efada08bd866d601ba4
258          * counter = 2666
259          */
260         BigInteger p2048_224 =
261             new BigInteger("8f7935d9b9aae9bfabed887acf4951b6f32ec59e3b" +
262                            "af3718e8eac4961f3efd3606e74351a9c4183339b8" +
263                            "09e7c2ae1c539ba7475b85d011adb8b47987754984" +
264                            "695cac0e8f14b3360828a22ffa27110a3d62a99345" +
265                            "3409a0fe696c4658f84bdd20819c3709a01057b195" +
266                            "adcd00233dba5484b6291f9d648ef883448677979c" +
267                            "ec04b434a6ac2e75e9985de23db0292fc1118c9ffa" +
268                            "9d8181e7338db792b730d7b9e349592f6809987215" +
269                            "3915ea3d6b8b4653c633458f803b32a4c2e0f27290" +
270                            "256e4e3f8a3b0838a1c450e4e18c1a29a37ddf5ea1" +
271                            "43de4b66ff04903ed5cf1623e158d487c608e97f21" +
272                            "1cd81dca23cb6e380765f822e342be484c05763939" +
273                            "601cd667", 16);
274 
275         BigInteger q2048_224 =
276             new BigInteger("baf696a68578f7dfdee7fa67c977c785ef32b233ba" +
277                            "e580c0bcd5695d", 16);
278 
279         BigInteger g2048_224 =
280             new BigInteger("16a65c58204850704e7502a39757040d34da3a3478" +
281                            "c154d4e4a5c02d242ee04f96e61e4bd0904abdac8f" +
282                            "37eeb1e09f3182d23c9043cb642f88004160edf9ca" +
283                            "09b32076a79c32a627f2473e91879ba2c4e744bd20" +
284                            "81544cb55b802c368d1fa83ed489e94e0fa0688e32" +
285                            "428a5c78c478c68d0527b71c9a3abb0b0be12c4468" +
286                            "9639e7d3ce74db101a65aa2b87f64c6826db3ec72f" +
287                            "4b5599834bb4edb02f7c90e9a496d3a55d535bebfc" +
288                            "45d4f619f63f3dedbb873925c2f224e07731296da8" +
289                            "87ec1e4748f87efb5fdeb75484316b2232dee553dd" +
290                            "af02112b0d1f02da30973224fe27aeda8b9d4b2922" +
291                            "d9ba8be39ed9e103a63c52810bc688b7e2ed4316e1" +
292                            "ef17dbde", 16);
293 
294         dsaCache.put(Integer.valueOf(2048+224),
DSAParameterSpec(p2048_224, q2048_224, g2048_224)295                      new DSAParameterSpec(p2048_224, q2048_224, g2048_224));
296 
297         /*
298          * L = 2048, N = 256
299          * SEED = b0b4417601b59cbc9d8ac8f935cadaec \
300          *        4f5fbb2f23785609ae466748d9b5a536
301          * counter = 497
302          */
303         BigInteger p2048_256 =
304             new BigInteger("95475cf5d93e596c3fcd1d902add02f427f5f3c721" +
305                            "0313bb45fb4d5bb2e5fe1cbd678cd4bbdd84c9836b" +
306                            "e1f31c0777725aeb6c2fc38b85f48076fa76bcd814" +
307                            "6cc89a6fb2f706dd719898c2083dc8d896f84062e2" +
308                            "c9c94d137b054a8d8096adb8d51952398eeca852a0" +
309                            "af12df83e475aa65d4ec0c38a9560d5661186ff98b" +
310                            "9fc9eb60eee8b030376b236bc73be3acdbd74fd61c" +
311                            "1d2475fa3077b8f080467881ff7e1ca56fee066d79" +
312                            "506ade51edbb5443a563927dbc4ba520086746175c" +
313                            "8885925ebc64c6147906773496990cb714ec667304" +
314                            "e261faee33b3cbdf008e0c3fa90650d97d3909c927" +
315                            "5bf4ac86ffcb3d03e6dfc8ada5934242dd6d3bcca2" +
316                            "a406cb0b", 16);
317 
318         BigInteger q2048_256 =
319             new BigInteger("f8183668ba5fc5bb06b5981e6d8b795d30b8978d43" +
320                            "ca0ec572e37e09939a9773", 16);
321 
322         BigInteger g2048_256 =
323             new BigInteger("42debb9da5b3d88cc956e08787ec3f3a09bba5f48b" +
324                            "889a74aaf53174aa0fbe7e3c5b8fcd7a53bef563b0" +
325                            "e98560328960a9517f4014d3325fc7962bf1e04937" +
326                            "0d76d1314a76137e792f3f0db859d095e4a5b93202" +
327                            "4f079ecf2ef09c797452b0770e1350782ed57ddf79" +
328                            "4979dcef23cb96f183061965c4ebc93c9c71c56b92" +
329                            "5955a75f94cccf1449ac43d586d0beee43251b0b22" +
330                            "87349d68de0d144403f13e802f4146d882e057af19" +
331                            "b6f6275c6676c8fa0e3ca2713a3257fd1b27d0639f" +
332                            "695e347d8d1cf9ac819a26ca9b04cb0eb9b7b03598" +
333                            "8d15bbac65212a55239cfc7e58fae38d7250ab9991" +
334                            "ffbc97134025fe8ce04c4399ad96569be91a546f49" +
335                            "78693c7a", 16);
336 
337         dsaCache.put(Integer.valueOf(2048+256),
DSAParameterSpec(p2048_256, q2048_256, g2048_256)338                 new DSAParameterSpec(p2048_256, q2048_256, g2048_256));
339 
340 
341         /*
342          * L = 3072, N = 256
343          * SEED = 9fe304be4d6b9919559f39d5911d12e9 \
344          *        5158d6946598cd59775b8f3b8fff3a3f
345          * counter = 1186
346          */
347         BigInteger p3072_256 = new BigInteger(
348                 "ea9cda9f5fbda66dd830494609405687ab7cf38538e058d1" +
349                 "e2f68dea95364866e1c05beacded24227edee28cad80bcec" +
350                 "ad39913be3b713267b3b96c8d9f0f6a03b5dfc9222d5cfe4" +
351                 "afcc9982f33784f760c3b759aebe3bbe9098a6b84c96f1fd" +
352                 "e44ce11c084c2a082c7a76a0ef142928b4f328406ab9beb2" +
353                 "4f84577dd0f46ce86fd8f08488269998bf4742d6425f7a0e" +
354                 "c75d8660c5dd6f4e3b3d3bee81b2c21afe8c9e8b84b87192" +
355                 "e2cc20f961d2bcd8133afcf3675ab80681cb374c78f33e29" +
356                 "d1011083d89f9c5728b94676fccb1b57bc60288c15d85ae8" +
357                 "38ae1941c5a20ae2b2049b3583fe30da455ddb3e6ad9b995" +
358                 "5cd9bb5681431622beb0f92da533fcab496cebc447aa1bb5" +
359                 "a8039522f2da98ff416289323a64df626ab6881870927dce" +
360                 "e387f13b5c9d24d6cba1d82ed375a082506ee87bc7ae3006" +
361                 "7f4a94e2ee363d992c40f2725b5db4b3525ebde22bbbfd0f" +
362                 "a124a588b0f5a4acb3a86951aff09f8c8198fb5b53da0c93" +
363                 "1cedc598b4f835b779d04d99026c7ba08c4b27f118ac1e3d", 16);
364 
365         BigInteger q3072_256 = new BigInteger(
366                 "c4eeac2bbab79bd831946d717a56a6e687547aa8e9c5494a" +
367                 "5a4b2f4ca13d6c11", 16);
368 
369         BigInteger g3072_256 = new BigInteger(
370                 "42e5fa7844f8fa9d8998d830d004e7b15b1d276bcbe5f12c" +
371                 "35ec90c1a25f5832018a6724bd9cdbe803b675509bed167f" +
372                 "3d7cf8599fc865c6d5a0f79158c1bc918f00a944d0ad0f38" +
373                 "f520fb91d85d82674d0d5f874faa5fcdfe56cd178c1afdc7" +
374                 "ce8795727b7dee966ed0b3c5cedcef8aca628befebf2d105" +
375                 "c7aff8eb0da9c9610737dd64dce1237b82c1b2bc8608d55f" +
376                 "fda98d7189444e65883315669c05716bde36c78b130aa3df" +
377                 "2e4d609914c7c8dc470f4e300187c775f81e7b1a9c0dce40" +
378                 "5d6eab2cbb9d9c4ef44412ba573dd403c4ed7bc2364772f5" +
379                 "6a30c48de78f5003f9371c55262d2c8ac2246ade3b02fdcf" +
380                 "cf5cbfde74fbcbfe6e0e0fdf3160764f84d311c179a40af6" +
381                 "79a8f47ab13c8f706893245eb11edcce451fa2ab98001998" +
382                 "7f125d8dc96622d419ba0d71f16c6024dce9d364c3b26d8e" +
383                 "c1a3c828f6c9d14b1d0333b95db77bfdbe3c6bce5337a1a5" +
384                 "a7ace10111219448447197e2a344cc423be768bb89e27be6" +
385                 "cbd22085614a5a3360be23b1bfbb6e6e6471363d32c85d31", 16);
386 
387         dsaCache.put(Integer.valueOf(3072+256),
DSAParameterSpec(p3072_256, q3072_256, g3072_256)388                 new DSAParameterSpec(p3072_256, q3072_256, g3072_256));
389 
390         //
391         // Diffie-Hellman Groups
392         //
393 
394         // the common generator
395         BigInteger dhG = BigInteger.TWO;
396 
397         //
398         // From RFC 7296
399 
400         // The prime is: 2^768 - 2 ^704 - 1 + 2^64 * { [2^638 pi] + 149686 }
401         BigInteger dhP768 = new BigInteger(
402                 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
403                 "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
404                 "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
405                 "E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF", 16);
406 
407         // The prime is 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 }
408         BigInteger dhP1024 = new BigInteger(
409                 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
410                 "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
411                 "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
412                 "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
413                 "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" +
414                 "FFFFFFFFFFFFFFFF", 16);
415 
416         //
417         // From RFC 3526
418 
419         // The prime is: 2^1536 - 2^1472 - 1 + 2^64 * { [2^1406 pi] + 741804 }
420         BigInteger dhP1536 = new BigInteger(
421                 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
422                 "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
423                 "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
424                 "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
425                 "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
426                 "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
427                 "83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
428                 "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF", 16);
429 
430         // This prime is: 2^2048 - 2^1984 - 1 + 2^64 * { [2^1918 pi] + 124476 }
431         BigInteger dhP2048 = new BigInteger(
432                 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
433                 "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
434                 "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
435                 "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
436                 "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
437                 "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
438                 "83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
439                 "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" +
440                 "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" +
441                 "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" +
442                 "15728E5A8AACAA68FFFFFFFFFFFFFFFF", 16);
443 
444         // This prime is: 2^3072 - 2^3008 - 1 + 2^64 * { [2^2942 pi] + 1690314 }
445         BigInteger dhP3072 = new BigInteger(
446                 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
447                 "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
448                 "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
449                 "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
450                 "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
451                 "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
452                 "83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
453                 "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" +
454                 "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" +
455                 "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" +
456                 "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" +
457                 "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" +
458                 "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" +
459                 "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" +
460                 "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" +
461                 "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF", 16);
462 
463         // This prime is: 2^4096 - 2^4032 - 1 + 2^64 * { [2^3966 pi] + 240904 }
464         BigInteger dhP4096 = new BigInteger(
465                 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
466                 "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
467                 "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
468                 "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
469                 "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
470                 "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
471                 "83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
472                 "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" +
473                 "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" +
474                 "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" +
475                 "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" +
476                 "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" +
477                 "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" +
478                 "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" +
479                 "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" +
480                 "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" +
481                 "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" +
482                 "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" +
483                 "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" +
484                 "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" +
485                 "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" +
486                 "FFFFFFFFFFFFFFFF", 16);
487 
488         // This prime is: 2^6144 - 2^6080 - 1 + 2^64 * { [2^6014 pi] + 929484 }
489         BigInteger dhP6144 = new BigInteger(
490                 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E08" +
491                 "8A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B" +
492                 "302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9" +
493                 "A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE6" +
494                 "49286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8" +
495                 "FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
496                 "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C" +
497                 "180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF695581718" +
498                 "3995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D" +
499                 "04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7D" +
500                 "B3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D226" +
501                 "1AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200C" +
502                 "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFC" +
503                 "E0FD108E4B82D120A92108011A723C12A787E6D788719A10BDBA5B26" +
504                 "99C327186AF4E23C1A946834B6150BDA2583E9CA2AD44CE8DBBBC2DB" +
505                 "04DE8EF92E8EFC141FBECAA6287C59474E6BC05D99B2964FA090C3A2" +
506                 "233BA186515BE7ED1F612970CEE2D7AFB81BDD762170481CD0069127" +
507                 "D5B05AA993B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492" +
508                 "36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BDF8FF9406" +
509                 "AD9E530EE5DB382F413001AEB06A53ED9027D831179727B0865A8918" +
510                 "DA3EDBEBCF9B14ED44CE6CBACED4BB1BDB7F1447E6CC254B33205151" +
511                 "2BD7AF426FB8F401378CD2BF5983CA01C64B92ECF032EA15D1721D03" +
512                 "F482D7CE6E74FEF6D55E702F46980C82B5A84031900B1C9E59E7C97F" +
513                 "BEC7E8F323A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA" +
514                 "CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE32806A1D58B" +
515                 "B7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55CDA56C9EC2EF29632" +
516                 "387FE8D76E3C0468043E8F663F4860EE12BF2D5B0B7474D6E694F91E" +
517                 "6DCC4024FFFFFFFFFFFFFFFF", 16);
518 
519         // This prime is: 2^8192 - 2^8128 - 1 + 2^64 * { [2^8062 pi] + 4743158 }
520         BigInteger dhP8192 = new BigInteger(
521                 "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" +
522                 "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" +
523                 "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" +
524                 "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" +
525                 "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" +
526                 "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" +
527                 "83655D23DCA3AD961C62F356208552BB9ED529077096966D" +
528                 "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" +
529                 "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" +
530                 "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" +
531                 "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" +
532                 "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" +
533                 "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" +
534                 "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" +
535                 "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" +
536                 "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" +
537                 "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" +
538                 "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" +
539                 "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" +
540                 "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" +
541                 "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492" +
542                 "36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BD" +
543                 "F8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831" +
544                 "179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B" +
545                 "DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF" +
546                 "5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6" +
547                 "D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F3" +
548                 "23A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA" +
549                 "CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE328" +
550                 "06A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55C" +
551                 "DA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE" +
552                 "12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E4" +
553                 "38777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300" +
554                 "741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F568" +
555                 "3423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD9" +
556                 "22222E04A4037C0713EB57A81A23F0C73473FC646CEA306B" +
557                 "4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A" +
558                 "062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A36" +
559                 "4597E899A0255DC164F31CC50846851DF9AB48195DED7EA1" +
560                 "B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F92" +
561                 "4009438B481C6CD7889A002ED5EE382BC9190DA6FC026E47" +
562                 "9558E4475677E9AA9E3050E2765694DFC81F56E880B96E71" +
563                 "60C980DD98EDD3DFFFFFFFFFFFFFFFFF", 16);
564 
565         // use DSA parameters for DH for sizes not defined in RFC 7296, 3526
DHParameterSpec(p512, g512)566         dhCache.put(Integer.valueOf(512), new DHParameterSpec(p512, g512));
567 
DHParameterSpec(dhP768, dhG)568         dhCache.put(Integer.valueOf(768), new DHParameterSpec(dhP768, dhG));
DHParameterSpec(dhP1024, dhG)569         dhCache.put(Integer.valueOf(1024), new DHParameterSpec(dhP1024, dhG));
DHParameterSpec(dhP1536, dhG)570         dhCache.put(Integer.valueOf(1536), new DHParameterSpec(dhP1536, dhG));
DHParameterSpec(dhP2048, dhG)571         dhCache.put(Integer.valueOf(2048), new DHParameterSpec(dhP2048, dhG));
DHParameterSpec(dhP3072, dhG)572         dhCache.put(Integer.valueOf(3072), new DHParameterSpec(dhP3072, dhG));
DHParameterSpec(dhP4096, dhG)573         dhCache.put(Integer.valueOf(4096), new DHParameterSpec(dhP4096, dhG));
DHParameterSpec(dhP6144, dhG)574         dhCache.put(Integer.valueOf(6144), new DHParameterSpec(dhP6144, dhG));
DHParameterSpec(dhP8192, dhG)575         dhCache.put(Integer.valueOf(8192), new DHParameterSpec(dhP8192, dhG));
576     }
577 }
578