psa_mac_compute() function
Calculate the MAC (message authentication code) of a message.
Arguments
key
Identifier of the key to use for the operation. It must allow the usage PSA_KEY_USAGE_SIGN_MESSAGE.
alg
The MAC algorithm to compute (\c PSA_ALG_XXX value such that #PSA_ALG_IS_MAC(\p alg) is true).
input
Buffer containing the input message.
input_length
Size of the \p input buffer in bytes.
mac
Buffer where the MAC value is to be written.
mac_size
Size of the \p mac buffer in bytes.
mac_length
On success, the number of bytes that make up the MAC value.
Return value
#PSA_SUCCESS Success. #PSA_ERROR_INVALID_HANDLE \emptydescription #PSA_ERROR_NOT_PERMITTED \emptydescription #PSA_ERROR_INVALID_ARGUMENT \p key is not compatible with \p alg. #PSA_ERROR_NOT_SUPPORTED \p alg is not supported or is not a MAC algorithm. #PSA_ERROR_BUFFER_TOO_SMALL \p mac_size is too small #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription #PSA_ERROR_HARDWARE_FAILURE \emptydescription #PSA_ERROR_CORRUPTION_DETECTED \emptydescription #PSA_ERROR_STORAGE_FAILURE The key could not be retrieved from storage. #PSA_ERROR_BAD_STATE 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.
Notes
To verify the MAC of a message against an expected value, use psa_mac_verify() instead. Beware that comparing integrity or authenticity data such as MAC values with a function such as \c memcmp is risky because the time taken by the comparison may leak information about the MAC value which could allow an attacker to guess a valid MAC and thereby bypass security controls.