cctools
md5.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2022 The University of Notre Dame
3 This software is distributed under the GNU General Public License.
4 See the file COPYING for details.
5 */
6 
7 #ifndef MD5_H
8 #define MD5_H
9 
10 #include <stdint.h>
11 #include <stdlib.h>
12 
13 /* Functions named md5_X are commonly used in a number of libraries. Protect the namespace by renaming our functions to cctools_md5_X */
14 
15 #ifndef DOXYGEN
16 #define md5_init cctools_md5_init
17 #define md5_update cctools_md5_update
18 #define md5_final cctools_md5_final
19 #define md5_buffer cctools_md5_buffer
20 #define md5_file cctools_md5_file
21 #define md5_to_string cctools_md5_to_string
22 #define md5_of_string cctools_md5_of_string
23 #endif
24 
29 #define MD5_DIGEST_LENGTH 16
30 #define MD5_DIGEST_LENGTH_HEX (MD5_DIGEST_LENGTH<<1)
31 
32 typedef struct {
33  uint32_t state[4];
34  uint32_t count[2];
35  uint8_t buffer[64];
37 
38 void md5_init(md5_context_t * ctx);
39 void md5_update(md5_context_t * ctx, const void *, size_t);
40 void md5_final(unsigned char digest[MD5_DIGEST_LENGTH], md5_context_t * ctx);
41 
49 void md5_buffer(const void *buffer, size_t length, unsigned char digest[MD5_DIGEST_LENGTH]);
50 
55 const char *md5_to_string(unsigned char digest[MD5_DIGEST_LENGTH]);
56 
57 /* md5_of_string calculates the md5 checksum of string s.
58  * @param s: a string pointer
59  * return the md5 checksum of s on success, return NULL on failure.
60  * The caller should free the returned string.
61  */
62 char *md5_of_string(const char *s);
63 
71 int md5_file(const char *filename, unsigned char digest[MD5_DIGEST_LENGTH]);
72 
73 #endif
md5_file
int md5_file(const char *filename, unsigned char digest[MD5_DIGEST_LENGTH])
Checksum a local file.
md5_buffer
void md5_buffer(const void *buffer, size_t length, unsigned char digest[MD5_DIGEST_LENGTH])
Checksum a memory buffer.
buffer
Definition: buffer.h:26
md5_context_t
Definition: md5.h:32
md5_to_string
const char * md5_to_string(unsigned char digest[MD5_DIGEST_LENGTH])
Convert an MD5 digest into a printable string.