summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ec/ecp_oct.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/ec/ecp_oct.c')
-rw-r--r--src/lib/libcrypto/ec/ecp_oct.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/lib/libcrypto/ec/ecp_oct.c b/src/lib/libcrypto/ec/ecp_oct.c
index 994f0b08b1..b93b516907 100644
--- a/src/lib/libcrypto/ec/ecp_oct.c
+++ b/src/lib/libcrypto/ec/ecp_oct.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecp_oct.c,v 1.7 2015/02/09 15:49:22 jsing Exp $ */ 1/* $OpenBSD: ecp_oct.c,v 1.8 2017/01/29 17:49:23 beck 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.
@@ -155,9 +155,9 @@ ec_GFp_simple_set_compressed_coordinates(const EC_GROUP * group,
155 155
156 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) { 156 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {
157 ERR_clear_error(); 157 ERR_clear_error();
158 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT); 158 ECerror(EC_R_INVALID_COMPRESSED_POINT);
159 } else 159 } else
160 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB); 160 ECerror(ERR_R_BN_LIB);
161 goto err; 161 goto err;
162 } 162 }
163 if (y_bit != BN_is_odd(y)) { 163 if (y_bit != BN_is_odd(y)) {
@@ -169,20 +169,20 @@ ec_GFp_simple_set_compressed_coordinates(const EC_GROUP * group,
169 goto err; 169 goto err;
170 170
171 if (kron == 1) 171 if (kron == 1)
172 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSION_BIT); 172 ECerror(EC_R_INVALID_COMPRESSION_BIT);
173 else 173 else
174 /* 174 /*
175 * BN_mod_sqrt() should have cought this 175 * BN_mod_sqrt() should have cought this
176 * error (not a square) 176 * error (not a square)
177 */ 177 */
178 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT); 178 ECerror(EC_R_INVALID_COMPRESSED_POINT);
179 goto err; 179 goto err;
180 } 180 }
181 if (!BN_usub(y, &group->field, y)) 181 if (!BN_usub(y, &group->field, y))
182 goto err; 182 goto err;
183 } 183 }
184 if (y_bit != BN_is_odd(y)) { 184 if (y_bit != BN_is_odd(y)) {
185 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_INTERNAL_ERROR); 185 ECerror(ERR_R_INTERNAL_ERROR);
186 goto err; 186 goto err;
187 } 187 }
188 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx)) 188 if (!EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx))
@@ -210,14 +210,14 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
210 if ((form != POINT_CONVERSION_COMPRESSED) 210 if ((form != POINT_CONVERSION_COMPRESSED)
211 && (form != POINT_CONVERSION_UNCOMPRESSED) 211 && (form != POINT_CONVERSION_UNCOMPRESSED)
212 && (form != POINT_CONVERSION_HYBRID)) { 212 && (form != POINT_CONVERSION_HYBRID)) {
213 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_INVALID_FORM); 213 ECerror(EC_R_INVALID_FORM);
214 goto err; 214 goto err;
215 } 215 }
216 if (EC_POINT_is_at_infinity(group, point) > 0) { 216 if (EC_POINT_is_at_infinity(group, point) > 0) {
217 /* encodes to a single 0 octet */ 217 /* encodes to a single 0 octet */
218 if (buf != NULL) { 218 if (buf != NULL) {
219 if (len < 1) { 219 if (len < 1) {
220 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); 220 ECerror(EC_R_BUFFER_TOO_SMALL);
221 return 0; 221 return 0;
222 } 222 }
223 buf[0] = 0; 223 buf[0] = 0;
@@ -231,7 +231,7 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
231 /* if 'buf' is NULL, just return required length */ 231 /* if 'buf' is NULL, just return required length */
232 if (buf != NULL) { 232 if (buf != NULL) {
233 if (len < ret) { 233 if (len < ret) {
234 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, EC_R_BUFFER_TOO_SMALL); 234 ECerror(EC_R_BUFFER_TOO_SMALL);
235 goto err; 235 goto err;
236 } 236 }
237 if (ctx == NULL) { 237 if (ctx == NULL) {
@@ -258,7 +258,7 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
258 258
259 skip = field_len - BN_num_bytes(x); 259 skip = field_len - BN_num_bytes(x);
260 if (skip > field_len) { 260 if (skip > field_len) {
261 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 261 ECerror(ERR_R_INTERNAL_ERROR);
262 goto err; 262 goto err;
263 } 263 }
264 while (skip > 0) { 264 while (skip > 0) {
@@ -268,13 +268,13 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
268 skip = BN_bn2bin(x, buf + i); 268 skip = BN_bn2bin(x, buf + i);
269 i += skip; 269 i += skip;
270 if (i != 1 + field_len) { 270 if (i != 1 + field_len) {
271 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 271 ECerror(ERR_R_INTERNAL_ERROR);
272 goto err; 272 goto err;
273 } 273 }
274 if (form == POINT_CONVERSION_UNCOMPRESSED || form == POINT_CONVERSION_HYBRID) { 274 if (form == POINT_CONVERSION_UNCOMPRESSED || form == POINT_CONVERSION_HYBRID) {
275 skip = field_len - BN_num_bytes(y); 275 skip = field_len - BN_num_bytes(y);
276 if (skip > field_len) { 276 if (skip > field_len) {
277 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 277 ECerror(ERR_R_INTERNAL_ERROR);
278 goto err; 278 goto err;
279 } 279 }
280 while (skip > 0) { 280 while (skip > 0) {
@@ -285,7 +285,7 @@ ec_GFp_simple_point2oct(const EC_GROUP * group, const EC_POINT * point, point_co
285 i += skip; 285 i += skip;
286 } 286 }
287 if (i != ret) { 287 if (i != ret) {
288 ECerr(EC_F_EC_GFP_SIMPLE_POINT2OCT, ERR_R_INTERNAL_ERROR); 288 ECerror(ERR_R_INTERNAL_ERROR);
289 goto err; 289 goto err;
290 } 290 }
291 } 291 }
@@ -314,7 +314,7 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
314 int ret = 0; 314 int ret = 0;
315 315
316 if (len == 0) { 316 if (len == 0) {
317 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL); 317 ECerror(EC_R_BUFFER_TOO_SMALL);
318 return 0; 318 return 0;
319 } 319 }
320 form = buf[0]; 320 form = buf[0];
@@ -323,16 +323,16 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
323 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED) 323 if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)
324 && (form != POINT_CONVERSION_UNCOMPRESSED) 324 && (form != POINT_CONVERSION_UNCOMPRESSED)
325 && (form != POINT_CONVERSION_HYBRID)) { 325 && (form != POINT_CONVERSION_HYBRID)) {
326 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 326 ECerror(EC_R_INVALID_ENCODING);
327 return 0; 327 return 0;
328 } 328 }
329 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) { 329 if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) {
330 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 330 ECerror(EC_R_INVALID_ENCODING);
331 return 0; 331 return 0;
332 } 332 }
333 if (form == 0) { 333 if (form == 0) {
334 if (len != 1) { 334 if (len != 1) {
335 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 335 ECerror(EC_R_INVALID_ENCODING);
336 return 0; 336 return 0;
337 } 337 }
338 return EC_POINT_set_to_infinity(group, point); 338 return EC_POINT_set_to_infinity(group, point);
@@ -341,7 +341,7 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
341 enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len; 341 enc_len = (form == POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;
342 342
343 if (len != enc_len) { 343 if (len != enc_len) {
344 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 344 ECerror(EC_R_INVALID_ENCODING);
345 return 0; 345 return 0;
346 } 346 }
347 if (ctx == NULL) { 347 if (ctx == NULL) {
@@ -358,7 +358,7 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
358 if (!BN_bin2bn(buf + 1, field_len, x)) 358 if (!BN_bin2bn(buf + 1, field_len, x))
359 goto err; 359 goto err;
360 if (BN_ucmp(x, &group->field) >= 0) { 360 if (BN_ucmp(x, &group->field) >= 0) {
361 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 361 ECerror(EC_R_INVALID_ENCODING);
362 goto err; 362 goto err;
363 } 363 }
364 if (form == POINT_CONVERSION_COMPRESSED) { 364 if (form == POINT_CONVERSION_COMPRESSED) {
@@ -368,12 +368,12 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
368 if (!BN_bin2bn(buf + 1 + field_len, field_len, y)) 368 if (!BN_bin2bn(buf + 1 + field_len, field_len, y))
369 goto err; 369 goto err;
370 if (BN_ucmp(y, &group->field) >= 0) { 370 if (BN_ucmp(y, &group->field) >= 0) {
371 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 371 ECerror(EC_R_INVALID_ENCODING);
372 goto err; 372 goto err;
373 } 373 }
374 if (form == POINT_CONVERSION_HYBRID) { 374 if (form == POINT_CONVERSION_HYBRID) {
375 if (y_bit != BN_is_odd(y)) { 375 if (y_bit != BN_is_odd(y)) {
376 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING); 376 ECerror(EC_R_INVALID_ENCODING);
377 goto err; 377 goto err;
378 } 378 }
379 } 379 }
@@ -383,7 +383,7 @@ ec_GFp_simple_oct2point(const EC_GROUP * group, EC_POINT * point,
383 383
384 /* test required by X9.62 */ 384 /* test required by X9.62 */
385 if (EC_POINT_is_on_curve(group, point, ctx) <= 0) { 385 if (EC_POINT_is_on_curve(group, point, ctx) <= 0) {
386 ECerr(EC_F_EC_GFP_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE); 386 ECerror(EC_R_POINT_IS_NOT_ON_CURVE);
387 goto err; 387 goto err;
388 } 388 }
389 ret = 1; 389 ret = 1;