---
 src/crypto/srp/srp_lib.c |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/crypto/srp/srp_lib.c b/src/crypto/srp/srp_lib.c
index 0875b29..932fe63 100644
--- a/src/crypto/srp/srp_lib.c
+++ b/src/crypto/srp/srp_lib.c
@@ -80,6 +80,7 @@
 static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g)
        {
        /* k = SHA1(N | PAD(g)) -- tls-srp draft 8 */
+       BIGNUM *ret = NULL;
 
        unsigned char digest[SHA_DIGEST_LENGTH];
        unsigned char *tmp;
@@ -92,19 +93,26 @@ static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g)
        BN_bn2bin(N,tmp) ;
 
        EVP_MD_CTX_init(&ctxt);
-       EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL);
-       EVP_DigestUpdate(&ctxt, tmp, longN);
+       if (!EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL))
+               goto err;
+       if (!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);
-       free(tmp);
+       if (!EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg))
+               goto err;
+       if (!EVP_DigestUpdate(&ctxt, tmp, longg))
+               goto err;
 
-       EVP_DigestFinal_ex(&ctxt, digest, NULL);
+       if (!EVP_DigestFinal_ex(&ctxt, digest, NULL))
+               goto err;
+       ret = BN_bin2bn(digest, sizeof(digest), NULL);  
+err:
        EVP_MD_CTX_cleanup(&ctxt);
-       return BN_bin2bn(digest, sizeof(digest), NULL); 
+       free(tmp);
+       return ret;
        }
 
 BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N)
-- 
1.7.10.4

Reply via email to