ecc: add API to get supported groups
PATCH 1/1 ecc: add API to get supported groups
Protocols using ECC need a way to query which groups ELL supports. ecc.c now has a zero-terminated list of supported groups, which is returned by l_ecc_curve_get_groups().
--- ell/ecc.c | 7 +++++++ ell/ecc.h | 1 + 2 files changed, 8 insertions(+)
ell/ecc.c +7 -0
@@ -85,6 +85,8 @@ static const struct l_ecc_curve p384 = { .b = P384_CURVE_B }; +static const unsigned int ecc_groups[] = {19 ,20 ,0 }; +static const struct l_ecc_curve *curves[] = { &p256, &p384,
@@ -102,6 +104,11 @@ LIB_EXPORT const struct l_ecc_curve *l_ecc_curve_get(unsigned int group)return NULL ; } +LIB_EXPORT const unsigned int *l_ecc_curve_get_groups(void) +{ +return ecc_groups; +} +static bool ecc_valid_point (struct l_ecc_point *point) {const struct l_ecc_curve *curve = point->curve;
ell/ecc.h +1 -0
@@ -43,6 +43,7 @@ enum l_ecc_point_type { };const struct l_ecc_curve *l_ecc_curve_get (unsigned int group); +const unsigned int *l_ecc_curve_get_groups (void );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,
Signature · 1 line
2.17.1
Hi James,
Quoted 8 lines · James Prestwood
Protocols using ECC need a way to query which groups ELL supports.
ecc.cnow has a zero-terminated list of supported groups, which is returned byl_ecc_curve_get_groups().--- ell/ecc.c | 7 +++++++ ell/ecc.h | 1 + 2 files changed, 8 insertions(+)
You're missing ell.sym entries...
ell/ecc.c static const struct l_ecc_curve p384 = { · line 89
Quoted 10 lines
ell/ecc.c +2
-0@@ -85,6 +85,8 @@ static const struct l_ecc_curve p384 = { .b = P384_CURVE_B }; +static const unsigned int ecc_groups[] = {19 ,20 ,0 }; +
For maintainability it might be worth building this at runtime, otherwise someone forgets to update this...
ell/ecc.c LIB_EXPORT const struct l_ecc_curve *l_ecc_curve_get(unsigned int group) · line 107
Quoted 8 lines
ell/ecc.c +1
-0static const struct l_ecc_curve *curves[] = { &p256, &p384,@@ -102,6 +104,11 @@ LIB_EXPORT const struct l_ecc_curve *l_ecc_curve_get(unsigned int group)return NULL ; } +LIB_EXPORT const unsigned int *l_ecc_curve_get_groups(void)
lets call this l_ecc_curve_get_supported_groups. Also, some docs to figure out where the group number came from would be nice.
ell/ecc.c LIB_EXPORT const struct l_ecc_curve *l_ecc_curve_get(unsigned int group) · line 109
Quoted 2 lines
ell/ecc.c +2
-0+{ +return ecc_groups;
Maybe something like:
static unsigned int supported_groups[L_ARRAY_SIZE(curves) + 1]; static bool first = true;
if (first) {
unsigned int i;
for (i = 0; i < L_ARRAY_SIZE(curves); i++)
supported_groups[i] = curves[i].group;
supported_groups[i] = 0;
}return supported_groups;
Quoted 11 lines
ell/ecc.c +2
-0+} +static bool ecc_valid_point (struct l_ecc_point *point) {const struct l_ecc_curve *curve = point->curve;ell/ecc.h +0
-0
ell/ecc.h enum l_ecc_point_type { · line 49
Quoted 7 lines
ell/ecc.h +1
-0@@ -43,6 +43,7 @@ enum l_ecc_point_type { };const struct l_ecc_curve *l_ecc_curve_get (unsigned int group); +const unsigned int *l_ecc_curve_get_groups (void );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,
Regards,
-Denis