@@ -921,27 +921,12 @@ psa_status_t psa_wrap_key_with_policy(psa_key_handle_t wrapping_key,
921
921
* a public key and the unwrapping operation uses the corresponding private
922
922
* key, you must unwrap with the corresponding unwrapping key.
923
923
*
924
+ * The resulting key object has the same attributes as the original key:
925
+ * same lifetime, same identifier if persistent, same usage policy.
926
+ * To restore a key to a different location or with a different policy,
927
+ * use psa_unwrap_key_to_alternate_lifetime().
928
+ *
924
929
* \param wrapping_key Handle to the key to unwrap with.
925
- * \param[in] attributes The attributes for the new key.
926
- * They are used as follows:
927
- * - The key type and size may be 0. If either is
928
- * nonzero, it must match the corresponding
929
- * attribute of the wrapped key data.
930
- * - The key location (the lifetime and, for
931
- * persistent keys, the key identifier) is
932
- * used directly.
933
- * If the wrapped key does not have the usage
934
- * flag #PSA_KEY_USAGE_COPY, then the location
935
- * must match the location embedded in \p data.
936
- * If the wrapped key has the usage
937
- * flag #PSA_KEY_USAGE_COPY, then the location
938
- * embedded in \p data is ignored.
939
- * - The policy constraints (usage flags and
940
- * algorithm policy) are combined from
941
- * the wrapped key data and \p attributes so that
942
- * both sets of restrictions apply. The
943
- * policy restrictions are calculated in the
944
- * same way as in psa_copy_key().
945
930
* \param[in] data Buffer containing the wrapped key material.
946
931
* The expected format of this buffer depends
947
932
* on the wrapping key.
@@ -957,19 +942,16 @@ psa_status_t psa_wrap_key_with_policy(psa_key_handle_t wrapping_key,
957
942
* This is an attempt to create a persistent key, and there is
958
943
* already a persistent key with the given identifier.
959
944
* \retval #PSA_ERROR_INVALID_ARGUMENT
960
- * The key attributes, as a whole, are invalid.
961
- * \retval #PSA_ERROR_INVALID_ARGUMENT
962
945
* The key data is not correctly formatted.
963
946
* \retval #PSA_ERROR_INVALID_ARGUMENT
964
- * The size in \p attributes is nonzero and does not match the size
965
- * of the key data.
966
- * \retval #PSA_ERROR_INVALID_ARGUMENT
967
947
* \p wrapping_key does not support unwrapping keys with metadata.
968
948
* \retval #PSA_ERROR_INVALID_SIGNATURE
969
949
* \p data is not a valid wrapped key for \p wrapping_key.
970
950
* \retval #PSA_ERROR_NOT_SUPPORTED
971
- * Some of the metadata in either \p attributes or \p data is
972
- * not supported.
951
+ * Some of the metadata encoded in \p data is not supported.
952
+ * This can only happen when attempting to unwrap a key that
953
+ * was wrapped under a different implementation or a
954
+ * differently-configured implementation.
973
955
* \retval #PSA_ERROR_INSUFFICIENT_MEMORY
974
956
* \retval #PSA_ERROR_INSUFFICIENT_STORAGE
975
957
* \retval #PSA_ERROR_COMMUNICATION_FAILURE
@@ -982,11 +964,89 @@ psa_status_t psa_wrap_key_with_policy(psa_key_handle_t wrapping_key,
982
964
* results in this error code.
983
965
*/
984
966
psa_status_t psa_unwrap_key_with_policy (psa_key_handle_t wrapping_key ,
985
- const psa_key_attributes_t * attributes ,
986
967
const uint8_t * data ,
987
968
size_t data_length ,
988
969
psa_key_handle_t * handle );
989
970
971
+ /**
972
+ * \brief Import a wrapped key with its metadata to volatile memory.
973
+ *
974
+ * This function supports any output from psa_wrap_key_with_policy()
975
+ * where the wrapped key has the usage flag #PSA_KEY_USAGE_COPY set.
976
+ * For symmetric wrapping, you must unwrap with the same key that was
977
+ * used to wrap. For asymmetric wrapping where the wrapping operation uses
978
+ * a public key and the unwrapping operation uses the corresponding private
979
+ * key, you must unwrap with the corresponding unwrapping key.
980
+ *
981
+ * The resulting key object has the same attributes as the original key
982
+ * apart from its lifetime, in particular it has the same usage policy.
983
+ * To unwrap a key and give it a more restrictive policy or place it
984
+ * in a different location:
985
+ * -# Call psa_unwrap_key_to_alternate_lifetime() to unwrap the key to a
986
+ * volatile location.
987
+ * -# If desired, call psa_get_key_attributes() to retrieve the
988
+ * attributes of the key, then modify them as desired for the
989
+ * subsequent copy.
990
+ * -# Call psa_copy_key() to copy the key to its desired location
991
+ * (volatile or persistent) and with the desired policy.
992
+ * -# Call psa_destroy_key() to destroy the intermediate volatile key.
993
+ *
994
+ * The resulting key does not have a persistent identifier, therefore
995
+ * the target lifetime must be volatile.
996
+ *
997
+ * \param wrapping_key Handle to the key to unwrap with.
998
+ * \param lifetime The lifetime to unwrap to.
999
+ * This must be a volatile lifetime.
1000
+ * The wrapping key may constrain which lifetimes
1001
+ * are permitted; such constraints are
1002
+ * implementation-defined. As a guideline,
1003
+ * implementations should allow unwrapping a key
1004
+ * to a lifetime that is in the same location
1005
+ * as the original key.
1006
+ * \param[in] data Buffer containing the wrapped key material.
1007
+ * The expected format of this buffer depends
1008
+ * on the wrapping key.
1009
+ * \param data_length Size of the \p data buffer in bytes.
1010
+ * \param[out] handle On success, a handle to the newly created key.
1011
+ * \c 0 on failure.
1012
+ *
1013
+ * \retval #PSA_SUCCESS
1014
+ * Success.
1015
+ * If the unwrapped key is persistent, the key material and the
1016
+ * key's metadata have been saved to persistent storage.
1017
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1018
+ * \p lifetime is not a volatile lifetime.
1019
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1020
+ * The key data is not correctly formatted.
1021
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1022
+ * \p wrapping_key does not support unwrapping keys with metadata.
1023
+ * \retval #PSA_ERROR_INVALID_SIGNATURE
1024
+ * \p data is not a valid wrapped key for \p wrapping_key.
1025
+ * \retval #PSA_ERROR_NOT_SUPPORTED
1026
+ * Some of the metadata encoded in \p data is not supported.
1027
+ * This can only happen when attempting to unwrap a key that
1028
+ * was wrapped under a different implementation or a
1029
+ * differently-configured implementation.
1030
+ * \retval #PSA_ERROR_NOT_PERMITTED
1031
+ * The wrapped key does not have the #PSA_KEY_USAGE_COPY flag.
1032
+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
1033
+ * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
1034
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
1035
+ * \retval #PSA_ERROR_STORAGE_FAILURE
1036
+ * \retval #PSA_ERROR_HARDWARE_FAILURE
1037
+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
1038
+ * \retval #PSA_ERROR_BAD_STATE
1039
+ * The library has not been previously initialized by psa_crypto_init().
1040
+ * It is implementation-dependent whether a failure to initialize
1041
+ * results in this error code.
1042
+ */
1043
+ psa_status_t psa_unwrap_key_to_alternate_lifetime (
1044
+ psa_key_handle_t wrapping_key ,
1045
+ psa_key_lifetime_t lifetime ,
1046
+ const uint8_t * data ,
1047
+ size_t data_length ,
1048
+ psa_key_handle_t * handle );
1049
+
990
1050
/**
991
1051
* \brief Export key material in wrapped form.
992
1052
*
0 commit comments