[go: up one dir, main page]

File: md5.h

package info (click to toggle)
cctools 1%3A7.15.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 40,008 kB
  • sloc: ansic: 117,215; python: 30,569; cpp: 20,301; sh: 13,834; perl: 4,056; xml: 3,688; makefile: 1,502
file content (73 lines) | stat: -rw-r--r-- 2,392 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Copyright (C) 2022 The University of Notre Dame
This software is distributed under the GNU General Public License.
See the file COPYING for details.
*/

#ifndef MD5_H
#define MD5_H

#include <stdint.h>
#include <stdlib.h>

/* Functions named md5_X are commonly used in a number of libraries.  Protect the namespace by renaming our functions to cctools_md5_X */

#ifndef DOXYGEN
#define md5_init cctools_md5_init
#define md5_update cctools_md5_update
#define md5_final cctools_md5_final
#define md5_buffer cctools_md5_buffer
#define md5_file cctools_md5_file
#define md5_to_string cctools_md5_to_string
#define md5_of_string cctools_md5_of_string
#endif

/** @file md5.h
Routines for computing MD5 checksums.
*/

#define MD5_DIGEST_LENGTH 16
#define MD5_DIGEST_LENGTH_HEX (MD5_DIGEST_LENGTH<<1)

typedef struct {
	uint32_t state[4];
	uint32_t count[2];
	uint8_t buffer[64];
} md5_context_t;

void md5_init(md5_context_t * ctx);
void md5_update(md5_context_t * ctx, const void *, size_t);
void md5_final(unsigned char digest[MD5_DIGEST_LENGTH], md5_context_t * ctx);

/** Checksum a memory buffer.
Note that this function produces a digest in binary form
which  must be converted to a human readable form with @ref md5_to_string.
@param buffer Pointer to a memory buffer.
@param length Length of the buffer in bytes.
@param digest Pointer to a buffer to store the digest.
*/
void md5_buffer(const void *buffer, size_t length, unsigned char digest[MD5_DIGEST_LENGTH]);

/** Convert an MD5 digest into a printable string.
@param digest A binary digest returned from @ref md5_file, @ref md5_buffer, or @ref chirp_reli_md5.
@returns A static pointer to a human readable form of the digest.
*/
const char *md5_to_string(unsigned char digest[MD5_DIGEST_LENGTH]);

/* md5_of_string calculates the md5 checksum of string s.
 * @param s: a string pointer
 * return the md5 checksum of s on success, return NULL on failure.
 * The caller should free the returned string.
 */
char *md5_of_string(const char *s);

/** Checksum a local file.
Note that this function produces a digest in binary form
which  must be converted to a human readable form with @ref md5_to_string.
@param filename Path to the file to checksum.
@param digest Pointer to a buffer to store the digest.
@return One on success, zero on failure.
*/
int md5_file(const char *filename, unsigned char digest[MD5_DIGEST_LENGTH]);

#endif