diff options
| author | tb <> | 2024-11-30 21:09:59 +0000 |
|---|---|---|
| committer | tb <> | 2024-11-30 21:09:59 +0000 |
| commit | 07c8646d26fc16dffec24d00b748fd0c79737e40 (patch) | |
| tree | 6ae3aed64b6827756f2a5efd89b1c53c99db42c5 /src/lib/libcrypto/ec/ec_lib.c | |
| parent | 529820265bc18529d80625ea64a94b5502e646aa (diff) | |
| download | openbsd-07c8646d26fc16dffec24d00b748fd0c79737e40.tar.gz openbsd-07c8646d26fc16dffec24d00b748fd0c79737e40.tar.bz2 openbsd-07c8646d26fc16dffec24d00b748fd0c79737e40.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/lib/libcrypto/ec/ec_lib.c')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 46 |
1 files changed, 21 insertions, 25 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 | ||
