summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2025-01-06 14:22:55 +0000
committertb <>2025-01-06 14:22:55 +0000
commitff1ace8f50a4d6bd350ebd7bcc6c29fa0a3af23c (patch)
tree337cc220cce5f6aa9f5e4a93b5b6990f8b41d555
parent31e21337bdcd445b6ecbcb0fa4e05e90bbc45f3e (diff)
downloadopenbsd-ff1ace8f50a4d6bd350ebd7bcc6c29fa0a3af23c.tar.gz
openbsd-ff1ace8f50a4d6bd350ebd7bcc6c29fa0a3af23c.tar.bz2
openbsd-ff1ace8f50a4d6bd350ebd7bcc6c29fa0a3af23c.zip
Inline the copy handlers in EC_GROUP_copy()
This is another bit of indirection that makes this code so hard to follow. ok jsing
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c25
-rw-r--r--src/lib/libcrypto/ec/ecp_methods.c45
2 files changed, 19 insertions, 51 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index b1aad34017..8bae5940c2 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_lib.c,v 1.97 2025/01/06 12:35:14 jsing Exp $ */ 1/* $OpenBSD: ec_lib.c,v 1.98 2025/01/06 14:22:55 tb Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -150,10 +150,6 @@ LCRYPTO_ALIAS(EC_GROUP_clear_free);
150int 150int
151EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src) 151EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
152{ 152{
153 if (dest->meth->group_copy == NULL) {
154 ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
155 return 0;
156 }
157 if (dest->meth != src->meth) { 153 if (dest->meth != src->meth) {
158 ECerror(EC_R_INCOMPATIBLE_OBJECTS); 154 ECerror(EC_R_INCOMPATIBLE_OBJECTS);
159 return 0; 155 return 0;
@@ -161,8 +157,23 @@ EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
161 if (dest == src) 157 if (dest == src)
162 return 1; 158 return 1;
163 159
164 if (!dest->meth->group_copy(dest, src)) 160 if (!bn_copy(dest->p, src->p))
165 return 0; 161 return 0;
162 if (!bn_copy(dest->a, src->a))
163 return 0;
164 if (!bn_copy(dest->b, src->b))
165 return 0;
166
167 dest->a_is_minus3 = src->a_is_minus3;
168
169 BN_MONT_CTX_free(dest->mont_ctx);
170 dest->mont_ctx = NULL;
171 if (src->mont_ctx != NULL) {
172 if ((dest->mont_ctx = BN_MONT_CTX_new()) == NULL)
173 return 0;
174 if (!BN_MONT_CTX_copy(dest->mont_ctx, src->mont_ctx))
175 return 0;
176 }
166 177
167 EC_POINT_free(dest->generator); 178 EC_POINT_free(dest->generator);
168 dest->generator = NULL; 179 dest->generator = NULL;
@@ -185,7 +196,7 @@ EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
185 if (!EC_GROUP_set_seed(dest, src->seed, src->seed_len)) 196 if (!EC_GROUP_set_seed(dest, src->seed, src->seed_len))
186 return 0; 197 return 0;
187 198
188 return dest->meth->group_copy(dest, src); 199 return 1;
189} 200}
190LCRYPTO_ALIAS(EC_GROUP_copy); 201LCRYPTO_ALIAS(EC_GROUP_copy);
191 202
diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c
index 44322f27f2..042db054a8 100644
--- a/src/lib/libcrypto/ec/ecp_methods.c
+++ b/src/lib/libcrypto/ec/ecp_methods.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_methods.c,v 1.22 2025/01/06 12:36:41 jsing Exp $ */ 1/* $OpenBSD: ecp_methods.c,v 1.23 2025/01/06 14:22:55 tb Exp $ */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project.
4 * Includes code written by Bodo Moeller for the OpenSSL project. 4 * Includes code written by Bodo Moeller for the OpenSSL project.
@@ -85,21 +85,6 @@
85 */ 85 */
86 86
87static int 87static int
88ec_group_copy(EC_GROUP *dest, const EC_GROUP *src)
89{
90 if (!bn_copy(dest->p, src->p))
91 return 0;
92 if (!bn_copy(dest->a, src->a))
93 return 0;
94 if (!bn_copy(dest->b, src->b))
95 return 0;
96
97 dest->a_is_minus3 = src->a_is_minus3;
98
99 return 1;
100}
101
102static int
103ec_decode_scalar(const EC_GROUP *group, BIGNUM *bn, const BIGNUM *x, BN_CTX *ctx) 88ec_decode_scalar(const EC_GROUP *group, BIGNUM *bn, const BIGNUM *x, BN_CTX *ctx)
104{ 89{
105 if (bn == NULL) 90 if (bn == NULL)
@@ -1459,32 +1444,6 @@ ec_mont_group_clear(EC_GROUP *group)
1459} 1444}
1460 1445
1461static int 1446static int
1462ec_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
1463{
1464 ec_mont_group_clear(dest);
1465
1466 if (!ec_group_copy(dest, src))
1467 return 0;
1468
1469 if (src->mont_ctx != NULL) {
1470 dest->mont_ctx = BN_MONT_CTX_new();
1471 if (dest->mont_ctx == NULL)
1472 return 0;
1473 if (!BN_MONT_CTX_copy(dest->mont_ctx, src->mont_ctx))
1474 goto err;
1475 }
1476
1477 return 1;
1478
1479 err:
1480 if (dest->mont_ctx != NULL) {
1481 BN_MONT_CTX_free(dest->mont_ctx);
1482 dest->mont_ctx = NULL;
1483 }
1484 return 0;
1485}
1486
1487static int
1488ec_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, 1447ec_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a,
1489 const BIGNUM *b, BN_CTX *ctx) 1448 const BIGNUM *b, BN_CTX *ctx)
1490{ 1449{
@@ -1559,7 +1518,6 @@ ec_mont_field_decode(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
1559 1518
1560static const EC_METHOD ec_GFp_simple_method = { 1519static const EC_METHOD ec_GFp_simple_method = {
1561 .field_type = NID_X9_62_prime_field, 1520 .field_type = NID_X9_62_prime_field,
1562 .group_copy = ec_group_copy,
1563 .group_set_curve = ec_group_set_curve, 1521 .group_set_curve = ec_group_set_curve,
1564 .group_get_curve = ec_group_get_curve, 1522 .group_get_curve = ec_group_get_curve,
1565 .group_get_degree = ec_group_get_degree, 1523 .group_get_degree = ec_group_get_degree,
@@ -1591,7 +1549,6 @@ LCRYPTO_ALIAS(EC_GFp_simple_method);
1591 1549
1592static const EC_METHOD ec_GFp_mont_method = { 1550static const EC_METHOD ec_GFp_mont_method = {
1593 .field_type = NID_X9_62_prime_field, 1551 .field_type = NID_X9_62_prime_field,
1594 .group_copy = ec_mont_group_copy,
1595 .group_set_curve = ec_mont_group_set_curve, 1552 .group_set_curve = ec_mont_group_set_curve,
1596 .group_get_curve = ec_group_get_curve, 1553 .group_get_curve = ec_group_get_curve,
1597 .group_get_degree = ec_group_get_degree, 1554 .group_get_degree = ec_group_get_degree,