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