xref: /openbsd/lib/libcrypto/man/MD5.3 (revision 6427274d)
1.\"	$OpenBSD: MD5.3,v 1.9 2024/05/26 09:54:16 tb Exp $
2.\"	OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
3.\"
4.\" This file was written by Ulf Moeller <ulf@openssl.org> and
5.\" Richard Levitte <levitte@openssl.org>.
6.\" Copyright (c) 2000, 2006 The OpenSSL Project.  All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in
17.\"    the documentation and/or other materials provided with the
18.\"    distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\"    software must display the following acknowledgment:
22.\"    "This product includes software developed by the OpenSSL Project
23.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\"    endorse or promote products derived from this software without
27.\"    prior written permission. For written permission, please contact
28.\"    openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\"    nor may "OpenSSL" appear in their names without prior written
32.\"    permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\"    acknowledgment:
36.\"    "This product includes software developed by the OpenSSL Project
37.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: May 26 2024 $
53.Dt MD5 3
54.Os
55.Sh NAME
56.Nm MD4 ,
57.Nm MD5 ,
58.Nm MD4_Init ,
59.Nm MD4_Update ,
60.Nm MD4_Final ,
61.Nm MD5_Init ,
62.Nm MD5_Update ,
63.Nm MD5_Final
64.Nd MD4 and MD5 hash functions
65.Sh SYNOPSIS
66.In openssl/md4.h
67.Ft unsigned char *
68.Fo MD4
69.Fa "const unsigned char *d"
70.Fa "unsigned long n"
71.Fa "unsigned char *md"
72.Fc
73.Ft int
74.Fo MD4_Init
75.Fa "MD4_CTX *c"
76.Fc
77.Ft int
78.Fo MD4_Update
79.Fa "MD4_CTX *c"
80.Fa "const void *data"
81.Fa "unsigned long len"
82.Fc
83.Ft int
84.Fo MD4_Final
85.Fa "unsigned char *md"
86.Fa "MD4_CTX *c"
87.Fc
88.In openssl/md5.h
89.Ft unsigned char *
90.Fo MD5
91.Fa "const unsigned char *d"
92.Fa "unsigned long n"
93.Fa "unsigned char *md"
94.Fc
95.Ft int
96.Fo MD5_Init
97.Fa "MD5_CTX *c"
98.Fc
99.Ft int
100.Fo MD5_Update
101.Fa "MD5_CTX *c"
102.Fa "const void *data"
103.Fa "unsigned long len"
104.Fc
105.Ft int
106.Fo MD5_Final
107.Fa "unsigned char *md"
108.Fa "MD5_CTX *c"
109.Fc
110.Sh DESCRIPTION
111MD4 and MD5 are cryptographic hash functions with a 128-bit
112output.
113.Pp
114.Fn MD4
115and
116.Fn MD5
117compute the MD4 and MD5 message digest of the
118.Fa n
119bytes at
120.Fa d
121and place it in
122.Fa md ,
123which must have space for
124.Dv MD4_DIGEST_LENGTH No == Dv MD5_DIGEST_LENGTH No == 16
125bytes of output.
126.Pp
127The following functions may be used if the message is not completely
128stored in memory:
129.Pp
130.Fn MD5_Init
131initializes a
132.Vt MD5_CTX
133structure.
134.Pp
135.Fn MD5_Update
136can be called repeatedly with chunks of the message to be hashed
137.Pq Fa len No bytes at Fa data .
138.Pp
139.Fn MD5_Final
140places the message digest in
141.Fa md ,
142which must have space for
143.Dv MD5_DIGEST_LENGTH No == 16
144bytes of output, and erases the
145.Vt MD5_CTX .
146.Pp
147.Fn MD4_Init ,
148.Fn MD4_Update ,
149and
150.Fn MD4_Final
151are analogous using an
152.Vt MD4_CTX
153structure.
154.Pp
155Applications should use the higher level functions
156.Xr EVP_DigestInit 3
157etc. instead of calling these hash functions directly.
158.Sh RETURN VALUES
159.Fn MD4
160and
161.Fn MD5
162return pointers to the hash value.
163.Pp
164.Fn MD4_Init ,
165.Fn MD4_Update ,
166.Fn MD4_Final ,
167.Fn MD5_Init ,
168.Fn MD5_Update ,
169and
170.Fn MD5_Final
171return 1 for success or 0 otherwise.
172.Sh SEE ALSO
173.Xr EVP_DigestInit 3
174.Sh STANDARDS
175RFC 1320, RFC 1321
176.Sh HISTORY
177.Fn MD5 ,
178.Fn MD5_Init ,
179.Fn MD5_Update ,
180and
181.Fn MD5_Final
182appeared in SSLeay 0.4 or earlier and have been available since
183.Ox 2.4 .
184.Pp
185.Fn MD4 ,
186.Fn MD4_Init ,
187.Fn MD4_Update ,
188and
189.Fn MD4_Final
190first appeared in OpenSSL 0.9.6 and have been available since
191.Ox 2.9 .
192.Sh CAVEATS
193Other implementations allow
194.Fa md
195in
196.Fn MD4
197and
198.Fn MD5
199to be
200.Dv NULL
201and return a static array, which is not thread safe.
202