提交 53dd4ddf 编写于 作者: E Emilia Kasper

Fix error checking and memory leaks in NISTZ256 precomputation.

Thanks to Brian Smith for reporting these issues.
Reviewed-by: NRich Salz <rsalz@openssl.org>
上级 c028254b
...@@ -765,6 +765,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx) ...@@ -765,6 +765,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
EC_POINT *P = NULL, *T = NULL; EC_POINT *P = NULL, *T = NULL;
const EC_POINT *generator; const EC_POINT *generator;
EC_PRE_COMP *pre_comp; EC_PRE_COMP *pre_comp;
BN_CTX *new_ctx = NULL;
int i, j, k, ret = 0; int i, j, k, ret = 0;
size_t w; size_t w;
...@@ -794,7 +795,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx) ...@@ -794,7 +795,7 @@ static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
return 0; return 0;
if (ctx == NULL) { if (ctx == NULL) {
ctx = BN_CTX_new(); ctx = new_ctx = BN_CTX_new();
if (ctx == NULL) if (ctx == NULL)
goto err; goto err;
} }
...@@ -825,15 +826,19 @@ static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx) ...@@ -825,15 +826,19 @@ static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
P = EC_POINT_new(group); P = EC_POINT_new(group);
T = EC_POINT_new(group); T = EC_POINT_new(group);
if (P == NULL || T == NULL)
goto err;
/* /*
* The zero entry is implicitly infinity, and we skip it, storing other * The zero entry is implicitly infinity, and we skip it, storing other
* values with -1 offset. * values with -1 offset.
*/ */
EC_POINT_copy(T, generator); if (!EC_POINT_copy(T, generator))
goto err;
for (k = 0; k < 64; k++) { for (k = 0; k < 64; k++) {
EC_POINT_copy(P, T); if (!EC_POINT_copy(P, T))
goto err;
for (j = 0; j < 37; j++) { for (j = 0; j < 37; j++) {
P256_POINT_AFFINE temp; P256_POINT_AFFINE temp;
/* /*
...@@ -871,6 +876,8 @@ static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx) ...@@ -871,6 +876,8 @@ static int ecp_nistz256_mult_precompute(EC_GROUP *group, BN_CTX *ctx)
err: err:
if (ctx != NULL) if (ctx != NULL)
BN_CTX_end(ctx); BN_CTX_end(ctx);
BN_CTX_free(new_ctx);
ecp_nistz256_pre_comp_free(pre_comp); ecp_nistz256_pre_comp_free(pre_comp);
if (precomp_storage) if (precomp_storage)
OPENSSL_free(precomp_storage); OPENSSL_free(precomp_storage);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册