Implementation of the MD5 hashing function.
More...
Implementation of the MD5 hashing function.
None of this will make any sense unless you're studying RFC 1321 as you read the code.
There are three primary motivations for this particular implementation. 1) Programmer's pride. I wanted to be able to say I'd done it, and I wanted to learn from the experience. 2) Portability. I wanted an implementation that I knew to be portable to a reasonable number of platforms. In particular, the algorithm is designed with little-endian platforms in mind, but I wanted an endian-agnostic implementation. 3) Compactness. While not an overriding goal, I thought it worth-while to see if I could reduce the overall size of the result. This is in keeping with my hopes that this library will be suitable for use in some embedded environments. Beyond that, cleanliness and clarity are always worth pursuing.
As mentioned above, the code really only makes sense if you are familiar with the MD5 algorithm or are using RFC 1321 as a guide. This code is quirky, however, so you'll want to be reading carefully.
|
file | md5.h |
| MD5 interface definition.
|
|
|
void | md5_init (md5_ctx_t *ctx) |
| Initialize the MD5 calculation context. More...
|
|
void | md5_update (md5_ctx_t *ctx, const void *data, size_t len) |
| Build an MD5 Message Digest within the given context. More...
|
|
void | md5_final (md5_ctx_t *ctx, void *digest) |
| Finish up the current MD5 hash calculation generate the final hash. More...
|
|
void | md5 (void *digest, const void *data, size_t len) |
| Calculate a MD5 hash from the given data. More...
|
|
◆ md5()
void md5 |
( |
void * |
digest, |
|
|
const void * |
data, |
|
|
size_t |
len |
|
) |
| |
Calculate a MD5 hash from the given data.
- Parameters
-
[out] | digest | Result location, must be 16 byte |
[in] | data | Input data |
[in] | len | Length of src |
◆ md5_final()
void md5_final |
( |
md5_ctx_t * |
ctx, |
|
|
void * |
digest |
|
) |
| |
Finish up the current MD5 hash calculation generate the final hash.
- Parameters
-
[in] | ctx | Context of the current calculation |
[out] | digest | Result location, must be 16 byte |
◆ md5_init()
Initialize the MD5 calculation context.
- Parameters
-
[out] | ctx | Pointer to the context to be initialized |
The purpose of the context is to make it possible to generate an MD5 Message Digest in stages, rather than having to pass a single large block to a single MD5 function. The context structure keeps track of various bits of state information.
Once the context is initialized, the blocks of message data are passed to the <md5_update()> function. Once the final bit of data has been handed to <md5_update()> the context can be closed out by calling <md5_final()>, which also calculates the final MD5 result. Don't forget to free an allocated context structure when you've finished using it.
◆ md5_update()
void md5_update |
( |
md5_ctx_t * |
ctx, |
|
|
const void * |
data, |
|
|
size_t |
len |
|
) |
| |
Build an MD5 Message Digest within the given context.
- Parameters
-
[in,out] | ctx | Context of the current calculation |
[in] | data | Input data |
[in] | len | Length of data |