Skip to content

Commit 83b348b

Browse files
author
tb
committed
Simplify RSA_setup_blinding()
Make this look a bit more like other code we cleaned up avoiding nesting and unnecessary else branches. ok jsing
1 parent 63944d7 commit 83b348b

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/lib/libcrypto/rsa/rsa_crpt.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: rsa_crpt.c,v 1.23 2023/07/28 10:05:16 tb Exp $ */
1+
/* $OpenBSD: rsa_crpt.c,v 1.24 2023/08/08 13:49:45 tb Exp $ */
22
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
33
* All rights reserved.
44
*
@@ -187,44 +187,39 @@ rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p, const BIGNUM *q,
187187
BN_BLINDING *
188188
RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)
189189
{
190-
BIGNUM *e;
190+
BIGNUM *e = NULL;
191191
BIGNUM n;
192-
BN_CTX *ctx;
192+
BN_CTX *ctx = NULL;
193193
BN_BLINDING *ret = NULL;
194194

195-
if (in_ctx == NULL) {
196-
if ((ctx = BN_CTX_new()) == NULL)
197-
return 0;
198-
} else
199-
ctx = in_ctx;
195+
if ((ctx = in_ctx) == NULL)
196+
ctx = BN_CTX_new();
197+
if (ctx == NULL)
198+
goto err;
200199

201200
BN_CTX_start(ctx);
202201

203-
if (rsa->e == NULL) {
202+
if ((e = rsa->e) == NULL)
204203
e = rsa_get_public_exp(rsa->d, rsa->p, rsa->q, ctx);
205-
if (e == NULL) {
206-
RSAerror(RSA_R_NO_PUBLIC_EXPONENT);
207-
goto err;
208-
}
209-
} else
210-
e = rsa->e;
204+
if (e == NULL) {
205+
RSAerror(RSA_R_NO_PUBLIC_EXPONENT);
206+
goto err;
207+
}
211208

212209
BN_init(&n);
213210
BN_with_flags(&n, rsa->n, BN_FLG_CONSTTIME);
214211

215-
ret = BN_BLINDING_create_param(NULL, e, &n, ctx, rsa->meth->bn_mod_exp,
216-
rsa->_method_mod_n);
217-
218-
if (ret == NULL) {
212+
if ((ret = BN_BLINDING_create_param(NULL, e, &n, ctx,
213+
rsa->meth->bn_mod_exp, rsa->_method_mod_n)) == NULL) {
219214
RSAerror(ERR_R_BN_LIB);
220215
goto err;
221216
}
222217
CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret));
223218
err:
224219
BN_CTX_end(ctx);
225-
if (in_ctx == NULL)
220+
if (ctx != in_ctx)
226221
BN_CTX_free(ctx);
227-
if (rsa->e == NULL)
222+
if (e != rsa->e)
228223
BN_free(e);
229224

230225
return ret;

0 commit comments

Comments
 (0)