cctools
md5.h
Go to the documentation of this file.
1/*
2Copyright (C) 2022 The University of Notre Dame
3This software is distributed under the GNU General Public License.
4See 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
32typedef struct {
33 uint32_t state[4];
34 uint32_t count[2];
35 uint8_t buffer[64];
37
38void md5_init(md5_context_t * ctx);
39void md5_update(md5_context_t * ctx, const void *, size_t);
40void md5_final(unsigned char digest[MD5_DIGEST_LENGTH], md5_context_t * ctx);
41
49void md5_buffer(const void *buffer, size_t length, unsigned char digest[MD5_DIGEST_LENGTH]);
50
55const 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 */
62char *md5_of_string(const char *s);
63
71int md5_file(const char *filename, unsigned char digest[MD5_DIGEST_LENGTH]);
72
73#endif
int md5_file(const char *filename, unsigned char digest[MD5_DIGEST_LENGTH])
Checksum a local file.
const char * md5_to_string(unsigned char digest[MD5_DIGEST_LENGTH])
Convert an MD5 digest into a printable string.
void md5_buffer(const void *buffer, size_t length, unsigned char digest[MD5_DIGEST_LENGTH])
Checksum a memory buffer.
Definition buffer.h:26
Definition md5.h:32