Skip to main content

mbedtls_cipher_finish

Function mbedtls_cipher_finish 

Source
pub unsafe extern "C" fn mbedtls_cipher_finish(
    ctx: *mut mbedtls_cipher_context_t,
    output: *mut c_uchar,
    olen: *mut usize,
) -> c_int
Expand description

\brief The generic cipher finalization function. If data still needs to be flushed from an incomplete block, the data contained in it is padded to the size of the last block, and written to the \p output buffer.

\warning This function reports invalid padding through an error code. Adversaries may be able to decrypt encrypted data if they can submit chosen ciphertexts and detect whether it has valid padding or not, either through direct observation or through a side channel such as timing. This is known as a padding oracle attack. Therefore applications that call this function for decryption with a cipher that involves padding should take care around error handling. Preferably, such applications should use mbedtls_cipher_finish_padded() instead of this function.

\param ctx The generic cipher context. This must be initialized and bound to a key. \param output The buffer to write data to. This needs to be a writable buffer of at least block_size Bytes. \param olen The length of the data written to the \p output buffer. This may not be \c NULL. Note that when decrypting in a mode with padding, the actual output length is sensitive and may be used to mount a padding oracle attack (see warning above), although less efficiently than through the invalid-padding condition.

\return \c 0 on success. \return #MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA on parameter-verification failure. \return #MBEDTLS_ERR_CIPHER_FULL_BLOCK_EXPECTED on decryption expecting a full block but not receiving one. \return #MBEDTLS_ERR_CIPHER_INVALID_PADDING on invalid padding while decrypting. Note that invalid-padding errors should be handled carefully; see the warning above. \return A cipher-specific error code on failure.