1RMD160(3)                BSD Library Functions Manual                RMD160(3)
2

NAME

4     RMD160Init, RMD160Update, RMD160Pad, RMD160Final, RMD160Transform,
5     RMD160End, RMD160File, RMD160FileChunk, RMD160Data — calculate the
6     ``RIPEMD-160'' message digest
7

LIBRARY

9     Message Digest (MD4, MD5, etc.) Support Library (libmd, -lmd)
10

SYNOPSIS

12     #include <sys/types.h>
13     #include <rmd160.h>
14
15     void
16     RMD160Init(RMD160_CTX *context);
17
18     void
19     RMD160Update(RMD160_CTX *context, const uint8_t *data, uint32_t nbytes);
20
21     void
22     RMD160Pad(RMD160_CTX *context);
23
24     void
25     RMD160Final(uint8_t digest[RMD160_DIGEST_LENGTH], RMD160_CTX *context);
26
27     void
28     RMD160Transform(uint32_t state[5],
29         const uint8_t block[RMD160_BLOCK_LENGTH]);
30
31     char *
32     RMD160End(RMD160_CTX *context, char *buf);
33
34     char *
35     RMD160File(const char *filename, char *buf);
36
37     char *
38     RMD160FileChunk(const char *filename, char *buf, off_t offset,
39         off_t length);
40
41     char *
42     RMD160Data(const uint8_t *data, size_t len, char *buf);
43

DESCRIPTION

45     The RMD160 functions implement the 160-bit RIPE message digest hash algo‐
46     rithm (RMD-160).  RMD-160 is used to generate a condensed representation
47     of a message called a message digest.  The algorithm takes a message less
48     than 2^64 bits as input and produces a 160-bit digest suitable for use as
49     a digital signature.
50
51     The RMD160 functions are considered to be more secure than the md4(3),
52     md5(3) and sha1(3) functions.  All share a similar interface.
53
54     The RMD160Init() function initializes a RMD160_CTX context for use with
55     RMD160Update(), and RMD160Final().  The RMD160Update() function adds data
56     of length nbytes to the RMD160_CTX specified by context.  RMD160Final()
57     is called when all data has been added via RMD160Update() and stores a
58     message digest in the digest parameter.
59
60     The RMD160Pad() function can be used to apply padding to the message di‐
61     gest as in RMD160Final(), but the current context can still be used with
62     RMD160Update().
63
64     The RMD160Transform() function is used by RMD160Update() to hash 512-bit
65     blocks and forms the core of the algorithm.  Most programs should use the
66     interface provided by RMD160Init(), RMD160Update() and RMD160Final() in‐
67     stead of calling RMD160Transform() directly.
68
69     The RMD160End() function is a front end for RMD160Final() which converts
70     the digest into an ASCII representation of the 160 bit digest in hexadec‐
71     imal.
72
73     The RMD160File() function calculates the digest for a file and returns
74     the result via RMD160End().  If RMD160File() is unable to open the file a
75     NULL pointer is returned.
76
77     RMD160FileChunk() behaves like RMD160File() but calculates the digest
78     only for that portion of the file starting at offset and continuing for
79     length bytes or until end of file is reached, whichever comes first.  A
80     zero length can be specified to read until end of file.  A negative
81     length or offset will be ignored.
82
83     The RMD160Data() function calculates the digest of an arbitrary string
84     and returns the result via RMD160End().
85
86     For each of the RMD160End(), RMD160File(), and RMD160Data() functions the
87     buf parameter should either be a string of at least 41 characters in size
88     or a NULL pointer.  In the latter case, space will be dynamically allo‐
89     cated via malloc(3) and should be freed using free(3) when it is no
90     longer needed.
91

EXAMPLES

93     The follow code fragment will calculate the digest for the string "abc"
94     which is ``0x8eb208f7e05d987a9b044a8e98c6b087f15a0bfc''.
95
96           RMD160_CTX rmd;
97           uint8_t results[RMD160_DIGEST_LENGTH];
98           char *buf;
99           int n;
100
101           buf = "abc";
102           n = strlen(buf);
103           RMD160Init(&rmd);
104           RMD160Update(&rmd, (uint8_t *)buf, n);
105           RMD160Final(results, &rmd);
106
107           /* Print the digest as one long hex value */
108           printf("0x");
109           for (n = 0; n < RMD160_DIGEST_LENGTH; n++)
110                   printf("%02x", results[n]);
111           putchar('\n');
112
113     Alternately, the helper functions could be used in the following way:
114
115           RMD160_CTX rmd;
116           uint8_t output[RMD160_DIGEST_STRING_LENGTH];
117           char *buf = "abc";
118
119           printf("0x%s\n", RMD160Data(buf, strlen(buf), output));
120

SEE ALSO

122     cksum(1), md4(3), md5(3), sha1(3), sha2(3)
123
124     H. Dobbertin, A. Bosselaers, B. Preneel, RIPEMD-160, a strengthened
125     version of RIPEMD.
126
127     Information technology - Security techniques - Hash-functions - Part 3:
128     Dedicated hash-functions, ISO/IEC 10118-3.
129
130     H. Dobbertin, A. Bosselaers, B. Preneel, “The RIPEMD-160 cryptographic
131     hash function”, Dr. Dobb's Journal, Vol. 22, No. 1, pp. 24-28, January
132     1997.
133

HISTORY

135     The RMD-160 functions appeared in OpenBSD 2.1.
136

AUTHORS

138     This implementation of RMD-160 was written by Markus Friedl.
139
140     The RMD160End(), RMD160File(), RMD160FileChunk(), and RMD160Data() helper
141     functions are derived from code written by Poul-Henning Kamp.
142

CAVEATS

144     If a message digest is to be copied to a multi-byte type (ie: an array of
145     five 32-bit integers) it will be necessary to perform byte swapping on
146     little endian machines such as the i386, alpha, and vax.
147
148BSD                              July 13, 2010                             BSD
Impressum