@@ -987,7 +987,116 @@ psa_status_t psa_unwrap_key_with_policy(psa_key_handle_t wrapping_key,
987
987
size_t data_length ,
988
988
psa_key_handle_t * handle );
989
989
990
+ /**
991
+ * \brief Export key material in wrapped form.
992
+ *
993
+ * A wrapped form of the key material preserves the confidentiality
994
+ * and authenticity of the key material. In practical terms, the key
995
+ * material is encrypted and authenticated.
996
+ *
997
+ * The policy on the key must have the usage flag
998
+ * #PSA_KEY_USAGE_EXPORT_WRAPPED set.
999
+ *
1000
+ * \param wrapping_key Handle to the key to wrap with.
1001
+ * \param alg The key wrapping algorithm to compute
1002
+ * (\c PSA_ALG_XXX value such that
1003
+ * #PSA_ALG_IS_KEY_WRAP(\p alg) is true).
1004
+ * \param handle Handle to the key whose material is to be
1005
+ * exported in wrapped form.
1006
+ * \param[out] data Buffer where the wrapped key data is to be written.
1007
+ * \param data_size Size of the \p data buffer in bytes.
1008
+ * \param[out] data_length On success, the number of bytes
1009
+ * that make up the wrapped key data.
1010
+ *
1011
+ * \retval #PSA_SUCCESS
1012
+ * \retval #PSA_ERROR_INVALID_HANDLE
1013
+ * One or both of \p handle and \p wrapping_key is not a valid
1014
+ * handle to a key.
1015
+ * \retval #PSA_ERROR_NOT_PERMITTED
1016
+ * The key \p handle does not have the #PSA_KEY_USAGE_BACKUP flag.
1017
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1018
+ * \p wrapping_key does not support wrapping key material.
1019
+ * \retval #PSA_ERROR_NOT_SUPPORTED
1020
+ * \p wrapping_key does not support wrapping the key designated
1021
+ * by \p handle.
1022
+ * \retval #PSA_ERROR_BUFFER_TOO_SMALL
1023
+ * The size of the \p data buffer is too small. You can determine a
1024
+ * sufficient buffer size by calling
1025
+ * #PSA_WRAP_KEY_MATERIAL_OUTPUT_SIZE(\p alg, \c type, \c bits)
1026
+ * where \c type is the key type of \p handle
1027
+ * and \c bits is the key size of \p handle in bits.
1028
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
1029
+ * \retval #PSA_ERROR_HARDWARE_FAILURE
1030
+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
1031
+ * \retval #PSA_ERROR_STORAGE_FAILURE
1032
+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
1033
+ * \retval #PSA_ERROR_BAD_STATE
1034
+ * The library has not been previously initialized by psa_crypto_init().
1035
+ * It is implementation-dependent whether a failure to initialize
1036
+ * results in this error code.
1037
+ */
1038
+ psa_status_t psa_wrap_key_material (psa_key_handle_t wrapping_key ,
1039
+ psa_algorithm_t alg ,
1040
+ psa_key_handle_t handle ,
1041
+ uint8_t * data ,
1042
+ size_t data_size ,
1043
+ size_t * data_length );
990
1044
1045
+ /**
1046
+ * \brief Import wrapped key material.
1047
+ *
1048
+ * \param wrapping_key Handle to the key to unwrap with.
1049
+ * \param alg The key unwrapping algorithm to compute
1050
+ * (\c PSA_ALG_XXX value such that
1051
+ * #PSA_ALG_IS_KEY_WRAP(\p alg) is true).
1052
+ * \param[in] attributes The attributes for the new key.
1053
+ * They are used in the same way as by
1054
+ * psa_import_key().
1055
+ * \param[in] data Buffer containing the key data. The expected
1056
+ * format of this buffer depends on the wrapping
1057
+ * key and on the type declared in \p attributes.
1058
+ * \param data_length Size of the \p data buffer in bytes.
1059
+ * \param[out] handle On success, a handle to the newly created key.
1060
+ * \c 0 on failure.
1061
+ *
1062
+ * \retval #PSA_SUCCESS
1063
+ * Success.
1064
+ * If the unwrapped key is persistent, the key material and the
1065
+ * key's metadata have been saved to persistent storage.
1066
+ * \retval #PSA_ERROR_ALREADY_EXISTS
1067
+ * This is an attempt to create a persistent key, and there is
1068
+ * already a persistent key with the given identifier.
1069
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1070
+ * The key attributes, as a whole, are invalid.
1071
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1072
+ * The key data is not correctly formatted.
1073
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1074
+ * The size in \p attributes is nonzero and does not match the size
1075
+ * of the key data.
1076
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1077
+ * \p wrapping_key does not support unwrapping keys with metadata.
1078
+ * \retval #PSA_ERROR_INVALID_SIGNATURE
1079
+ * \p data is not a valid wrapped key for \p wrapping_key.
1080
+ * \retval #PSA_ERROR_NOT_SUPPORTED
1081
+ * The key type or key size is not supported, either by the
1082
+ * implementation in general or in this particular persistent location.
1083
+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
1084
+ * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
1085
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
1086
+ * \retval #PSA_ERROR_STORAGE_FAILURE
1087
+ * \retval #PSA_ERROR_HARDWARE_FAILURE
1088
+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
1089
+ * \retval #PSA_ERROR_BAD_STATE
1090
+ * The library has not been previously initialized by psa_crypto_init().
1091
+ * It is implementation-dependent whether a failure to initialize
1092
+ * results in this error code.
1093
+ */
1094
+ psa_status_t psa_unwrap_key_material (psa_key_handle_t wrapping_key ,
1095
+ psa_algorithm_t alg ,
1096
+ const psa_key_attributes_t * attributes ,
1097
+ const uint8_t * data ,
1098
+ size_t data_length ,
1099
+ psa_key_handle_t * handle );
991
1100
992
1101
/**@}*/
993
1102
0 commit comments