diff options
Diffstat (limited to 'src/lib/libcrypto/dh')
| -rw-r--r-- | src/lib/libcrypto/dh/dh_ameth.c | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/dh/dh_check.c | 68 | ||||
| -rw-r--r-- | src/lib/libcrypto/dh/dh_gen.c | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/dh/dh_key.c | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/dh/dh_lib.c | 4 | ||||
| -rw-r--r-- | src/lib/libcrypto/dh/dh_pmeth.c | 4 |
6 files changed, 75 insertions, 13 deletions
diff --git a/src/lib/libcrypto/dh/dh_ameth.c b/src/lib/libcrypto/dh/dh_ameth.c index 289307bfd6..ec59245b9c 100644 --- a/src/lib/libcrypto/dh/dh_ameth.c +++ b/src/lib/libcrypto/dh/dh_ameth.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dh_ameth.c,v 1.42 2025/01/17 05:04:25 tb Exp $ */ | 1 | /* $OpenBSD: dh_ameth.c,v 1.43 2025/05/10 05:54:38 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 2006. | 3 | * project 2006. |
| 4 | */ | 4 | */ |
| @@ -61,12 +61,12 @@ | |||
| 61 | #include <openssl/asn1.h> | 61 | #include <openssl/asn1.h> |
| 62 | #include <openssl/bn.h> | 62 | #include <openssl/bn.h> |
| 63 | #include <openssl/dh.h> | 63 | #include <openssl/dh.h> |
| 64 | #include <openssl/err.h> | ||
| 65 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
| 66 | 65 | ||
| 67 | #include "asn1_local.h" | 66 | #include "asn1_local.h" |
| 68 | #include "bn_local.h" | 67 | #include "bn_local.h" |
| 69 | #include "dh_local.h" | 68 | #include "dh_local.h" |
| 69 | #include "err_local.h" | ||
| 70 | #include "evp_local.h" | 70 | #include "evp_local.h" |
| 71 | 71 | ||
| 72 | static void | 72 | static void |
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c index a880f9fca1..d724e33eec 100644 --- a/src/lib/libcrypto/dh/dh_check.c +++ b/src/lib/libcrypto/dh/dh_check.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dh_check.c,v 1.30 2024/11/29 15:59:57 tb Exp $ */ | 1 | /* $OpenBSD: dh_check.c,v 1.33 2026/01/23 08:32:22 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -60,7 +60,6 @@ | |||
| 60 | 60 | ||
| 61 | #include <openssl/bn.h> | 61 | #include <openssl/bn.h> |
| 62 | #include <openssl/dh.h> | 62 | #include <openssl/dh.h> |
| 63 | #include <openssl/err.h> | ||
| 64 | 63 | ||
| 65 | #include "bn_local.h" | 64 | #include "bn_local.h" |
| 66 | #include "dh_local.h" | 65 | #include "dh_local.h" |
| @@ -105,6 +104,63 @@ DH_check_params(const DH *dh, int *flags) | |||
| 105 | return ok; | 104 | return ok; |
| 106 | } | 105 | } |
| 107 | 106 | ||
| 107 | typedef BIGNUM *(*get_p_fn)(BIGNUM *); | ||
| 108 | |||
| 109 | static const get_p_fn get_well_known_p[] = { | ||
| 110 | BN_get_rfc2409_prime_768, | ||
| 111 | BN_get_rfc2409_prime_1024, | ||
| 112 | BN_get_rfc3526_prime_1536, | ||
| 113 | BN_get_rfc3526_prime_2048, | ||
| 114 | BN_get_rfc3526_prime_3072, | ||
| 115 | BN_get_rfc3526_prime_4096, | ||
| 116 | BN_get_rfc3526_prime_6144, | ||
| 117 | BN_get_rfc3526_prime_8192, | ||
| 118 | BN_get_rfc7919_prime_2048, | ||
| 119 | BN_get_rfc7919_prime_3072, | ||
| 120 | BN_get_rfc7919_prime_4096, | ||
| 121 | BN_get_rfc7919_prime_6144, | ||
| 122 | BN_get_rfc7919_prime_8192, | ||
| 123 | }; | ||
| 124 | |||
| 125 | #define N_WELL_KNOWN_P_FN (sizeof(get_well_known_p) / sizeof(get_well_known_p[0])) | ||
| 126 | |||
| 127 | /* | ||
| 128 | * Scapy special: on startup it now calls DH_check() on all the well-known DH | ||
| 129 | * primes, which is a sensible thing to do. In any case, using BN_is_prime_ex() | ||
| 130 | * on a standardized domain parameter is dumb, so avoid it. | ||
| 131 | */ | ||
| 132 | static int | ||
| 133 | dh_is_well_known_p(const BIGNUM *p, BN_CTX *ctx, int *is_well_known) | ||
| 134 | { | ||
| 135 | BIGNUM *bn; | ||
| 136 | size_t i; | ||
| 137 | int ret = 0; | ||
| 138 | |||
| 139 | *is_well_known = 0; | ||
| 140 | |||
| 141 | BN_CTX_start(ctx); | ||
| 142 | if ((bn = BN_CTX_get(ctx)) == NULL) | ||
| 143 | goto err; | ||
| 144 | |||
| 145 | for (i = 0; i < N_WELL_KNOWN_P_FN; i++) { | ||
| 146 | get_p_fn get_p = get_well_known_p[i]; | ||
| 147 | |||
| 148 | if (get_p(bn) == NULL) | ||
| 149 | goto err; | ||
| 150 | if (BN_cmp(bn, p) == 0) { | ||
| 151 | *is_well_known = 1; | ||
| 152 | break; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | |||
| 156 | ret = 1; | ||
| 157 | |||
| 158 | err: | ||
| 159 | BN_CTX_end(ctx); | ||
| 160 | |||
| 161 | return ret; | ||
| 162 | } | ||
| 163 | |||
| 108 | /* | 164 | /* |
| 109 | * Check that p is a safe prime and that g is a suitable generator. | 165 | * Check that p is a safe prime and that g is a suitable generator. |
| 110 | */ | 166 | */ |
| @@ -113,7 +169,7 @@ int | |||
| 113 | DH_check(const DH *dh, int *flags) | 169 | DH_check(const DH *dh, int *flags) |
| 114 | { | 170 | { |
| 115 | BN_CTX *ctx = NULL; | 171 | BN_CTX *ctx = NULL; |
| 116 | int is_prime; | 172 | int is_prime, is_well_known; |
| 117 | int ok = 0; | 173 | int ok = 0; |
| 118 | 174 | ||
| 119 | *flags = 0; | 175 | *flags = 0; |
| @@ -151,6 +207,11 @@ DH_check(const DH *dh, int *flags) | |||
| 151 | *flags |= DH_CHECK_INVALID_Q_VALUE; | 207 | *flags |= DH_CHECK_INVALID_Q_VALUE; |
| 152 | } | 208 | } |
| 153 | 209 | ||
| 210 | if (!dh_is_well_known_p(dh->p, ctx, &is_well_known)) | ||
| 211 | goto err; | ||
| 212 | if (is_well_known) | ||
| 213 | goto done; | ||
| 214 | |||
| 154 | is_prime = BN_is_prime_ex(dh->p, DH_NUMBER_ITERATIONS_FOR_PRIME, | 215 | is_prime = BN_is_prime_ex(dh->p, DH_NUMBER_ITERATIONS_FOR_PRIME, |
| 155 | ctx, NULL); | 216 | ctx, NULL); |
| 156 | if (is_prime < 0) | 217 | if (is_prime < 0) |
| @@ -172,6 +233,7 @@ DH_check(const DH *dh, int *flags) | |||
| 172 | *flags |= DH_CHECK_P_NOT_SAFE_PRIME; | 233 | *flags |= DH_CHECK_P_NOT_SAFE_PRIME; |
| 173 | } | 234 | } |
| 174 | 235 | ||
| 236 | done: | ||
| 175 | ok = 1; | 237 | ok = 1; |
| 176 | 238 | ||
| 177 | err: | 239 | err: |
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c index 3ffa5d80f1..f28f75909c 100644 --- a/src/lib/libcrypto/dh/dh_gen.c +++ b/src/lib/libcrypto/dh/dh_gen.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dh_gen.c,v 1.21 2023/07/08 15:29:03 beck Exp $ */ | 1 | /* $OpenBSD: dh_gen.c,v 1.22 2025/05/10 05:54:38 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -60,10 +60,10 @@ | |||
| 60 | 60 | ||
| 61 | #include <openssl/bn.h> | 61 | #include <openssl/bn.h> |
| 62 | #include <openssl/dh.h> | 62 | #include <openssl/dh.h> |
| 63 | #include <openssl/err.h> | ||
| 64 | 63 | ||
| 65 | #include "bn_local.h" | 64 | #include "bn_local.h" |
| 66 | #include "dh_local.h" | 65 | #include "dh_local.h" |
| 66 | #include "err_local.h" | ||
| 67 | 67 | ||
| 68 | static int dh_builtin_genparams(DH *ret, int prime_len, int generator, | 68 | static int dh_builtin_genparams(DH *ret, int prime_len, int generator, |
| 69 | BN_GENCB *cb); | 69 | BN_GENCB *cb); |
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c index 93b04f398f..89a02c8309 100644 --- a/src/lib/libcrypto/dh/dh_key.c +++ b/src/lib/libcrypto/dh/dh_key.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dh_key.c,v 1.42 2024/05/09 20:43:36 tb Exp $ */ | 1 | /* $OpenBSD: dh_key.c,v 1.43 2025/05/10 05:54:38 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -60,10 +60,10 @@ | |||
| 60 | 60 | ||
| 61 | #include <openssl/bn.h> | 61 | #include <openssl/bn.h> |
| 62 | #include <openssl/dh.h> | 62 | #include <openssl/dh.h> |
| 63 | #include <openssl/err.h> | ||
| 64 | 63 | ||
| 65 | #include "bn_local.h" | 64 | #include "bn_local.h" |
| 66 | #include "dh_local.h" | 65 | #include "dh_local.h" |
| 66 | #include "err_local.h" | ||
| 67 | 67 | ||
| 68 | static int | 68 | static int |
| 69 | generate_key(DH *dh) | 69 | generate_key(DH *dh) |
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c index 803aca6421..db76244550 100644 --- a/src/lib/libcrypto/dh/dh_lib.c +++ b/src/lib/libcrypto/dh/dh_lib.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dh_lib.c,v 1.46 2024/11/29 15:59:57 tb Exp $ */ | 1 | /* $OpenBSD: dh_lib.c,v 1.47 2025/05/10 05:54:38 tb Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -63,9 +63,9 @@ | |||
| 63 | 63 | ||
| 64 | #include <openssl/bn.h> | 64 | #include <openssl/bn.h> |
| 65 | #include <openssl/dh.h> | 65 | #include <openssl/dh.h> |
| 66 | #include <openssl/err.h> | ||
| 67 | 66 | ||
| 68 | #include "dh_local.h" | 67 | #include "dh_local.h" |
| 68 | #include "err_local.h" | ||
| 69 | 69 | ||
| 70 | static const DH_METHOD *default_DH_method = NULL; | 70 | static const DH_METHOD *default_DH_method = NULL; |
| 71 | 71 | ||
diff --git a/src/lib/libcrypto/dh/dh_pmeth.c b/src/lib/libcrypto/dh/dh_pmeth.c index 1e5327b11f..18517b0cde 100644 --- a/src/lib/libcrypto/dh/dh_pmeth.c +++ b/src/lib/libcrypto/dh/dh_pmeth.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dh_pmeth.c,v 1.17 2024/08/26 22:00:47 op Exp $ */ | 1 | /* $OpenBSD: dh_pmeth.c,v 1.18 2025/05/10 05:54:38 tb Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 2006. | 3 | * project 2006. |
| 4 | */ | 4 | */ |
| @@ -64,12 +64,12 @@ | |||
| 64 | #include <openssl/asn1t.h> | 64 | #include <openssl/asn1t.h> |
| 65 | #include <openssl/bn.h> | 65 | #include <openssl/bn.h> |
| 66 | #include <openssl/dh.h> | 66 | #include <openssl/dh.h> |
| 67 | #include <openssl/err.h> | ||
| 68 | #include <openssl/evp.h> | 67 | #include <openssl/evp.h> |
| 69 | #include <openssl/x509.h> | 68 | #include <openssl/x509.h> |
| 70 | 69 | ||
| 71 | #include "bn_local.h" | 70 | #include "bn_local.h" |
| 72 | #include "dh_local.h" | 71 | #include "dh_local.h" |
| 72 | #include "err_local.h" | ||
| 73 | #include "evp_local.h" | 73 | #include "evp_local.h" |
| 74 | 74 | ||
| 75 | /* DH pkey context structure */ | 75 | /* DH pkey context structure */ |
