-
Notifications
You must be signed in to change notification settings - Fork 2.1k
pkg/micro-ecc: Add PSA Crypto Wrappers #18581
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These comments apply for both curves
makefiles/pseudomodules.inc.mk
Outdated
@@ -191,6 +191,7 @@ PSEUDOMODULES += posix_headers | |||
PSEUDOMODULES += printf_float | |||
PSEUDOMODULES += prng | |||
PSEUDOMODULES += prng_% | |||
PSEUDOMODULES += psa_uecc_% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
#include "psa/crypto.h" | ||
#include "uECC.h" | ||
|
||
psa_status_t psa_generate_ecc_p192r1_key_pair( const psa_key_attributes_t *attributes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a given guarantee from the upper layer that all these pointers will always be valid? Otherwise I'd keep my defensive approach 🛡️ and check them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attributes are checked first thing in psa_crypto.c
and all key buffers come from inside the implementation, not from the user or application. So they'll be valid here =)
pkg/micro-ecc/psa_uecc/p192.c
Outdated
*priv_key_buffer_length = PSA_BITS_TO_BYTES(attributes->bits); | ||
*pub_key_buffer_length = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(attributes->type, attributes->bits); | ||
|
||
struct uECC_Curve_t *curve = (struct uECC_Curve_t *)uECC_secp192r1(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is all this casting needed? For what I see uECC_secp192r1
returns type uECC_Curve
, which is also the type for uECC_make_key
, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it should work without casting
size_t hash_length, uint8_t *signature, | ||
size_t signature_size, size_t *signature_length) | ||
{ | ||
int ret = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check that signature
has enough space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to check all the input buffer sizes at a higher level (psa_crypto.c
), to abort operations before involving the key management and the driver?
Also that would provide some general protection in case future glue code contains mistakes.
In this case I forgot to write the check in psa_crypto.c
, but I'll go through the code again to make sure all user inputs are validated.
To make this easier to test and work on are going to keep working on the original branch: #18547 |
Contribution description
This adds wrappers for the PSA Crypto module to the Micro ECC package.
Issues/PRs references
Prerequisite: #18578
Split up PR #18547