aboutsummaryrefslogtreecommitdiff
path: root/crypto/rsa
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2015-10-30 11:12:26 +0000
committerMatt Caswell <matt@openssl.org>2015-11-09 22:48:41 +0000
commit90945fa31a42dcf3beb90540c618e4d627c595ea (patch)
treee73870c253abf0c37ca618384e30a7937a996b55 /crypto/rsa
parenta71edf3ba275b946224b5bcded0a8ecfce1855c0 (diff)
downloadopenssl-90945fa31a42dcf3beb90540c618e4d627c595ea.zip
openssl-90945fa31a42dcf3beb90540c618e4d627c595ea.tar.gz
openssl-90945fa31a42dcf3beb90540c618e4d627c595ea.tar.bz2
Continue standardising malloc style for libcrypto
Continuing from previous commit ensure our style is consistent for malloc return checks. Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Diffstat (limited to 'crypto/rsa')
-rw-r--r--crypto/rsa/rsa_ameth.c14
-rw-r--r--crypto/rsa/rsa_asn1.c2
-rw-r--r--crypto/rsa/rsa_crpt.c2
-rw-r--r--crypto/rsa/rsa_depr.c2
-rw-r--r--crypto/rsa/rsa_eay.c21
-rw-r--r--crypto/rsa/rsa_gen.c2
-rw-r--r--crypto/rsa/rsa_pmeth.c12
-rw-r--r--crypto/rsa/rsa_prn.c2
-rw-r--r--crypto/rsa/rsa_pss.c4
-rw-r--r--crypto/rsa/rsa_x931g.c18
10 files changed, 40 insertions, 39 deletions
diff --git a/crypto/rsa/rsa_ameth.c b/crypto/rsa/rsa_ameth.c
index 63f88e5..bae43f2 100644
--- a/crypto/rsa/rsa_ameth.c
+++ b/crypto/rsa/rsa_ameth.c
@@ -449,7 +449,7 @@ static int rsa_md_to_algor(X509_ALGOR **palg, const EVP_MD *md)
if (EVP_MD_type(md) == NID_sha1)
return 1;
*palg = X509_ALGOR_new();
- if (!*palg)
+ if (*palg == NULL)
return 0;
X509_ALGOR_set_md(*palg, md);
return 1;
@@ -469,7 +469,7 @@ static int rsa_md_to_mgf1(X509_ALGOR **palg, const EVP_MD *mgf1md)
if (!ASN1_item_pack(algtmp, ASN1_ITEM_rptr(X509_ALGOR), &stmp))
goto err;
*palg = X509_ALGOR_new();
- if (!*palg)
+ if (*palg == NULL)
goto err;
X509_ALGOR_set0(*palg, OBJ_nid2obj(NID_mgf1), V_ASN1_SEQUENCE, stmp);
stmp = NULL;
@@ -542,11 +542,11 @@ static ASN1_STRING *rsa_ctx_to_pss(EVP_PKEY_CTX *pkctx)
saltlen--;
}
pss = RSA_PSS_PARAMS_new();
- if (!pss)
+ if (pss == NULL)
goto err;
if (saltlen != 20) {
pss->saltLength = ASN1_INTEGER_new();
- if (!pss->saltLength)
+ if (pss->saltLength == NULL)
goto err;
if (!ASN1_INTEGER_set(pss->saltLength, saltlen))
goto err;
@@ -876,7 +876,7 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri)
if (labellen < 0)
goto err;
oaep = RSA_OAEP_PARAMS_new();
- if (!oaep)
+ if (oaep == NULL)
goto err;
if (!rsa_md_to_algor(&oaep->hashFunc, md))
goto err;
@@ -885,9 +885,9 @@ static int rsa_cms_encrypt(CMS_RecipientInfo *ri)
if (labellen > 0) {
ASN1_OCTET_STRING *los = ASN1_OCTET_STRING_new();
oaep->pSourceFunc = X509_ALGOR_new();
- if (!oaep->pSourceFunc)
+ if (oaep->pSourceFunc == NULL)
goto err;
- if (!los)
+ if (los == NULL)
goto err;
if (!ASN1_OCTET_STRING_set(los, label, labellen)) {
ASN1_OCTET_STRING_free(los);
diff --git a/crypto/rsa/rsa_asn1.c b/crypto/rsa/rsa_asn1.c
index 8061aed..16c40e3 100644
--- a/crypto/rsa/rsa_asn1.c
+++ b/crypto/rsa/rsa_asn1.c
@@ -70,7 +70,7 @@ static int rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
{
if (operation == ASN1_OP_NEW_PRE) {
*pval = (ASN1_VALUE *)RSA_new();
- if (*pval)
+ if (*pval != NULL)
return 2;
return 0;
} else if (operation == ASN1_OP_FREE_PRE) {
diff --git a/crypto/rsa/rsa_crpt.c b/crypto/rsa/rsa_crpt.c
index 3c4fd67..4df1662 100644
--- a/crypto/rsa/rsa_crpt.c
+++ b/crypto/rsa/rsa_crpt.c
@@ -199,7 +199,7 @@ BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)
if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {
/* Set BN_FLG_CONSTTIME flag */
local_n = n = BN_new();
- if (!local_n) {
+ if (local_n == NULL) {
RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_MALLOC_FAILURE);
goto err;
}
diff --git a/crypto/rsa/rsa_depr.c b/crypto/rsa/rsa_depr.c
index b76781b..5bd0275 100644
--- a/crypto/rsa/rsa_depr.c
+++ b/crypto/rsa/rsa_depr.c
@@ -78,7 +78,7 @@ RSA *RSA_generate_key(int bits, unsigned long e_value,
RSA *rsa = RSA_new();
BIGNUM *e = BN_new();
- if (!cb || !rsa || !e)
+ if (cb == NULL || rsa == NULL || e == NULL)
goto err;
/*
diff --git a/crypto/rsa/rsa_eay.c b/crypto/rsa/rsa_eay.c
index a41964d..a09fbf0 100644
--- a/crypto/rsa/rsa_eay.c
+++ b/crypto/rsa/rsa_eay.c
@@ -184,7 +184,7 @@ static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num);
- if (!f || !ret || !buf) {
+ if (f == NULL || ret == NULL || buf == NULL) {
RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
@@ -361,7 +361,7 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num);
- if (!f || !ret || !buf) {
+ if (f == NULL || ret == NULL || buf == NULL) {
RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
@@ -422,7 +422,7 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {
local_d = d = BN_new();
- if (!d) {
+ if (d == NULL) {
RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
@@ -500,7 +500,7 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num);
- if (!f || !ret || !buf) {
+ if (f == NULL || ret == NULL || buf == NULL) {
RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
@@ -554,7 +554,7 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {
local_d = d = BN_new();
- if (!d) {
+ if (d == NULL) {
RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
@@ -646,7 +646,7 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
ret = BN_CTX_get(ctx);
num = BN_num_bytes(rsa->n);
buf = OPENSSL_malloc(num);
- if (!f || !ret || !buf) {
+ if (f == NULL || ret == NULL || buf == NULL) {
RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
@@ -723,7 +723,8 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
local_dmq1 = BN_new();
local_c = BN_new();
local_r1 = BN_new();
- if (!local_dmp1 || !local_dmq1 || !local_c || !local_r1)
+ if (local_dmp1 == NULL
+ || local_dmq1 == NULL || local_c == NULL || local_r1 == NULL)
goto err;
r1 = BN_CTX_get(ctx);
@@ -740,12 +741,12 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
*/
if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {
local_p = p = BN_new();
- if (!p)
+ if (p == NULL)
goto err;
BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);
local_q = q = BN_new();
- if (!q) {
+ if (q == NULL) {
BN_free(local_p);
goto err;
}
@@ -880,7 +881,7 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) {
local_d = d = BN_new();
- if (!d)
+ if (d == NULL)
goto err;
BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME);
} else
diff --git a/crypto/rsa/rsa_gen.c b/crypto/rsa/rsa_gen.c
index e40186a..dc3e5d3 100644
--- a/crypto/rsa/rsa_gen.c
+++ b/crypto/rsa/rsa_gen.c
@@ -97,7 +97,7 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value,
local_r0 = BN_new();
local_d = BN_new();
local_p = BN_new();
- if (!local_r0 || !local_d || !local_p)
+ if (local_r0 == NULL || local_d == NULL || local_p == NULL)
goto err;
ctx = BN_CTX_new();
diff --git a/crypto/rsa/rsa_pmeth.c b/crypto/rsa/rsa_pmeth.c
index dd7b7dd..a2022bb 100644
--- a/crypto/rsa/rsa_pmeth.c
+++ b/crypto/rsa/rsa_pmeth.c
@@ -98,7 +98,7 @@ static int pkey_rsa_init(EVP_PKEY_CTX *ctx)
{
RSA_PKEY_CTX *rctx;
rctx = OPENSSL_zalloc(sizeof(*rctx));
- if (!rctx)
+ if (rctx == NULL)
return 0;
rctx->nbits = 1024;
rctx->pad_mode = RSA_PKCS1_PADDING;
@@ -141,7 +141,7 @@ static int setup_tbuf(RSA_PKEY_CTX *ctx, EVP_PKEY_CTX *pk)
if (ctx->tbuf)
return 1;
ctx->tbuf = OPENSSL_malloc(EVP_PKEY_size(pk->pkey));
- if (!ctx->tbuf)
+ if (ctx->tbuf == NULL)
return 0;
return 1;
}
@@ -634,17 +634,17 @@ static int pkey_rsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
RSA_PKEY_CTX *rctx = ctx->data;
BN_GENCB *pcb;
int ret;
- if (!rctx->pub_exp) {
+ if (rctx->pub_exp == NULL) {
rctx->pub_exp = BN_new();
- if (!rctx->pub_exp || !BN_set_word(rctx->pub_exp, RSA_F4))
+ if (rctx->pub_exp == NULL || !BN_set_word(rctx->pub_exp, RSA_F4))
return 0;
}
rsa = RSA_new();
- if (!rsa)
+ if (rsa == NULL)
return 0;
if (ctx->pkey_gencb) {
pcb = BN_GENCB_new();
- if (!pcb) {
+ if (pcb == NULL) {
RSA_free(rsa);
return 0;
}
diff --git a/crypto/rsa/rsa_prn.c b/crypto/rsa/rsa_prn.c
index 3d8c800..fd29280 100644
--- a/crypto/rsa/rsa_prn.c
+++ b/crypto/rsa/rsa_prn.c
@@ -84,7 +84,7 @@ int RSA_print(BIO *bp, const RSA *x, int off)
EVP_PKEY *pk;
int ret;
pk = EVP_PKEY_new();
- if (!pk || !EVP_PKEY_set1_RSA(pk, (RSA *)x))
+ if (pk == NULL || !EVP_PKEY_set1_RSA(pk, (RSA *)x))
return 0;
ret = EVP_PKEY_print_private(bp, pk, off, NULL);
EVP_PKEY_free(pk);
diff --git a/crypto/rsa/rsa_pss.c b/crypto/rsa/rsa_pss.c
index 03d900c..95bf6b0 100644
--- a/crypto/rsa/rsa_pss.c
+++ b/crypto/rsa/rsa_pss.c
@@ -134,7 +134,7 @@ int RSA_verify_PKCS1_PSS_mgf1(RSA *rsa, const unsigned char *mHash,
maskedDBLen = emLen - hLen - 1;
H = EM + maskedDBLen;
DB = OPENSSL_malloc(maskedDBLen);
- if (!DB) {
+ if (DB == NULL) {
RSAerr(RSA_F_RSA_VERIFY_PKCS1_PSS_MGF1, ERR_R_MALLOC_FAILURE);
goto err;
}
@@ -231,7 +231,7 @@ int RSA_padding_add_PKCS1_PSS_mgf1(RSA *rsa, unsigned char *EM,
}
if (sLen > 0) {
salt = OPENSSL_malloc(sLen);
- if (!salt) {
+ if (salt == NULL) {
RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_PSS_MGF1,
ERR_R_MALLOC_FAILURE);
goto err;
diff --git a/crypto/rsa/rsa_x931g.c b/crypto/rsa/rsa_x931g.c
index e158c6d..24d3cb9 100644
--- a/crypto/rsa/rsa_x931g.c
+++ b/crypto/rsa/rsa_x931g.c
@@ -78,7 +78,7 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
goto err;
ctx = BN_CTX_new();
- if (!ctx)
+ if (ctx == NULL)
goto err;
BN_CTX_start(ctx);
@@ -101,9 +101,9 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
* test programs to output selective parameters.
*/
- if (Xp && !rsa->p) {
+ if (Xp && rsa->p == NULL) {
rsa->p = BN_new();
- if (!rsa->p)
+ if (rsa->p == NULL)
goto err;
if (!BN_X931_derive_prime_ex(rsa->p, p1, p2,
@@ -111,16 +111,16 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
goto err;
}
- if (Xq && !rsa->q) {
+ if (Xq && rsa->q == NULL) {
rsa->q = BN_new();
- if (!rsa->q)
+ if (rsa->q == NULL)
goto err;
if (!BN_X931_derive_prime_ex(rsa->q, q1, q2,
Xq, Xq1, Xq2, e, ctx, cb))
goto err;
}
- if (!rsa->p || !rsa->q) {
+ if (rsa->p == NULL || rsa->q == NULL) {
BN_CTX_end(ctx);
BN_CTX_free(ctx);
return 2;
@@ -153,7 +153,7 @@ int RSA_X931_derive_ex(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1,
goto err; /* LCM((p-1)(q-1)) */
ctx2 = BN_CTX_new();
- if (!ctx2)
+ if (ctx2 == NULL)
goto err;
rsa->d = BN_mod_inverse(NULL, rsa->e, r0, ctx2); /* d */
@@ -196,7 +196,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
BN_CTX *ctx = NULL;
ctx = BN_CTX_new();
- if (!ctx)
+ if (ctx == NULL)
goto error;
BN_CTX_start(ctx);
@@ -207,7 +207,7 @@ int RSA_X931_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e,
rsa->p = BN_new();
rsa->q = BN_new();
- if (!rsa->p || !rsa->q)
+ if (rsa->p == NULL || rsa->q == NULL)
goto error;
/* Generate two primes from Xp, Xq */