summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormiod <>2014-07-10 20:18:51 +0000
committermiod <>2014-07-10 20:18:51 +0000
commit9d441e0f87e5a0448670901b8098808268b7d10c (patch)
treeffa4bcd6133fb00493477097192ad7d8293404cd /src
parent6e361a5efba1d72a7ea4416e1d69e02910fa9414 (diff)
downloadopenbsd-9d441e0f87e5a0448670901b8098808268b7d10c.tar.gz
openbsd-9d441e0f87e5a0448670901b8098808268b7d10c.tar.bz2
openbsd-9d441e0f87e5a0448670901b8098808268b7d10c.zip
Make sure SRP_Calc_client_key() returns NULL instead of a pristine BN_new()
upon error; from Florian Zumbiehl (florz , florz . de) on tech@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/srp/srp_lib.c13
-rw-r--r--src/lib/libssl/src/crypto/srp/srp_lib.c13
2 files changed, 18 insertions, 8 deletions
diff --git a/src/lib/libcrypto/srp/srp_lib.c b/src/lib/libcrypto/srp/srp_lib.c
index 81fc11d2a3..a57ee3640f 100644
--- a/src/lib/libcrypto/srp/srp_lib.c
+++ b/src/lib/libcrypto/srp/srp_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: srp_lib.c,v 1.5 2014/06/12 15:49:30 deraadt Exp $ */ 1/* $OpenBSD: srp_lib.c,v 1.6 2014/07/10 20:18:51 miod Exp $ */
2/* Written by Christophe Renou (christophe.renou@edelweb.fr) with 2/* Written by Christophe Renou (christophe.renou@edelweb.fr) with
3 * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr) 3 * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr)
4 * for the EdelKey project and contributed to the OpenSSL project 2004. 4 * for the EdelKey project and contributed to the OpenSSL project 2004.
@@ -89,14 +89,14 @@ static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g)
89 89
90 if ((tmp = malloc(longN)) == NULL) 90 if ((tmp = malloc(longN)) == NULL)
91 return NULL; 91 return NULL;
92 BN_bn2bin(N,tmp) ; 92 BN_bn2bin(N,tmp);
93 93
94 EVP_MD_CTX_init(&ctxt); 94 EVP_MD_CTX_init(&ctxt);
95 EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); 95 EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL);
96 EVP_DigestUpdate(&ctxt, tmp, longN); 96 EVP_DigestUpdate(&ctxt, tmp, longN);
97 97
98 memset(tmp, 0, longN); 98 memset(tmp, 0, longN);
99 longg = BN_bn2bin(g,tmp) ; 99 longg = BN_bn2bin(g,tmp);
100 /* use the zeros behind to pad on left */ 100 /* use the zeros behind to pad on left */
101 EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg); 101 EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg);
102 EVP_DigestUpdate(&ctxt, tmp, longg); 102 EVP_DigestUpdate(&ctxt, tmp, longg);
@@ -257,6 +257,7 @@ BIGNUM *SRP_Calc_A(BIGNUM *a, BIGNUM *N, BIGNUM *g)
257BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, BIGNUM *a, BIGNUM *u) 257BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, BIGNUM *a, BIGNUM *u)
258 { 258 {
259 BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL , *k = NULL, *K = NULL; 259 BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL , *k = NULL, *K = NULL;
260 BIGNUM *ret = NULL;
260 BN_CTX *bn_ctx; 261 BN_CTX *bn_ctx;
261 262
262 if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL || a == NULL || 263 if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL || a == NULL ||
@@ -285,13 +286,17 @@ BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, BIGNUM *
285 if (!BN_mod_exp(K,tmp,tmp2,N,bn_ctx)) 286 if (!BN_mod_exp(K,tmp,tmp2,N,bn_ctx))
286 goto err; 287 goto err;
287 288
289 ret = K;
290 K = NULL;
291
288err : 292err :
289 BN_CTX_free(bn_ctx); 293 BN_CTX_free(bn_ctx);
290 BN_clear_free(tmp); 294 BN_clear_free(tmp);
291 BN_clear_free(tmp2); 295 BN_clear_free(tmp2);
292 BN_clear_free(tmp3); 296 BN_clear_free(tmp3);
293 BN_free(k); 297 BN_free(k);
294 return K; 298 BN_clear_free(K);
299 return ret;
295 } 300 }
296 301
297int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N) 302int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N)
diff --git a/src/lib/libssl/src/crypto/srp/srp_lib.c b/src/lib/libssl/src/crypto/srp/srp_lib.c
index 81fc11d2a3..a57ee3640f 100644
--- a/src/lib/libssl/src/crypto/srp/srp_lib.c
+++ b/src/lib/libssl/src/crypto/srp/srp_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: srp_lib.c,v 1.5 2014/06/12 15:49:30 deraadt Exp $ */ 1/* $OpenBSD: srp_lib.c,v 1.6 2014/07/10 20:18:51 miod Exp $ */
2/* Written by Christophe Renou (christophe.renou@edelweb.fr) with 2/* Written by Christophe Renou (christophe.renou@edelweb.fr) with
3 * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr) 3 * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr)
4 * for the EdelKey project and contributed to the OpenSSL project 2004. 4 * for the EdelKey project and contributed to the OpenSSL project 2004.
@@ -89,14 +89,14 @@ static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g)
89 89
90 if ((tmp = malloc(longN)) == NULL) 90 if ((tmp = malloc(longN)) == NULL)
91 return NULL; 91 return NULL;
92 BN_bn2bin(N,tmp) ; 92 BN_bn2bin(N,tmp);
93 93
94 EVP_MD_CTX_init(&ctxt); 94 EVP_MD_CTX_init(&ctxt);
95 EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); 95 EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL);
96 EVP_DigestUpdate(&ctxt, tmp, longN); 96 EVP_DigestUpdate(&ctxt, tmp, longN);
97 97
98 memset(tmp, 0, longN); 98 memset(tmp, 0, longN);
99 longg = BN_bn2bin(g,tmp) ; 99 longg = BN_bn2bin(g,tmp);
100 /* use the zeros behind to pad on left */ 100 /* use the zeros behind to pad on left */
101 EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg); 101 EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg);
102 EVP_DigestUpdate(&ctxt, tmp, longg); 102 EVP_DigestUpdate(&ctxt, tmp, longg);
@@ -257,6 +257,7 @@ BIGNUM *SRP_Calc_A(BIGNUM *a, BIGNUM *N, BIGNUM *g)
257BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, BIGNUM *a, BIGNUM *u) 257BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, BIGNUM *a, BIGNUM *u)
258 { 258 {
259 BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL , *k = NULL, *K = NULL; 259 BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL , *k = NULL, *K = NULL;
260 BIGNUM *ret = NULL;
260 BN_CTX *bn_ctx; 261 BN_CTX *bn_ctx;
261 262
262 if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL || a == NULL || 263 if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL || a == NULL ||
@@ -285,13 +286,17 @@ BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, BIGNUM *
285 if (!BN_mod_exp(K,tmp,tmp2,N,bn_ctx)) 286 if (!BN_mod_exp(K,tmp,tmp2,N,bn_ctx))
286 goto err; 287 goto err;
287 288
289 ret = K;
290 K = NULL;
291
288err : 292err :
289 BN_CTX_free(bn_ctx); 293 BN_CTX_free(bn_ctx);
290 BN_clear_free(tmp); 294 BN_clear_free(tmp);
291 BN_clear_free(tmp2); 295 BN_clear_free(tmp2);
292 BN_clear_free(tmp3); 296 BN_clear_free(tmp3);
293 BN_free(k); 297 BN_free(k);
294 return K; 298 BN_clear_free(K);
299 return ret;
295 } 300 }
296 301
297int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N) 302int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N)