diff options
| author | tb <> | 2025-01-06 14:22:55 +0000 |
|---|---|---|
| committer | tb <> | 2025-01-06 14:22:55 +0000 |
| commit | d945002b89bc5ba99f11a610b8906e1ebaa241c0 (patch) | |
| tree | 337cc220cce5f6aa9f5e4a93b5b6990f8b41d555 /src | |
| parent | 5fe1809b29ea07bb51ff7e8df06c129f64c5c9fb (diff) | |
| download | openbsd-d945002b89bc5ba99f11a610b8906e1ebaa241c0.tar.gz openbsd-d945002b89bc5ba99f11a610b8906e1ebaa241c0.tar.bz2 openbsd-d945002b89bc5ba99f11a610b8906e1ebaa241c0.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
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 25 | ||||
| -rw-r--r-- | src/lib/libcrypto/ec/ecp_methods.c | 45 |
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); | |||
| 150 | int | 150 | int |
| 151 | EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src) | 151 | EC_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 | } |
| 190 | LCRYPTO_ALIAS(EC_GROUP_copy); | 201 | LCRYPTO_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 | ||
| 87 | static int | 87 | static int |
| 88 | ec_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 | |||
| 102 | static int | ||
| 103 | ec_decode_scalar(const EC_GROUP *group, BIGNUM *bn, const BIGNUM *x, BN_CTX *ctx) | 88 | ec_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 | ||
| 1461 | static int | 1446 | static int |
| 1462 | ec_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 | |||
| 1487 | static int | ||
| 1488 | ec_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, | 1447 | ec_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 | ||
| 1560 | static const EC_METHOD ec_GFp_simple_method = { | 1519 | static 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 | ||
| 1592 | static const EC_METHOD ec_GFp_mont_method = { | 1550 | static 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, |
