Skip to content
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

pkg/micro-ecc: Add PSA Crypto Wrappers #18581

Closed

Conversation

Einhornhool
Copy link
Contributor

Contribution description

This adds wrappers for the PSA Crypto module to the Micro ECC package.

Issues/PRs references

Prerequisite: #18578

Split up PR #18547

@github-actions github-actions bot added Area: build system Area: Build system Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports labels Sep 12, 2022
Copy link
Contributor

@leandrolanzieri leandrolanzieri left a 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

@@ -191,6 +191,7 @@ PSEUDOMODULES += posix_headers
PSEUDOMODULES += printf_float
PSEUDOMODULES += prng
PSEUDOMODULES += prng_%
PSEUDOMODULES += psa_uecc_%
Copy link
Contributor

Choose a reason for hiding this comment

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

6w8m7e

Copy link
Contributor Author

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,
Copy link
Contributor

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

Copy link
Contributor Author

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 =)

*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();
Copy link
Contributor

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?

https://github.com/kmackay/micro-ecc/blob/master/uECC.h

Copy link
Contributor Author

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;
Copy link
Contributor

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

Copy link
Contributor Author

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.

@Einhornhool
Copy link
Contributor Author

To make this easier to test and work on are going to keep working on the original branch: #18547

@Einhornhool Einhornhool closed this Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants