Skip to content

Update the example to the new driver API #10

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
merged 4 commits into from
Sep 6, 2019
Merged

Conversation

AndrzejKurek
Copy link
Contributor

@AndrzejKurek AndrzejKurek commented Aug 7, 2019

The key slot numbers used in PSA currently map directly to the hardware slots.
Because of this, as slot 0 is reserved in PSA, slot 1 is used for private key instead.
Change direct low-level driver calls to calls to the PSA API.
Remove the public key exporting during private key generation test, since this functionality is not present anymore.
The storage is purged after the first key generation test for two reasons:
first - so that the same key slot can be reused and second - so that key
registration can be tested as a second way to have a key in a PSA slot.

This PR is based on:

@Patater Patater changed the title Update the example to the new driver API. Update the example to the new driver API Aug 15, 2019
@Patater
Copy link
Contributor

Patater commented Sep 5, 2019

Could we please rebase this to apply fixups and remove the merge commits?

@k-stachowiak
Copy link
Contributor

I have tested this, with the mbed-os-atecc608a.lib containing:

https://github.com/AndrzejKurek/mbed-os-atecc608a/#7cc48d30f16474fde86b12d052a6384a14926205,

Which currently is the head of Andrzej's key-registration-api branch.

I confirm it works and passes all the tests on K64F, built with GCC_ARM.

@AndrzejKurek
Copy link
Contributor Author

@Patater done.

@k-stachowiak
Copy link
Contributor

I have repeated the test after the rebase and the tests still pass.

k-stachowiak
k-stachowiak previously approved these changes Sep 5, 2019
@Patater Patater self-requested a review September 5, 2019 17:40
@AndrzejKurek
Copy link
Contributor Author

AndrzejKurek commented Sep 6, 2019

Please note that before this PR is merged, the mbed-os-atecc608a.lib file has to point to the result of merging ARMmbed/mbed-os-atecc608a#7.

Copy link

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

The handle initialization is not right (I only checked one function but please check them all). Otherwise LGTM.

exit:
psa_close_key(*private_handle);
psa_close_key(verify_handle);

Choose a reason for hiding this comment

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

verify_handle may be uninitialized if there was an error before the call to psa_open_key that uses it. Initialize it to 0.

atecc608a/main.c Outdated
exit:
psa_close_key(*private_handle);

Choose a reason for hiding this comment

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

*private_handle is guaranteed to be initialized because nothing in this function can fail before the call to psa_open_key that uses it. But this is very fragile. Please initialize *private_handle to 0 before doing anything that can fail.

@Patater
Copy link
Contributor

Patater commented Sep 6, 2019

The commit "Revert incorredt differentiation between priv..." should be applied as a fixup to the commit that caused the trouble. Does the example work after this reversion? The key size change was made to get the example working, but maybe we fixed that in another way.

@gilles-peskine-arm
Copy link

Please avoid fixups for nontrivial issues found during a review.

I haven't checked how the code could work with incorrect sizes, but I suspect that it did because the sizes were never actually used in any calculation. For an ECC key, the key type determines everything and the bit size is redundant.

@Patater
Copy link
Contributor

Patater commented Sep 6, 2019

Please avoid adding dead end wrong solutions to the permanent history. Keeps mistakes made on your own branches within your own branches. This issue is dumb enough that we don't even need a code comment explaining our past failed attempt. The key size is always 256 bits.

Andrzej Kurek and others added 3 commits September 6, 2019 16:08
The key slot numbers used in PSA currently map directly to the hardware slots.
Because of this, as slot 0 is reserved in PSA, slot 1 is used for private key
instead.
Change direct low-level driver calls to calls to the PSA API.
Remove the public key exporting during private key generation test, since this
functionality is not present anymore.
The storage is purged after the first key generation test for two reasons:
first - so that the same key slot can be reused and second - so that key
registration can be tested as a second way to have a key in a PSA slot.
Update the pointer to the new driver library in mbed-os-atecc608a.lib
@AndrzejKurek
Copy link
Contributor Author

Cleared the history and addressed all of the comments. @gilles-peskine-arm, @Patater - please re-review.

@Patater
Copy link
Contributor

Patater commented Sep 6, 2019

What testing was done with this?

@Patater
Copy link
Contributor

Patater commented Sep 6, 2019

Here's what I get

$ mbed compile -m K64F -t GCC_ARM --flash --sterm
...
Private key slot in use: 1, public: 9
Running tests...
test_hash_sha256 succesful!
test_sign_verify succesful!
test_export_import succesful!
test_psa_import_verify succesful!
assertion failed at ./main.c:392 (actual=109 expected=0)


Available commands:
 - info - print configuration information;
 - test - run all tests on the device;
 - exit - exit the interactive loop;
 - generate_private[=%d] - generate a private key in a given slot (0-15),
                           default slot - 0.
 - generate_public=%d_%d - generate a public key in a given slot

@Patater
Copy link
Contributor

Patater commented Sep 6, 2019

After running lock_data, I was able to proceed.

test
Running tests...
test_hash_sha256 succesful!
test_sign_verify succesful!
test_export_import succesful!
test_psa_import_verify succesful!
test_write_read_slot succesful!

Copy link
Contributor

@Patater Patater left a comment

Choose a reason for hiding this comment

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

LGTM

@Patater
Copy link
Contributor

Patater commented Sep 6, 2019

Tested on K64F+HAS_CRYPTOSHIELD

@Patater Patater merged commit 4322b6e into master Sep 6, 2019
@AndrzejKurek
Copy link
Contributor Author

This was also tested by me on K64F with ATECC608A connected - I've run the test suites in succession and the tests passed.

@AndrzejKurek AndrzejKurek deleted the psa-key-registration branch September 9, 2019 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants