diff options
| author | tb <> | 2024-11-04 13:19:08 +0000 |
|---|---|---|
| committer | tb <> | 2024-11-04 13:19:08 +0000 |
| commit | ecafe74e6ae94e6476e79eea52072b6df1d41508 (patch) | |
| tree | 280d79d9312cff522e9a60e9e27d8e0db7570229 | |
| parent | 09078a9b234db559ee050bf5dfe8dbaf55fbfdf2 (diff) | |
| download | openbsd-ecafe74e6ae94e6476e79eea52072b6df1d41508.tar.gz openbsd-ecafe74e6ae94e6476e79eea52072b6df1d41508.tar.bz2 openbsd-ecafe74e6ae94e6476e79eea52072b6df1d41508.zip | |
Rewrite EC_POINT_new() and EC_POINT_dup()
Like most of the code in this file that hasn't been overhauled, these are
just terrible. As jsing points out, we will need to ensure that finish()
works on a not fully initialized point. That's currently safe.
ok jsing
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/ec/ec_lib.c | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index 327cda900b..0d28df59ba 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.77 2024/11/03 13:53:14 tb Exp $ */ | 1 | /* $OpenBSD: ec_lib.c,v 1.78 2024/11/04 13:19:08 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 | */ |
| @@ -762,28 +762,33 @@ ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx) | |||
| 762 | EC_POINT * | 762 | EC_POINT * |
| 763 | EC_POINT_new(const EC_GROUP *group) | 763 | EC_POINT_new(const EC_GROUP *group) |
| 764 | { | 764 | { |
| 765 | EC_POINT *ret; | 765 | EC_POINT *point = NULL; |
| 766 | 766 | ||
| 767 | if (group == NULL) { | 767 | if (group == NULL) { |
| 768 | ECerror(ERR_R_PASSED_NULL_PARAMETER); | 768 | ECerror(ERR_R_PASSED_NULL_PARAMETER); |
| 769 | return NULL; | 769 | goto err; |
| 770 | } | 770 | } |
| 771 | if (group->meth->point_init == NULL) { | 771 | if (group->meth->point_init == NULL) { |
| 772 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 772 | ECerror(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
| 773 | return NULL; | 773 | goto err; |
| 774 | } | 774 | } |
| 775 | ret = malloc(sizeof *ret); | 775 | |
| 776 | if (ret == NULL) { | 776 | if ((point = calloc(1, sizeof(*point))) == NULL) { |
| 777 | ECerror(ERR_R_MALLOC_FAILURE); | 777 | ECerror(ERR_R_MALLOC_FAILURE); |
| 778 | return NULL; | 778 | goto err; |
| 779 | } | 779 | } |
| 780 | ret->meth = group->meth; | ||
| 781 | 780 | ||
| 782 | if (!ret->meth->point_init(ret)) { | 781 | point->meth = group->meth; |
| 783 | free(ret); | 782 | |
| 784 | return NULL; | 783 | if (!point->meth->point_init(point)) |
| 785 | } | 784 | goto err; |
| 786 | return ret; | 785 | |
| 786 | return point; | ||
| 787 | |||
| 788 | err: | ||
| 789 | EC_POINT_free(point); | ||
| 790 | |||
| 791 | return NULL; | ||
| 787 | } | 792 | } |
| 788 | LCRYPTO_ALIAS(EC_POINT_new); | 793 | LCRYPTO_ALIAS(EC_POINT_new); |
| 789 | 794 | ||
| @@ -825,23 +830,25 @@ EC_POINT_copy(EC_POINT *dest, const EC_POINT *src) | |||
| 825 | LCRYPTO_ALIAS(EC_POINT_copy); | 830 | LCRYPTO_ALIAS(EC_POINT_copy); |
| 826 | 831 | ||
| 827 | EC_POINT * | 832 | EC_POINT * |
| 828 | EC_POINT_dup(const EC_POINT *a, const EC_GROUP *group) | 833 | EC_POINT_dup(const EC_POINT *in_point, const EC_GROUP *group) |
| 829 | { | 834 | { |
| 830 | EC_POINT *t; | 835 | EC_POINT *point = NULL; |
| 831 | int r; | ||
| 832 | 836 | ||
| 833 | if (a == NULL) | 837 | if (in_point == NULL) |
| 834 | return NULL; | 838 | goto err; |
| 835 | 839 | ||
| 836 | t = EC_POINT_new(group); | 840 | if ((point = EC_POINT_new(group)) == NULL) |
| 837 | if (t == NULL) | 841 | goto err; |
| 838 | return (NULL); | 842 | |
| 839 | r = EC_POINT_copy(t, a); | 843 | if (!EC_POINT_copy(point, in_point)) |
| 840 | if (!r) { | 844 | goto err; |
| 841 | EC_POINT_free(t); | 845 | |
| 842 | return NULL; | 846 | return point; |
| 843 | } else | 847 | |
| 844 | return t; | 848 | err: |
| 849 | EC_POINT_free(point); | ||
| 850 | |||
| 851 | return NULL; | ||
| 845 | } | 852 | } |
| 846 | LCRYPTO_ALIAS(EC_POINT_dup); | 853 | LCRYPTO_ALIAS(EC_POINT_dup); |
| 847 | 854 | ||
