summaryrefslogtreecommitdiffstats
path: root/crypto/srp
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/srp
parent1fc431ba57d12189a9bdacd3999ea2a7b91458d8 (diff)
check return values for EVP_Digest*() APIs
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/srp')
-rw-r--r--crypto/srp/srp_lib.c45
-rw-r--r--crypto/srp/srp_vfy.c10
2 files changed, 32 insertions, 23 deletions
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,