diff options
author | tb <> | 2020-09-12 17:25:11 +0000 |
---|---|---|
committer | tb <> | 2020-09-12 17:25:11 +0000 |
commit | 03c71a8ebd470d39849c9370adaf344cbcae3fdf (patch) | |
tree | 1db1cc37c738f9ee475e2871a7e7b650413114d9 | |
parent | f43b806e9c49f2808400fc8ecb084846433c8052 (diff) | |
download | openbsd-03c71a8ebd470d39849c9370adaf344cbcae3fdf.tar.gz openbsd-03c71a8ebd470d39849c9370adaf344cbcae3fdf.tar.bz2 openbsd-03c71a8ebd470d39849c9370adaf344cbcae3fdf.zip |
Simplify tls1_set_ec_id() a bit
Use more descriptive variable names, explain why NID_undef is fine
and simplify the logic.
ok beck jsing
-rw-r--r-- | src/lib/libssl/t1_lib.c | 43 |
1 files changed, 19 insertions, 24 deletions
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c index 2bc830b2ed..f091dd001b 100644 --- a/src/lib/libssl/t1_lib.c +++ b/src/lib/libssl/t1_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: t1_lib.c,v 1.175 2020/09/07 08:04:29 tb Exp $ */ | 1 | /* $OpenBSD: t1_lib.c,v 1.176 2020/09/12 17:25:11 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -506,43 +506,38 @@ tls1_set_ec_id(uint16_t *curve_id, uint8_t *comp_id, EC_KEY *ec) | |||
506 | { | 506 | { |
507 | const EC_GROUP *grp; | 507 | const EC_GROUP *grp; |
508 | const EC_METHOD *meth; | 508 | const EC_METHOD *meth; |
509 | int is_prime = 0; | 509 | int prime_field; |
510 | int nid, id; | 510 | int nid; |
511 | 511 | ||
512 | if (ec == NULL) | 512 | if (ec == NULL) |
513 | return (0); | 513 | return (0); |
514 | 514 | ||
515 | /* Determine if it is a prime field. */ | 515 | /* Determine whether the curve is defined over a prime field. */ |
516 | if ((grp = EC_KEY_get0_group(ec)) == NULL) | 516 | if ((grp = EC_KEY_get0_group(ec)) == NULL) |
517 | return (0); | 517 | return (0); |
518 | if ((meth = EC_GROUP_method_of(grp)) == NULL) | 518 | if ((meth = EC_GROUP_method_of(grp)) == NULL) |
519 | return (0); | 519 | return (0); |
520 | if (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field) | 520 | prime_field = (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field); |
521 | is_prime = 1; | ||
522 | 521 | ||
523 | /* Determine curve ID. */ | 522 | /* Determine curve ID - NID_undef results in a curve ID of zero. */ |
524 | nid = EC_GROUP_get_curve_name(grp); | 523 | nid = EC_GROUP_get_curve_name(grp); |
525 | id = tls1_ec_nid2curve_id(nid); | ||
526 | |||
527 | /* If we have an ID set it, otherwise set arbitrary explicit curve. */ | 524 | /* If we have an ID set it, otherwise set arbitrary explicit curve. */ |
528 | if (id != 0) | 525 | if ((*curve_id = tls1_ec_nid2curve_id(nid)) == 0) |
529 | *curve_id = id; | 526 | *curve_id = prime_field ? 0xff01 : 0xff02; |
530 | else | ||
531 | *curve_id = is_prime ? 0xff01 : 0xff02; | ||
532 | 527 | ||
533 | /* Specify the compression identifier. */ | 528 | if (comp_id == NULL) |
534 | if (comp_id != NULL) { | 529 | return (1); |
535 | if (EC_KEY_get0_public_key(ec) == NULL) | ||
536 | return (0); | ||
537 | 530 | ||
538 | if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_COMPRESSED) { | 531 | /* Specify the compression identifier. */ |
539 | *comp_id = is_prime ? | 532 | if (EC_KEY_get0_public_key(ec) == NULL) |
540 | TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime : | 533 | return (0); |
541 | TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; | 534 | *comp_id = TLSEXT_ECPOINTFORMAT_uncompressed; |
542 | } else { | 535 | if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_COMPRESSED) { |
543 | *comp_id = TLSEXT_ECPOINTFORMAT_uncompressed; | 536 | *comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2; |
544 | } | 537 | if (prime_field) |
538 | *comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime; | ||
545 | } | 539 | } |
540 | |||
546 | return (1); | 541 | return (1); |
547 | } | 542 | } |
548 | 543 | ||