All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
md5.h
Go to the documentation of this file.
1 #ifndef _FR_MD5_H
2 #define _FR_MD5_H
3 /**
4  * $Id: 268196dc6a0b39afbbaf10d03fb174c370bccba9 $
5  *
6  * @note license is LGPL, but largely derived from a public domain source.
7  *
8  * @file include/md5.h
9  * @brief Structures and prototypes for md5.
10  */
11 RCSIDH(md5_h, "$Id: 268196dc6a0b39afbbaf10d03fb174c370bccba9 $")
12 
13 #ifdef HAVE_INTTYPES_H
14 # include <inttypes.h>
15 #endif
16 
17 #ifdef HAVE_SYS_TYPES_H
18 # include <sys/types.h>
19 #endif
20 
21 #ifdef HAVE_STDINT_H
22 # include <stdint.h>
23 #endif
24 
25 # include <string.h>
26 
27 #ifdef HAVE_OPENSSL_EVP_H
28 # include <openssl/evp.h>
29 #endif
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #ifndef MD5_DIGEST_LENGTH
36 # define MD5_DIGEST_LENGTH 16
37 #endif
38 
39 #ifndef HAVE_OPENSSL_EVP_H
40 /*
41  * The MD5 code used here and in md5.c was originally retrieved from:
42  * http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/crypto/md5.h?rev=1.1
43  *
44  * This code implements the MD5 message-digest algorithm.
45  * The algorithm is due to Ron Rivest. This code was
46  * written by Colin Plumb in 1993, no copyright is claimed.
47  * This code is in the public domain; do with it what you wish.
48  *
49  * Equivalent code is available from RSA Data Security, Inc.
50  * This code has been tested against that, and is equivalent,
51  * except that you don't need to include two pages of legalese
52  * with every copy.
53  */
54 # define MD5_BLOCK_LENGTH 64
55 typedef struct FR_MD5Context {
56  uint32_t state[4]; //!< State.
57  uint32_t count[2]; //!< Number of bits, mod 2^64.
58  uint8_t buffer[MD5_BLOCK_LENGTH]; //!< Input buffer.
59 } FR_MD5_CTX;
60 
61 void fr_md5_init(FR_MD5_CTX *ctx);
62 void fr_md5_update(FR_MD5_CTX *ctx, uint8_t const *in, size_t inlen)
63  CC_BOUNDED(__string__, 2, 3);
64 void fr_md5_final(uint8_t out[MD5_DIGEST_LENGTH], FR_MD5_CTX *ctx)
65  CC_BOUNDED(__minbytes__, 1, MD5_DIGEST_LENGTH);
66 void fr_md5_transform(uint32_t state[4], uint8_t const block[MD5_BLOCK_LENGTH])
67  CC_BOUNDED(__size__, 1, 4, 4)
68  CC_BOUNDED(__minbytes__, 2, MD5_BLOCK_LENGTH);
69 # define fr_md5_copy(_out, _in) memcpy(_out, _in, sizeof(*_out))
70 #else /* HAVE_OPENSSL_EVP_H */
72 #include <openssl/md5.h>
73 # define FR_MD5_CTX MD5_CTX
74 # define fr_md5_init MD5_Init
75 # define fr_md5_update MD5_Update
76 # define fr_md5_final MD5_Final
77 # define fr_md5_transform MD5_Transform
78 # define fr_md5_copy(_out, _in) memcpy(_out, _in, sizeof(*_out))
79 #endif
80 
81 /* hmac.c */
82 void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *text, size_t text_len,
83  uint8_t const *key, size_t key_len)
84  CC_BOUNDED(__minbytes__, 1, MD5_DIGEST_LENGTH);
85 
86 /* md5.c */
87 void fr_md5_calc(uint8_t *out, uint8_t const *in, size_t inlen);
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif /* _FR_MD5_H */
void fr_md5_calc(uint8_t *out, uint8_t const *in, size_t inlen)
Calculate the MD5 hash of the contents of a buffer.
Definition: md5.c:28
#define RCSIDH(h, id)
Definition: build.h:136
uint32_t count[2]
Number of bits, mod 2^64.
Definition: md5.h:57
#define MD5_BLOCK_LENGTH
Definition: md5.h:54
void fr_md5_init(FR_MD5_CTX *ctx)
Initialise a new MD5 context.
Definition: md5.c:84
void fr_md5_update(FR_MD5_CTX *ctx, uint8_t const *in, size_t inlen) CC_BOUNDED(__string__
uint8_t buffer[MD5_BLOCK_LENGTH]
Input buffer.
Definition: md5.h:58
struct FR_MD5Context FR_MD5_CTX
void fr_hmac_md5(uint8_t digest[MD5_DIGEST_LENGTH], uint8_t const *text, size_t text_len, uint8_t const *key, size_t key_len) CC_BOUNDED(__minbytes__
#define CC_BOUNDED(...)
Definition: build.h:77
uint32_t state[4]
State.
Definition: md5.h:56
unsigned int state
Definition: proto_bfd.c:200
void void fr_md5_final(uint8_t out[MD5_DIGEST_LENGTH], FR_MD5_CTX *ctx) CC_BOUNDED(__minbytes__
#define MD5_DIGEST_LENGTH
Definition: md5.h:36
void fr_md5_transform(uint32_t state[4], uint8_t const block[MD5_BLOCK_LENGTH]) CC_BOUNDED(__minbytes__
#define USES_APPLE_DEPRECATED_API
Definition: build.h:122