diff options
Diffstat (limited to 'src/lib/libcrypto/dsa')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_ossl.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c index d32168a48e..ece1026fc9 100644 --- a/src/lib/libcrypto/dsa/dsa_ossl.c +++ b/src/lib/libcrypto/dsa/dsa_ossl.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dsa_ossl.c,v 1.49 2023/03/04 21:06:17 tb Exp $ */ | 1 | /* $OpenBSD: dsa_ossl.c,v 1.50 2023/03/04 21:30:23 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 | * |
@@ -92,6 +92,16 @@ DSA_OpenSSL(void) | |||
92 | return &openssl_dsa_meth; | 92 | return &openssl_dsa_meth; |
93 | } | 93 | } |
94 | 94 | ||
95 | /* | ||
96 | * Since DSA parameters are entirely arbitrary and checking them to be | ||
97 | * consistent is very expensive, we cannot do so on every sign operation. | ||
98 | * Instead, cap the number of retries so we do not loop indefinitely if | ||
99 | * the generator of the multiplicative group happens to be nilpotent. | ||
100 | * The probability of needing a retry with valid parameters is negligible, | ||
101 | * so trying 32 times is amply enough. | ||
102 | */ | ||
103 | #define DSA_MAX_SIGN_ITERATIONS 32 | ||
104 | |||
95 | static DSA_SIG * | 105 | static DSA_SIG * |
96 | dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | 106 | dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) |
97 | { | 107 | { |
@@ -100,6 +110,7 @@ dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | |||
100 | BN_CTX *ctx = NULL; | 110 | BN_CTX *ctx = NULL; |
101 | int reason = ERR_R_BN_LIB; | 111 | int reason = ERR_R_BN_LIB; |
102 | DSA_SIG *ret = NULL; | 112 | DSA_SIG *ret = NULL; |
113 | int attempts = 0; | ||
103 | int noredo = 0; | 114 | int noredo = 0; |
104 | 115 | ||
105 | if (!dsa_check_key(dsa)) { | 116 | if (!dsa_check_key(dsa)) { |
@@ -187,6 +198,10 @@ dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | |||
187 | reason = DSA_R_NEED_NEW_SETUP_VALUES; | 198 | reason = DSA_R_NEED_NEW_SETUP_VALUES; |
188 | goto err; | 199 | goto err; |
189 | } | 200 | } |
201 | if (++attempts > DSA_MAX_SIGN_ITERATIONS) { | ||
202 | reason = DSA_R_INVALID_PARAMETERS; | ||
203 | goto err; | ||
204 | } | ||
190 | goto redo; | 205 | goto redo; |
191 | } | 206 | } |
192 | 207 | ||