summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2024-08-30 17:44:56 +0000
committertb <>2024-08-30 17:44:56 +0000
commitee27a83f96b570b17b650e3dbb3424206be95bc6 (patch)
treefb9f42bfb23469de86813e1534965b22b59fa684 /src/lib
parent0191f2decd866397df1b2c19c627901a64630be3 (diff)
downloadopenbsd-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.c68
-rw-r--r--src/lib/libcrypto/dh/dh_local.h11
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
75int 74static int
76DH_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
91int
92DH_check_params(const DH *dh, int *flags) 75DH_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
130int 112int
131DH_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
156int
157DH_check(const DH *dh, int *flags) 113DH_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)
230LCRYPTO_ALIAS(DH_check); 186LCRYPTO_ALIAS(DH_check);
231 187
232int 188int
233DH_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
250int
251DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *flags) 189DH_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
109int DH_check_params_ex(const DH *dh);
110int DH_check_params(const DH *dh, int *flags);
111int DH_check_ex(const DH *dh);
112int 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 */