xref: /minix/lib/libc/hash/rmd160/rmd160.3 (revision 83ee113e)
1.\"	$NetBSD: rmd160.3,v 1.3 2010/04/05 21:26:30 joerg Exp $
2.\"	$OpenBSD: rmd160.3,v 1.12 2000/04/18 03:01:29 aaron Exp $
3.\"
4.\" Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. The name of the author may not be used to endorse or promote products
16.\"    derived from this software without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
21.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28.\"
29.\" See http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
30.\"	for detailed information about RIPEMD-160.
31.\"
32.Dd July 16, 1997
33.Dt RMD160 3
34.Os
35.Sh NAME
36.Nm RMD160Init ,
37.Nm RMD160Update ,
38.Nm RMD160Final ,
39.Nm RMD160Transform ,
40.Nm RMD160End ,
41.Nm RMD160File ,
42.Nm RMD160Data
43.Nd calculate the ``RIPEMD-160'' message digest
44.Sh SYNOPSIS
45.In sys/types.h
46.In rmd160.h
47.Ft void
48.Fn RMD160Init "RMD160_CTX *context"
49.Ft void
50.Fn RMD160Update "RMD160_CTX *context" "const u_char *data" "u_int nbytes"
51.Ft void
52.Fn RMD160Final "u_char digest[20]" "RMD160_CTX *context"
53.Ft void
54.Fn RMD160Transform "uint32_t state[5]" "const uint32_t block[16]"
55.Ft "char *"
56.Fn RMD160End "RMD160_CTX *context" "char *buf"
57.Ft "char *"
58.Fn RMD160File "char *filename" "char *buf"
59.Ft "char *"
60.Fn RMD160Data "u_char *data" "size_t len" "char *buf"
61.Sh DESCRIPTION
62The RMD160 functions implement the 160-bit RIPE message digest hash algorithm
63(RMD-160).
64RMD-160 is used to generate a condensed representation
65of a message called a message digest.
66The algorithm takes a
67message less than 2^64 bits as input and produces a 160-bit digest
68suitable for use as a digital signature.
69.Pp
70The RMD160 functions are considered to be more secure than the
71.Xr md4 3
72and
73.Xr md5 3
74functions and at least as secure as the
75.Xr sha1 3
76function.
77All share a similar interface.
78.Pp
79The
80.Fn RMD160Init
81function initializes a RMD160_CTX
82.Ar context
83for use with
84.Fn RMD160Update ,
85and
86.Fn RMD160Final .
87The
88.Fn RMD160Update
89function adds
90.Ar data
91of length
92.Ar nbytes
93to the RMD160_CTX specified by
94.Ar context .
95.Fn RMD160Final
96is called when all data has been added via
97.Fn RMD160Update
98and stores a message digest in the
99.Ar digest
100parameter.
101When a null pointer is passed to
102.Fn RMD160Final
103as first argument only the final padding will be applied and the
104current context can still be used with
105.Fn RMD160Update .
106.Pp
107The
108.Fn RMD160Transform
109function is used by
110.Fn RMD160Update
111to hash 512-bit blocks and forms the core of the algorithm.
112Most programs should use the interface provided by
113.Fn RMD160Init ,
114.Fn RMD160Update
115and
116.Fn RMD160Final
117instead of calling
118.Fn RMD160Transform
119directly.
120.Pp
121The
122.Fn RMD160End
123function is a front end for
124.Fn RMD160Final
125which converts the digest into an
126.Tn ASCII
127representation of the 160 bit digest in hexadecimal.
128.Pp
129The
130.Fn RMD160File
131function calculates the digest for a file and returns the result via
132.Fn RMD160End .
133If
134.Fn RMD160File
135is unable to open the file a NULL pointer is returned.
136.Pp
137The
138.Fn RMD160Data
139function
140calculates the digest of an arbitrary string and returns the result via
141.Fn RMD160End .
142.Pp
143For each of the
144.Fn RMD160End ,
145.Fn RMD160File ,
146and
147.Fn RMD160Data
148functions the
149.Ar buf
150parameter should either be a string of at least 41 characters in
151size or a NULL pointer.
152In the latter case, space will be dynamically allocated via
153.Xr malloc 3
154and should be freed using
155.Xr free 3
156when it is no longer needed.
157.Sh EXAMPLES
158The follow code fragment will calculate the digest for
159the string "abc" which is ``0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc''.
160.Bd -literal -offset indent
161RMD160_CTX rmd;
162u_char results[20];
163char *buf;
164int n;
165
166buf = "abc";
167n = strlen(buf);
168RMD160Init(\*[Am]rmd);
169RMD160Update(\*[Am]rmd, (u_char *)buf, n);
170RMD160Final(results, \*[Am]rmd);
171
172/* Print the digest as one long hex value */
173printf("0x");
174for (n = 0; n \*[Lt] 20; n++)
175	printf("%02x", results[n]);
176putchar('\en');
177.Ed
178.Pp
179Alternately, the helper functions could be used in the following way:
180.Bd -literal -offset indent
181RMD160_CTX rmd;
182u_char output[41];
183char *buf = "abc";
184
185printf("0x%s\en", RMD160Data(buf, strlen(buf), output));
186.Ed
187.Sh SEE ALSO
188.Xr rmd160 1 ,
189.Xr md4 3 ,
190.Xr md5 3 ,
191.Xr sha1 3
192.Pp
193.Rs
194.%A H. Dobbertin, A. Bosselaers, B. Preneel
195.%T RIPEMD-160, a strengthened version of RIPEMD
196.Re
197.Rs
198.%T Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions
199.%O ISO/IEC 10118-3
200.Re
201.Rs
202.%A H. Dobbertin, A. Bosselaers, B. Preneel
203.%T The RIPEMD-160 cryptographic hash function
204.%J Dr. Dobb's Journal
205.%V Vol. 22, No. 1
206.%D January 1997
207.%P pp. 24-28
208.Re
209.Sh HISTORY
210The RMD-160 functions appeared in
211.Ox 2.1 .
212.Sh AUTHORS
213This implementation of RMD-160 was written by Antoon Bosselaers.
214.Pp
215The
216.Fn RMD160End ,
217.Fn RMD160File ,
218and
219.Fn RMD160Data
220helper functions are derived from code written by Poul-Henning Kamp.
221.Sh BUGS
222If a message digest is to be copied to a multi-byte type (ie:
223an array of five 32-bit integers) it will be necessary to
224perform byte swapping on little endian machines such as the i386, alpha,
225and VAX.
226