Skip to content

Add hardware signing and key exporting #2

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

Closed
wants to merge 1 commit into from
Closed

Add hardware signing and key exporting #2

wants to merge 1 commit into from

Conversation

AndrzejKurek
Copy link
Contributor

This PR implements hardware ECDSA signing and public key exporting using ATECC608A or ATECC508A.
Prerequisite - a cryptoauth device (508A or 608A) comissioned, with a locked configuration and a private key generated in slot 0 (warning - configuration locking is irreversible!). An example application doing this with a quite safe config can be seen here.

This PR is a prerequisite for ARMmbed/mbed-os-example-atecc608a#2.


psa_status_t atecc608a_check_config_locked()
{
bool config_locked;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this header include stdbool.h?

return PSA_ERROR_HARDWARE_FAILURE;
}

if (atcab_release() != ATCA_SUCCESS)
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 need to init and release after every operation? I was under the impression we could do init once when initializing the hardware, and then release when we deinit'd the hardware. We may not have driver callbacks for this functionality yet, so we may want to lazy-init the hardware on first access.

Copy link
Contributor Author

@AndrzejKurek AndrzejKurek May 22, 2019

Choose a reason for hiding this comment

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

These are the two possible approaches that I can think of. I opted for this approach for two reasons:

  • It was written this way when I approached the code (hence I thought that's a design decision);
  • It doesn't depend on the fact that someone else initialized the library - every call takes care of its prerequisites;

Let me know if I should change it, I'm fine either way.

atcab_release();
return atecc608a_to_psa_error(ret);
}
p_data[0] = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's this 4 about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Yes, please do add a comment that explains that what you get from atcab_get_pubkey is the concatenated x and y values, and the desired format is 0x04 + x + y. That explains both the 4 here and the p_data+1 above.

const uint16_t key_id = key_slot;

/* We can only do ECDSA on SHA-256 */
/* PSA_ALG_ECDSA(PSA_ALG_SHA_256) */
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment (only line 174) is just a note for which algorithm we support. We don't really need it, since the line below shows this.


/* Signature will be returned here. Format is R and S integers in
* big-endian format. 64 bytes for P256 curve. */

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest to remove newline here


if ((ret = atcab_get_pubkey(slot, &p_data[1])) != ATCA_SUCCESS)
{
atcab_release();

Choose a reason for hiding this comment

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

If actab_release fails, that means there's something wrong with the hardware or there's a driver bug. Should we return HARDWARE_FAILURE in that case? Mbed Crypto currently tends to ignore cleanup errors when an error has already happened, but I wonder if that's the right decision. If something is wrong during cleanup, like failing hardware or memory corruption, shouldn't we let the caller know?

atcab_release();
return atecc608a_to_psa_error(ret);
}
p_data[0] = 4;

Choose a reason for hiding this comment

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

Yes, please do add a comment that explains that what you get from atcab_get_pubkey is the concatenated x and y values, and the desired format is 0x04 + x + y. That explains both the 4 here and the p_data+1 above.

@AndrzejKurek
Copy link
Contributor Author

AndrzejKurek commented May 24, 2019

@Patater, @gilles-peskine-arm - all of your suggestions have been addressed, but unfortunately due to the change of repository visibility (from private to public), my fork has been disconnected and this PR had to be recreated here: #3

@AndrzejKurek
Copy link
Contributor Author

Work continued here: #3.

k-stachowiak pushed a commit to k-stachowiak/mbed-os-atecc608a that referenced this pull request Sep 5, 2019
Adjust the driver to the new PSA API
rajkan01 pushed a commit to rajkan01/mbed-os-atecc608a that referenced this pull request Nov 17, 2020
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.

3 participants