This function finishes the GCM operation and generates the authentication tag. It wraps up the GCM stream, and generates the tag. The tag can have a maximum length of 16 Bytes.
The buffer for the final output. If \p output_size is nonzero, this must be a writable buffer of at least \p output_size bytes.
output_size
size_t
The size of the \p output buffer in bytes. This must be large enough for the output that mbedtls_gcm_update() has not produced. In particular: - If mbedtls_gcm_update() produces immediate output, or if the total input size is a multiple of \c 16, then mbedtls_gcm_finish() never produces any output, so \p output_size can be \c 0. - \p output_size never needs to be more than \c 15.
output_length
size_t*
On success, \p *output_length contains the actual length of the output written in \p output. On failure, the content of \p *output_length is unspecified.
tag
unsignedchar*
The buffer for holding the tag. This must be a writable buffer of at least \p tag_len Bytes.
tag_len
size_t
The length of the tag to generate. This must be at least four.
Return value
\c 0 on success. #MBEDTLS_ERR_GCM_BAD_INPUT on failure: invalid value of \p tag_len, or \p output_size too small.
This function feeds an input buffer into an ongoing GCM encryption or decryption operation. You may call this function zero, one or more times to pass successive parts of the input: the plaintext to encrypt, or the ciphertext (not including the tag) to decrypt. After the last part of the input, call mbedtls_gcm_finish(). This function may produce output in one of the following ways: - Immediate output: the output length is always equal to the input length. - Buffered output: the output consists of a whole number of 16-byte blocks. If the total input length so far (not including associated data) is 16 \* *B* + *A* with *A* < 16 then the total output length is 16 \* *B*. In particular: - It is always correct to call this function with \p output_size >= \p input_length + 15. - If \p input_length is a multiple of 16 for all the calls to this function during an operation, then it is correct to use \p output_size = \p input_length.
This function feeds an input buffer as associated data (authenticated but not encrypted data) in a GCM encryption or decryption operation. Call this function after mbedtls_gcm_starts() to pass the associated data. If the associated data is empty, you do not need to call this function. You may not call this function after calling mbedtls_cipher_update().