diff options
| author | tb <> | 2023-08-08 13:49:45 +0000 |
|---|---|---|
| committer | tb <> | 2023-08-08 13:49:45 +0000 |
| commit | 0bdaf3daedd5dff6d199a2e3f97a6e8e718bc0fc (patch) | |
| tree | 57c8cb478b97ba41f5c5bc3b3997555b1dc7937e /src/lib/libc | |
| parent | 409280fb4ae64371e28c3111dba6a52b1f295a56 (diff) | |
| download | openbsd-0bdaf3daedd5dff6d199a2e3f97a6e8e718bc0fc.tar.gz openbsd-0bdaf3daedd5dff6d199a2e3f97a6e8e718bc0fc.tar.bz2 openbsd-0bdaf3daedd5dff6d199a2e3f97a6e8e718bc0fc.zip | |
Simplify RSA_setup_blinding()
Make this look a bit more like other code we cleaned up avoiding nesting
and unnecessary else branches.
ok jsing
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_crpt.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_crpt.c b/src/lib/libcrypto/rsa/rsa_crpt.c index 15108e24f0..a53ec54b32 100644 --- a/src/lib/libcrypto/rsa/rsa_crpt.c +++ b/src/lib/libcrypto/rsa/rsa_crpt.c | |||
| @@ -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 $ */ |
| 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 | * |
| @@ -187,44 +187,39 @@ err: | |||
| 187 | BN_BLINDING * | 187 | BN_BLINDING * |
| 188 | RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx) | 188 | RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx) |
| 189 | { | 189 | { |
| 190 | BIGNUM *e; | 190 | BIGNUM *e = NULL; |
| 191 | BIGNUM n; | 191 | BIGNUM n; |
| 192 | BN_CTX *ctx; | 192 | BN_CTX *ctx = NULL; |
| 193 | BN_BLINDING *ret = NULL; | 193 | BN_BLINDING *ret = NULL; |
| 194 | 194 | ||
| 195 | if (in_ctx == NULL) { | 195 | if ((ctx = in_ctx) == NULL) |
| 196 | if ((ctx = BN_CTX_new()) == NULL) | 196 | ctx = BN_CTX_new(); |
| 197 | return 0; | 197 | if (ctx == NULL) |
| 198 | } else | 198 | goto err; |
| 199 | ctx = in_ctx; | ||
| 200 | 199 | ||
| 201 | BN_CTX_start(ctx); | 200 | BN_CTX_start(ctx); |
| 202 | 201 | ||
| 203 | if (rsa->e == NULL) { | 202 | if ((e = rsa->e) == NULL) |
| 204 | e = rsa_get_public_exp(rsa->d, rsa->p, rsa->q, ctx); | 203 | e = rsa_get_public_exp(rsa->d, rsa->p, rsa->q, ctx); |
| 205 | if (e == NULL) { | 204 | if (e == NULL) { |
| 206 | RSAerror(RSA_R_NO_PUBLIC_EXPONENT); | 205 | RSAerror(RSA_R_NO_PUBLIC_EXPONENT); |
| 207 | goto err; | 206 | goto err; |
| 208 | } | 207 | } |
| 209 | } else | ||
| 210 | e = rsa->e; | ||
| 211 | 208 | ||
| 212 | BN_init(&n); | 209 | BN_init(&n); |
| 213 | BN_with_flags(&n, rsa->n, BN_FLG_CONSTTIME); | 210 | BN_with_flags(&n, rsa->n, BN_FLG_CONSTTIME); |
| 214 | 211 | ||
| 215 | ret = BN_BLINDING_create_param(NULL, e, &n, ctx, rsa->meth->bn_mod_exp, | 212 | if ((ret = BN_BLINDING_create_param(NULL, e, &n, ctx, |
| 216 | rsa->_method_mod_n); | 213 | rsa->meth->bn_mod_exp, rsa->_method_mod_n)) == NULL) { |
| 217 | |||
| 218 | if (ret == NULL) { | ||
| 219 | RSAerror(ERR_R_BN_LIB); | 214 | RSAerror(ERR_R_BN_LIB); |
| 220 | goto err; | 215 | goto err; |
| 221 | } | 216 | } |
| 222 | CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret)); | 217 | CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret)); |
| 223 | err: | 218 | err: |
| 224 | BN_CTX_end(ctx); | 219 | BN_CTX_end(ctx); |
| 225 | if (in_ctx == NULL) | 220 | if (ctx != in_ctx) |
| 226 | BN_CTX_free(ctx); | 221 | BN_CTX_free(ctx); |
| 227 | if (rsa->e == NULL) | 222 | if (e != rsa->e) |
| 228 | BN_free(e); | 223 | BN_free(e); |
| 229 | 224 | ||
| 230 | return ret; | 225 | return ret; |
