mirror of
https://github.com/aaru-dps/Aaru.Checksums.Native.git
synced 2025-12-16 11:14:29 +00:00
Add documentation.
This commit is contained in:
39
fletcher32.c
39
fletcher32.c
@@ -28,6 +28,15 @@
|
||||
#include "library.h"
|
||||
#include "fletcher32.h"
|
||||
|
||||
/**
|
||||
* @brief Initializes the Fletcher-32 checksum algorithm.
|
||||
*
|
||||
* This function initializes the state variables required for the Fletcher-32
|
||||
* checksum algorithm. It prepares the algorithm to calculate the checksum
|
||||
* for a new data set.
|
||||
*
|
||||
* @return Pointer to a structure containing the checksum state.
|
||||
*/
|
||||
AARU_EXPORT fletcher32_ctx* AARU_CALL fletcher32_init()
|
||||
{
|
||||
fletcher32_ctx* ctx;
|
||||
@@ -42,6 +51,17 @@ AARU_EXPORT fletcher32_ctx* AARU_CALL fletcher32_init()
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Updates the Fletcher-32 checksum with new data.
|
||||
*
|
||||
* This function updates the Fletcher-32 checksum.
|
||||
* The checksum is updated for the given data by iterating through each byte and
|
||||
* applying the corresponding calculations to the rolling checksum values.
|
||||
*
|
||||
* @param ctx Pointer to the Fletcher-32 context structure.
|
||||
* @param data Pointer to the input data buffer.
|
||||
* @param len The length of the input data buffer.
|
||||
*/
|
||||
AARU_EXPORT int AARU_CALL fletcher32_update(fletcher32_ctx* ctx, const uint8_t* data, uint32_t len)
|
||||
{
|
||||
if(!ctx || !data) return -1;
|
||||
@@ -206,6 +226,17 @@ AARU_EXPORT int AARU_CALL fletcher32_update(fletcher32_ctx* ctx, const uint8_t*
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Finalizes the calculation of the Fletcher-32 checksum.
|
||||
*
|
||||
* This function finalizes the calculation of the Fletcher-32 checksum and returns
|
||||
* its value.
|
||||
*
|
||||
* @param[in] ctx Pointer to the Fletcher-32 context structure.
|
||||
* @param[out] checksum Pointer to a 32-bit unsigned integer to store the checksum value.
|
||||
*
|
||||
* @returns 0 on success, -1 on error.
|
||||
*/
|
||||
AARU_EXPORT int AARU_CALL fletcher32_final(fletcher32_ctx* ctx, uint32_t* checksum)
|
||||
{
|
||||
if(!ctx) return -1;
|
||||
@@ -214,6 +245,14 @@ AARU_EXPORT int AARU_CALL fletcher32_final(fletcher32_ctx* ctx, uint32_t* checks
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Frees the resources allocated for the Fletcher-32 checksum context.
|
||||
*
|
||||
* This function should be called to release the memory used by the Fletcher-32 checksum
|
||||
* context structure after it is no longer needed.
|
||||
*
|
||||
* @param ctx The Fletcher-32 checksum context structure, to be freed.
|
||||
*/
|
||||
AARU_EXPORT void AARU_CALL fletcher32_free(fletcher32_ctx* ctx)
|
||||
{
|
||||
if(!ctx) return;
|
||||
|
||||
Reference in New Issue
Block a user