summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ecp_nist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ecp_nist.c')
-rw-r--r--src/lib/libcrypto/ec/ecp_nist.c58
1 files changed, 11 insertions, 47 deletions
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c
index c736526a66..9478b4dc6e 100644
--- a/src/lib/libcrypto/ec/ecp_nist.c
+++ b/src/lib/libcrypto/ec/ecp_nist.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_nist.c,v 1.25 2023/04/11 18:53:20 jsing Exp $ */ 1/* $OpenBSD: ecp_nist.c,v 1.26 2023/04/11 18:58:20 jsing Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -80,15 +80,6 @@ static int
80ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p, 80ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
81 const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) 81 const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
82{ 82{
83 int ret = 0;
84 BN_CTX *new_ctx = NULL;
85
86 if (ctx == NULL)
87 if ((ctx = new_ctx = BN_CTX_new()) == NULL)
88 return 0;
89
90 BN_CTX_start(ctx);
91
92 if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0) 83 if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0)
93 group->field_mod_func = BN_nist_mod_192; 84 group->field_mod_func = BN_nist_mod_192;
94 else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0) 85 else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0)
@@ -101,67 +92,40 @@ ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
101 group->field_mod_func = BN_nist_mod_521; 92 group->field_mod_func = BN_nist_mod_521;
102 else { 93 else {
103 ECerror(EC_R_NOT_A_NIST_PRIME); 94 ECerror(EC_R_NOT_A_NIST_PRIME);
104 goto err; 95 return 0;
105 } 96 }
106 97
107 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx); 98 return ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
108
109 err:
110 BN_CTX_end(ctx);
111 BN_CTX_free(new_ctx);
112 return ret;
113} 99}
114 100
115static int 101static int
116ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, 102ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
117 const BIGNUM *b, BN_CTX *ctx) 103 const BIGNUM *b, BN_CTX *ctx)
118{ 104{
119 int ret = 0; 105 if (group == NULL || r == NULL || a == NULL || b == NULL) {
120 BN_CTX *ctx_new = NULL;
121
122 if (!group || !r || !a || !b) {
123 ECerror(ERR_R_PASSED_NULL_PARAMETER); 106 ECerror(ERR_R_PASSED_NULL_PARAMETER);
124 goto err; 107 return 0;
125 } 108 }
126 if (!ctx)
127 if ((ctx_new = ctx = BN_CTX_new()) == NULL)
128 goto err;
129 109
130 if (!BN_mul(r, a, b, ctx)) 110 if (!BN_mul(r, a, b, ctx))
131 goto err; 111 return 0;
132 if (!group->field_mod_func(r, r, &group->field, ctx))
133 goto err;
134 112
135 ret = 1; 113 return group->field_mod_func(r, r, &group->field, ctx);
136 err:
137 BN_CTX_free(ctx_new);
138 return ret;
139} 114}
140 115
141static int 116static int
142ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, 117ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
143 BN_CTX *ctx) 118 BN_CTX *ctx)
144{ 119{
145 int ret = 0; 120 if (group == NULL || r == NULL || a == NULL) {
146 BN_CTX *ctx_new = NULL;
147
148 if (!group || !r || !a) {
149 ECerror(EC_R_PASSED_NULL_PARAMETER); 121 ECerror(EC_R_PASSED_NULL_PARAMETER);
150 goto err; 122 return 0;
151 } 123 }
152 if (!ctx)
153 if ((ctx_new = ctx = BN_CTX_new()) == NULL)
154 goto err;
155 124
156 if (!BN_sqr(r, a, ctx)) 125 if (!BN_sqr(r, a, ctx))
157 goto err; 126 return 0;
158 if (!group->field_mod_func(r, r, &group->field, ctx))
159 goto err;
160 127
161 ret = 1; 128 return group->field_mod_func(r, r, &group->field, ctx);
162 err:
163 BN_CTX_free(ctx_new);
164 return ret;
165} 129}
166 130
167static const EC_METHOD ec_GFp_nist_method = { 131static const EC_METHOD ec_GFp_nist_method = {