@@ -854,6 +854,135 @@ psa_status_t psa_export_public_key(psa_key_handle_t handle,
854854 size_t data_size ,
855855 size_t * data_length );
856856
857+ /**
858+ * \brief Export a key and its metadata in wrapped form.
859+ *
860+ * A wrapped form of the key object preserves the confidentiality and
861+ * authenticity of the key material and the authenticity of the key
862+ * policy. In practical terms, the key material is encrypted, and
863+ * the key data and metadata are authenticated together.
864+ *
865+ * The format of the wrapped data is implementation-dependent. It may depend
866+ * both on the choice of wrapping key and on the type of key to wrap.
867+ *
868+ * The policy on the key must have the usage flag
869+ * #PSA_KEY_USAGE_EXPORT_WRAPPED set.
870+ *
871+ * \param wrapping_key Handle to the key to wrap with.
872+ * \param handle Handle to the key to export in wrapped form.
873+ * \param[out] data Buffer where the wrapped key data is to be written.
874+ * \param data_size Size of the \p data buffer in bytes.
875+ * \param[out] data_length On success, the number of bytes
876+ * that make up the wrapped key data.
877+ *
878+ * \retval #PSA_SUCCESS
879+ * \retval #PSA_ERROR_INVALID_HANDLE
880+ * One or both of \p handle and \p wrapping_key is not a valid
881+ * handle to a key.
882+ * \retval #PSA_ERROR_NOT_PERMITTED
883+ * The key \p handle does not have the #PSA_KEY_USAGE_BACKUP flag.
884+ * \retval #PSA_ERROR_INVALID_ARGUMENT
885+ * \p wrapping_key does not support wrapping keys with metadata.
886+ * \retval #PSA_ERROR_NOT_SUPPORTED
887+ * \p wrapping_key does not support wrapping the key designated
888+ * by \p handle.
889+ * \retval #PSA_ERROR_BUFFER_TOO_SMALL
890+ * The size of the \p data buffer is too small. You can determine a
891+ * sufficient buffer size by calling
892+ * #PSA_WRAP_KEY_WITH_POLICY_OUTPUT_SIZE(\c type, \c bits)
893+ * where \c type is the key type of \p handle
894+ * and \c bits is the key size of \p handle in bits.
895+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
896+ * \retval #PSA_ERROR_HARDWARE_FAILURE
897+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
898+ * \retval #PSA_ERROR_STORAGE_FAILURE
899+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
900+ * \retval #PSA_ERROR_BAD_STATE
901+ * The library has not been previously initialized by psa_crypto_init().
902+ * It is implementation-dependent whether a failure to initialize
903+ * results in this error code.
904+ */
905+ psa_status_t psa_wrap_key_with_policy (psa_key_handle_t wrapping_key ,
906+ psa_key_handle_t handle ,
907+ uint8_t * data ,
908+ size_t data_size ,
909+ size_t * data_length );
910+
911+ /**
912+ * \brief Import a wrapped key with its metadata.
913+ *
914+ * This function supports any output from psa_wrap_key_with_policy().
915+ * For symmetric wrapping, you must unwrap with the same key that was
916+ * used to wrap. For asymmetric wrapping where the wrapping operation uses
917+ * a public key and the unwrapping operation uses the corresponding private
918+ * key, you must unwrap with the corresponding unwrapping key.
919+ *
920+ * \param wrapping_key Handle to the key to unwrap with.
921+ * \param[in] attributes The attributes for the new key.
922+ * They are used as follows:
923+ * - The key type and size may be 0. If either is
924+ * nonzero, it must match the corresponding
925+ * attribute of the wrapped key data.
926+ * - The key location (the lifetime and, for
927+ * persistent keys, the key identifier) is
928+ * used directly.
929+ * If the wrapped key does not have the usage
930+ * flag #PSA_KEY_USAGE_COPY, then the location
931+ * must match the location embedded in \p data.
932+ * If the wrapped key has the usage
933+ * flag #PSA_KEY_USAGE_COPY, then the location
934+ * embedded in \p data is ignored.
935+ * - The policy constraints (usage flags and
936+ * algorithm policy) are combined from
937+ * the wrapped key data and \p attributes so that
938+ * both sets of restrictions apply. The
939+ * policy restrictions are calculated in the
940+ * same way as in psa_copy_key().
941+ * \param[in] data Buffer containing the wrapped key material.
942+ * The expected format of this buffer depends
943+ * on the wrapping key.
944+ * \param data_length Size of the \p data buffer in bytes.
945+ * \param[out] handle On success, a handle to the newly created key.
946+ * \c 0 on failure.
947+ *
948+ * \retval #PSA_SUCCESS
949+ * Success.
950+ * If the unwrapped key is persistent, the key material and the
951+ * key's metadata have been saved to persistent storage.
952+ * \retval #PSA_ERROR_ALREADY_EXISTS
953+ * This is an attempt to create a persistent key, and there is
954+ * already a persistent key with the given identifier.
955+ * \retval #PSA_ERROR_INVALID_ARGUMENT
956+ * The key attributes, as a whole, are invalid.
957+ * \retval #PSA_ERROR_INVALID_ARGUMENT
958+ * The key data is not correctly formatted.
959+ * \retval #PSA_ERROR_INVALID_ARGUMENT
960+ * The size in \p attributes is nonzero and does not match the size
961+ * of the key data.
962+ * \retval #PSA_ERROR_INVALID_ARGUMENT
963+ * \p wrapping_key does not support unwrapping keys with metadata.
964+ * \retval #PSA_ERROR_INVALID_SIGNATURE
965+ * \p data is not a valid wrapped key for \p wrapping_key.
966+ * \retval #PSA_ERROR_NOT_SUPPORTED
967+ * Some of the metadata in either \p attributes or \p data is
968+ * not supported.
969+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
970+ * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
971+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
972+ * \retval #PSA_ERROR_STORAGE_FAILURE
973+ * \retval #PSA_ERROR_HARDWARE_FAILURE
974+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
975+ * \retval #PSA_ERROR_BAD_STATE
976+ * The library has not been previously initialized by psa_crypto_init().
977+ * It is implementation-dependent whether a failure to initialize
978+ * results in this error code.
979+ */
980+ psa_status_t psa_unwrap_key_with_policy (psa_key_handle_t wrapping_key ,
981+ const psa_key_attributes_t * attributes ,
982+ const uint8_t * data ,
983+ size_t data_length ,
984+ psa_key_handle_t * handle );
985+
857986
858987
859988/**@}*/
0 commit comments