summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec_mult.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ec_mult.c')
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c22
1 files changed, 5 insertions, 17 deletions
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
index c792725661..b70e60a1b4 100644
--- a/src/lib/libcrypto/ec/ec_mult.c
+++ b/src/lib/libcrypto/ec/ec_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_mult.c,v 1.28 2023/03/08 05:45:31 jsing Exp $ */ 1/* $OpenBSD: ec_mult.c,v 1.29 2023/04/11 18:58:20 jsing Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project. 3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -335,7 +335,6 @@ int
335ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 335ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
336 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) 336 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
337{ 337{
338 BN_CTX *new_ctx = NULL;
339 const EC_POINT *generator = NULL; 338 const EC_POINT *generator = NULL;
340 EC_POINT *tmp = NULL; 339 EC_POINT *tmp = NULL;
341 size_t totalnum; 340 size_t totalnum;
@@ -375,11 +374,6 @@ ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
375 } 374 }
376 } 375 }
377 376
378 if (ctx == NULL) {
379 ctx = new_ctx = BN_CTX_new();
380 if (ctx == NULL)
381 goto err;
382 }
383 if (scalar != NULL) { 377 if (scalar != NULL) {
384 generator = EC_GROUP_get0_generator(group); 378 generator = EC_GROUP_get0_generator(group);
385 if (generator == NULL) { 379 if (generator == NULL) {
@@ -679,7 +673,6 @@ ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
679 ret = 1; 673 ret = 1;
680 674
681 err: 675 err:
682 BN_CTX_free(new_ctx);
683 EC_POINT_free(tmp); 676 EC_POINT_free(tmp);
684 free(wsize); 677 free(wsize);
685 free(wNAF_len); 678 free(wNAF_len);
@@ -726,7 +719,6 @@ ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
726{ 719{
727 const EC_POINT *generator; 720 const EC_POINT *generator;
728 EC_POINT *tmp_point = NULL, *base = NULL, **var; 721 EC_POINT *tmp_point = NULL, *base = NULL, **var;
729 BN_CTX *new_ctx = NULL;
730 BIGNUM *order; 722 BIGNUM *order;
731 size_t i, bits, w, pre_points_per_block, blocksize, numblocks, 723 size_t i, bits, w, pre_points_per_block, blocksize, numblocks,
732 num; 724 num;
@@ -745,12 +737,9 @@ ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
745 ECerror(EC_R_UNDEFINED_GENERATOR); 737 ECerror(EC_R_UNDEFINED_GENERATOR);
746 goto err; 738 goto err;
747 } 739 }
748 if (ctx == NULL) { 740
749 ctx = new_ctx = BN_CTX_new();
750 if (ctx == NULL)
751 goto err;
752 }
753 BN_CTX_start(ctx); 741 BN_CTX_start(ctx);
742
754 if ((order = BN_CTX_get(ctx)) == NULL) 743 if ((order = BN_CTX_get(ctx)) == NULL)
755 goto err; 744 goto err;
756 745
@@ -857,10 +846,9 @@ ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
857 pre_comp = NULL; 846 pre_comp = NULL;
858 847
859 ret = 1; 848 ret = 1;
849
860 err: 850 err:
861 if (ctx != NULL) 851 BN_CTX_end(ctx);
862 BN_CTX_end(ctx);
863 BN_CTX_free(new_ctx);
864 ec_pre_comp_free(pre_comp); 852 ec_pre_comp_free(pre_comp);
865 if (points) { 853 if (points) {
866 EC_POINT **p; 854 EC_POINT **p;