summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2020-09-12 17:25:12 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2020-09-12 17:25:12 +0000
commit5118b1667ca80e4c272a71bae3bb5dfd2154ce3c (patch)
treeee100fa0c70b97db0867bf3690922df61beafc25
parente0d41b507327833c6b05e597cff2a21695143991 (diff)
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--lib/libssl/t1_lib.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/lib/libssl/t1_lib.c b/lib/libssl/t1_lib.c
index 2bc830b2ed5..f091dd001be 100644
--- a/lib/libssl/t1_lib.c
+++ b/lib/libssl/t1_lib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: t1_lib.c,v 1.175 2020/09/07 08:04:29 tb Exp $ */
+/* $OpenBSD: t1_lib.c,v 1.176 2020/09/12 17:25:11 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -506,43 +506,38 @@ tls1_set_ec_id(uint16_t *curve_id, uint8_t *comp_id, EC_KEY *ec)
{
const EC_GROUP *grp;
const EC_METHOD *meth;
- int is_prime = 0;
- int nid, id;
+ int prime_field;
+ int nid;
if (ec == NULL)
return (0);
- /* Determine if it is a prime field. */
+ /* Determine whether the curve is defined over a prime field. */
if ((grp = EC_KEY_get0_group(ec)) == NULL)
return (0);
if ((meth = EC_GROUP_method_of(grp)) == NULL)
return (0);
- if (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field)
- is_prime = 1;
+ prime_field = (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field);
- /* Determine curve ID. */
+ /* Determine curve ID - NID_undef results in a curve ID of zero. */
nid = EC_GROUP_get_curve_name(grp);
- id = tls1_ec_nid2curve_id(nid);
-
/* If we have an ID set it, otherwise set arbitrary explicit curve. */
- if (id != 0)
- *curve_id = id;
- else
- *curve_id = is_prime ? 0xff01 : 0xff02;
+ if ((*curve_id = tls1_ec_nid2curve_id(nid)) == 0)
+ *curve_id = prime_field ? 0xff01 : 0xff02;
- /* Specify the compression identifier. */
- if (comp_id != NULL) {
- if (EC_KEY_get0_public_key(ec) == NULL)
- return (0);
+ if (comp_id == NULL)
+ return (1);
- if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_COMPRESSED) {
- *comp_id = is_prime ?
- TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime :
- TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;
- } else {
- *comp_id = TLSEXT_ECPOINTFORMAT_uncompressed;
- }
+ /* Specify the compression identifier. */
+ if (EC_KEY_get0_public_key(ec) == NULL)
+ return (0);
+ *comp_id = TLSEXT_ECPOINTFORMAT_uncompressed;
+ if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_COMPRESSED) {
+ *comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;
+ if (prime_field)
+ *comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime;
}
+
return (1);
}