Bug 880: Prevent SIGSEGV in init_python when -no-home is used.
[elinks.git] / src / util / md5.h
blob7c29c927145effddbf340ade4840cd485d3e7a25
1 #ifndef EL__UTIL_MD5_H
2 #define EL__UTIL_MD5_H
4 /* Optionally MD5 support can depend on external implementation when linking
5 * against a SSL library that supports it. */
6 #ifndef CONFIG_MD5
7 #if defined(CONFIG_OPENSSL)
8 #include <openssl/md5.h>
9 #elif defined(CONFIG_GNUTLS_OPENSSL_COMPAT)
10 #include <gnutls/openssl.h>
11 #endif
12 #endif
14 /* GNU TLS doesn't define this */
15 #ifndef MD5_DIGEST_LENGTH
16 #define MD5_DIGEST_LENGTH 16
17 #endif
19 #define MD5_HEX_DIGEST_LENGTH (MD5_DIGEST_LENGTH * 2)
21 typedef unsigned char md5_digest_bin_T[MD5_DIGEST_LENGTH];
22 typedef unsigned char md5_digest_hex_T[MD5_HEX_DIGEST_LENGTH];
24 struct md5_context {
25 uint32_t buf[4];
26 uint32_t bits[2];
27 unsigned char in[64];
30 /* The interface for digesting several chunks of data. To compute the message
31 * digest of a chunk of bytes, declare an md5_context structure, pass it to
32 * init_md5(), call update_md5() as needed on buffers full of bytes, and then
33 * call done_md5(), which will fill a supplied 16-byte array with the digest. */
34 void init_md5(struct md5_context *context);
35 void update_md5(struct md5_context *context, const unsigned char *data, unsigned long length);
36 void done_md5(struct md5_context *context, md5_digest_bin_T digest);
38 /* Digest the passed @data with the given length and stores the MD5 digest in
39 * the @digest parameter. */
40 unsigned char *
41 digest_md5(const unsigned char *data, unsigned long length, md5_digest_bin_T digest);
43 #ifdef CONFIG_MD5
44 /* Provide compatibility with the OpenSSL interface: */
46 typedef struct md5_context MD5_CTX;
47 #define MD5_Init(context) init_md5(context)
48 #define MD5_Update(context, data, len) update_md5(context, data, len)
49 #define MD5_Final(md5, context) done_md5(context, md5)
50 #define MD5(data, len, md5) digest_md5(data, len, md5)
52 #endif /* CONFIG_MD5 */
54 #endif