import from branch_1_1:
[freeradius.git] / src / include / md5.h
1 /*
2  * md5.h        Structures and prototypes for md5.
3  *
4  * Version:     $Id$
5  * License:             LGPL, but largely derived from a public domain source.
6  *
7  */
8
9 #ifndef _LRAD_MD5_H
10 #define _LRAD_MD5_H
11
12 #include <freeradius-devel/ident.h>
13 RCSIDH(md5_h, "$Id$")
14
15 #ifdef HAVE_INTTYPES_H
16 #include <inttypes.h>
17 #endif
18
19 #ifdef HAVE_SYS_TYPES_H
20 #include <sys/types.h>
21 #endif
22
23 #ifdef HAVE_STDINT_H
24 #include <stdint.h>
25 #endif
26
27 #include <string.h>
28 /*
29  *  FreeRADIUS defines to ensure globally unique MD5 function names,
30  *  so that we don't pick up vendor-specific broken MD5 libraries.
31  */
32 #define MD5_CTX         lrad_MD5_CTX
33 #define MD5Init         lrad_MD5Init
34 #define MD5Update       lrad_MD5Update
35 #define MD5Final        lrad_MD5Final
36 #define MD5Transform    lrad_MD5Transform
37
38
39 /*  The below was retrieved from
40  *  http://www.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/crypto/md5.h?rev=1.1
41  *  With the following changes: uint64_t => uint32_t[2]
42  *  Commented out #include <sys/cdefs.h>
43  *  Commented out the __BEGIN and __END _DECLS, and the __attributes.
44  */
45
46 /*
47  * This code implements the MD5 message-digest algorithm.
48  * The algorithm is due to Ron Rivest.  This code was
49  * written by Colin Plumb in 1993, no copyright is claimed.
50  * This code is in the public domain; do with it what you wish.
51  *
52  * Equivalent code is available from RSA Data Security, Inc.
53  * This code has been tested against that, and is equivalent,
54  * except that you don't need to include two pages of legalese
55  * with every copy.
56  */
57
58 #define MD5_BLOCK_LENGTH                64
59 #define MD5_DIGEST_LENGTH               16
60
61 typedef struct lrad_MD5Context {
62         uint32_t state[4];                      /* state */
63         uint32_t count[2];                      /* number of bits, mod 2^64 */
64         uint8_t buffer[MD5_BLOCK_LENGTH];       /* input buffer */
65 } lrad_MD5_CTX;
66
67 /* include <sys/cdefs.h> */
68
69 /* __BEGIN_DECLS */
70 void     lrad_MD5Init(lrad_MD5_CTX *);
71 void     lrad_MD5Update(lrad_MD5_CTX *, const uint8_t *, size_t)
72 /*              __attribute__((__bounded__(__string__,2,3)))*/;
73 void     lrad_MD5Final(uint8_t [MD5_DIGEST_LENGTH], lrad_MD5_CTX *)
74 /*              __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)))*/;
75 void     lrad_MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH])
76 /*              __attribute__((__bounded__(__minbytes__,1,4)))*/
77 /*              __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)))*/;
78 /* __END_DECLS */
79
80 #endif /* _LRAD_MD5_H */