Skip to content

PSA: EC curve size macro #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

gilles-peskine-arm
Copy link
Collaborator

New macro to get the bit size of an elliptic curve.

Fix a minor bug in private Weierstrass elliptic curve key import whereby a buffer that was too short was accepted and implicitly padded to the left with zeros.

@gilles-peskine-arm gilles-peskine-arm added bug Something isn't working enhancement New feature or request needs: review The pull request is ready for review. This generally means that it has no known issues. labels May 13, 2019
@@ -621,6 +621,9 @@ static psa_status_t psa_import_ec_private_key( psa_ecc_curve_t curve,
mbedtls_ecp_keypair *ecp = NULL;
mbedtls_ecp_group_id grp_id = mbedtls_ecc_group_of_psa( curve );

if( PSA_BITS_TO_BYTES( PSA_ECC_CURVE_BITS( curve ) ) != data_length )
return( PSA_ERROR_INVALID_ARGUMENT );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support curves with bit sizes not even multiples of 8? Would we zero-pad within the first or last byte? I looked at export key format, but didn't see the answer, although we do mention endianness.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes (P521). It's zero-padded in the most significant byte, which you know because the spec tells you you have to represent the number in a given number of bits. You know which byte that is because you're told the endianness.

@gilles-peskine-arm gilles-peskine-arm added this to the api-1.0-beta-3 milestone May 15, 2019
When importing a private elliptic curve key, require the input to have
exactly the right size. RFC 5915 requires the right size (you aren't
allow to omit leading zeros). A different buffer size likely means
that something is wrong, e.g. a mismatch between the declared key type
and the actual data.
@gilles-peskine-arm
Copy link
Collaborator Author

I rebased the PR on top of the target branch. There was an undetected conflict: the test case added in this PR needed to be updated to match the change in the test function in the target branch.

Copy link
Collaborator

@yanesca yanesca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@yanesca yanesca added needs: ci Needs a passing full CI run and removed needs: review The pull request is ready for review. This generally means that it has no known issues. labels May 16, 2019
@Patater
Copy link
Contributor

Patater commented May 16, 2019

CI failure is ABI job (known to fail until Mbed-TLS/mbedtls#2636 lands in the development branch) and USE_PSA_CRYPTO, which doesn't work on the API branch.

@Patater Patater merged commit 826e326 into ARMmbed:psa-api-1.0-beta May 16, 2019
@Patater Patater removed the needs: ci Needs a passing full CI run label May 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants