@@ -928,12 +928,51 @@ psa_status_t psa_hash_abort(psa_hash_operation_t *operation);
928
928
*/
929
929
930
930
/** The type of the state data structure for multipart MAC operations.
931
+ *
932
+ * Before calling any function on a MAC operation object, the application must
933
+ * initialize it by any of the following means:
934
+ * - Set the structure to all-bits-zero, for example:
935
+ * \code
936
+ * psa_mac_operation_t operation;
937
+ * memset(&operation, 0, sizeof(operation));
938
+ * \endcode
939
+ * - Initialize the structure to logical zero values, for example:
940
+ * \code
941
+ * psa_mac_operation_t operation = {0};
942
+ * \endcode
943
+ * - Initialize the structure to the initializer #PSA_MAC_OPERATION_INIT,
944
+ * for example:
945
+ * \code
946
+ * psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
947
+ * \endcode
948
+ * - Assign the result of the function psa_mac_operation_init()
949
+ * to the structure, for example:
950
+ * \code
951
+ * psa_mac_operation_t operation;
952
+ * operation = psa_mac_operation_init();
953
+ * \endcode
931
954
*
932
955
* This is an implementation-defined \c struct. Applications should not
933
956
* make any assumptions about the content of this structure except
934
957
* as directed by the documentation of a specific implementation. */
935
958
typedef struct psa_mac_operation_s psa_mac_operation_t ;
936
959
960
+ /** \def PSA_MAC_OPERATION_INIT
961
+ *
962
+ * This macro returns a suitable initializer for a MAC operation object of type
963
+ * #psa_mac_operation_t.
964
+ */
965
+ #ifdef __DOXYGEN_ONLY__
966
+ /* This is an example definition for documentation purposes.
967
+ * Implementations should define a suitable value in `crypto_struct.h`.
968
+ */
969
+ #define PSA_MAC_OPERATION_INIT {0}
970
+ #endif
971
+
972
+ /** Return an initial value for a MAC operation object.
973
+ */
974
+ static psa_mac_operation_t psa_mac_operation_init (void );
975
+
937
976
/** Start a multipart MAC calculation operation.
938
977
*
939
978
* This function sets up the calculation of the MAC
@@ -944,6 +983,8 @@ typedef struct psa_mac_operation_s psa_mac_operation_t;
944
983
* The sequence of operations to calculate a MAC is as follows:
945
984
* -# Allocate an operation object which will be passed to all the functions
946
985
* listed here.
986
+ * -# Initialize the operation object with one of the methods described in the
987
+ * documentation for #psa_mac_operation_t, e.g. PSA_MAC_OPERATION_INIT.
947
988
* -# Call psa_mac_sign_setup() to specify the algorithm and key.
948
989
* The key remains associated with the operation even if the content
949
990
* of the key slot changes.
@@ -954,14 +995,16 @@ typedef struct psa_mac_operation_s psa_mac_operation_t;
954
995
* calculating the MAC value and retrieve it.
955
996
*
956
997
* The application may call psa_mac_abort() at any time after the operation
957
- * has been initialized with psa_mac_sign_setup() .
998
+ * has been initialized.
958
999
*
959
1000
* After a successful call to psa_mac_sign_setup(), the application must
960
1001
* eventually terminate the operation through one of the following methods:
961
1002
* - A failed call to psa_mac_update().
962
1003
* - A call to psa_mac_sign_finish() or psa_mac_abort().
963
1004
*
964
- * \param[out] operation The operation object to use.
1005
+ * \param[in,out] operation The operation object to set up. It must have
1006
+ * been initialized as per the documentation for
1007
+ * #psa_mac_operation_t and not yet in use.
965
1008
* \param handle Handle to the key to use for the operation.
966
1009
* \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value
967
1010
* such that #PSA_ALG_IS_MAC(alg) is true).
@@ -996,6 +1039,8 @@ psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
996
1039
* The sequence of operations to verify a MAC is as follows:
997
1040
* -# Allocate an operation object which will be passed to all the functions
998
1041
* listed here.
1042
+ * -# Initialize the operation object with one of the methods described in the
1043
+ * documentation for #psa_mac_operation_t, e.g. PSA_MAC_OPERATION_INIT.
999
1044
* -# Call psa_mac_verify_setup() to specify the algorithm and key.
1000
1045
* The key remains associated with the operation even if the content
1001
1046
* of the key slot changes.
@@ -1007,14 +1052,16 @@ psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
1007
1052
* the expected value.
1008
1053
*
1009
1054
* The application may call psa_mac_abort() at any time after the operation
1010
- * has been initialized with psa_mac_verify_setup() .
1055
+ * has been initialized.
1011
1056
*
1012
1057
* After a successful call to psa_mac_verify_setup(), the application must
1013
1058
* eventually terminate the operation through one of the following methods:
1014
1059
* - A failed call to psa_mac_update().
1015
1060
* - A call to psa_mac_verify_finish() or psa_mac_abort().
1016
1061
*
1017
- * \param[out] operation The operation object to use.
1062
+ * \param[in,out] operation The operation object to set up. It must have
1063
+ * been initialized as per the documentation for
1064
+ * #psa_mac_operation_t and not yet in use.
1018
1065
* \param handle Handle to the key to use for the operation.
1019
1066
* \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value
1020
1067
* such that #PSA_ALG_IS_MAC(\p alg) is true).
0 commit comments