Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/crypto/fipsmodule/dh/dh.c

raw
1 // Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved.
2 // SPDX-License-Identifier: Apache-2.0
3
4 #include <openssl/dh.h>
5 #include <limits.h>
6
7 #include <string.h>
8
9 #include <openssl/bn.h>
10 #include <openssl/err.h>
11 #include <openssl/digest.h>
12 #include <openssl/mem.h>
13 #include <openssl/thread.h>
14
15 #include "internal.h"
16 #include "../../internal.h"
17 #include "../bn/internal.h"
18
19
20 DH *DH_new(void) {
21 DH *dh = OPENSSL_zalloc(sizeof(DH));
22 if (dh == NULL) {
23 return NULL;
24 }
25
26 CRYPTO_MUTEX_init(&dh->method_mont_p_lock);
27 dh->references = 1;
28 return dh;
29 }
30
31 DH *DH_new_by_nid(int nid) {
32 switch (nid) {
33 case NID_ffdhe2048:
34 return DH_get_rfc7919_2048();
35 case NID_ffdhe3072:
36 return DH_get_rfc7919_3072();
37 case NID_ffdhe4096:
38 return DH_get_rfc7919_4096();
39 case NID_ffdhe8192:
40 return DH_get_rfc7919_8192();
41 default:
42 OPENSSL_PUT_ERROR(DH, DH_R_INVALID_NID);
43 return NULL;
44 }
45 }
46
47 void DH_free(DH *dh) {
48 SET_DIT_AUTO_RESET;
49 if (dh == NULL) {
50 return;
51 }
52
53 if (!CRYPTO_refcount_dec_and_test_zero(&dh->references)) {
54 return;
55 }
56
57 BN_MONT_CTX_free(dh->method_mont_p);
58 BN_clear_free(dh->p);
59 BN_clear_free(dh->g);
60 BN_clear_free(dh->q);
61 BN_clear_free(dh->pub_key);
62 BN_clear_free(dh->priv_key);
63 CRYPTO_MUTEX_cleanup(&dh->method_mont_p_lock);
64
65 OPENSSL_free(dh);
66 }
67
68 unsigned DH_bits(const DH *dh) {
69 SET_DIT_AUTO_RESET;
70 return BN_num_bits(dh->p);
71 }
72
73 const BIGNUM *DH_get0_pub_key(const DH *dh) {
74 SET_DIT_AUTO_RESET;
75 return dh->pub_key;;
76 }
77
78 const BIGNUM *DH_get0_priv_key(const DH *dh) {
79 SET_DIT_AUTO_RESET;
80 return dh->priv_key;
81 }
82
83 const BIGNUM *DH_get0_p(const DH *dh) {
84 SET_DIT_AUTO_RESET;
85 return dh->p;
86 }
87
88 const BIGNUM *DH_get0_q(const DH *dh) {
89 SET_DIT_AUTO_RESET;
90 return dh->q;
91 }
92
93 const BIGNUM *DH_get0_g(const DH *dh) {
94 SET_DIT_AUTO_RESET;
95 return dh->g;
96 }
97
98 void DH_get0_key(const DH *dh, const BIGNUM **out_pub_key,
99 const BIGNUM **out_priv_key) {
100 SET_DIT_AUTO_RESET;
101 if (out_pub_key != NULL) {
102 *out_pub_key = dh->pub_key;
103 }
104 if (out_priv_key != NULL) {
105 *out_priv_key = dh->priv_key;
106 }
107 }
108
109 void DH_clear_flags(DH *dh, int flags) {
110 SET_DIT_AUTO_RESET;
111 (void) dh;
112 (void) flags;
113 }
114
115 int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) {
116 SET_DIT_AUTO_RESET;
117 if (pub_key != NULL) {
118 BN_free(dh->pub_key);
119 dh->pub_key = pub_key;
120 }
121
122 if (priv_key != NULL) {
123 BN_free(dh->priv_key);
124 dh->priv_key = priv_key;
125 }
126
127 return 1;
128 }
129
130 void DH_get0_pqg(const DH *dh, const BIGNUM **out_p, const BIGNUM **out_q,
131 const BIGNUM **out_g) {
132 SET_DIT_AUTO_RESET;
133 if (out_p != NULL) {
134 *out_p = dh->p;
135 }
136 if (out_q != NULL) {
137 *out_q = dh->q;
138 }
139 if (out_g != NULL) {
140 *out_g = dh->g;
141 }
142 }
143
144 int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) {
145 SET_DIT_AUTO_RESET;
146 if ((dh->p == NULL && p == NULL) ||
147 (dh->g == NULL && g == NULL)) {
148 return 0;
149 }
150
151 if (p != NULL) {
152 BN_free(dh->p);
153 dh->p = p;
154 }
155
156 if (q != NULL) {
157 BN_free(dh->q);
158 dh->q = q;
159 }
160
161 if (g != NULL) {
162 BN_free(dh->g);
163 dh->g = g;
164 }
165
166 // Invalidate the cached Montgomery parameters.
167 BN_MONT_CTX_free(dh->method_mont_p);
168 dh->method_mont_p = NULL;
169 return 1;
170 }
171
172 int DH_set_length(DH *dh, unsigned priv_length) {
173 SET_DIT_AUTO_RESET;
174 dh->priv_length = priv_length;
175 return 1;
176 }
177
178 int DH_generate_key(DH *dh) {
179 SET_DIT_AUTO_RESET;
180 boringssl_ensure_ffdh_self_test();
181
182 if (!dh_check_params_fast(dh)) {
183 return 0;
184 }
185
186 int ok = 0;
187 int generate_new_key = 0;
188 BN_CTX *ctx = NULL;
189 BIGNUM *pub_key = NULL, *priv_key = NULL, *priv_key_limit = NULL;
190
191 ctx = BN_CTX_new();
192 if (ctx == NULL) {
193 goto err;
194 }
195
196 if (dh->priv_key == NULL) {
197 priv_key = BN_new();
198 if (priv_key == NULL) {
199 goto err;
200 }
201 generate_new_key = 1;
202 } else {
203 priv_key = dh->priv_key;
204 }
205
206 if (dh->pub_key == NULL) {
207 pub_key = BN_new();
208 if (pub_key == NULL) {
209 goto err;
210 }
211 } else {
212 pub_key = dh->pub_key;
213 }
214
215 if (!BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock,
216 dh->p, ctx)) {
217 goto err;
218 }
219
220 if (generate_new_key) {
221 if (dh->q) {
222 // Section 5.6.1.1.4 of SP 800-56A Rev3 generates a private key uniformly
223 // from [1, min(2^N-1, q-1)].
224 //
225 // Although SP 800-56A Rev3 now permits a private key length N,
226 // |dh->priv_length| historically was ignored when q is available. We
227 // continue to ignore it and interpret such a configuration as N = len(q).
228 if (!BN_rand_range_ex(priv_key, 1, dh->q)) {
229 goto err;
230 }
231 } else {
232 // If q is unspecified, we expect p to be a safe prime, with g generating
233 // the (p-1)/2 subgroup. So, we use q = (p-1)/2. (If g generates a smaller
234 // prime-order subgroup, q will still divide (p-1)/2.)
235 //
236 // We set N from |dh->priv_length|. Section 5.6.1.1.4 of SP 800-56A Rev3
237 // says to reject N > len(q), or N > num_bits(p) - 1. However, this logic
238 // originally aligned with PKCS#3, which allows num_bits(p). Instead, we
239 // clamp |dh->priv_length| before invoking the algorithm.
240
241 // Compute M = min(2^N, q).
242 priv_key_limit = BN_new();
243 if (priv_key_limit == NULL) {
244 goto err;
245 }
246 if (dh->priv_length == 0 || dh->priv_length >= BN_num_bits(dh->p) - 1) {
247 // M = q = (p - 1) / 2.
248 if (!BN_rshift1(priv_key_limit, dh->p)) {
249 goto err;
250 }
251 } else {
252 // M = 2^N.
253 if (!BN_set_bit(priv_key_limit, dh->priv_length)) {
254 goto err;
255 }
256 }
257
258 // Choose a private key uniformly from [1, M-1].
259 if (!BN_rand_range_ex(priv_key, 1, priv_key_limit)) {
260 goto err;
261 }
262 }
263 }
264
265 if (!BN_mod_exp_mont_consttime(pub_key, dh->g, priv_key, dh->p, ctx,
266 dh->method_mont_p)) {
267 goto err;
268 }
269
270 dh->pub_key = pub_key;
271 dh->priv_key = priv_key;
272 ok = 1;
273
274 err:
275 if (ok != 1) {
276 OPENSSL_PUT_ERROR(DH, ERR_R_BN_LIB);
277 }
278
279 if (dh->pub_key == NULL) {
280 BN_free(pub_key);
281 }
282 if (dh->priv_key == NULL) {
283 BN_free(priv_key);
284 }
285 BN_free(priv_key_limit);
286 BN_CTX_free(ctx);
287 return ok;
288 }
289
290 static int dh_compute_key(DH *dh, BIGNUM *out_shared_key,
291 const BIGNUM *peers_key, BN_CTX *ctx) {
292 if (!dh_check_params_fast(dh)) {
293 return 0;
294 }
295
296 if (dh->priv_key == NULL) {
297 OPENSSL_PUT_ERROR(DH, DH_R_NO_PRIVATE_VALUE);
298 return 0;
299 }
300
301 int check_result;
302 if (!DH_check_pub_key(dh, peers_key, &check_result) || check_result) {
303 OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PUBKEY);
304 return 0;
305 }
306
307 int ret = 0;
308 BN_CTX_start(ctx);
309 BIGNUM *p_minus_1 = BN_CTX_get(ctx);
310
311 if (!p_minus_1 ||
312 !BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock,
313 dh->p, ctx)) {
314 goto err;
315 }
316
317 if (!BN_mod_exp_mont_consttime(out_shared_key, peers_key, dh->priv_key, dh->p,
318 ctx, dh->method_mont_p) ||
319 !BN_copy(p_minus_1, dh->p) ||
320 !BN_sub_word(p_minus_1, 1)) {
321 OPENSSL_PUT_ERROR(DH, ERR_R_BN_LIB);
322 goto err;
323 }
324
325 // This performs the check required by SP 800-56Ar3 section 5.7.1.1 step two.
326 if (BN_cmp_word(out_shared_key, 1) <= 0 ||
327 BN_cmp(out_shared_key, p_minus_1) == 0) {
328 OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PUBKEY);
329 goto err;
330 }
331
332 ret = 1;
333
334 err:
335 BN_CTX_end(ctx);
336 return ret;
337 }
338
339 int dh_compute_key_padded_no_self_test(unsigned char *out,
340 const BIGNUM *peers_key, DH *dh) {
341 BN_CTX *ctx = BN_CTX_new();
342 if (ctx == NULL) {
343 return -1;
344 }
345 BN_CTX_start(ctx);
346
347 int dh_size = DH_size(dh);
348 int ret = -1;
349 BIGNUM *shared_key = BN_CTX_get(ctx);
350 if (shared_key &&
351 dh_compute_key(dh, shared_key, peers_key, ctx) &&
352 BN_bn2bin_padded(out, dh_size, shared_key)) {
353 ret = dh_size;
354 }
355
356 BN_CTX_end(ctx);
357 BN_CTX_free(ctx);
358 return ret;
359 }
360
361 int DH_compute_key_padded(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
362 boringssl_ensure_ffdh_self_test();
363 SET_DIT_AUTO_RESET;
364
365 return dh_compute_key_padded_no_self_test(out, peers_key, dh);
366 }
367
368 int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
369 boringssl_ensure_ffdh_self_test();
370 SET_DIT_AUTO_RESET;
371
372 BN_CTX *ctx = BN_CTX_new();
373 if (ctx == NULL) {
374 return -1;
375 }
376 BN_CTX_start(ctx);
377
378 int ret = -1;
379 BIGNUM *shared_key = BN_CTX_get(ctx);
380 if (shared_key && dh_compute_key(dh, shared_key, peers_key, ctx)) {
381 // A |BIGNUM|'s byte count fits in |int|.
382 ret = (int)BN_bn2bin(shared_key, out);
383 }
384
385 BN_CTX_end(ctx);
386 BN_CTX_free(ctx);
387 return ret;
388 }
389
390 int DH_compute_key_hashed(DH *dh, uint8_t *out, size_t *out_len,
391 size_t max_out_len, const BIGNUM *peers_key,
392 const EVP_MD *digest) {
393 SET_DIT_AUTO_RESET;
394
395 *out_len = SIZE_MAX;
396
397 const size_t digest_len = EVP_MD_size(digest);
398 if ((EVP_MD_flags(digest) & EVP_MD_FLAG_XOF) || digest_len > max_out_len
399 #if SIZE_MAX > UINT_MAX
400 || digest_len > UINT_MAX
401 #endif
402 ) {
403 return 0;
404 }
405
406 // We have to avoid the underlying |EVP_Digest| services updating the indicator
407 // state, so we lock the state here.
408 FIPS_service_indicator_lock_state();
409
410 int ret = 0;
411 const size_t dh_len = DH_size(dh);
412 uint8_t *shared_bytes = OPENSSL_malloc(dh_len);
413 unsigned out_len_unsigned = (unsigned)digest_len;
414 if (!shared_bytes ||
415 // SP 800-56A is ambiguous about whether the output should be padded prior
416 // to revision three. But revision three, section C.1, awkwardly specifies
417 // padding to the length of p.
418 //
419 // Also, padded output avoids side-channels, so is always strongly
420 // advisable.
421 DH_compute_key_padded(shared_bytes, peers_key, dh) != (int)dh_len ||
422 !EVP_Digest(shared_bytes, dh_len, out, &out_len_unsigned, digest, NULL) ||
423 out_len_unsigned != digest_len) {
424 goto err;
425 }
426
427 *out_len = digest_len;
428 ret = 1;
429
430 err:
431 FIPS_service_indicator_unlock_state();
432 OPENSSL_free(shared_bytes);
433 return ret;
434 }
435
436 int DH_size(const DH *dh) {
437 SET_DIT_AUTO_RESET;
438 return BN_num_bytes(dh->p);
439 }
440
441 unsigned DH_num_bits(const DH *dh) {
442 SET_DIT_AUTO_RESET;
443 return BN_num_bits(dh->p);
444 }
445
446 int DH_up_ref(DH *dh) {
447 SET_DIT_AUTO_RESET;
448 CRYPTO_refcount_inc(&dh->references);
449 return 1;
450 }
451
452 // All the groups in RFC 7919 are of the form:
453 // q = (p-1)/2
454 // g = 2
455 static DH *calculate_rfc7919_DH_from_p(const BN_ULONG data[], size_t data_len) {
456 BIGNUM *const ffdhe_p = BN_new();
457 BIGNUM *const ffdhe_q = BN_new();
458 BIGNUM *const ffdhe_g = BN_new();
459 DH *const dh = DH_new();
460
461 if (!ffdhe_p || !ffdhe_q || !ffdhe_g || !dh) {
462 goto err;
463 }
464
465 bn_set_static_words(ffdhe_p, data, data_len);
466
467 if (!BN_rshift1(ffdhe_q, ffdhe_p) ||
468 !BN_set_word(ffdhe_g, 2) ||
469 !DH_set0_pqg(dh, ffdhe_p, ffdhe_q, ffdhe_g)) {
470 goto err;
471 }
472
473 return dh;
474
475 err:
476 BN_free(ffdhe_p);
477 BN_free(ffdhe_q);
478 BN_free(ffdhe_g);
479 DH_free(dh);
480 return NULL;
481
482 }
483
484 DH *DH_get_rfc7919_2048(void) {
485 // This is the prime from https://tools.ietf.org/html/rfc7919#appendix-A.1,
486 // which is specifically approved for FIPS in appendix D of SP 800-56Ar3.
487 static const BN_ULONG kFFDHE2048Data[] = {
488 TOBN(0xffffffff, 0xffffffff), TOBN(0x886b4238, 0x61285c97),
489 TOBN(0xc6f34a26, 0xc1b2effa), TOBN(0xc58ef183, 0x7d1683b2),
490 TOBN(0x3bb5fcbc, 0x2ec22005), TOBN(0xc3fe3b1b, 0x4c6fad73),
491 TOBN(0x8e4f1232, 0xeef28183), TOBN(0x9172fe9c, 0xe98583ff),
492 TOBN(0xc03404cd, 0x28342f61), TOBN(0x9e02fce1, 0xcdf7e2ec),
493 TOBN(0x0b07a7c8, 0xee0a6d70), TOBN(0xae56ede7, 0x6372bb19),
494 TOBN(0x1d4f42a3, 0xde394df4), TOBN(0xb96adab7, 0x60d7f468),
495 TOBN(0xd108a94b, 0xb2c8e3fb), TOBN(0xbc0ab182, 0xb324fb61),
496 TOBN(0x30acca4f, 0x483a797a), TOBN(0x1df158a1, 0x36ade735),
497 TOBN(0xe2a689da, 0xf3efe872), TOBN(0x984f0c70, 0xe0e68b77),
498 TOBN(0xb557135e, 0x7f57c935), TOBN(0x85636555, 0x3ded1af3),
499 TOBN(0x2433f51f, 0x5f066ed0), TOBN(0xd3df1ed5, 0xd5fd6561),
500 TOBN(0xf681b202, 0xaec4617a), TOBN(0x7d2fe363, 0x630c75d8),
501 TOBN(0xcc939dce, 0x249b3ef9), TOBN(0xa9e13641, 0x146433fb),
502 TOBN(0xd8b9c583, 0xce2d3695), TOBN(0xafdc5620, 0x273d3cf1),
503 TOBN(0xadf85458, 0xa2bb4a9a), TOBN(0xffffffff, 0xffffffff),
504 };
505
506 return calculate_rfc7919_DH_from_p(kFFDHE2048Data, OPENSSL_ARRAY_SIZE(kFFDHE2048Data));
507 }
508
509 DH *DH_get_rfc7919_3072(void) {
510 // This is the prime from https://tools.ietf.org/html/rfc7919#appendix-A.2,
511 // which is specifically approved for FIPS in appendix D of SP 800-56Ar3.
512 static const BN_ULONG kFFDHE3072Data[] = {
513 TOBN(0xffffffff, 0xffffffff), TOBN(0x25e41d2b, 0x66c62e37),
514 TOBN(0x3c1b20ee, 0x3fd59d7c), TOBN(0x0abcd06b, 0xfa53ddef),
515 TOBN(0x1dbf9a42, 0xd5c4484e), TOBN(0xabc52197, 0x9b0deada),
516 TOBN(0xe86d2bc5, 0x22363a0d), TOBN(0x5cae82ab, 0x9c9df69e),
517 TOBN(0x64f2e21e, 0x71f54bff), TOBN(0xf4fd4452, 0xe2d74dd3),
518 TOBN(0xb4130c93, 0xbc437944), TOBN(0xaefe1309, 0x85139270),
519 TOBN(0x598cb0fa, 0xc186d91c), TOBN(0x7ad91d26, 0x91f7f7ee),
520 TOBN(0x61b46fc9, 0xd6e6c907), TOBN(0xbc34f4de, 0xf99c0238),
521 TOBN(0xde355b3b, 0x6519035b), TOBN(0x886b4238, 0x611fcfdc),
522 TOBN(0xc6f34a26, 0xc1b2effa), TOBN(0xc58ef183, 0x7d1683b2),
523 TOBN(0x3bb5fcbc, 0x2ec22005), TOBN(0xc3fe3b1b, 0x4c6fad73),
524 TOBN(0x8e4f1232, 0xeef28183), TOBN(0x9172fe9c, 0xe98583ff),
525 TOBN(0xc03404cd, 0x28342f61), TOBN(0x9e02fce1, 0xcdf7e2ec),
526 TOBN(0x0b07a7c8, 0xee0a6d70), TOBN(0xae56ede7, 0x6372bb19),
527 TOBN(0x1d4f42a3, 0xde394df4), TOBN(0xb96adab7, 0x60d7f468),
528 TOBN(0xd108a94b, 0xb2c8e3fb), TOBN(0xbc0ab182, 0xb324fb61),
529 TOBN(0x30acca4f, 0x483a797a), TOBN(0x1df158a1, 0x36ade735),
530 TOBN(0xe2a689da, 0xf3efe872), TOBN(0x984f0c70, 0xe0e68b77),
531 TOBN(0xb557135e, 0x7f57c935), TOBN(0x85636555, 0x3ded1af3),
532 TOBN(0x2433f51f, 0x5f066ed0), TOBN(0xd3df1ed5, 0xd5fd6561),
533 TOBN(0xf681b202, 0xaec4617a), TOBN(0x7d2fe363, 0x630c75d8),
534 TOBN(0xcc939dce, 0x249b3ef9), TOBN(0xa9e13641, 0x146433fb),
535 TOBN(0xd8b9c583, 0xce2d3695), TOBN(0xafdc5620, 0x273d3cf1),
536 TOBN(0xadf85458, 0xa2bb4a9a), TOBN(0xffffffff, 0xffffffff)};
537
538 return calculate_rfc7919_DH_from_p(kFFDHE3072Data,
539 OPENSSL_ARRAY_SIZE(kFFDHE3072Data));
540 }
541
542 DH *DH_get_rfc7919_4096(void) {
543 // This is the prime from https://tools.ietf.org/html/rfc7919#appendix-A.3,
544 // which is specifically approved for FIPS in appendix D of SP 800-56Ar3.
545 static const BN_ULONG kFFDHE4096Data[] = {
546 TOBN(0xFFFFFFFF, 0xFFFFFFFF),TOBN(0xC68A007E, 0x5E655F6A),
547 TOBN(0x4DB5A851, 0xF44182E1),TOBN(0x8EC9B55A, 0x7F88A46B),
548 TOBN(0x0A8291CD, 0xCEC97DCF),TOBN(0x2A4ECEA9, 0xF98D0ACC),
549 TOBN(0x1A1DB93D, 0x7140003C),TOBN(0x092999A3, 0x33CB8B7A),
550 TOBN(0x6DC778F9, 0x71AD0038),TOBN(0xA907600A, 0x918130C4),
551 TOBN(0xED6A1E01, 0x2D9E6832),TOBN(0x7135C886, 0xEFB4318A),
552 TOBN(0x87F55BA5, 0x7E31CC7A),TOBN(0x7763CF1D, 0x55034004),
553 TOBN(0xAC7D5F42, 0xD69F6D18),TOBN(0x7930E9E4, 0xE58857B6),
554 TOBN(0x6E6F52C3, 0x164DF4FB),TOBN(0x25E41D2B, 0x669E1EF1),
555 TOBN(0x3C1B20EE, 0x3FD59D7C),TOBN(0x0ABCD06B, 0xFA53DDEF),
556 TOBN(0x1DBF9A42, 0xD5C4484E),TOBN(0xABC52197, 0x9B0DEADA),
557 TOBN(0xE86D2BC5, 0x22363A0D),TOBN(0x5CAE82AB, 0x9C9DF69E),
558 TOBN(0x64F2E21E, 0x71F54BFF),TOBN(0xF4FD4452, 0xE2D74DD3),
559 TOBN(0xB4130C93, 0xBC437944),TOBN(0xAEFE1309, 0x85139270),
560 TOBN(0x598CB0FA, 0xC186D91C),TOBN(0x7AD91D26, 0x91F7F7EE),
561 TOBN(0x61B46FC9, 0xD6E6C907),TOBN(0xBC34F4DE, 0xF99C0238),
562 TOBN(0xDE355B3B, 0x6519035B),TOBN(0x886B4238, 0x611FCFDC),
563 TOBN(0xC6F34A26, 0xC1B2EFFA),TOBN(0xC58EF183, 0x7D1683B2),
564 TOBN(0x3BB5FCBC, 0x2EC22005),TOBN(0xC3FE3B1B, 0x4C6FAD73),
565 TOBN(0x8E4F1232, 0xEEF28183),TOBN(0x9172FE9C, 0xE98583FF),
566 TOBN(0xC03404CD, 0x28342F61),TOBN(0x9E02FCE1, 0xCDF7E2EC),
567 TOBN(0x0B07A7C8, 0xEE0A6D70),TOBN(0xAE56EDE7, 0x6372BB19),
568 TOBN(0x1D4F42A3, 0xDE394DF4),TOBN(0xB96ADAB7, 0x60D7F468),
569 TOBN(0xD108A94B, 0xB2C8E3FB),TOBN(0xBC0AB182, 0xB324FB61),
570 TOBN(0x30ACCA4F, 0x483A797A),TOBN(0x1DF158A1, 0x36ADE735),
571 TOBN(0xE2A689DA, 0xF3EFE872),TOBN(0x984F0C70, 0xE0E68B77),
572 TOBN(0xB557135E, 0x7F57C935),TOBN(0x85636555, 0x3DED1AF3),
573 TOBN(0x2433F51F, 0x5F066ED0),TOBN(0xD3DF1ED5, 0xD5FD6561),
574 TOBN(0xF681B202, 0xAEC4617A),TOBN(0x7D2FE363, 0x630C75D8),
575 TOBN(0xCC939DCE, 0x249B3EF9),TOBN(0xA9E13641, 0x146433FB),
576 TOBN(0xD8B9C583, 0xCE2D3695),TOBN(0xAFDC5620, 0x273D3CF1),
577 TOBN(0xADF85458, 0xA2BB4A9A),TOBN(0xFFFFFFFF, 0xFFFFFFFF)
578 };
579
580 return calculate_rfc7919_DH_from_p(kFFDHE4096Data, OPENSSL_ARRAY_SIZE(kFFDHE4096Data));
581 }
582
583 DH *DH_get_rfc7919_8192(void) {
584 // This is the prime from https://tools.ietf.org/html/rfc7919#appendix-A.4,
585 // which is specifically approved for FIPS in appendix D of SP 800-56Ar3.
586 static const BN_ULONG kFFDHE8192Data[] = {
587 TOBN(0xffffffff, 0xffffffff), TOBN(0xd68c8bb7, 0xc5c6424c),
588 TOBN(0x011e2a94, 0x838ff88c), TOBN(0x0822e506, 0xa9f4614e),
589 TOBN(0x97d11d49, 0xf7a8443d), TOBN(0xa6bbfde5, 0x30677f0d),
590 TOBN(0x2f741ef8, 0xc1fe86fe), TOBN(0xfafabe1c, 0x5d71a87e),
591 TOBN(0xded2fbab, 0xfbe58a30), TOBN(0xb6855dfe, 0x72b0a66e),
592 TOBN(0x1efc8ce0, 0xba8a4fe8), TOBN(0x83f81d4a, 0x3f2fa457),
593 TOBN(0xa1fe3075, 0xa577e231), TOBN(0xd5b80194, 0x88d9c0a0),
594 TOBN(0x624816cd, 0xad9a95f9), TOBN(0x99e9e316, 0x50c1217b),
595 TOBN(0x51aa691e, 0x0e423cfc), TOBN(0x1c217e6c, 0x3826e52c),
596 TOBN(0x51a8a931, 0x09703fee), TOBN(0xbb709987, 0x6a460e74),
597 TOBN(0x541fc68c, 0x9c86b022), TOBN(0x59160cc0, 0x46fd8251),
598 TOBN(0x2846c0ba, 0x35c35f5c), TOBN(0x54504ac7, 0x8b758282),
599 TOBN(0x29388839, 0xd2af05e4), TOBN(0xcb2c0f1c, 0xc01bd702),
600 TOBN(0x555b2f74, 0x7c932665), TOBN(0x86b63142, 0xa3ab8829),
601 TOBN(0x0b8cc3bd, 0xf64b10ef), TOBN(0x687feb69, 0xedd1cc5e),
602 TOBN(0xfdb23fce, 0xc9509d43), TOBN(0x1e425a31, 0xd951ae64),
603 TOBN(0x36ad004c, 0xf600c838), TOBN(0xa40e329c, 0xcff46aaa),
604 TOBN(0xa41d570d, 0x7938dad4), TOBN(0x62a69526, 0xd43161c1),
605 TOBN(0x3fdd4a8e, 0x9adb1e69), TOBN(0x5b3b71f9, 0xdc6b80d6),
606 TOBN(0xec9d1810, 0xc6272b04), TOBN(0x8ccf2dd5, 0xcacef403),
607 TOBN(0xe49f5235, 0xc95b9117), TOBN(0x505dc82d, 0xb854338a),
608 TOBN(0x62292c31, 0x1562a846), TOBN(0xd72b0374, 0x6ae77f5e),
609 TOBN(0xf9c9091b, 0x462d538c), TOBN(0x0ae8db58, 0x47a67cbe),
610 TOBN(0xb3a739c1, 0x22611682), TOBN(0xeeaac023, 0x2a281bf6),
611 TOBN(0x94c6651e, 0x77caf992), TOBN(0x763e4e4b, 0x94b2bbc1),
612 TOBN(0x587e38da, 0x0077d9b4), TOBN(0x7fb29f8c, 0x183023c3),
613 TOBN(0x0abec1ff, 0xf9e3a26e), TOBN(0xa00ef092, 0x350511e3),
614 TOBN(0xb855322e, 0xdb6340d8), TOBN(0xa52471f7, 0xa9a96910),
615 TOBN(0x388147fb, 0x4cfdb477), TOBN(0x9b1f5c3e, 0x4e46041f),
616 TOBN(0xcdad0657, 0xfccfec71), TOBN(0xb38e8c33, 0x4c701c3a),
617 TOBN(0x917bdd64, 0xb1c0fd4c), TOBN(0x3bb45432, 0x9b7624c8),
618 TOBN(0x23ba4442, 0xcaf53ea6), TOBN(0x4e677d2c, 0x38532a3a),
619 TOBN(0x0bfd64b6, 0x45036c7a), TOBN(0xc68a007e, 0x5e0dd902),
620 TOBN(0x4db5a851, 0xf44182e1), TOBN(0x8ec9b55a, 0x7f88a46b),
621 TOBN(0x0a8291cd, 0xcec97dcf), TOBN(0x2a4ecea9, 0xf98d0acc),
622 TOBN(0x1a1db93d, 0x7140003c), TOBN(0x092999a3, 0x33cb8b7a),
623 TOBN(0x6dc778f9, 0x71ad0038), TOBN(0xa907600a, 0x918130c4),
624 TOBN(0xed6a1e01, 0x2d9e6832), TOBN(0x7135c886, 0xefb4318a),
625 TOBN(0x87f55ba5, 0x7e31cc7a), TOBN(0x7763cf1d, 0x55034004),
626 TOBN(0xac7d5f42, 0xd69f6d18), TOBN(0x7930e9e4, 0xe58857b6),
627 TOBN(0x6e6f52c3, 0x164df4fb), TOBN(0x25e41d2b, 0x669e1ef1),
628 TOBN(0x3c1b20ee, 0x3fd59d7c), TOBN(0x0abcd06b, 0xfa53ddef),
629 TOBN(0x1dbf9a42, 0xd5c4484e), TOBN(0xabc52197, 0x9b0deada),
630 TOBN(0xe86d2bc5, 0x22363a0d), TOBN(0x5cae82ab, 0x9c9df69e),
631 TOBN(0x64f2e21e, 0x71f54bff), TOBN(0xf4fd4452, 0xe2d74dd3),
632 TOBN(0xb4130c93, 0xbc437944), TOBN(0xaefe1309, 0x85139270),
633 TOBN(0x598cb0fa, 0xc186d91c), TOBN(0x7ad91d26, 0x91f7f7ee),
634 TOBN(0x61b46fc9, 0xd6e6c907), TOBN(0xbc34f4de, 0xf99c0238),
635 TOBN(0xde355b3b, 0x6519035b), TOBN(0x886b4238, 0x611fcfdc),
636 TOBN(0xc6f34a26, 0xc1b2effa), TOBN(0xc58ef183, 0x7d1683b2),
637 TOBN(0x3bb5fcbc, 0x2ec22005), TOBN(0xc3fe3b1b, 0x4c6fad73),
638 TOBN(0x8e4f1232, 0xeef28183), TOBN(0x9172fe9c, 0xe98583ff),
639 TOBN(0xc03404cd, 0x28342f61), TOBN(0x9e02fce1, 0xcdf7e2ec),
640 TOBN(0x0b07a7c8, 0xee0a6d70), TOBN(0xae56ede7, 0x6372bb19),
641 TOBN(0x1d4f42a3, 0xde394df4), TOBN(0xb96adab7, 0x60d7f468),
642 TOBN(0xd108a94b, 0xb2c8e3fb), TOBN(0xbc0ab182, 0xb324fb61),
643 TOBN(0x30acca4f, 0x483a797a), TOBN(0x1df158a1, 0x36ade735),
644 TOBN(0xe2a689da, 0xf3efe872), TOBN(0x984f0c70, 0xe0e68b77),
645 TOBN(0xb557135e, 0x7f57c935), TOBN(0x85636555, 0x3ded1af3),
646 TOBN(0x2433f51f, 0x5f066ed0), TOBN(0xd3df1ed5, 0xd5fd6561),
647 TOBN(0xf681b202, 0xaec4617a), TOBN(0x7d2fe363, 0x630c75d8),
648 TOBN(0xcc939dce, 0x249b3ef9), TOBN(0xa9e13641, 0x146433fb),
649 TOBN(0xd8b9c583, 0xce2d3695), TOBN(0xafdc5620, 0x273d3cf1),
650 TOBN(0xadf85458, 0xa2bb4a9a), TOBN(0xffffffff, 0xffffffff)};
651
652 return calculate_rfc7919_DH_from_p(kFFDHE8192Data,
653 OPENSSL_ARRAY_SIZE(kFFDHE8192Data));
654 }