Function esp_idf_sys::psa_key_derivation_verify_bytes

source ·
pub unsafe extern "C" fn psa_key_derivation_verify_bytes(
    operation: *mut psa_key_derivation_operation_t,
    expected_output: *const u8,
    output_length: usize,
) -> psa_status_t
Expand description

Compare output data from a key derivation operation to an expected value.

This function calculates output bytes from a key derivation algorithm and compares those bytes to an expected value in constant time. If you view the key derivation’s output as a stream of bytes, this function destructively reads the expected number of bytes from the stream before comparing them. The operation’s capacity decreases by the number of bytes read.

This is functionally equivalent to the following code: \code psa_key_derivation_output_bytes(operation, tmp, output_length); if (memcmp(output, tmp, output_length) != 0) return PSA_ERROR_INVALID_SIGNATURE; \endcode except (1) it works even if the key’s policy does not allow outputting the bytes, and (2) the comparison will be done in constant time.

If this function returns an error status other than #PSA_ERROR_INSUFFICIENT_DATA or #PSA_ERROR_INVALID_SIGNATURE, the operation enters an error state and must be aborted by calling psa_key_derivation_abort().

\param[in,out] operation The key derivation operation object to read from. \param[in] expected_output Buffer containing the expected derivation output. \param output_length Length of the expected output; this is also the number of bytes that will be read.

\retval #PSA_SUCCESS \emptydescription \retval #PSA_ERROR_INVALID_SIGNATURE The output was read successfully, but it differs from the expected output. \retval #PSA_ERROR_NOT_PERMITTED One of the inputs was a key whose policy didn’t allow #PSA_KEY_USAGE_VERIFY_DERIVATION. \retval #PSA_ERROR_INSUFFICIENT_DATA The operation’s capacity was less than \p output_length bytes. Note that in this case, the operation’s capacity is set to 0, thus subsequent calls to this function will not succeed, even with a smaller expected output. \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription \retval #PSA_ERROR_HARDWARE_FAILURE \emptydescription \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription \retval #PSA_ERROR_BAD_STATE The operation state is not valid (it must be active and completed all required input steps), or the library has not been previously initialized by psa_crypto_init(). It is implementation-dependent whether a failure to initialize results in this error code.