diff options
author | Richard Levitte <levitte@openssl.org> | 2015-11-27 14:02:12 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2015-12-07 17:39:23 +0100 |
commit | 6e59a892db781658c050e5217127c4147c116ac9 (patch) | |
tree | eec9e79e1c71f9c2897f49b29084bf42a66e96db /crypto/srp/srp_lib.c | |
parent | 9b6c00707eae2cbce79479f4b1a5dc11019abca0 (diff) |
Adjust all accesses to EVP_MD_CTX to use accessor functions.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/srp/srp_lib.c')
-rw-r--r-- | crypto/srp/srp_lib.c | 89 |
1 files changed, 52 insertions, 37 deletions
diff --git a/crypto/srp/srp_lib.c b/crypto/srp/srp_lib.c index 850ec2ce64..649d2b5a66 100644 --- a/crypto/srp/srp_lib.c +++ b/crypto/srp/srp_lib.c @@ -70,31 +70,36 @@ static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g) unsigned char digest[SHA_DIGEST_LENGTH]; unsigned char *tmp; - EVP_MD_CTX ctxt; + EVP_MD_CTX *ctxt = NULL; int longg; int longN = BN_num_bytes(N); + BIGNUM *res = NULL; if (BN_ucmp(g, N) >= 0) return NULL; - if ((tmp = OPENSSL_malloc(longN)) == NULL) + ctxt = EVP_MD_CTX_create(); + if (ctxt == NULL) return NULL; + if ((tmp = OPENSSL_malloc(longN)) == NULL) + goto err; BN_bn2bin(N, tmp); - EVP_MD_CTX_init(&ctxt); - EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); - EVP_DigestUpdate(&ctxt, tmp, longN); + EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL); + EVP_DigestUpdate(ctxt, tmp, longN); 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); + EVP_DigestUpdate(ctxt, tmp + longg, longN - longg); + EVP_DigestUpdate(ctxt, tmp, longg); OPENSSL_free(tmp); - EVP_DigestFinal_ex(&ctxt, digest, NULL); - EVP_MD_CTX_cleanup(&ctxt); - return BN_bin2bn(digest, sizeof(digest), NULL); + EVP_DigestFinal_ex(ctxt, digest, NULL); + res = BN_bin2bn(digest, sizeof(digest), NULL); + err: + EVP_MD_CTX_destroy(ctxt); + return res; } BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N) @@ -104,7 +109,7 @@ BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N) BIGNUM *u; unsigned char cu[SHA_DIGEST_LENGTH]; unsigned char *cAB; - EVP_MD_CTX ctxt; + EVP_MD_CTX *ctxt = NULL; int longN; if ((A == NULL) || (B == NULL) || (N == NULL)) return NULL; @@ -114,25 +119,30 @@ BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N) longN = BN_num_bytes(N); - if ((cAB = OPENSSL_malloc(2 * longN)) == NULL) + ctxt = EVP_MD_CTX_create(); + if (ctxt == NULL) return NULL; + if ((cAB = OPENSSL_malloc(2 * longN)) == NULL) + goto err; memset(cAB, 0, longN); - EVP_MD_CTX_init(&ctxt); - 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); + 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); OPENSSL_free(cAB); - EVP_DigestFinal_ex(&ctxt, cu, NULL); - EVP_MD_CTX_cleanup(&ctxt); + EVP_DigestFinal_ex(ctxt, cu, NULL); if ((u = BN_bin2bn(cu, sizeof(cu), NULL)) == NULL) - return NULL; - if (!BN_is_zero(u)) - return u; - BN_free(u); - return NULL; + goto err; + if (BN_is_zero(u)) { + BN_free(u); + u = NULL; + } + err: + EVP_MD_CTX_destroy(ctxt); + + return u; } BIGNUM *SRP_Calc_server_key(BIGNUM *A, BIGNUM *v, BIGNUM *u, BIGNUM *b, @@ -196,31 +206,36 @@ BIGNUM *SRP_Calc_B(BIGNUM *b, BIGNUM *N, BIGNUM *g, BIGNUM *v) BIGNUM *SRP_Calc_x(BIGNUM *s, const char *user, const char *pass) { unsigned char dig[SHA_DIGEST_LENGTH]; - EVP_MD_CTX ctxt; + EVP_MD_CTX *ctxt; unsigned char *cs; + BIGNUM *res = NULL; if ((s == NULL) || (user == NULL) || (pass == NULL)) return NULL; - if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL) + ctxt = EVP_MD_CTX_create(); + if (ctxt == NULL) return NULL; + if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL) + goto err; - EVP_MD_CTX_init(&ctxt); - 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); + 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); + EVP_DigestInit_ex(ctxt, EVP_sha1(), NULL); BN_bn2bin(s, cs); - EVP_DigestUpdate(&ctxt, cs, BN_num_bytes(s)); + EVP_DigestUpdate(ctxt, cs, BN_num_bytes(s)); OPENSSL_free(cs); - EVP_DigestUpdate(&ctxt, dig, sizeof(dig)); - EVP_DigestFinal_ex(&ctxt, dig, NULL); - EVP_MD_CTX_cleanup(&ctxt); + EVP_DigestUpdate(ctxt, dig, sizeof(dig)); + EVP_DigestFinal_ex(ctxt, dig, NULL); - return BN_bin2bn(dig, sizeof(dig), NULL); + res = BN_bin2bn(dig, sizeof(dig), NULL); + err: + EVP_MD_CTX_destroy(ctxt); + return res; } BIGNUM *SRP_Calc_A(BIGNUM *a, BIGNUM *N, BIGNUM *g) |