summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2016-06-18 15:46:13 +0100
committerDr. Stephen Henson <steve@openssl.org>2016-07-15 14:09:05 +0100
commitd166ed8c11e10e9fdaeac182effb9dd318843924 (patch)
treefd47ffb1f5d42b121b04d14c1a8f6bdc659637f6 /crypto
parent1fc431ba57d12189a9bdacd3999ea2a7b91458d8 (diff)
check return values for EVP_Digest*() APIs
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/dh/dh_kdf.c4
-rw-r--r--crypto/ec/ecdh_kdf.c3
-rw-r--r--crypto/rand/md_rand.c15
-rw-r--r--crypto/srp/srp_lib.c45
-rw-r--r--crypto/srp/srp_vfy.c10
5 files changed, 45 insertions, 32 deletions
diff --git a/crypto/dh/dh_kdf.c b/crypto/dh/dh_kdf.c
index f2f3d24158..2782eeee6e 100644
--- a/crypto/dh/dh_kdf.c
+++ b/crypto/dh/dh_kdf.c
@@ -117,8 +117,8 @@ int DH_KDF_X9_42(unsigned char *out, size_t outlen,
goto err;
for (i = 1;; i++) {
unsigned char mtmp[EVP_MAX_MD_SIZE];
- EVP_DigestInit_ex(mctx, md, NULL);
- if (!EVP_DigestUpdate(mctx, Z, Zlen))
+ if (!EVP_DigestInit_ex(mctx, md, NULL)
+ || !EVP_DigestUpdate(mctx, Z, Zlen))
goto err;
ctr[3] = i & 0xFF;
ctr[2] = (i >> 8) & 0xFF;
diff --git a/crypto/ec/ecdh_kdf.c b/crypto/ec/ecdh_kdf.c
index 6cb0e11c22..d47486eb34 100644
--- a/crypto/ec/ecdh_kdf.c
+++ b/crypto/ec/ecdh_kdf.c
@@ -34,7 +34,8 @@ int ECDH_KDF_X9_62(unsigned char *out, size_t outlen,
mdlen = EVP_MD_size(md);
for (i = 1;; i++) {
unsigned char mtmp[EVP_MAX_MD_SIZE];
- EVP_DigestInit_ex(mctx, md, NULL);
+ if (!EVP_DigestInit_ex(mctx, md, NULL))
+ goto err;
ctr[3] = i & 0xFF;
ctr[2] = (i >> 8) & 0xFF;
ctr[1] = (i >> 16) & 0xFF;
diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c
index 137851f596..0d25aeb532 100644
--- a/crypto/rand/md_rand.c
+++ b/crypto/rand/md_rand.c
@@ -60,7 +60,7 @@ static CRYPTO_THREAD_ID locking_threadid;
int rand_predictable = 0;
#endif
-static void rand_hw_seed(EVP_MD_CTX *ctx);
+static int rand_hw_seed(EVP_MD_CTX *ctx);
static void rand_cleanup(void);
static int rand_seed(const void *buf, int num);
@@ -446,7 +446,8 @@ static int rand_bytes(unsigned char *buf, int num, int pseudo)
if (!MD_Update(m, (unsigned char *)&tv, sizeof tv))
goto err;
curr_time = 0;
- rand_hw_seed(m);
+ if (!rand_hw_seed(m))
+ goto err;
}
if (!MD_Update(m, local_md, MD_DIGEST_LENGTH))
goto err;
@@ -597,18 +598,20 @@ static int rand_status(void)
size_t OPENSSL_ia32_rdrand(void);
extern unsigned int OPENSSL_ia32cap_P[];
-static void rand_hw_seed(EVP_MD_CTX *ctx)
+static int rand_hw_seed(EVP_MD_CTX *ctx)
{
int i;
if (!(OPENSSL_ia32cap_P[1] & (1 << (62 - 32))))
- return;
+ return 1;
for (i = 0; i < RDRAND_CALLS; i++) {
size_t rnd;
rnd = OPENSSL_ia32_rdrand();
if (rnd == 0)
- return;
- MD_Update(ctx, (unsigned char *)&rnd, sizeof(size_t));
+ return 1;
+ if (!MD_Update(ctx, (unsigned char *)&rnd, sizeof(size_t)))
+ return 0;
}
+ return 1;
}
/* XOR an existing buffer with random data */
diff --git a/crypto/srp/srp_lib.c b/crypto/srp/srp_lib.c
index 06671749a6..7f297be81a 100644
--- a/crypto/srp/srp_lib.c
+++ b/crypto/srp/srp_lib.c
@@ -35,17 +35,20 @@ static BIGNUM *srp_Calc_k(const BIGNUM *N, const BIGNUM *g)
goto err;
BN_bn2bin(N, tmp);
- EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);
- EVP_DigestUpdate(ctxt, tmp, longN);
+ if (!EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
+ || !EVP_DigestUpdate(ctxt, tmp, longN))
+ goto err;
memset(tmp, 0, longN);
longg = BN_bn2bin(g, tmp);
/* use the zeros behind to pad on left */
- EVP_DigestUpdate(ctxt, tmp + longg, longN - longg);
- EVP_DigestUpdate(ctxt, tmp, longg);
+ if (!EVP_DigestUpdate(ctxt, tmp + longg, longN - longg)
+ || !EVP_DigestUpdate(ctxt, tmp, longg))
+ goto err;
OPENSSL_free(tmp);
- EVP_DigestFinal_ex(ctxt, digest, NULL);
+ if (!EVP_DigestFinal_ex(ctxt, digest, NULL))
+ goto err;
res = BN_bin2bn(digest, sizeof(digest), NULL);
err:
EVP_MD_CTX_free(ctxt);
@@ -77,11 +80,13 @@ BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N)
memset(cAB, 0, longN);
- EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);
- EVP_DigestUpdate(ctxt, cAB + BN_bn2bin(A, cAB + longN), longN);
- EVP_DigestUpdate(ctxt, cAB + BN_bn2bin(B, cAB + longN), longN);
+ if (!EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
+ || !EVP_DigestUpdate(ctxt, cAB + BN_bn2bin(A, cAB + longN), longN)
+ || !EVP_DigestUpdate(ctxt, cAB + BN_bn2bin(B, cAB + longN), longN))
+ goto err;
OPENSSL_free(cAB);
- EVP_DigestFinal_ex(ctxt, cu, NULL);
+ if (!EVP_DigestFinal_ex(ctxt, cu, NULL))
+ goto err;
if ((u = BN_bin2bn(cu, sizeof(cu), NULL)) == NULL)
goto err;
@@ -173,18 +178,20 @@ BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass)
if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL)
goto err;
- EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);
- EVP_DigestUpdate(ctxt, user, strlen(user));
- EVP_DigestUpdate(ctxt, ":", 1);
- EVP_DigestUpdate(ctxt, pass, strlen(pass));
- EVP_DigestFinal_ex(ctxt, dig, NULL);
-
- EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);
+ if (!EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
+ || !EVP_DigestUpdate(ctxt, user, strlen(user))
+ || !EVP_DigestUpdate(ctxt, ":", 1)
+ || !EVP_DigestUpdate(ctxt, pass, strlen(pass))
+ || !EVP_DigestFinal_ex(ctxt, dig, NULL)
+ || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL))
+ goto err;
BN_bn2bin(s, cs);
- EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s));
+ if (!EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)))
+ goto err;
OPENSSL_free(cs);
- EVP_DigestUpdate(ctxt, dig, sizeof(dig));
- EVP_DigestFinal_ex(ctxt, dig, NULL);
+ if (!EVP_DigestUpdate(ctxt, dig, sizeof(dig))
+ || !EVP_DigestFinal_ex(ctxt, dig, NULL))
+ goto err;
res = BN_bin2bn(dig, sizeof(dig), NULL);
err:
diff --git a/crypto/srp/srp_vfy.c b/crypto/srp/srp_vfy.c
index f99fa1b278..73ea4e61cf 100644
--- a/crypto/srp/srp_vfy.c
+++ b/crypto/srp/srp_vfy.c
@@ -500,10 +500,12 @@ SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username)
if (RAND_bytes(digv, SHA_DIGEST_LENGTH) <= 0)
goto err;
ctxt = EVP_MD_CTX_new();
- EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL);
- EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key));
- EVP_DigestUpdate(ctxt, username, strlen(username));
- EVP_DigestFinal_ex(ctxt, digs, NULL);
+ if (ctxt == NULL
+ || !EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL)
+ || !EVP_DigestUpdate(ctxt, vb->seed_key, strlen(vb->seed_key))
+ || !EVP_DigestUpdate(ctxt, username, strlen(username))
+ || !EVP_DigestFinal_ex(ctxt, digs, NULL))
+ goto err;
EVP_MD_CTX_free(ctxt);
ctxt = NULL;
if (SRP_user_pwd_set_sv_BN(user,