[go: up one dir, main page]

File: md5.h

package info (click to toggle)
cctools 9.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 44,624 kB
  • sloc: ansic: 192,539; python: 20,827; cpp: 20,199; sh: 11,719; perl: 4,106; xml: 3,688; makefile: 1,224
file content (71 lines) | stat: -rw-r--r-- 2,163 bytes parent folder | download | duplicates (3)
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
/*
Copyright (C) 2008- 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>

#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_string cctools_md5_string

/** @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_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]);

/** 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_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]);

/** 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_string(unsigned char digest[MD5_DIGEST_LENGTH]);

/* md5_cal 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_cal(const char *s);

#endif