Skip to content

Commit db85683

Browse files
author
tb
committed
Remove retry loop in BN_BLINDING_setup()
If we generate a non-invertible blinding, we have accidentally factored the modulus. This won't happen, so get rid of this ugly complication. ok jsing
1 parent afdf1ff commit db85683

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

src/lib/libcrypto/bn/bn_blind.c

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 $ */
22
/* ====================================================================
33
* Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
44
*
@@ -181,29 +181,10 @@ BN_BLINDING_free(BN_BLINDING *r)
181181
static int
182182
BN_BLINDING_setup(BN_BLINDING *b, BN_CTX *ctx)
183183
{
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;
207188

208189
if (b->bn_mod_exp != NULL && b->m_ctx != NULL) {
209190
if (!b->bn_mod_exp(b->A, b->A, b->e, b->mod, ctx, b->m_ctx))

0 commit comments

Comments
 (0)