ecc: clarify curves to group mapping
PATCH 1/2 ecc: clarify curves to group mapping
RFC 5114 defines the ECC group numbers, and depending on if your using TLS these group numbers differ. Rather than TLS maintaining the mapping between TLS group numbers and IKE group numbers we store both group numbers in the curve structures as 'ike_group' and 'tls_group'. Also, the curve name was added.
There are now several new APIs where you can get a curve for either tls or ike, as well as get a curve by group name. Similarly there is a set of APIs for getting supported groups for both ike and tls.
--- ell/ecc-private.h | 4 ++- ell/ecc.c | 83 ++++++++++++++++++++++++++++++++++++++++------- ell/ecc.h | 8 +++-- ell/tls-suites.c | 4 +-- 4 files changed, 82 insertions(+), 17 deletions(-)
ell/ecc-private.h +3 -1
@@ -35,7 +35,9 @@ struct l_ecc_point {struct l_ecc_curve {unsigned int ndigits; -unsigned int group; +unsigned int ike_group; +unsigned int tls_group; +const char *name;struct l_ecc_point g;uint64_t p[L_ECC_MAX_DIGITS ];uint64_t n[L_ECC_MAX_DIGITS ];
ell/ecc.c +71 -12
119 lines not on this page · raw message
ell/ecc.h +6 -2
@@ -42,8 +42,12 @@ enum l_ecc_point_type { L_ECC_POINT_TYPE_FULL = 0x04, }; -const struct l_ecc_curve *l_ecc_curve_get (unsigned int group); -const unsigned int *l_ecc_curve_get_supported_groups (void ); +const struct l_ecc_curve *l_ecc_curve_get (const char *name); +const char *l_ecc_curve_get_name (const struct l_ecc_curve *curve); +const unsigned int *l_ecc_curve_get_supported_ike_groups (void ); +const unsigned int *l_ecc_curve_get_supported_tls_groups (void ); +const struct l_ecc_curve *l_ecc_curve_get_ike_group (unsigned int group); +const struct l_ecc_curve *l_ecc_curve_get_tls_group (unsigned int group);struct l_ecc_point *l_ecc_point_new (const struct l_ecc_curve *curve); struct l_ecc_point *l_ecc_point_from_data(const struct l_ecc_curve *curve,
ell/tls-suites.c +2 -2
@@ -428,7 +428,7 @@ static bool tls_send_ecdhe_server_key_xchg(struct l_tls *tls)*/ params = l_new(struct tls_ecdhe_params, 1); - params->curve =l_ecc_curve_get (tls->negotiated_curve->ec.l_group); + params->curve =l_ecc_curve_get_tls_group (tls->negotiated_curve->id); tls->pending.key_xchg_params = params; if (!l_ecdh_generate_key_pair(params->curve,
@@ -510,7 +510,7 @@ static void tls_handle_ecdhe_server_key_xchg(struct l_tls *tls,* format is used. */ params = l_new(struct tls_ecdhe_params, 1); - params->curve =l_ecc_curve_get (tls->negotiated_curve->ec.l_group); + params->curve =l_ecc_curve_get_tls_group (tls->negotiated_curve->id); params->public =l_ecc_point_from_data (params->curve,L_ECC_POINT_TYPE_FULL , buf, len);
Signature · 1 line
2.17.1
PATCH 2/2 unit: update test-ecc and test-ecdh with new ECC APIs
--- unit/test-ecc.c | 2 +- unit/test-ecdh.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
unit/test-ecc.c +1 -1
@@ -218,7 +218,7 @@ static void run_test_p256(const void *arg) scalar[L_ECC_MAX_DIGITS ], result[L_ECC_MAX_DIGITS ], check[L_ECC_MAX_DIGITS ];struct l_ecc_point point1, point2, point_ret; -const struct l_ecc_curve *curve =l_ecc_curve_get (19 ); +const struct l_ecc_curve *curve =l_ecc_curve_get_ike_group (19 ); point_ret.curve = curve;
unit/test-ecdh.c +3 -3
@@ -65,7 +65,7 @@ bool __wrap_l_getrandom(void *buf, size_t len)*/ static void test_basic (const void *data) { -const struct l_ecc_curve *curve =l_ecc_curve_get (19 ); +const struct l_ecc_curve *curve =l_ecc_curve_get_ike_group (19 );struct l_ecc_scalar *private1;struct l_ecc_scalar *private2;
@@ -97,7 +97,7 @@ static void test_basic(const void *data)*/ static void test_vector_p256 (const void *data) { -const struct l_ecc_curve *curve =l_ecc_curve_get (19 ); +const struct l_ecc_curve *curve =l_ecc_curve_get_ike_group (19 );uint64_t a_sec_buf[4 ] = {0x867B7291D507A3AFull ,0x3FAF432A5ABCE59Eull ,0xE96A8E337A128499ull ,0x814264145F2F56F2ull };
@@ -157,7 +157,7 @@ static void test_vector_p256(const void *data)*/ static void test_vector_p384 (const void *data) { -const struct l_ecc_curve *curve =l_ecc_curve_get (20 ); +const struct l_ecc_curve *curve =l_ecc_curve_get_ike_group (20 );uint64_t a_sec_buf[6 ] = {0x86F05FEADB9376F1ull ,0xD706A90CBCB5DF29ull ,0xD709EE7A7962A156ull ,0x5DFD8A7965571C48ull ,
Signature · 1 line
2.17.1
Hi James,
Quoted 9 lines · James Prestwood
RFC 5114 defines the ECC group numbers, and depending on if your using TLS these group numbers differ. Rather than TLS maintaining the mapping between TLS group numbers and IKE group numbers we store both group numbers in the curve structures as '
ike_group' and 'tls_group'. Also, the curve name was added.There are now several new APIs where you can get a curve for either tls or ike, as well as get a curve by group name. Similarly there is a set of APIs for getting supported groups for both ike and tls.
Quoted 7 lines
--- ell/ecc-private.h | 4 ++- ell/ecc.c | 83 ++++++++++++++++++++++++++++++++++++++++------- ell/ecc.h | 8 +++-- ell/tls-suites.c | 4 +-- 4 files changed, 82 insertions(+), 17 deletions(-)
Both applied, thanks.
Regards,
-Denis