Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / Digest::MD5.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Digest::MD5 3"
132.TH Digest::MD5 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
133.SH "NAME"
134Digest::MD5 \- Perl interface to the MD5 Algorithm
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 2
138\& # Functional style
139\& use Digest::MD5 qw(md5 md5_hex md5_base64);
140.Ve
141.PP
142.Vb 3
143\& $digest = md5($data);
144\& $digest = md5_hex($data);
145\& $digest = md5_base64($data);
146.Ve
147.PP
148.Vb 2
149\& # OO style
150\& use Digest::MD5;
151.Ve
152.PP
153.Vb 1
154\& $ctx = Digest::MD5->new;
155.Ve
156.PP
157.Vb 2
158\& $ctx->add($data);
159\& $ctx->addfile(*FILE);
160.Ve
161.PP
162.Vb 3
163\& $digest = $ctx->digest;
164\& $digest = $ctx->hexdigest;
165\& $digest = $ctx->b64digest;
166.Ve
167.SH "DESCRIPTION"
168.IX Header "DESCRIPTION"
169The \f(CW\*(C`Digest::MD5\*(C'\fR module allows you to use the \s-1RSA\s0 Data Security
170Inc. \s-1MD5\s0 Message Digest algorithm from within Perl programs. The
171algorithm takes as input a message of arbitrary length and produces as
172output a 128\-bit \*(L"fingerprint\*(R" or \*(L"message digest\*(R" of the input.
173.PP
174Note that the \s-1MD5\s0 algorithm is not as strong as it used to be. It has
175since 2005 been easy to generate different messages that produce the
176same \s-1MD5\s0 digest. It still seems hard to generate messages that
177produce a given digest, but it is probably wise to move to stronger
178algorithms for applications that depend on the digest to uniquely identify
179a message.
180.PP
181The \f(CW\*(C`Digest::MD5\*(C'\fR module provide a procedural interface for simple
182use, as well as an object oriented interface that can handle messages
183of arbitrary length and which can read files directly.
184.SH "FUNCTIONS"
185.IX Header "FUNCTIONS"
186The following functions are provided by the \f(CW\*(C`Digest::MD5\*(C'\fR module.
187None of these functions are exported by default.
188.IP "md5($data,...)" 4
189.IX Item "md5($data,...)"
190This function will concatenate all arguments, calculate the \s-1MD5\s0 digest
191of this \*(L"message\*(R", and return it in binary form. The returned string
192will be 16 bytes long.
193.Sp
194The result of md5(\*(L"a\*(R", \*(L"b\*(R", \*(L"c\*(R") will be exactly the same as the
195result of md5(\*(L"abc\*(R").
196.IP "md5_hex($data,...)" 4
197.IX Item "md5_hex($data,...)"
198Same as \fImd5()\fR, but will return the digest in hexadecimal form. The
199length of the returned string will be 32 and it will only contain
200characters from this set: '0'..'9' and 'a'..'f'.
201.IP "md5_base64($data,...)" 4
202.IX Item "md5_base64($data,...)"
203Same as \fImd5()\fR, but will return the digest as a base64 encoded string.
204The length of the returned string will be 22 and it will only contain
205characters from this set: 'A'..'Z', 'a'..'z', '0'..'9', '+' and
206\&'/'.
207.Sp
208Note that the base64 encoded string returned is not padded to be a
209multiple of 4 bytes long. If you want interoperability with other
210base64 encoded md5 digests you might want to append the redundant
211string \*(L"==\*(R" to the result.
212.SH "METHODS"
213.IX Header "METHODS"
214The object oriented interface to \f(CW\*(C`Digest::MD5\*(C'\fR is described in this
215section. After a \f(CW\*(C`Digest::MD5\*(C'\fR object has been created, you will add
216data to it and finally ask for the digest in a suitable format. A
217single object can be used to calculate multiple digests.
218.PP
219The following methods are provided:
220.IP "$md5 = Digest::MD5\->new" 4
221.IX Item "$md5 = Digest::MD5->new"
222The constructor returns a new \f(CW\*(C`Digest::MD5\*(C'\fR object which encapsulate
223the state of the \s-1MD5\s0 message-digest algorithm.
224.Sp
225If called as an instance method (i.e. \f(CW$md5\fR\->new) it will just reset the
226state the object to the state of a newly created object. No new
227object is created in this case.
228.IP "$md5\->reset" 4
229.IX Item "$md5->reset"
230This is just an alias for \f(CW$md5\fR\->new.
231.IP "$md5\->clone" 4
232.IX Item "$md5->clone"
233This a copy of the \f(CW$md5\fR object. It is useful when you do not want to
234destroy the digests state, but need an intermediate value of the
235digest, e.g. when calculating digests iteratively on a continuous data
236stream. Example:
237.Sp
238.Vb 5
239\& my $md5 = Digest::MD5->new;
240\& while (<>) {
241\& $md5->add($_);
242\& print "Line $.: ", $md5->clone->hexdigest, "\en";
243\& }
244.Ve
245.IP "$md5\->add($data,...)" 4
246.IX Item "$md5->add($data,...)"
247The \f(CW$data\fR provided as argument are appended to the message we
248calculate the digest for. The return value is the \f(CW$md5\fR object itself.
249.Sp
250All these lines will have the same effect on the state of the \f(CW$md5\fR
251object:
252.Sp
253.Vb 4
254\& $md5->add("a"); $md5->add("b"); $md5->add("c");
255\& $md5->add("a")->add("b")->add("c");
256\& $md5->add("a", "b", "c");
257\& $md5->add("abc");
258.Ve
259.IP "$md5\->addfile($io_handle)" 4
260.IX Item "$md5->addfile($io_handle)"
261The \f(CW$io_handle\fR will be read until \s-1EOF\s0 and its content appended to the
262message we calculate the digest for. The return value is the \f(CW$md5\fR
263object itself.
264.Sp
265The \fIaddfile()\fR method will \fIcroak()\fR if it fails reading data for some
266reason. If it croaks it is unpredictable what the state of the \f(CW$md5\fR
267object will be in. The \fIaddfile()\fR method might have been able to read
268the file partially before it failed. It is probably wise to discard
269or reset the \f(CW$md5\fR object if this occurs.
270.Sp
271In most cases you want to make sure that the \f(CW$io_handle\fR is in
272\&\f(CW\*(C`binmode\*(C'\fR before you pass it as argument to the \fIaddfile()\fR method.
273.ie n .IP "$md5\->add_bits($data, $nbits)" 4
274.el .IP "$md5\->add_bits($data, \f(CW$nbits\fR)" 4
275.IX Item "$md5->add_bits($data, $nbits)"
276.PD 0
277.IP "$md5\->add_bits($bitstring)" 4
278.IX Item "$md5->add_bits($bitstring)"
279.PD
280Since the \s-1MD5\s0 algorithm is byte oriented you might only add bits as
281multiples of 8, so you probably want to just use \fIadd()\fR instead. The
282\&\fIadd_bits()\fR method is provided for compatibility with other digest
283implementations. See Digest for description of the arguments
284that \fIadd_bits()\fR take.
285.IP "$md5\->digest" 4
286.IX Item "$md5->digest"
287Return the binary digest for the message. The returned string will be
28816 bytes long.
289.Sp
290Note that the \f(CW\*(C`digest\*(C'\fR operation is effectively a destructive,
291read-once operation. Once it has been performed, the \f(CW\*(C`Digest::MD5\*(C'\fR
292object is automatically \f(CW\*(C`reset\*(C'\fR and can be used to calculate another
293digest value. Call \f(CW$md5\fR\->clone\->digest if you want to calculate the
294digest without resetting the digest state.
295.IP "$md5\->hexdigest" 4
296.IX Item "$md5->hexdigest"
297Same as \f(CW$md5\fR\->digest, but will return the digest in hexadecimal
298form. The length of the returned string will be 32 and it will only
299contain characters from this set: '0'..'9' and 'a'..'f'.
300.IP "$md5\->b64digest" 4
301.IX Item "$md5->b64digest"
302Same as \f(CW$md5\fR\->digest, but will return the digest as a base64 encoded
303string. The length of the returned string will be 22 and it will only
304contain characters from this set: 'A'..'Z', 'a'..'z', '0'..'9', '+'
305and '/'.
306.Sp
307The base64 encoded string returned is not padded to be a multiple of 4
308bytes long. If you want interoperability with other base64 encoded
309md5 digests you might want to append the string \*(L"==\*(R" to the result.
310.SH "EXAMPLES"
311.IX Header "EXAMPLES"
312The simplest way to use this library is to import the \fImd5_hex()\fR
313function (or one of its cousins):
314.PP
315.Vb 2
316\& use Digest::MD5 qw(md5_hex);
317\& print "Digest is ", md5_hex("foobarbaz"), "\en";
318.Ve
319.PP
320The above example would print out the message:
321.PP
322.Vb 1
323\& Digest is 6df23dc03f9b54cc38a0fc1483df6e21
324.Ve
325.PP
326The same checksum can also be calculated in \s-1OO\s0 style:
327.PP
328.Vb 1
329\& use Digest::MD5;
330.Ve
331.PP
332.Vb 4
333\& $md5 = Digest::MD5->new;
334\& $md5->add('foo', 'bar');
335\& $md5->add('baz');
336\& $digest = $md5->hexdigest;
337.Ve
338.PP
339.Vb 1
340\& print "Digest is $digest\en";
341.Ve
342.PP
343With \s-1OO\s0 style you can break the message arbitrary. This means that we
344are no longer limited to have space for the whole message in memory, i.e.
345we can handle messages of any size.
346.PP
347This is useful when calculating checksum for files:
348.PP
349.Vb 1
350\& use Digest::MD5;
351.Ve
352.PP
353.Vb 3
354\& my $file = shift || "/etc/passwd";
355\& open(FILE, $file) or die "Can't open '$file': $!";
356\& binmode(FILE);
357.Ve
358.PP
359.Vb 6
360\& $md5 = Digest::MD5->new;
361\& while (<FILE>) {
362\& $md5->add($_);
363\& }
364\& close(FILE);
365\& print $md5->b64digest, " $file\en";
366.Ve
367.PP
368Or we can use the addfile method for more efficient reading of
369the file:
370.PP
371.Vb 1
372\& use Digest::MD5;
373.Ve
374.PP
375.Vb 3
376\& my $file = shift || "/etc/passwd";
377\& open(FILE, $file) or die "Can't open '$file': $!";
378\& binmode(FILE);
379.Ve
380.PP
381.Vb 1
382\& print Digest::MD5->new->addfile(*FILE)->hexdigest, " $file\en";
383.Ve
384.PP
385Perl 5.8 support Unicode characters in strings. Since the \s-1MD5\s0
386algorithm is only defined for strings of bytes, it can not be used on
387strings that contains chars with ordinal number above 255. The \s-1MD5\s0
388functions and methods will croak if you try to feed them such input
389data:
390.PP
391.Vb 1
392\& use Digest::MD5 qw(md5_hex);
393.Ve
394.PP
395.Vb 3
396\& my $str = "abc\ex{300}";
397\& print md5_hex($str), "\en"; # croaks
398\& # Wide character in subroutine entry
399.Ve
400.PP
401What you can do is calculate the \s-1MD5\s0 checksum of the \s-1UTF\-8\s0
402representation of such strings. This is achieved by filtering the
403string through \fIencode_utf8()\fR function:
404.PP
405.Vb 2
406\& use Digest::MD5 qw(md5_hex);
407\& use Encode qw(encode_utf8);
408.Ve
409.PP
410.Vb 3
411\& my $str = "abc\ex{300}";
412\& print md5_hex(encode_utf8($str)), "\en";
413\& # 8c2d46911f3f5a326455f0ed7a8ed3b3
414.Ve
415.SH "SEE ALSO"
416.IX Header "SEE ALSO"
417Digest,
418Digest::MD2,
419Digest::SHA1,
420Digest::HMAC
421.PP
422\&\fImd5sum\fR\|(1)
423.PP
424\&\s-1RFC\s0 1321
425.PP
426http://en.wikipedia.org/wiki/MD5
427.PP
428The paper \*(L"How to Break \s-1MD5\s0 and Other Hash Functions\*(R" by Xiaoyun Wang
429and Hongbo Yu.
430.SH "COPYRIGHT"
431.IX Header "COPYRIGHT"
432This library is free software; you can redistribute it and/or
433modify it under the same terms as Perl itself.
434.PP
435.Vb 3
436\& Copyright 1998-2003 Gisle Aas.
437\& Copyright 1995-1996 Neil Winton.
438\& Copyright 1991-1992 RSA Data Security, Inc.
439.Ve
440.PP
441The \s-1MD5\s0 algorithm is defined in \s-1RFC\s0 1321. This implementation is
442derived from the reference C code in \s-1RFC\s0 1321 which is covered by
443the following copyright statement:
444.IP "\(bu" 4
445Copyright (C) 1991\-2, \s-1RSA\s0 Data Security, Inc. Created 1991. All
446rights reserved.
447.Sp
448License to copy and use this software is granted provided that it
449is identified as the \*(L"\s-1RSA\s0 Data Security, Inc. \s-1MD5\s0 Message-Digest
450Algorithm\*(R" in all material mentioning or referencing this software
451or this function.
452.Sp
453License is also granted to make and use derivative works provided
454that such works are identified as \*(L"derived from the \s-1RSA\s0 Data
455Security, Inc. \s-1MD5\s0 Message-Digest Algorithm\*(R" in all material
456mentioning or referencing the derived work.
457.Sp
458\&\s-1RSA\s0 Data Security, Inc. makes no representations concerning either
459the merchantability of this software or the suitability of this
460software for any particular purpose. It is provided \*(L"as is\*(R"
461without express or implied warranty of any kind.
462.Sp
463These notices must be retained in any copies of any part of this
464documentation and/or software.
465.PP
466This copyright does not prohibit distribution of any version of Perl
467containing this extension under the terms of the \s-1GNU\s0 or Artistic
468licenses.
469.SH "AUTHORS"
470.IX Header "AUTHORS"
471The original \f(CW\*(C`MD5\*(C'\fR interface was written by Neil Winton
472(\f(CW\*(C`N.Winton@axion.bt.co.uk\*(C'\fR).
473.PP
474The \f(CW\*(C`Digest::MD5\*(C'\fR module is written by Gisle Aas <gisle@ActiveState.com>.