From: Nikos Mavrogiannopoulos Date: Sat, 21 May 2011 17:08:55 +0000 (+0200) Subject: Curve TLS ID is being stored in algorithms/ecc.c. X-Git-Tag: gnutls_2_99_2~45 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8dcf7e8299fed143c2e61500da55b5e5910eb54c;p=thirdparty%2Fgnutls.git Curve TLS ID is being stored in algorithms/ecc.c. --- diff --git a/lib/algorithms.h b/lib/algorithms.h index 4877076284..5d7d7fa248 100644 --- a/lib/algorithms.h +++ b/lib/algorithms.h @@ -130,6 +130,7 @@ struct gnutls_ecc_curve_entry_st { const char *name; ecc_curve_t id; + int tls_id; /* The RFC4492 namedCurve ID */ int size; /* the size in bytes */ /** The prime that defines the field the curve is in (encoded in hex) */ @@ -151,5 +152,7 @@ const char * _gnutls_ecc_curve_get_name (ecc_curve_t curve); const gnutls_ecc_curve_entry_st * _gnutls_ecc_curve_get_params (ecc_curve_t curve); int _gnutls_ecc_curve_get_size (ecc_curve_t curve); ecc_curve_t _gnutls_ecc_curve_get_id (const char *name); +int _gnutls_tls_id_to_ecc_curve (int num); +int _gnutls_ecc_curve_get_tls_id (ecc_curve_t supported_ecc); #endif diff --git a/lib/algorithms/ciphersuites.c b/lib/algorithms/ciphersuites.c index 050d9646bb..6b7f4eb4b1 100644 --- a/lib/algorithms/ciphersuites.c +++ b/lib/algorithms/ciphersuites.c @@ -615,10 +615,13 @@ gnutls_cipher_suite_get_name (gnutls_kx_algorithm_t kx_algorithm, const char *ret = NULL; /* avoid prefix */ - GNUTLS_CIPHER_SUITE_LOOP (if (kx_algorithm == p->kx_algorithm && - cipher_algorithm == p->block_algorithm && - mac_algorithm == p->mac_algorithm) - ret = p->name + sizeof ("GNUTLS_") - 1); + GNUTLS_CIPHER_SUITE_LOOP ( + if (kx_algorithm == p->kx_algorithm && + cipher_algorithm == p->block_algorithm && mac_algorithm == p->mac_algorithm) + { + ret = p->name + sizeof ("GNUTLS_") - 1); + break; + } return ret; } diff --git a/lib/algorithms/ecc.c b/lib/algorithms/ecc.c index 66174e6b75..4bd2a130ba 100644 --- a/lib/algorithms/ecc.c +++ b/lib/algorithms/ecc.c @@ -35,6 +35,7 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = { { .name = "SECP224R1", .id = GNUTLS_ECC_CURVE_SECP224R1, + .tls_id = 21, .size = 28, .prime = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001", .A = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE", @@ -46,6 +47,7 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = { { .name = "SECP256R1", .id = GNUTLS_ECC_CURVE_SECP256R1, + .tls_id = 23, .size = 32, .prime = "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", .A = "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", @@ -57,6 +59,7 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = { { .name = "SECP384R1", .id = GNUTLS_ECC_CURVE_SECP384R1, + .tls_id = 24, .size = 48, .prime = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF", .A = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC", @@ -68,6 +71,7 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = { { .name = "SECP521R1", .id = GNUTLS_ECC_CURVE_SECP521R1, + .tls_id = 25, .size = 66, .prime = "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", .A = "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC", @@ -82,6 +86,46 @@ static const gnutls_ecc_curve_entry_st ecc_curves[] = { #define GNUTLS_ECC_CURVE_LOOP(b) \ { const gnutls_ecc_curve_entry_st *p; \ for(p = ecc_curves; p->name != NULL; p++) { b ; } } + + +/* Returns the TLS id of the given curve + */ +int +_gnutls_tls_id_to_ecc_curve (int num) +{ + ecc_curve_t ret = GNUTLS_ECC_CURVE_INVALID; + + GNUTLS_ECC_CURVE_LOOP ( + if (p->tls_id == num) + { + ret = p->id; + break; + } + ); + + return ret; +} + +/* Maps numbers to TLS NamedCurve IDs (RFC4492). + * Returns a negative number on error. + */ +int +_gnutls_ecc_curve_get_tls_id (ecc_curve_t supported_ecc) +{ + int ret = GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; + + GNUTLS_ECC_CURVE_LOOP ( + if (p->id == supported_ecc) + { + ret = p->tls_id; + break; + } + ); + + return ret; +} + + /*- * _gnutls_ecc_curve_get_id: * @name: is a MAC algorithm name diff --git a/lib/auth/ecdh_common.c b/lib/auth/ecdh_common.c index eb879d98c4..556f34a253 100644 --- a/lib/auth/ecdh_common.c +++ b/lib/auth/ecdh_common.c @@ -148,7 +148,7 @@ _gnutls_proc_ecdh_common_server_kx (gnutls_session_t session, return gnutls_assert_val(GNUTLS_E_ECC_NO_SUPPORTED_CURVES); DECR_LEN (data_size, 2); - curve = _gnutls_num_to_ecc(_gnutls_read_uint16 (&data[i])); + curve = _gnutls_tls_id_to_ecc_curve(_gnutls_read_uint16 (&data[i])); i += 2; ret = _gnutls_session_supports_ecc_curve(session, curve); @@ -190,7 +190,7 @@ int _gnutls_ecdh_common_print_server_kx (gnutls_session_t session, gnutls_buffer if (ret < 0) return gnutls_assert_val(ret); - ret = _gnutls_buffer_append_prefix(data, 16, _gnutls_ecc_to_num(curve)); + ret = _gnutls_buffer_append_prefix(data, 16, _gnutls_ecc_curve_get_tls_id(curve)); if (ret < 0) return gnutls_assert_val(ret); diff --git a/lib/ext/ecc.c b/lib/ext/ecc.c index 11c00716e4..b417a2bcfd 100644 --- a/lib/ext/ecc.c +++ b/lib/ext/ecc.c @@ -33,6 +33,7 @@ #include #include #include +#include /* Maps record size to numbers according to the * extensions draft. @@ -110,7 +111,7 @@ _gnutls_supported_ecc_recv_params (gnutls_session_t session, for (i = 0; i < len; i+=2) { - new_type = _gnutls_num_to_ecc (_gnutls_read_uint16(&p[i])); + new_type = _gnutls_tls_id_to_ecc_curve (_gnutls_read_uint16(&p[i])); if (new_type < 0) continue; @@ -177,7 +178,7 @@ _gnutls_supported_ecc_send_params (gnutls_session_t session, gnutls_buffer_st* e for (i = 0; i < len; i++) { p = - _gnutls_ecc_to_num (session->internals.priorities. + _gnutls_ecc_curve_get_tls_id (session->internals.priorities. supported_ecc.priority[i]); ret = _gnutls_buffer_append_prefix(extdata, 16, p); if (ret < 0) @@ -246,40 +247,6 @@ _gnutls_supported_ecc_pf_send_params (gnutls_session_t session, gnutls_buffer_st return 2; } -/* Maps numbers to record sizes according to the - * extensions draft. - */ -int -_gnutls_num_to_ecc (int num) -{ - switch (num) - { - case 23: - /* sec256r1 */ - return GNUTLS_ECC_CURVE_SECP256R1; - case 24: - return GNUTLS_ECC_CURVE_SECP384R1; - default: - return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; - } -} - -/* Maps record size to numbers according to the - * extensions draft. - */ -int -_gnutls_ecc_to_num (ecc_curve_t supported_ecc) -{ - switch (supported_ecc) - { - case GNUTLS_ECC_CURVE_SECP256R1: - return 23; - case GNUTLS_ECC_CURVE_SECP384R1: - return 24; - default: - return GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER; - } -} /* Returns 0 if the given ECC curve is allowed in the current * session. A negative error value is returned otherwise. diff --git a/lib/ext/ecc.h b/lib/ext/ecc.h index 745a000815..b2c22a478f 100644 --- a/lib/ext/ecc.h +++ b/lib/ext/ecc.h @@ -29,8 +29,6 @@ extern extension_entry_st ext_mod_supported_ecc; extern extension_entry_st ext_mod_supported_ecc_pf; -int _gnutls_num_to_ecc (int num); -int _gnutls_ecc_to_num (ecc_curve_t); int _gnutls_session_supports_ecc_curve (gnutls_session_t session, int ecc_type);