You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a follow-up to #7779: take advantage of the new code structure in order to provide an alternative when ECP_LIGHT is not enabled.
This should consist of providing alternative implementation of the functions introduced in #7779: mbedtls_pk_group_id_from_p() and the various mbedtls_pk_validate_X() functions. Suggested strategy: have a table of curve data as follows:
struct curve_entry {
mbedtls_ecp_group_id id,
size_t p_len,
unsigned char *p,
/* ... */
};
static const struct curve_entry curves[] = {
#if defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
/* data for this curve */
#endif
/* etc for each curve except the two Montgomery ones */
};
(Curve data can be found in ecp_curves.c though beware of endianness. This means we'll be duplicating the data in our source, but OTOH each config will only have one set of the data: either the one from ecp_curves.c or the one from pkparse.c, so we won't have duplication in any binary.)
Then mbedtls_pk_group_id_from_p() traverses this table looking for a match on p and returns the corresponding id, and the various mbedtls_pk_validate_X() functions traverse it looking for a match on id and return success or failure depending on whether X matches as well.
There is a subtlety for validate_g(): I suggest storing the point in compressed from in the table, in order to save size. Then if we get passed the point in uncompressed form, we should ignore the first byte (that indicates compressed or not), and make sure the x coordinate, as well as the lsb of y, are correct (as the current code does, see here and here). (We might want to add a test case for that, as the only test data we have so far uses compressed.)
Definition of Done
Once that's done, we can remove the part of build_info.h that auto-enables ECP_LIGHT when MBEDTLS_PK_PARSE_EXTENDED is requested, and add MBEDTLS_PK_PARSE_EXTENDED to the config of the all.sh that builds without ECP at all.
Note: it's OK to have source-level duplication of the curve constants (one copy in ecp_curves.c, one in pkparse.c) at the end of this issue. That duplication will be removed in #8065.
This is a follow-up to #7779: take advantage of the new code structure in order to provide an alternative when
ECP_LIGHT
is not enabled.This should consist of providing alternative implementation of the functions introduced in #7779:
mbedtls_pk_group_id_from_p()
and the variousmbedtls_pk_validate_X()
functions. Suggested strategy: have a table of curve data as follows:(Curve data can be found in
ecp_curves.c
though beware of endianness. This means we'll be duplicating the data in our source, but OTOH each config will only have one set of the data: either the one fromecp_curves.c
or the one frompkparse.c
, so we won't have duplication in any binary.)Then
mbedtls_pk_group_id_from_p()
traverses this table looking for a match onp
and returns the correspondingid
, and the variousmbedtls_pk_validate_X()
functions traverse it looking for a match onid
and return success or failure depending on whetherX
matches as well.There is a subtlety for
validate_g()
: I suggest storing the point in compressed from in the table, in order to save size. Then if we get passed the point in uncompressed form, we should ignore the first byte (that indicates compressed or not), and make sure the x coordinate, as well as the lsb of y, are correct (as the current code does, see here and here). (We might want to add a test case for that, as the only test data we have so far uses compressed.)Definition of Done
Once that's done, we can remove the part of
build_info.h
that auto-enablesECP_LIGHT
whenMBEDTLS_PK_PARSE_EXTENDED
is requested, and addMBEDTLS_PK_PARSE_EXTENDED
to the config of theall.sh
that builds withoutECP
at all.Note: it's OK to have source-level duplication of the curve constants (one copy in
ecp_curves.c
, one inpkparse.c
) at the end of this issue. That duplication will be removed in #8065.Depends on: #7779
The text was updated successfully, but these errors were encountered: