summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ec2_mult.c
diff options
context:
space:
mode:
authorjsing <>2023-04-11 18:58:20 +0000
committerjsing <>2023-04-11 18:58:20 +0000
commitb0ee26c7d2e2ba5f8d9159d9c269c93565c36841 (patch)
tree566c48c290ac86140f8df6c959b74661e1d596a7 /src/lib/libcrypto/ec/ec2_mult.c
parent9253152f1f616a3508716fdac0238296418c2025 (diff)
downloadopenbsd-b0ee26c7d2e2ba5f8d9159d9c269c93565c36841.tar.gz
openbsd-b0ee26c7d2e2ba5f8d9159d9c269c93565c36841.tar.bz2
openbsd-b0ee26c7d2e2ba5f8d9159d9c269c93565c36841.zip
Handle BN_CTX at the EC API boundary.
The EC API allows callers to optionally pass in a BN_CTX, which means that any code needing a BN_CTX has to check if one was provided, allocate one if not, then free it again. Rather than doing this dance throughout the EC code, handle the BN_CTX existance at the EC API boundary. This means that lower level implementation code can simply assume that the BN_CTX is available. ok tb@
Diffstat (limited to 'src/lib/libcrypto/ec/ec2_mult.c')
-rw-r--r--src/lib/libcrypto/ec/ec2_mult.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/lib/libcrypto/ec/ec2_mult.c b/src/lib/libcrypto/ec/ec2_mult.c
index d32b7442c4..d7cbd933f2 100644
--- a/src/lib/libcrypto/ec/ec2_mult.c
+++ b/src/lib/libcrypto/ec/ec2_mult.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec2_mult.c,v 1.16 2023/03/27 10:25:02 tb Exp $ */ 1/* $OpenBSD: ec2_mult.c,v 1.17 2023/04/11 18:58:20 jsing Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -375,17 +375,11 @@ int
375ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 375ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
376 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) 376 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
377{ 377{
378 BN_CTX *new_ctx = NULL;
379 int ret = 0;
380 size_t i;
381 EC_POINT *p = NULL; 378 EC_POINT *p = NULL;
382 EC_POINT *acc = NULL; 379 EC_POINT *acc = NULL;
380 size_t i;
381 int ret = 0;
383 382
384 if (ctx == NULL) {
385 ctx = new_ctx = BN_CTX_new();
386 if (ctx == NULL)
387 return 0;
388 }
389 /* 383 /*
390 * This implementation is more efficient than the wNAF implementation 384 * This implementation is more efficient than the wNAF implementation
391 * for 2 or fewer points. Use the ec_wNAF_mul implementation for 3 385 * for 2 or fewer points. Use the ec_wNAF_mul implementation for 3
@@ -432,7 +426,7 @@ ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
432 err: 426 err:
433 EC_POINT_free(p); 427 EC_POINT_free(p);
434 EC_POINT_free(acc); 428 EC_POINT_free(acc);
435 BN_CTX_free(new_ctx); 429
436 return ret; 430 return ret;
437} 431}
438 432