|
1 |
| -/* $OpenBSD: bn_blind.c,v 1.39 2023/08/09 08:31:13 tb Exp $ */ |
| 1 | +/* $OpenBSD: bn_blind.c,v 1.40 2023/08/09 08:35:59 tb Exp $ */ |
2 | 2 | /* ====================================================================
|
3 | 3 | * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
|
4 | 4 | *
|
@@ -181,29 +181,10 @@ BN_BLINDING_free(BN_BLINDING *r)
|
181 | 181 | static int
|
182 | 182 | BN_BLINDING_setup(BN_BLINDING *b, BN_CTX *ctx)
|
183 | 183 | {
|
184 |
| - int retry_counter = 32; |
185 |
| - |
186 |
| - /* |
187 |
| - * XXX - remove this loop. If we happen to find a non-invertible A, |
188 |
| - * we have basically factored mod = (p-1)(q-1)... |
189 |
| - */ |
190 |
| - do { |
191 |
| - if (!BN_rand_range(b->A, b->mod)) |
192 |
| - return 0; |
193 |
| - if (BN_mod_inverse_ct(b->Ai, b->A, b->mod, ctx) == NULL) { |
194 |
| - /* this should almost never happen for good RSA keys */ |
195 |
| - unsigned long error = ERR_peek_last_error(); |
196 |
| - if (ERR_GET_REASON(error) == BN_R_NO_INVERSE) { |
197 |
| - if (retry_counter-- == 0) { |
198 |
| - BNerror(BN_R_TOO_MANY_ITERATIONS); |
199 |
| - return 0; |
200 |
| - } |
201 |
| - ERR_clear_error(); |
202 |
| - } else |
203 |
| - return 0; |
204 |
| - } else |
205 |
| - break; |
206 |
| - } while (1); |
| 184 | + if (!bn_rand_interval(b->A, 1, b->mod)) |
| 185 | + return 0; |
| 186 | + if (BN_mod_inverse_ct(b->Ai, b->A, b->mod, ctx) == NULL) |
| 187 | + return 0; |
207 | 188 |
|
208 | 189 | if (b->bn_mod_exp != NULL && b->m_ctx != NULL) {
|
209 | 190 | if (!b->bn_mod_exp(b->A, b->A, b->e, b->mod, ctx, b->m_ctx))
|
|
0 commit comments