psa_mac_sign_setup() function
Set up a multipart MAC calculation operation. This function sets up the calculation of the MAC (message authentication code) of a byte string. To verify the MAC of a message against an expected value, use psa_mac_verify_setup() instead. The sequence of operations to calculate a MAC is as follows: -# Allocate an operation object which will be passed to all the functions listed here. -# Initialize the operation object with one of the methods described in the documentation for #psa_mac_operation_t, e.g. #PSA_MAC_OPERATION_INIT. -# Call psa_mac_sign_setup() to specify the algorithm and key. -# Call psa_mac_update() zero, one or more times, passing a fragment of the message each time. The MAC that is calculated is the MAC of the concatenation of these messages in order. -# At the end of the message, call psa_mac_sign_finish() to finish calculating the MAC value and retrieve it. If an error occurs at any step after a call to psa_mac_sign_setup(), the operation will need to be reset by a call to psa_mac_abort(). The application may call psa_mac_abort() at any time after the operation has been initialized. After a successful call to psa_mac_sign_setup(), the application must eventually terminate the operation through one of the following methods: - A successful call to psa_mac_sign_finish(). - A call to psa_mac_abort().
Arguments
operation
The operation object to set up. It must have been initialized as per the documentation for #psa_mac_operation_t and not yet in use.
key
Identifier of the key to use for the operation. It must remain valid until the operation terminates. 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).
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_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 operation state is not valid (it must be inactive), 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.