1MD4(3)                User Contributed Perl Documentation               MD4(3)
2
3
4

NAME

6       Digest::MD4 - Perl interface to the MD4 Algorithm
7

SYNOPSIS

9        # Functional style
10        use Digest::MD4 qw(md4 md4_hex md4_base64);
11
12        $digest = md4($data);
13        $digest = md4_hex($data);
14        $digest = md4_base64($data);
15
16        # OO style
17        use Digest::MD4;
18
19        $ctx = Digest::MD4->new;
20
21        $ctx->add($data);
22        $ctx->addfile(*FILE);
23
24        $digest = $ctx->digest;
25        $digest = $ctx->hexdigest;
26        $digest = $ctx->b64digest;
27

DESCRIPTION

29       The "Digest::MD4" module allows you to use the RSA Data Security Inc.
30       MD4 Message Digest algorithm from within Perl programs.  The algorithm
31       takes as input a message of arbitrary length and produces as output a
32       128-bit "fingerprint" or "message digest" of the input.
33
34       The "Digest::MD4" module provide a procedural interface for simple use,
35       as well as an object oriented interface that can handle messages of
36       arbitrary length and which can read files directly.
37

FUNCTIONS

39       The following functions are provided by the "Digest::MD4" module.  None
40       of these functions are exported by default.
41
42       md4($data,...)
43           This function will concatenate all arguments, calculate the MD4
44           digest of this "message", and return it in binary form.  The
45           returned string will be 16 bytes long.
46
47           The result of md4("a", "b", "c") will be exactly the same as the
48           result of md4("abc").
49
50       md4_hex($data,...)
51           Same as md4(), but will return the digest in hexadecimal form. The
52           length of the returned string will be 32 and it will only contain
53           characters from this set: '0'..'9' and 'a'..'f'.
54
55       md4_base64($data,...)
56           Same as md4(), but will return the digest as a base64 encoded
57           string.  The length of the returned string will be 22 and it will
58           only contain characters from this set: 'A'..'Z', 'a'..'z',
59           '0'..'9', '+' and '/'.
60
61           Note that the base64 encoded string returned is not padded to be a
62           multiple of 4 bytes long.  If you want interoperability with other
63           base64 encoded md4 digests you might want to append the redundant
64           string "==" to the result.
65

METHODS

67       The object oriented interface to "Digest::MD4" is described in this
68       section.  After a "Digest::MD4" object has been created, you will add
69       data to it and finally ask for the digest in a suitable format.  A
70       single object can be used to calculate multiple digests.
71
72       The following methods are provided:
73
74       $md4 = Digest::MD4->new
75           The constructor returns a new "Digest::MD4" object which
76           encapsulate the state of the MD4 message-digest algorithm.
77
78           If called as an instance method (i.e. $md4->new) it will just reset
79           the state the object to the state of a newly created object.  No
80           new object is created in this case.
81
82       $md4->reset
83           This is just an alias for $md4->new.
84
85       $md4->clone
86           This a copy of the $md4 object. It is useful when you do not want
87           to destroy the digests state, but need an intermediate value of the
88           digest, e.g. when calculating digests iteratively on a continuous
89           data stream.  Example:
90
91               my $md4 = Digest::MD4->new;
92               while (<>) {
93                   $md4->add($_);
94                   print "Line $.: ", $md4->clone->hexdigest, "\n";
95               }
96
97       $md4->add($data,...)
98           The $data provided as argument are appended to the message we
99           calculate the digest for.  The return value is the $md4 object
100           itself.
101
102           All these lines will have the same effect on the state of the $md4
103           object:
104
105               $md4->add("a"); $md4->add("b"); $md4->add("c");
106               $md4->add("a")->add("b")->add("c");
107               $md4->add("a", "b", "c");
108               $md4->add("abc");
109
110       $md4->addfile($io_handle)
111           The $io_handle will be read until EOF and its content appended to
112           the message we calculate the digest for.  The return value is the
113           $md4 object itself.
114
115           The addfile() method will croak() if it fails reading data for some
116           reason.  If it croaks it is unpredictable what the state of the
117           $md4 object will be in. The addfile() method might have been able
118           to read the file partially before it failed.  It is probably wise
119           to discard or reset the $md4 object if this occurs.
120
121           In most cases you want to make sure that the $io_handle is in
122           "binmode" before you pass it as argument to the addfile() method.
123
124       $md4->digest
125           Return the binary digest for the message.  The returned string will
126           be 16 bytes long.
127
128           Note that the "digest" operation is effectively a destructive,
129           read-once operation. Once it has been performed, the "Digest::MD4"
130           object is automatically "reset" and can be used to calculate
131           another digest value.  Call $md4->clone->digest if you want to
132           calculate the digest without reseting the digest state.
133
134       $md4->hexdigest
135           Same as $md4->digest, but will return the digest in hexadecimal
136           form. The length of the returned string will be 32 and it will only
137           contain characters from this set: '0'..'9' and 'a'..'f'.
138
139       $md4->b64digest
140           Same as $md4->digest, but will return the digest as a base64
141           encoded string.  The length of the returned string will be 22 and
142           it will only contain characters from this set: 'A'..'Z', 'a'..'z',
143           '0'..'9', '+' and '/'.
144
145           The base64 encoded string returned is not padded to be a multiple
146           of 4 bytes long.  If you want interoperability with other base64
147           encoded md4 digests you might want to append the string "==" to the
148           result.
149

EXAMPLES

151       The simplest way to use this library is to import the md4_hex()
152       function (or one of its cousins):
153
154           use Digest::MD4 qw(md4_hex);
155           print "Digest is ", md4_hex("foobarbaz"), "\n";
156
157       The above example would print out the message:
158
159           Digest is b2b2b528f632f554ae9cb2c02c904eeb
160
161       The same checksum can also be calculated in OO style:
162
163           use Digest::MD4;
164
165           $md4 = Digest::MD4->new;
166           $md4->add('foo', 'bar');
167           $md4->add('baz');
168           $digest = $md4->hexdigest;
169
170           print "Digest is $digest\n";
171
172       With OO style you can break the message arbitrary.  This means that we
173       are no longer limited to have space for the whole message in memory,
174       i.e.  we can handle messages of any size.
175
176       This is useful when calculating checksum for files:
177
178           use Digest::MD4;
179
180           my $file = shift || "/etc/passwd";
181           open(FILE, $file) or die "Can't open '$file': $!";
182           binmode(FILE);
183
184           $md4 = Digest::MD4->new;
185           while (<FILE>) {
186               $md4->add($_);
187           }
188           close(FILE);
189           print $md4->b64digest, " $file\n";
190
191       Or we can use the addfile method for more efficient reading of the
192       file:
193
194           use Digest::MD4;
195
196           my $file = shift || "/etc/passwd";
197           open(FILE, $file) or die "Can't open '$file': $!";
198           binmode(FILE);
199
200           print Digest::MD4->new->addfile(*FILE)->hexdigest, " $file\n";
201
202       Perl 5.8 support Unicode characters in strings.  Since the MD4
203       algorithm is only defined for strings of bytes, it can not be used on
204       strings that contains chars with ordinal number above 255.  The MD4
205       functions and methods will croak if you try to feed them such input
206       data:
207
208           use Digest::MD4 qw(md4_hex);
209
210           my $str = "abc\x{300}";
211           print md4_hex($str), "\n";  # croaks
212           # Wide character in subroutine entry
213
214       What you can do is calculate the MD4 checksum of the UTF-8
215       representation of such strings.  This is achieved by filtering the
216       string through encode_utf8() function:
217
218           use Digest::MD4 qw(md4_hex);
219           use Encode qw(encode_utf8);
220
221           my $str = "abc\x{300}";
222           print md4_hex(encode_utf8($str)), "\n";
223           # fc2ef2836f9bc3f44ed6d7adee2f1533
224

SEE ALSO

226       Digest, Digest::MD2, Digest::SHA1, Digest::HMAC
227
228       md4sum(1)
229
230       RFC 1320
231
233       This library is free software; you can redistribute it and/or modify it
234       under the same terms as Perl itself.
235
236        Copyright 1998-2003 Gisle Aas.
237        Copyright 1995-1996 Neil Winton.
238        Copyright 1991-1992 RSA Data Security, Inc.
239
240       The MD4 algorithm is defined in RFC 1320. This implementation is
241       derived from the reference C code in RFC 1320 which is covered by the
242       following copyright statement:
243
244
245
246
247              Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
248
249              License to copy and use this software is granted provided that it
250              is identified as the "RSA Data Security, Inc. MD4 Message-Digest
251              Algorithm" in all material mentioning or referencing this software
252              or this function.
253
254              License is also granted to make and use derivative works provided
255              that such works are identified as "derived from the RSA Data
256              Security, Inc. MD4 Message-Digest Algorithm" in all material
257              mentioning or referencing the derived work.
258
259              RSA Data Security, Inc. makes no representations concerning either
260              the merchantability of this software or the suitability of this
261              software for any particular purpose. It is provided "as is"
262              without express or implied warranty of any kind.
263
264              These notices must be retained in any copies of any part of this
265              documentation and/or software.
266
267       This copyright does not prohibit distribution of any version of Perl
268       containing this extension under the terms of the GNU or Artistic
269       licenses.
270

AUTHORS

272       The original "MD5" interface was written by Neil Winton
273       ("N.Winton@axion.bt.co.uk").
274
275       The "Digest::MD5" module is written by Gisle Aas
276       <gisle@ActiveState.com>.
277
278       The "Digest::MD4" module is derived from Digest::MD5 by Mike McCauley
279       (mikem@airspayce.com)
280
281
282
283perl v5.32.1                      2021-01-27                            MD4(3)
Impressum