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

Add policy usage flag to copy a key #108

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions include/psa/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,8 @@ psa_status_t psa_destroy_key(psa_key_handle_t handle);
* - For public keys (key types for which #PSA_KEY_TYPE_IS_PUBLIC_KEY is
* true), the format is the same as for psa_export_public_key().
*
* The policy on the key must have the usage flag #PSA_KEY_USAGE_EXPORT set.
*
* \param handle Handle to the key to export.
* \param[out] data Buffer where the key data is to be written.
* \param data_size Size of the \p data buffer in bytes.
Expand All @@ -743,6 +745,7 @@ psa_status_t psa_destroy_key(psa_key_handle_t handle);
* \retval #PSA_ERROR_INVALID_HANDLE
* \retval #PSA_ERROR_DOES_NOT_EXIST
* \retval #PSA_ERROR_NOT_PERMITTED
* The key does not have the #PSA_KEY_USAGE_EXPORT flag.
* \retval #PSA_ERROR_NOT_SUPPORTED
* \retval #PSA_ERROR_BUFFER_TOO_SMALL
* The size of the \p data buffer is too small. You can determine a
Expand Down Expand Up @@ -801,6 +804,9 @@ psa_status_t psa_export_key(psa_key_handle_t handle,
* big-endian byte string. The length of the byte string is the length of the
* base prime `p` in bytes.
*
* Exporting a public key object or the public part of a key pair is
* always permitted, regardless of the key's usage flags.
*
* \param handle Handle to the key to export.
* \param[out] data Buffer where the key data is to be written.
* \param data_size Size of the \p data buffer in bytes.
Expand Down Expand Up @@ -844,6 +850,15 @@ psa_status_t psa_export_public_key(psa_key_handle_t handle,
* this function may be used to share a key with a different party,
* subject to implementation-defined restrictions on key sharing.
*
* The policy on the source key must have the usage flag
* #PSA_KEY_USAGE_COPY set.
* In addition, some lifetimes also require the source key to have the
* usage flag #PSA_KEY_USAGE_EXPORT, because otherwise the source key
Copy link
Contributor

Choose a reason for hiding this comment

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

The wording isn't completely clear, for example:

  • who is doing the "locking inside"? - presume this is the SE designer, but better to avoid unnamed actors in the documentation.
  • Is the use case here one where a key is being copied out of the SE into a volatile key (for example), and the SE design defaults to denying this operation unless the key is extractable? - presumably a copy within the SE would only require COPY policy in this set up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I updated the documentation.

* is locked inside a secure processing environment and cannot be
* extracted. For keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE or
* #PSA_KEY_LIFETIME_PERSISTENT, the usage flag #PSA_KEY_USAGE_COPY
* is sufficient to permit the copy.
*
* The resulting key may only be used in a way that conforms to
* both the policy of the original key and the policy specified in
* the \p attributes parameter:
Expand Down Expand Up @@ -896,6 +911,8 @@ psa_status_t psa_export_public_key(psa_key_handle_t handle,
* \p attributes specifies a key type, domain parameters or key size
* which does not match the attributes of the source key.
* \retval #PSA_ERROR_NOT_PERMITTED
* The source key does not have the #PSA_KEY_USAGE_COPY usage flag.
* \retval #PSA_ERROR_NOT_PERMITTED
* The source key is not exportable and its lifetime does not
* allow copying it to the target's lifetime.
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
Expand Down
14 changes: 14 additions & 0 deletions include/psa/crypto_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,20 @@
*/
#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)

/** Whether the key may be copied.
*
* This flag allows the use of psa_crypto_copy() to make a copy of the key
Copy link
Contributor

Choose a reason for hiding this comment

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

psa_copy_key()

* with the same policy or a more restrictive policy.
*
* For some lifetimes, copying a key also requires the usage flag
* #PSA_KEY_USAGE_EXPORT, because otherwise the source key
* is locked inside a secure processing environment and cannot be
Copy link
Contributor

Choose a reason for hiding this comment

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

Clarify use case? - as above

* extracted. For keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE or
* #PSA_KEY_LIFETIME_PERSISTENT, the usage flag #PSA_KEY_USAGE_COPY
* is sufficient to permit the copy.
*/
#define PSA_KEY_USAGE_COPY ((psa_key_usage_t)0x00000002)

/** Whether the key may be used to encrypt a message.
*
* This flag allows the key to be used for a symmetric encryption operation,
Expand Down
1 change: 1 addition & 0 deletions library/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ static psa_status_t psa_set_key_policy_internal(
const psa_key_policy_t *policy )
{
if( ( policy->usage & ~( PSA_KEY_USAGE_EXPORT |
PSA_KEY_USAGE_COPY |
PSA_KEY_USAGE_ENCRYPT |
PSA_KEY_USAGE_DECRYPT |
PSA_KEY_USAGE_SIGN |
Expand Down