1md5(3EXT)                 Extended Library Functions                 md5(3EXT)
2
3
4

NAME

6       md5, md5_calc, MD5Init, MD5Update, MD5Final - MD5 digest functions
7

SYNOPSIS

9       cc [ flag ... ] file ... -lmd5 [ library ... ]
10       #include <md5.h>
11
12       void md5_calc(unsigned char *output, unsigned char *input,
13            unsigned int inlen);
14
15
16       void MD5Init(MD5_CTX *context);
17
18
19       void MD5Update(MD5_CTX *context, unsigned char *input,
20            unsigned int inlen);
21
22
23       void MD5Final(unsigned char *output, MD5_CTX *context);
24
25

DESCRIPTION

27       These functions implement the MD5 message-digest algorithm, which takes
28       as input a message of arbitrary length and produces as output a 128-bit
29       "fingerprint" or "message digest" of the input. It is intended for dig‐
30       ital signature applications, where large file must be "compressed" in a
31       secure  manner before being encrypted with a private (secret) key under
32       a public-key cryptosystem such as RSA.
33
34   md5_calc()
35       The md5_calc() function computes an MD5  digest  on  a  single  message
36       block. The inlen-byte block is pointed to by input, and the 16-byte MD5
37       digest is written to output.
38
39   MD5Init(), MD5Update(), MD5Final()
40       The MD5Init(), MD5Update(),  and  MD5Final()  functions  allow  an  MD5
41       digest to be computed over multiple message blocks; between blocks, the
42       state of the MD5 computation is held in an MD5 context structure, allo‐
43       cated by the caller. A complete digest computation consists of one call
44       to MD5Init(), one or  more  calls  to  MD5Update(),  and  one  call  to
45       MD5Final(), in that order.
46
47
48       The MD5Init() function initializes the MD5 context structure pointed to
49       by context.
50
51
52       The MD5Update() function computes a partial MD5 digest  on  the  inlen-
53       byte  message  block  pointed  to by input, and updates the MD5 context
54       structure pointed to by context accordingly.
55
56
57       The MD5Final() function generates the final MD5 digest, using  the  MD5
58       context  structure  pointed  to  by  context; the 16-byte MD5 digest is
59       written to output. After calling MD5Final(), the state of  the  context
60       structure  is undefined; it must be reinitialized with MD5Init() before
61       being used again.
62

RETURN VALUES

64       These functions do not return a value.
65

EXAMPLES

67       Example 1 Authenticate a message found in multiple buffers
68
69
70       The following is a sample function that  must  authenticate  a  message
71       that  is  found  in  multiple buffers. The calling function provides an
72       authentication buffer that will contain the result of the MD5 digest.
73
74
75         #include <sys/types.h>
76         #include <sys/uio.h>
77         #include <md5.h>
78
79         int
80         AuthenticateMsg(unsigned char *auth_buffer, struct iovec
81                         *messageIov, unsigned int num_buffers)
82         {
83             MD5_CTX md5_context;
84             unsigned int i;
85
86             MD5Init(&md5_context);
87
88             for(i=0; i<num_buffers; i++)
89             {
90                  MD5Update(&md5_context, messageIov->iov_base,
91                            messageIov->iov_len);
92                  messageIov += sizeof(struct iovec);
93             }
94
95             MD5Final(auth_buffer, &md5_context);
96
97             return 0;
98         }
99
100
101       Example 2 Use md5_calc() to generate the MD5 digest
102
103
104       Since the buffer to be computed is contiguous, the md5_calc()  function
105       can be used to generate the MD5 digest.
106
107
108         int AuthenticateMsg(unsigned char *auth_buffer, unsigned
109                             char *buffer, unsigned int length)
110         {
111             md5_calc(buffer, auth_buffer, length);
112
113             return (0);
114         }
115
116

ATTRIBUTES

118       See attributes(5) for descriptions of the following attributes:
119
120
121
122
123       ┌─────────────────────────────┬─────────────────────────────┐
124       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
125       ├─────────────────────────────┼─────────────────────────────┤
126       │Interface Stability          │Committed                    │
127       ├─────────────────────────────┼─────────────────────────────┤
128       │MT-Level                     │MT-Safe                      │
129       └─────────────────────────────┴─────────────────────────────┘
130

SEE ALSO

132       libmd5(3LIB)
133
134
135       Rivest, R., The MD5 Message-Digest Algorithm, RFC 1321, April 1992.
136
137
138
139SunOS 5.11                        13 Nov 2007                        md5(3EXT)
Impressum