summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2024-11-04 13:19:08 +0000
committertb <>2024-11-04 13:19:08 +0000
commitd5c28a21f36a8e340666157c55c2a534c013b5ae (patch)
tree280d79d9312cff522e9a60e9e27d8e0db7570229
parent4e33de4e2a854aa78f4333ad2336308b5209883e (diff)
downloadopenbsd-d5c28a21f36a8e340666157c55c2a534c013b5ae.tar.gz
openbsd-d5c28a21f36a8e340666157c55c2a534c013b5ae.tar.bz2
openbsd-d5c28a21f36a8e340666157c55c2a534c013b5ae.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
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c61
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)
762EC_POINT * 762EC_POINT *
763EC_POINT_new(const EC_GROUP *group) 763EC_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}
788LCRYPTO_ALIAS(EC_POINT_new); 793LCRYPTO_ALIAS(EC_POINT_new);
789 794
@@ -825,23 +830,25 @@ EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)
825LCRYPTO_ALIAS(EC_POINT_copy); 830LCRYPTO_ALIAS(EC_POINT_copy);
826 831
827EC_POINT * 832EC_POINT *
828EC_POINT_dup(const EC_POINT *a, const EC_GROUP *group) 833EC_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}
846LCRYPTO_ALIAS(EC_POINT_dup); 853LCRYPTO_ALIAS(EC_POINT_dup);
847 854