CANopen Slave Documentation
Version 7.00.02
|
This simple MD5 implementation is derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm and modified slightly to be functionally identical but condensed into control structures.
All functions provided by this module require a structure McMD5Context_s to store an intermediate hash value as well as the MD5 result (digest). The structure has to be initialized by McMD5Init(). The MD5 checksum is computed by calling McMD5Add() and McMD5Finalize().
The output of this code example is:
Data Structures | |
struct | McMD5Context_s |
Functions | |
void | McMD5Add (McMD5Context_ts *ptsMd5ContextV, uint8_t *pubInputV, uint32_t ulInputSizeV) |
void | McMD5Finalize (McMD5Context_ts *ptsMd5ContextV) |
void | McMD5Init (McMD5Context_ts *ptsMd5ContextV) |
void | McMD5String (McMD5Context_ts *ptsMd5ContextV, char *pszBufferV, bool_t btUpperCaseV) |
void McMD5Add | ( | McMD5Context_ts * | ptsMd5ContextV, |
uint8_t * | pubInputV, | ||
uint32_t | ulInputSizeV ) |
[in] | ptsMd5ContextV | Pointer to MD5 context structure |
[in] | pubInputV | Pointer to input data |
[in] | ulInputSizeV | Size of input data in bytes |
The function adds input data to the context MD5 context structure defined by ptsMd5ContextV
. The size of the input data in bytes is defined by parameter ulInputSizeV
.
If the input fills out a block of 512 bits, the internal MD5 algorithm is applied and the result in stored in the buffer of the MD5 context structure. The function also updates the overall size inside the context structure defined by ptsMd5ContextV
.
void McMD5Finalize | ( | McMD5Context_ts * | ptsMd5ContextV | ) |
[in] | ptsMd5ContextV | Pointer to MD5 context structure |
The function pads the current input which has been applied by McMD5Add() to get to 448 bytes. The result of the final iteration is saved into the digest of the MD5 context structure (McMD5Context_ts::aubDigest). The binary MD5 checksum can be retrieved by reading the digest array. As alternative it is possible to convert the MD5 checksum into a character string by calling McMD5String().
void McMD5Init | ( | McMD5Context_ts * | ptsMd5ContextV | ) |
[in] | ptsMd5ContextV | Pointer to MD5 context structure |
The function initializes the MD5 context structure defined by ptsMd5ContextV
for further operation.
void McMD5String | ( | McMD5Context_ts * | ptsMd5ContextV, |
char * | pszBufferV, | ||
bool_t | btUpperCaseV ) |
[in] | ptsMd5ContextV | Pointer to MD5 context structure |
[in] | pszBufferV | Pointer to string buffer |
[in] | btUpperCaseV | Flag for upper-case character output |
The function prints the digest (MD5 checksum) of the MD5 context structure defined by ptsMd5ContextV
to the character buffer pszBufferV
. The size of the buffer must be at least 33 bytes. By parameter btUpperCaseV
the output string can be controlled between lower-case and upper-case character.
The output of this code example is: