@@ -1029,6 +1029,117 @@ psa_status_t psa_get_wrapped_key_attributes(const uint8_t *data,
1029
1029
size_t data_length ,
1030
1030
psa_key_attributes_t * attributes );
1031
1031
1032
+ /**
1033
+ * \brief Export key material in wrapped form.
1034
+ *
1035
+ * A wrapped form of the key material preserves the confidentiality
1036
+ * and authenticity of the key material. In practical terms, the key
1037
+ * material is encrypted and authenticated.
1038
+ *
1039
+ * The policy on the key must have the usage flag
1040
+ * #PSA_KEY_USAGE_EXPORT_WRAPPED set.
1041
+ *
1042
+ * \param wrapping_key Handle to the key to wrap with.
1043
+ * \param alg The key wrapping algorithm to compute
1044
+ * (\c PSA_ALG_XXX value such that
1045
+ * #PSA_ALG_IS_KEY_WRAP(\p alg) is true).
1046
+ * \param handle Handle to the key whose material is to be
1047
+ * exported in wrapped form.
1048
+ * \param[out] data Buffer where the wrapped key data is to be written.
1049
+ * \param data_size Size of the \p data buffer in bytes.
1050
+ * \param[out] data_length On success, the number of bytes
1051
+ * that make up the wrapped key data.
1052
+ *
1053
+ * \retval #PSA_SUCCESS
1054
+ * \retval #PSA_ERROR_INVALID_HANDLE
1055
+ * One or both of \p handle and \p wrapping_key is not a valid
1056
+ * handle to a key.
1057
+ * \retval #PSA_ERROR_NOT_PERMITTED
1058
+ * The key \p handle does not have the #PSA_KEY_USAGE_BACKUP flag.
1059
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1060
+ * \p wrapping_key does not support wrapping key material.
1061
+ * \retval #PSA_ERROR_NOT_SUPPORTED
1062
+ * \p wrapping_key does not support wrapping the key designated
1063
+ * by \p handle.
1064
+ * \retval #PSA_ERROR_BUFFER_TOO_SMALL
1065
+ * The size of the \p data buffer is too small. You can determine a
1066
+ * sufficient buffer size by calling
1067
+ * #PSA_WRAP_KEY_MATERIAL_OUTPUT_SIZE(\p alg, \c type, \c bits)
1068
+ * where \c type is the key type of \p handle
1069
+ * and \c bits is the key size of \p handle in bits.
1070
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
1071
+ * \retval #PSA_ERROR_HARDWARE_FAILURE
1072
+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
1073
+ * \retval #PSA_ERROR_STORAGE_FAILURE
1074
+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
1075
+ * \retval #PSA_ERROR_BAD_STATE
1076
+ * The library has not been previously initialized by psa_crypto_init().
1077
+ * It is implementation-dependent whether a failure to initialize
1078
+ * results in this error code.
1079
+ */
1080
+ psa_status_t psa_wrap_key_material (psa_key_handle_t wrapping_key ,
1081
+ psa_algorithm_t alg ,
1082
+ psa_key_handle_t handle ,
1083
+ uint8_t * data ,
1084
+ size_t data_size ,
1085
+ size_t * data_length );
1086
+
1087
+ /**
1088
+ * \brief Import wrapped key material.
1089
+ *
1090
+ * \param wrapping_key Handle to the key to unwrap with.
1091
+ * \param alg The key unwrapping algorithm to compute
1092
+ * (\c PSA_ALG_XXX value such that
1093
+ * #PSA_ALG_IS_KEY_WRAP(\p alg) is true).
1094
+ * \param[in] attributes The attributes for the new key.
1095
+ * They are used in the same way as by
1096
+ * psa_import_key().
1097
+ * \param[in] data Buffer containing the key data. The expected
1098
+ * format of this buffer depends on the wrapping
1099
+ * key and on the type declared in \p attributes.
1100
+ * \param data_length Size of the \p data buffer in bytes.
1101
+ * \param[out] handle On success, a handle to the newly created key.
1102
+ * \c 0 on failure.
1103
+ *
1104
+ * \retval #PSA_SUCCESS
1105
+ * Success.
1106
+ * If the unwrapped key is persistent, the key material and the
1107
+ * key's metadata have been saved to persistent storage.
1108
+ * \retval #PSA_ERROR_ALREADY_EXISTS
1109
+ * This is an attempt to create a persistent key, and there is
1110
+ * already a persistent key with the given identifier.
1111
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1112
+ * The key attributes, as a whole, are invalid.
1113
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1114
+ * The key data is not correctly formatted.
1115
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1116
+ * The size in \p attributes is nonzero and does not match the size
1117
+ * of the key data.
1118
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
1119
+ * \p wrapping_key does not support unwrapping keys with metadata.
1120
+ * \retval #PSA_ERROR_INVALID_SIGNATURE
1121
+ * \p data is not a valid wrapped key for \p wrapping_key.
1122
+ * \retval #PSA_ERROR_NOT_SUPPORTED
1123
+ * Some of the metadata in either \p attributes or \p data is
1124
+ * not supported.
1125
+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
1126
+ * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
1127
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
1128
+ * \retval #PSA_ERROR_STORAGE_FAILURE
1129
+ * \retval #PSA_ERROR_HARDWARE_FAILURE
1130
+ * \retval #PSA_ERROR_CORRUPTION_DETECTED
1131
+ * \retval #PSA_ERROR_BAD_STATE
1132
+ * The library has not been previously initialized by psa_crypto_init().
1133
+ * It is implementation-dependent whether a failure to initialize
1134
+ * results in this error code.
1135
+ */
1136
+ psa_status_t psa_unwrap_key_material (psa_key_handle_t wrapping_key ,
1137
+ psa_algorithm_t alg ,
1138
+ const psa_key_attributes_t * attributes ,
1139
+ const uint8_t * data ,
1140
+ size_t data_length ,
1141
+ psa_key_handle_t * handle );
1142
+
1032
1143
1033
1144
1034
1145
/**@}*/
0 commit comments