diff options
author | tb <> | 2024-08-30 17:44:56 +0000 |
---|---|---|
committer | tb <> | 2024-08-30 17:44:56 +0000 |
commit | ee27a83f96b570b17b650e3dbb3424206be95bc6 (patch) | |
tree | fb9f42bfb23469de86813e1534965b22b59fa684 /src/lib | |
parent | 0191f2decd866397df1b2c19c627901a64630be3 (diff) | |
download | openbsd-ee27a83f96b570b17b650e3dbb3424206be95bc6.tar.gz openbsd-ee27a83f96b570b17b650e3dbb3424206be95bc6.tar.bz2 openbsd-ee27a83f96b570b17b650e3dbb3424206be95bc6.zip |
Garbage collect the DH_check*_ex() API
This was only needed by the EVP_PKEY_*check() API, which was defanged. So
this silly garbage can now go: it translated flags to errors on the error
stack so that openssl *check could print ugly errors while DoS-ing the
user.
ok beck
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/dh/dh_check.c | 68 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_local.h | 11 |
2 files changed, 4 insertions, 75 deletions
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c index be79c2a04b..57330b2068 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.28 2023/07/24 16:25:02 tb Exp $ */ | 1 | /* $OpenBSD: dh_check.c,v 1.29 2024/08/30 17:44:56 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 | * |
@@ -68,27 +68,10 @@ | |||
68 | #define DH_NUMBER_ITERATIONS_FOR_PRIME 64 | 68 | #define DH_NUMBER_ITERATIONS_FOR_PRIME 64 |
69 | 69 | ||
70 | /* | 70 | /* |
71 | * Check that p is odd and 1 < g < p - 1. The _ex version removes the need of | 71 | * Check that p is odd and 1 < g < p - 1. |
72 | * inspecting flags and pushes errors on the stack instead. | ||
73 | */ | 72 | */ |
74 | 73 | ||
75 | int | 74 | static int |
76 | DH_check_params_ex(const DH *dh) | ||
77 | { | ||
78 | int flags = 0; | ||
79 | |||
80 | if (!DH_check_params(dh, &flags)) | ||
81 | return 0; | ||
82 | |||
83 | if ((flags & DH_CHECK_P_NOT_PRIME) != 0) | ||
84 | DHerror(DH_R_CHECK_P_NOT_PRIME); | ||
85 | if ((flags & DH_NOT_SUITABLE_GENERATOR) != 0) | ||
86 | DHerror(DH_R_NOT_SUITABLE_GENERATOR); | ||
87 | |||
88 | return flags == 0; | ||
89 | } | ||
90 | |||
91 | int | ||
92 | DH_check_params(const DH *dh, int *flags) | 75 | DH_check_params(const DH *dh, int *flags) |
93 | { | 76 | { |
94 | BIGNUM *max_g = NULL; | 77 | BIGNUM *max_g = NULL; |
@@ -124,36 +107,9 @@ DH_check_params(const DH *dh, int *flags) | |||
124 | 107 | ||
125 | /* | 108 | /* |
126 | * Check that p is a safe prime and that g is a suitable generator. | 109 | * Check that p is a safe prime and that g is a suitable generator. |
127 | * The _ex version puts errors on the stack instead of returning flags. | ||
128 | */ | 110 | */ |
129 | 111 | ||
130 | int | 112 | int |
131 | DH_check_ex(const DH *dh) | ||
132 | { | ||
133 | int flags = 0; | ||
134 | |||
135 | if (!DH_check(dh, &flags)) | ||
136 | return 0; | ||
137 | |||
138 | if ((flags & DH_NOT_SUITABLE_GENERATOR) != 0) | ||
139 | DHerror(DH_R_NOT_SUITABLE_GENERATOR); | ||
140 | if ((flags & DH_CHECK_Q_NOT_PRIME) != 0) | ||
141 | DHerror(DH_R_CHECK_Q_NOT_PRIME); | ||
142 | if ((flags & DH_CHECK_INVALID_Q_VALUE) != 0) | ||
143 | DHerror(DH_R_CHECK_INVALID_Q_VALUE); | ||
144 | if ((flags & DH_CHECK_INVALID_J_VALUE) != 0) | ||
145 | DHerror(DH_R_CHECK_INVALID_J_VALUE); | ||
146 | if ((flags & DH_UNABLE_TO_CHECK_GENERATOR) != 0) | ||
147 | DHerror(DH_R_UNABLE_TO_CHECK_GENERATOR); | ||
148 | if ((flags & DH_CHECK_P_NOT_PRIME) != 0) | ||
149 | DHerror(DH_R_CHECK_P_NOT_PRIME); | ||
150 | if ((flags & DH_CHECK_P_NOT_SAFE_PRIME) != 0) | ||
151 | DHerror(DH_R_CHECK_P_NOT_SAFE_PRIME); | ||
152 | |||
153 | return flags == 0; | ||
154 | } | ||
155 | |||
156 | int | ||
157 | DH_check(const DH *dh, int *flags) | 113 | DH_check(const DH *dh, int *flags) |
158 | { | 114 | { |
159 | BN_CTX *ctx = NULL; | 115 | BN_CTX *ctx = NULL; |
@@ -230,24 +186,6 @@ DH_check(const DH *dh, int *flags) | |||
230 | LCRYPTO_ALIAS(DH_check); | 186 | LCRYPTO_ALIAS(DH_check); |
231 | 187 | ||
232 | int | 188 | int |
233 | DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key) | ||
234 | { | ||
235 | int flags = 0; | ||
236 | |||
237 | if (!DH_check_pub_key(dh, pub_key, &flags)) | ||
238 | return 0; | ||
239 | |||
240 | if ((flags & DH_CHECK_PUBKEY_TOO_SMALL) != 0) | ||
241 | DHerror(DH_R_CHECK_PUBKEY_TOO_SMALL); | ||
242 | if ((flags & DH_CHECK_PUBKEY_TOO_LARGE) != 0) | ||
243 | DHerror(DH_R_CHECK_PUBKEY_TOO_LARGE); | ||
244 | if ((flags & DH_CHECK_PUBKEY_INVALID) != 0) | ||
245 | DHerror(DH_R_CHECK_PUBKEY_INVALID); | ||
246 | |||
247 | return flags == 0; | ||
248 | } | ||
249 | |||
250 | int | ||
251 | DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *flags) | 189 | DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *flags) |
252 | { | 190 | { |
253 | BN_CTX *ctx = NULL; | 191 | BN_CTX *ctx = NULL; |
diff --git a/src/lib/libcrypto/dh/dh_local.h b/src/lib/libcrypto/dh/dh_local.h index 22e2256906..fe7c12bb05 100644 --- a/src/lib/libcrypto/dh/dh_local.h +++ b/src/lib/libcrypto/dh/dh_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dh_local.h,v 1.4 2023/11/29 21:35:57 tb Exp $ */ | 1 | /* $OpenBSD: dh_local.h,v 1.5 2024/08/30 17:44:56 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 | * |
@@ -102,15 +102,6 @@ struct dh_st { | |||
102 | const DH_METHOD *meth; | 102 | const DH_METHOD *meth; |
103 | }; | 103 | }; |
104 | 104 | ||
105 | /* | ||
106 | * Public API in OpenSSL that we only want to use internally. | ||
107 | */ | ||
108 | |||
109 | int DH_check_params_ex(const DH *dh); | ||
110 | int DH_check_params(const DH *dh, int *flags); | ||
111 | int DH_check_ex(const DH *dh); | ||
112 | int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key); | ||
113 | |||
114 | __END_HIDDEN_DECLS | 105 | __END_HIDDEN_DECLS |
115 | 106 | ||
116 | #endif /* !HEADER_DH_LOCAL_H */ | 107 | #endif /* !HEADER_DH_LOCAL_H */ |