summaryrefslogtreecommitdiffstats
path: root/crypto/rsa
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/rsa')
-rw-r--r--crypto/rsa/rsa_chk.c18
-rw-r--r--crypto/rsa/rsa_crpt.c13
-rw-r--r--crypto/rsa/rsa_depr.c6
-rw-r--r--crypto/rsa/rsa_eay.c77
-rw-r--r--crypto/rsa/rsa_gen.c14
-rw-r--r--crypto/rsa/rsa_lib.c30
-rw-r--r--crypto/rsa/rsa_pmeth.c3
-rw-r--r--crypto/rsa/rsa_x931g.c13
8 files changed, 61 insertions, 113 deletions
diff --git a/crypto/rsa/rsa_chk.c b/crypto/rsa/rsa_chk.c
index 51c1fa33e5..fa300a2e76 100644
--- a/crypto/rsa/rsa_chk.c
+++ b/crypto/rsa/rsa_chk.c
@@ -203,17 +203,11 @@ int RSA_check_key_ex(const RSA *key, BN_GENCB *cb)
}
err:
- if (i != NULL)
- BN_free(i);
- if (j != NULL)
- BN_free(j);
- if (k != NULL)
- BN_free(k);
- if (l != NULL)
- BN_free(l);
- if (m != NULL)
- BN_free(m);
- if (ctx != NULL)
- BN_CTX_free(ctx);
+ BN_free(i);
+ BN_free(j);
+ BN_free(k);
+ BN_free(l);
+ BN_free(m);
+ BN_CTX_free(ctx);
return (ret);
}
diff --git a/crypto/rsa/rsa_crpt.c b/crypto/rsa/rsa_crpt.c
index 052f42c620..f5f29e0e28 100644
--- a/crypto/rsa/rsa_crpt.c
+++ b/crypto/rsa/rsa_crpt.c
@@ -100,10 +100,8 @@ int RSA_flags(const RSA *r)
void RSA_blinding_off(RSA *rsa)
{
- if (rsa->blinding != NULL) {
- BN_BLINDING_free(rsa->blinding);
- rsa->blinding = NULL;
- }
+ BN_BLINDING_free(rsa->blinding);
+ rsa->blinding = NULL;
rsa->flags &= ~RSA_FLAG_BLINDING;
rsa->flags |= RSA_FLAG_NO_BLINDING;
}
@@ -213,12 +211,11 @@ BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)
CRYPTO_THREADID_current(BN_BLINDING_thread_id(ret));
err:
BN_CTX_end(ctx);
- if (in_ctx == NULL)
+ if (ctx != in_ctx)
BN_CTX_free(ctx);
- if (rsa->e == NULL)
+ if (e != rsa->e)
BN_free(e);
- if (local_n)
- BN_free(local_n);
+ BN_free(local_n);
return ret;
}
diff --git a/crypto/rsa/rsa_depr.c b/crypto/rsa/rsa_depr.c
index 8da6ec1238..042b2b72d5 100644
--- a/crypto/rsa/rsa_depr.c
+++ b/crypto/rsa/rsa_depr.c
@@ -99,11 +99,9 @@ RSA *RSA_generate_key(int bits, unsigned long e_value,
return rsa;
}
err:
- if (e)
- BN_free(e);
+ BN_free(e);
RSA_free(rsa);
- if (cb)
- BN_GENCB_free(cb);
+ BN_GENCB_free(cb);
return 0;
}
#endif
diff --git a/crypto/rsa/rsa_eay.c b/crypto/rsa/rsa_eay.c
index 49c157a842..5b8e21b7a5 100644
--- a/crypto/rsa/rsa_eay.c
+++ b/crypto/rsa/rsa_eay.c
@@ -239,10 +239,9 @@ static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
r = num;
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num);
return (r);
}
@@ -434,19 +433,16 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
if (!BN_MONT_CTX_set_locked
(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
rsa->_method_mod_n)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
}
if (blinding)
@@ -473,10 +469,9 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
r = num;
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num);
return (r);
}
@@ -570,18 +565,15 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
if (!BN_MONT_CTX_set_locked
(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
if (!rsa->meth->bn_mod_exp(ret, f, d, rsa->n, ctx,
rsa->_method_mod_n)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
}
if (blinding)
@@ -612,10 +604,9 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num);
return (r);
}
@@ -712,10 +703,9 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, RSA_R_PADDING_CHECK_FAILED);
err:
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
OPENSSL_clear_free(buf, num);
return (r);
}
@@ -769,17 +759,13 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
(&rsa->_method_mod_p, CRYPTO_LOCK_RSA, p, ctx)
|| !BN_MONT_CTX_set_locked(&rsa->_method_mod_q,
CRYPTO_LOCK_RSA, q, ctx)) {
- if (local_p)
- BN_free(local_p);
- if (local_q)
- BN_free(local_q);
+ BN_free(local_p);
+ BN_free(local_q);
goto err;
}
}
- if (local_p)
- BN_free(local_p);
- if (local_q)
- BN_free(local_q);
+ BN_free(local_p);
+ BN_free(local_q);
}
if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
@@ -900,25 +886,19 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
d = rsa->d;
if (!rsa->meth->bn_mod_exp(r0, I, d, rsa->n, ctx,
rsa->_method_mod_n)) {
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
goto err;
}
- if (local_d)
- BN_free(local_d);
+ BN_free(local_d);
}
}
ret = 1;
err:
- if (local_dmp1)
- BN_free(local_dmp1);
- if (local_dmq1)
- BN_free(local_dmq1);
- if (local_c)
- BN_free(local_c);
- if (local_r1)
- BN_free(local_r1);
+ BN_free(local_dmp1);
+ BN_free(local_dmq1);
+ BN_free(local_c);
+ BN_free(local_r1);
BN_CTX_end(ctx);
return (ret);
}
@@ -931,12 +911,9 @@ static int RSA_eay_init(RSA *rsa)
static int RSA_eay_finish(RSA *rsa)
{
- if (rsa->_method_mod_n != NULL)
- BN_MONT_CTX_free(rsa->_method_mod_n);
- if (rsa->_method_mod_p != NULL)
- BN_MONT_CTX_free(rsa->_method_mod_p);
- if (rsa->_method_mod_q != NULL)
- BN_MONT_CTX_free(rsa->_method_mod_q);
+ BN_MONT_CTX_free(rsa->_method_mod_n);
+ BN_MONT_CTX_free(rsa->_method_mod_p);
+ BN_MONT_CTX_free(rsa->_method_mod_q);
return (1);
}
diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c
index ae9c2d4dd7..ec2e18ee3c 100644
--- a/crypto/rsa/rsa_gen.c
+++ b/crypto/rsa/rsa_gen.c
@@ -227,20 +227,16 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value,
ok = 1;
err:
- if (local_r0)
- BN_free(local_r0);
- if (local_d)
- BN_free(local_d);
- if (local_p)
- BN_free(local_p);
+ BN_free(local_r0);
+ BN_free(local_d);
+ BN_free(local_p);
if (ok == -1) {
RSAerr(RSA_F_RSA_BUILTIN_KEYGEN, ERR_LIB_BN);
ok = 0;
}
- if (ctx != NULL) {
+ if (ctx != NULL)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
return ok;
}
diff --git a/crypto/rsa/rsa_lib.c b/crypto/rsa/rsa_lib.c
index 1430d5b0f3..d8a9132148 100644
--- a/crypto/rsa/rsa_lib.c
+++ b/crypto/rsa/rsa_lib.c
@@ -223,26 +223,16 @@ void RSA_free(RSA *r)
CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
- if (r->n != NULL)
- BN_clear_free(r->n);
- if (r->e != NULL)
- BN_clear_free(r->e);
- if (r->d != NULL)
- BN_clear_free(r->d);
- if (r->p != NULL)
- BN_clear_free(r->p);
- if (r->q != NULL)
- BN_clear_free(r->q);
- if (r->dmp1 != NULL)
- BN_clear_free(r->dmp1);
- if (r->dmq1 != NULL)
- BN_clear_free(r->dmq1);
- if (r->iqmp != NULL)
- BN_clear_free(r->iqmp);
- if (r->blinding != NULL)
- BN_BLINDING_free(r->blinding);
- if (r->mt_blinding != NULL)
- BN_BLINDING_free(r->mt_blinding);
+ BN_clear_free(r->n);
+ BN_clear_free(r->e);
+ BN_clear_free(r->d);
+ BN_clear_free(r->p);
+ BN_clear_free(r->q);
+ BN_clear_free(r->dmp1);
+ BN_clear_free(r->dmq1);
+ BN_clear_free(r->iqmp);
+ BN_BLINDING_free(r->blinding);
+ BN_BLINDING_free(r->mt_blinding);
OPENSSL_free_locked(r->bignum_data);
OPENSSL_free(r);
}
diff --git a/crypto/rsa/rsa_pmeth.c b/crypto/rsa/rsa_pmeth.c
index 91dc668ce7..866dd1601e 100644
--- a/crypto/rsa/rsa_pmeth.c
+++ b/crypto/rsa/rsa_pmeth.c
@@ -160,8 +160,7 @@ static void pkey_rsa_cleanup(EVP_PKEY_CTX *ctx)
{
RSA_PKEY_CTX *rctx = ctx->data;
if (rctx) {
- if (rctx->pub_exp)
- BN_free(rctx->pub_exp);
+ BN_free(rctx->pub_exp);
if (rctx->tbuf)
OPENSSL_free(rctx->tbuf);
if (rctx->oaep_label)
diff --git a/crypto/rsa/rsa_x931g.c b/crypto/rsa/rsa_x931g.c
index 5991615784..e158c6d443 100644
--- a/crypto/rsa/rsa_x931g.c
+++ b/crypto/rsa/rsa_x931g.c
@@ -179,12 +179,10 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
ret = 1;
err:
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
- if (ctx2)
- BN_CTX_free(ctx2);
+ BN_CTX_free(ctx);
+ BN_CTX_free(ctx2);
return ret;
@@ -234,10 +232,9 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
ok = 1;
error:
- if (ctx) {
+ if (ctx)
BN_CTX_end(ctx);
- BN_CTX_free(ctx);
- }
+ BN_CTX_free(ctx);
if (ok)
return 1;