xref: /openbsd/lib/libc/hash/RMD160Init.3 (revision 905646f0)
1.\"	$OpenBSD: RMD160Init.3,v 1.2 2019/12/05 21:45:05 jmc Exp $
2.\"
3.\" Copyright (c) 1997, 2004 Todd C. Miller <millert@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.\" See http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
18.\"	for detailed information about RIPEMD-160.
19.\"
20.Dd $Mdocdate: December 5 2019 $
21.Dt RMD160INIT 3
22.Os
23.Sh NAME
24.Nm RMD160Init ,
25.Nm RMD160Update ,
26.Nm RMD160Pad ,
27.Nm RMD160Final ,
28.Nm RMD160Transform ,
29.Nm RMD160End ,
30.Nm RMD160File ,
31.Nm RMD160FileChunk ,
32.Nm RMD160Data
33.Nd calculate the RIPEMD-160 message digest
34.Sh SYNOPSIS
35.In sys/types.h
36.In rmd160.h
37.Ft void
38.Fn RMD160Init "RMD160_CTX *context"
39.Ft void
40.Fn RMD160Update "RMD160_CTX *context" "const u_int8_t *data" "size_t nbytes"
41.Ft void
42.Fn RMD160Pad "RMD160_CTX *context"
43.Ft void
44.Fn RMD160Final "u_int8_t digest[RMD160_DIGEST_LENGTH]" "RMD160_CTX *context"
45.Ft void
46.Fn RMD160Transform "u_int32_t state[5]" "const u_int8_t block[RMD160_BLOCK_LENGTH]"
47.Ft "char *"
48.Fn RMD160End "RMD160_CTX *context" "char *buf"
49.Ft "char *"
50.Fn RMD160File "const char *filename" "char *buf"
51.Ft "char *"
52.Fn RMD160FileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
53.Ft "char *"
54.Fn RMD160Data "const u_int8_t *data" "size_t len" "char *buf"
55.Sh DESCRIPTION
56The RMD160 functions implement the 160-bit RIPE message digest hash algorithm
57(RMD-160).
58RMD-160 is used to generate a condensed representation
59of a message called a message digest.
60The algorithm takes a
61message less than 2^64 bits as input and produces a 160-bit digest
62suitable for use as a digital signature.
63.Pp
64The RMD160 functions are considered to be more secure than the
65MD5
66functions and at least as secure as the
67SHA1
68function.
69All share a similar interface.
70.Pp
71The
72.Fn RMD160Init
73function initializes a RMD160_CTX
74.Ar context
75for use with
76.Fn RMD160Update ,
77and
78.Fn RMD160Final .
79The
80.Fn RMD160Update
81function adds
82.Ar data
83of length
84.Ar nbytes
85to the RMD160_CTX specified by
86.Ar context .
87.Fn RMD160Final
88is called when all data has been added via
89.Fn RMD160Update
90and stores a message digest in the
91.Ar digest
92parameter.
93.Pp
94The
95.Fn RMD160Pad
96function can be used to apply padding to the message digest as in
97.Fn RMD160Final ,
98but the current context can still be used with
99.Fn RMD160Update .
100.Pp
101The
102.Fn RMD160Transform
103function is used by
104.Fn RMD160Update
105to hash 512-bit blocks and forms the core of the algorithm.
106Most programs should use the interface provided by
107.Fn RMD160Init ,
108.Fn RMD160Update
109and
110.Fn RMD160Final
111instead of calling
112.Fn RMD160Transform
113directly.
114.Pp
115The
116.Fn RMD160End
117function is a front end for
118.Fn RMD160Final
119which converts the digest into an ASCII
120representation of the 160 bit digest in hexadecimal.
121.Pp
122The
123.Fn RMD160File
124function calculates the digest for a file and returns the result via
125.Fn RMD160End .
126If
127.Fn RMD160File
128is unable to open the file a NULL pointer is returned.
129.Pp
130.Fn RMD160FileChunk
131behaves like
132.Fn RMD160File
133but calculates the digest only for that portion of the file starting at
134.Fa offset
135and continuing for
136.Fa length
137bytes or until end of file is reached, whichever comes first.
138A zero
139.Fa length
140can be specified to read until end of file.
141A negative
142.Fa length
143or
144.Fa offset
145will be ignored.
146.Pp
147The
148.Fn RMD160Data
149function
150calculates the digest of an arbitrary string and returns the result via
151.Fn RMD160End .
152.Pp
153For each of the
154.Fn RMD160End ,
155.Fn RMD160File ,
156and
157.Fn RMD160Data
158functions the
159.Ar buf
160parameter should either be a string of at least 41 characters in
161size or a NULL pointer.
162In the latter case, space will be dynamically allocated via
163.Xr malloc 3
164and should be freed using
165.Xr free 3
166when it is no longer needed.
167.Sh EXAMPLES
168The follow code fragment will calculate the digest for
169the string
170.Dq abc
171which is
172.Dq 0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc .
173.Bd -literal -offset indent
174RMD160_CTX rmd;
175u_int8_t results[RMD160_DIGEST_LENGTH];
176char *buf;
177int n;
178
179buf = "abc";
180n = strlen(buf);
181RMD160Init(&rmd);
182RMD160Update(&rmd, (u_int8_t *)buf, n);
183RMD160Final(results, &rmd);
184
185/* Print the digest as one long hex value */
186printf("0x");
187for (n = 0; n < RMD160_DIGEST_LENGTH; n++)
188	printf("%02x", results[n]);
189putchar('\en');
190.Ed
191.Pp
192Alternately, the helper functions could be used in the following way:
193.Bd -literal -offset indent
194RMD160_CTX rmd;
195u_int8_t output[RMD160_DIGEST_STRING_LENGTH];
196char *buf = "abc";
197
198printf("0x%s\en", RMD160Data(buf, strlen(buf), output));
199.Ed
200.Sh SEE ALSO
201.Xr cksum 1 ,
202.Xr MD5Init 3 ,
203.Xr SHA1Init 3 ,
204.Xr SHA256Init 3
205.Rs
206.%A H. Dobbertin, A. Bosselaers, B. Preneel
207.%T RIPEMD-160, a strengthened version of RIPEMD
208.Re
209.Rs
210.%T Information technology - Security techniques - Hash-functions - Part 3: Dedicated hash-functions
211.%O ISO/IEC 10118-3
212.Re
213.Rs
214.%A H. Dobbertin, A. Bosselaers, B. Preneel
215.%T The RIPEMD-160 cryptographic hash function
216.%J Dr. Dobb's Journal
217.%V Vol. 22, No. 1
218.%D January 1997
219.%P pp. 24-28
220.Re
221.Sh HISTORY
222The RMD-160 functions appeared in
223.Ox 2.1 .
224.Sh AUTHORS
225.An -nosplit
226This implementation of RMD-160 was written by
227.An Markus Friedl .
228.Pp
229The
230.Fn RMD160End ,
231.Fn RMD160File ,
232.Fn RMD160FileChunk ,
233and
234.Fn RMD160Data
235helper functions are derived from code written by
236.An Poul-Henning Kamp .
237