mirror of
https://github.com/openssl/openssl.git
synced 2024-12-19 23:13:49 +08:00
Simplify tls1_set_ec_id.
Reviewed-by: Matt Caswell <matt@openssl.org>
This commit is contained in:
parent
2fa2d15ac8
commit
2235b7f2dd
36
ssl/t1_lib.c
36
ssl/t1_lib.c
@ -221,6 +221,7 @@ typedef struct {
|
||||
unsigned int flags; /* Flags: currently just field type */
|
||||
} tls_curve_info;
|
||||
|
||||
# define TLS_CURVE_TYPE 0x1
|
||||
# define TLS_CURVE_CHAR2 0x1
|
||||
# define TLS_CURVE_PRIME 0x0
|
||||
|
||||
@ -617,46 +618,33 @@ int tls1_set_curves_list(unsigned char **pext, size_t *pextlen,
|
||||
static int tls1_set_ec_id(unsigned char *curve_id, unsigned char *comp_id,
|
||||
EC_KEY *ec)
|
||||
{
|
||||
int is_prime, id;
|
||||
int id;
|
||||
const EC_GROUP *grp;
|
||||
const EC_METHOD *meth;
|
||||
if (!ec)
|
||||
return 0;
|
||||
/* Determine if it is a prime field */
|
||||
grp = EC_KEY_get0_group(ec);
|
||||
if (!grp)
|
||||
return 0;
|
||||
meth = EC_GROUP_method_of(grp);
|
||||
if (!meth)
|
||||
return 0;
|
||||
if (EC_METHOD_get_field_type(meth) == NID_X9_62_prime_field)
|
||||
is_prime = 1;
|
||||
else
|
||||
is_prime = 0;
|
||||
/* Determine curve ID */
|
||||
id = EC_GROUP_get_curve_name(grp);
|
||||
id = tls1_ec_nid2curve_id(id);
|
||||
/* If we have an ID set it, otherwise set arbitrary explicit curve */
|
||||
if (id) {
|
||||
curve_id[0] = 0;
|
||||
curve_id[1] = (unsigned char)id;
|
||||
} else {
|
||||
curve_id[0] = 0xff;
|
||||
if (is_prime)
|
||||
curve_id[1] = 0x01;
|
||||
else
|
||||
curve_id[1] = 0x02;
|
||||
}
|
||||
/* If no id return error: we don't support arbitrary explicit curves */
|
||||
if (id == 0)
|
||||
return 0;
|
||||
curve_id[0] = 0;
|
||||
curve_id[1] = (unsigned char)id;
|
||||
if (comp_id) {
|
||||
if (EC_KEY_get0_public_key(ec) == NULL)
|
||||
return 0;
|
||||
if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_COMPRESSED) {
|
||||
if (is_prime)
|
||||
if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_UNCOMPRESSED) {
|
||||
*comp_id = TLSEXT_ECPOINTFORMAT_uncompressed;
|
||||
} else {
|
||||
if ((nid_list[id - 1].flags & TLS_CURVE_TYPE) == TLS_CURVE_PRIME)
|
||||
*comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime;
|
||||
else
|
||||
*comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2;
|
||||
} else
|
||||
*comp_id = TLSEXT_ECPOINTFORMAT_uncompressed;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user