diff options
author | tb <> | 2024-11-30 21:09:59 +0000 |
---|---|---|
committer | tb <> | 2024-11-30 21:09:59 +0000 |
commit | 56c2d56ad840436ee3e6f9e935795a718b9edb37 (patch) | |
tree | 6ae3aed64b6827756f2a5efd89b1c53c99db42c5 /src | |
parent | 98f7a26186887ba45c08f5491bb6ef3a594837bd (diff) | |
download | openbsd-56c2d56ad840436ee3e6f9e935795a718b9edb37.tar.gz openbsd-56c2d56ad840436ee3e6f9e935795a718b9edb37.tar.bz2 openbsd-56c2d56ad840436ee3e6f9e935795a718b9edb37.zip |
Inline trivial EC point methods
Like most of the "group" methods these are shared between Montgomery
curves and simple curves. There's no point in five methods hanging off
the EC_METHODS struct whne they can just as well be inlined in the
public API. It makes all files involved shorter...
ok jsing
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 46 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_local.h | 12 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ecp_methods.c | 60 |
3 files changed, 23 insertions, 95 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index 542f7a0ba2..a1c80c328b 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.88 2024/11/22 12:14:41 tb Exp $ */ | 1 | /* $OpenBSD: ec_lib.c,v 1.89 2024/11/30 21:09:59 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 | */ |
@@ -785,10 +785,6 @@ EC_POINT_new(const EC_GROUP *group) | |||
785 | ECerror(ERR_R_PASSED_NULL_PARAMETER); | 785 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
786 | goto err; | 786 | goto err; |
787 | } | 787 | } |
788 | if (group->meth->point_init == NULL) { | ||
789 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
790 | goto err; | ||
791 | } | ||
792 | 788 | ||
793 | if ((point = calloc(1, sizeof(*point))) == NULL) { | 789 | if ((point = calloc(1, sizeof(*point))) == NULL) { |
794 | ECerror(ERR_R_MALLOC_FAILURE); | 790 | ECerror(ERR_R_MALLOC_FAILURE); |
@@ -797,9 +793,6 @@ EC_POINT_new(const EC_GROUP *group) | |||
797 | 793 | ||
798 | point->meth = group->meth; | 794 | point->meth = group->meth; |
799 | 795 | ||
800 | if (!point->meth->point_init(point)) | ||
801 | goto err; | ||
802 | |||
803 | return point; | 796 | return point; |
804 | 797 | ||
805 | err: | 798 | err: |
@@ -815,8 +808,9 @@ EC_POINT_free(EC_POINT *point) | |||
815 | if (point == NULL) | 808 | if (point == NULL) |
816 | return; | 809 | return; |
817 | 810 | ||
818 | if (point->meth->point_finish != NULL) | 811 | BN_free(&point->X); |
819 | point->meth->point_finish(point); | 812 | BN_free(&point->Y); |
813 | BN_free(&point->Z); | ||
820 | 814 | ||
821 | freezero(point, sizeof *point); | 815 | freezero(point, sizeof *point); |
822 | } | 816 | } |
@@ -832,17 +826,22 @@ LCRYPTO_ALIAS(EC_POINT_clear_free); | |||
832 | int | 826 | int |
833 | EC_POINT_copy(EC_POINT *dest, const EC_POINT *src) | 827 | EC_POINT_copy(EC_POINT *dest, const EC_POINT *src) |
834 | { | 828 | { |
835 | if (dest->meth->point_copy == NULL) { | ||
836 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
837 | return 0; | ||
838 | } | ||
839 | if (dest->meth != src->meth) { | 829 | if (dest->meth != src->meth) { |
840 | ECerror(EC_R_INCOMPATIBLE_OBJECTS); | 830 | ECerror(EC_R_INCOMPATIBLE_OBJECTS); |
841 | return 0; | 831 | return 0; |
842 | } | 832 | } |
843 | if (dest == src) | 833 | if (dest == src) |
844 | return 1; | 834 | return 1; |
845 | return dest->meth->point_copy(dest, src); | 835 | |
836 | if (!bn_copy(&dest->X, &src->X)) | ||
837 | return 0; | ||
838 | if (!bn_copy(&dest->Y, &src->Y)) | ||
839 | return 0; | ||
840 | if (!bn_copy(&dest->Z, &src->Z)) | ||
841 | return 0; | ||
842 | dest->Z_is_one = src->Z_is_one; | ||
843 | |||
844 | return 1; | ||
846 | } | 845 | } |
847 | LCRYPTO_ALIAS(EC_POINT_copy); | 846 | LCRYPTO_ALIAS(EC_POINT_copy); |
848 | 847 | ||
@@ -879,15 +878,15 @@ LCRYPTO_ALIAS(EC_POINT_method_of); | |||
879 | int | 878 | int |
880 | EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point) | 879 | EC_POINT_set_to_infinity(const EC_GROUP *group, EC_POINT *point) |
881 | { | 880 | { |
882 | if (group->meth->point_set_to_infinity == NULL) { | ||
883 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
884 | return 0; | ||
885 | } | ||
886 | if (group->meth != point->meth) { | 881 | if (group->meth != point->meth) { |
887 | ECerror(EC_R_INCOMPATIBLE_OBJECTS); | 882 | ECerror(EC_R_INCOMPATIBLE_OBJECTS); |
888 | return 0; | 883 | return 0; |
889 | } | 884 | } |
890 | return group->meth->point_set_to_infinity(group, point); | 885 | |
886 | BN_zero(&point->Z); | ||
887 | point->Z_is_one = 0; | ||
888 | |||
889 | return 1; | ||
891 | } | 890 | } |
892 | LCRYPTO_ALIAS(EC_POINT_set_to_infinity); | 891 | LCRYPTO_ALIAS(EC_POINT_set_to_infinity); |
893 | 892 | ||
@@ -1196,15 +1195,12 @@ LCRYPTO_ALIAS(EC_POINT_invert); | |||
1196 | int | 1195 | int |
1197 | EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) | 1196 | EC_POINT_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) |
1198 | { | 1197 | { |
1199 | if (group->meth->is_at_infinity == NULL) { | ||
1200 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | ||
1201 | return 0; | ||
1202 | } | ||
1203 | if (group->meth != point->meth) { | 1198 | if (group->meth != point->meth) { |
1204 | ECerror(EC_R_INCOMPATIBLE_OBJECTS); | 1199 | ECerror(EC_R_INCOMPATIBLE_OBJECTS); |
1205 | return 0; | 1200 | return 0; |
1206 | } | 1201 | } |
1207 | return group->meth->is_at_infinity(group, point); | 1202 | |
1203 | return BN_is_zero(&point->Z); | ||
1208 | } | 1204 | } |
1209 | LCRYPTO_ALIAS(EC_POINT_is_at_infinity); | 1205 | LCRYPTO_ALIAS(EC_POINT_is_at_infinity); |
1210 | 1206 | ||
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index 5d1909db03..11cc36cf67 100644 --- a/src/lib/libcrypto/ec/ec_local.h +++ b/src/lib/libcrypto/ec/ec_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_local.h,v 1.39 2024/11/22 12:14:41 tb Exp $ */ | 1 | /* $OpenBSD: ec_local.h,v 1.40 2024/11/30 21:09:59 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 | */ |
@@ -101,11 +101,6 @@ struct ec_method_st { | |||
101 | int (*group_order_bits)(const EC_GROUP *); | 101 | int (*group_order_bits)(const EC_GROUP *); |
102 | int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *); | 102 | int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *); |
103 | 103 | ||
104 | int (*point_init)(EC_POINT *); | ||
105 | void (*point_finish)(EC_POINT *); | ||
106 | int (*point_copy)(EC_POINT *, const EC_POINT *); | ||
107 | |||
108 | int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *); | ||
109 | int (*point_set_Jprojective_coordinates)(const EC_GROUP *, EC_POINT *, | 104 | int (*point_set_Jprojective_coordinates)(const EC_GROUP *, EC_POINT *, |
110 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); | 105 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); |
111 | int (*point_get_Jprojective_coordinates)(const EC_GROUP *, | 106 | int (*point_get_Jprojective_coordinates)(const EC_GROUP *, |
@@ -122,7 +117,6 @@ struct ec_method_st { | |||
122 | int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); | 117 | int (*dbl)(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); |
123 | int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *); | 118 | int (*invert)(const EC_GROUP *, EC_POINT *, BN_CTX *); |
124 | 119 | ||
125 | int (*is_at_infinity)(const EC_GROUP *, const EC_POINT *); | ||
126 | int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *); | 120 | int (*is_on_curve)(const EC_GROUP *, const EC_POINT *, BN_CTX *); |
127 | int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, | 121 | int (*point_cmp)(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, |
128 | BN_CTX *); | 122 | BN_CTX *); |
@@ -140,10 +134,6 @@ struct ec_method_st { | |||
140 | const EC_POINT *point, BN_CTX *); | 134 | const EC_POINT *point, BN_CTX *); |
141 | 135 | ||
142 | /* | 136 | /* |
143 | * Internal methods. | ||
144 | */ | ||
145 | |||
146 | /* | ||
147 | * These can be used by 'add' and 'dbl' so that the same implementations | 137 | * These can be used by 'add' and 'dbl' so that the same implementations |
148 | * of point operations can be used with different optimized versions of | 138 | * of point operations can be used with different optimized versions of |
149 | * expensive field operations. | 139 | * expensive field operations. |
diff --git a/src/lib/libcrypto/ec/ecp_methods.c b/src/lib/libcrypto/ec/ecp_methods.c index b394206aea..b14cd0b158 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.11 2024/11/30 16:34:34 tb Exp $ */ | 1 | /* $OpenBSD: ecp_methods.c,v 1.12 2024/11/30 21:09:59 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. |
@@ -280,48 +280,6 @@ ec_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) | |||
280 | } | 280 | } |
281 | 281 | ||
282 | static int | 282 | static int |
283 | ec_point_init(EC_POINT * point) | ||
284 | { | ||
285 | BN_init(&point->X); | ||
286 | BN_init(&point->Y); | ||
287 | BN_init(&point->Z); | ||
288 | point->Z_is_one = 0; | ||
289 | |||
290 | return 1; | ||
291 | } | ||
292 | |||
293 | static void | ||
294 | ec_point_finish(EC_POINT *point) | ||
295 | { | ||
296 | BN_free(&point->X); | ||
297 | BN_free(&point->Y); | ||
298 | BN_free(&point->Z); | ||
299 | point->Z_is_one = 0; | ||
300 | } | ||
301 | |||
302 | static int | ||
303 | ec_point_copy(EC_POINT *dest, const EC_POINT *src) | ||
304 | { | ||
305 | if (!bn_copy(&dest->X, &src->X)) | ||
306 | return 0; | ||
307 | if (!bn_copy(&dest->Y, &src->Y)) | ||
308 | return 0; | ||
309 | if (!bn_copy(&dest->Z, &src->Z)) | ||
310 | return 0; | ||
311 | dest->Z_is_one = src->Z_is_one; | ||
312 | |||
313 | return 1; | ||
314 | } | ||
315 | |||
316 | static int | ||
317 | ec_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) | ||
318 | { | ||
319 | point->Z_is_one = 0; | ||
320 | BN_zero(&point->Z); | ||
321 | return 1; | ||
322 | } | ||
323 | |||
324 | static int | ||
325 | ec_set_Jprojective_coordinates(const EC_GROUP *group, EC_POINT *point, | 283 | ec_set_Jprojective_coordinates(const EC_GROUP *group, EC_POINT *point, |
326 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx) | 284 | const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *ctx) |
327 | { | 285 | { |
@@ -891,12 +849,6 @@ ec_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx) | |||
891 | } | 849 | } |
892 | 850 | ||
893 | static int | 851 | static int |
894 | ec_is_at_infinity(const EC_GROUP *group, const EC_POINT *point) | ||
895 | { | ||
896 | return BN_is_zero(&point->Z); | ||
897 | } | ||
898 | |||
899 | static int | ||
900 | ec_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) | 852 | ec_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx) |
901 | { | 853 | { |
902 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); | 854 | int (*field_mul) (const EC_GROUP *, BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); |
@@ -1738,10 +1690,6 @@ static const EC_METHOD ec_GFp_simple_method = { | |||
1738 | .group_get_degree = ec_group_get_degree, | 1690 | .group_get_degree = ec_group_get_degree, |
1739 | .group_order_bits = ec_group_simple_order_bits, | 1691 | .group_order_bits = ec_group_simple_order_bits, |
1740 | .group_check_discriminant = ec_group_check_discriminant, | 1692 | .group_check_discriminant = ec_group_check_discriminant, |
1741 | .point_init = ec_point_init, | ||
1742 | .point_finish = ec_point_finish, | ||
1743 | .point_copy = ec_point_copy, | ||
1744 | .point_set_to_infinity = ec_point_set_to_infinity, | ||
1745 | .point_set_Jprojective_coordinates = ec_set_Jprojective_coordinates, | 1693 | .point_set_Jprojective_coordinates = ec_set_Jprojective_coordinates, |
1746 | .point_get_Jprojective_coordinates = ec_get_Jprojective_coordinates, | 1694 | .point_get_Jprojective_coordinates = ec_get_Jprojective_coordinates, |
1747 | .point_set_affine_coordinates = ec_point_set_affine_coordinates, | 1695 | .point_set_affine_coordinates = ec_point_set_affine_coordinates, |
@@ -1750,7 +1698,6 @@ static const EC_METHOD ec_GFp_simple_method = { | |||
1750 | .add = ec_add, | 1698 | .add = ec_add, |
1751 | .dbl = ec_dbl, | 1699 | .dbl = ec_dbl, |
1752 | .invert = ec_invert, | 1700 | .invert = ec_invert, |
1753 | .is_at_infinity = ec_is_at_infinity, | ||
1754 | .is_on_curve = ec_is_on_curve, | 1701 | .is_on_curve = ec_is_on_curve, |
1755 | .point_cmp = ec_cmp, | 1702 | .point_cmp = ec_cmp, |
1756 | .make_affine = ec_make_affine, | 1703 | .make_affine = ec_make_affine, |
@@ -1780,10 +1727,6 @@ static const EC_METHOD ec_GFp_mont_method = { | |||
1780 | .group_get_degree = ec_group_get_degree, | 1727 | .group_get_degree = ec_group_get_degree, |
1781 | .group_order_bits = ec_group_simple_order_bits, | 1728 | .group_order_bits = ec_group_simple_order_bits, |
1782 | .group_check_discriminant = ec_group_check_discriminant, | 1729 | .group_check_discriminant = ec_group_check_discriminant, |
1783 | .point_init = ec_point_init, | ||
1784 | .point_finish = ec_point_finish, | ||
1785 | .point_copy = ec_point_copy, | ||
1786 | .point_set_to_infinity = ec_point_set_to_infinity, | ||
1787 | .point_set_Jprojective_coordinates = ec_set_Jprojective_coordinates, | 1730 | .point_set_Jprojective_coordinates = ec_set_Jprojective_coordinates, |
1788 | .point_get_Jprojective_coordinates = ec_get_Jprojective_coordinates, | 1731 | .point_get_Jprojective_coordinates = ec_get_Jprojective_coordinates, |
1789 | .point_set_affine_coordinates = ec_point_set_affine_coordinates, | 1732 | .point_set_affine_coordinates = ec_point_set_affine_coordinates, |
@@ -1792,7 +1735,6 @@ static const EC_METHOD ec_GFp_mont_method = { | |||
1792 | .add = ec_add, | 1735 | .add = ec_add, |
1793 | .dbl = ec_dbl, | 1736 | .dbl = ec_dbl, |
1794 | .invert = ec_invert, | 1737 | .invert = ec_invert, |
1795 | .is_at_infinity = ec_is_at_infinity, | ||
1796 | .is_on_curve = ec_is_on_curve, | 1738 | .is_on_curve = ec_is_on_curve, |
1797 | .point_cmp = ec_cmp, | 1739 | .point_cmp = ec_cmp, |
1798 | .make_affine = ec_make_affine, | 1740 | .make_affine = ec_make_affine, |