Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / src / nas,5.n2.os.2 / lib / python / html / python / lib / module-md5.html
CommitLineData
86530b38
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="lib.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="lib.html" title='Python Library Reference' />
8<link rel='contents' href='contents.html' title="Contents" />
9<link rel='index' href='genindex.html' title='Index' />
10<link rel='last' href='about.html' title='About this document...' />
11<link rel='help' href='about.html' title='About this document...' />
12<link rel="next" href="module-sha.html" />
13<link rel="prev" href="module-hmac.html" />
14<link rel="parent" href="crypto.html" />
15<link rel="next" href="module-sha.html" />
16<meta name='aesop' content='information' />
17<title>15.2 md5 -- MD5 message digest algorithm</title>
18</head>
19<body>
20<DIV CLASS="navigation">
21<div id='top-navigation-panel' xml:id='top-navigation-panel'>
22<table align="center" width="100%" cellpadding="0" cellspacing="2">
23<tr>
24<td class='online-navigation'><a rel="prev" title="15.1 hmac "
25 href="module-hmac.html"><img src='../icons/previous.png'
26 border='0' height='32' alt='Previous Page' width='32' /></A></td>
27<td class='online-navigation'><a rel="parent" title="15. Cryptographic Services"
28 href="crypto.html"><img src='../icons/up.png'
29 border='0' height='32' alt='Up One Level' width='32' /></A></td>
30<td class='online-navigation'><a rel="next" title="15.3 sha "
31 href="module-sha.html"><img src='../icons/next.png'
32 border='0' height='32' alt='Next Page' width='32' /></A></td>
33<td align="center" width="100%">Python Library Reference</td>
34<td class='online-navigation'><a rel="contents" title="Table of Contents"
35 href="contents.html"><img src='../icons/contents.png'
36 border='0' height='32' alt='Contents' width='32' /></A></td>
37<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
38 border='0' height='32' alt='Module Index' width='32' /></a></td>
39<td class='online-navigation'><a rel="index" title="Index"
40 href="genindex.html"><img src='../icons/index.png'
41 border='0' height='32' alt='Index' width='32' /></A></td>
42</tr></table>
43<div class='online-navigation'>
44<b class="navlabel">Previous:</b>
45<a class="sectref" rel="prev" href="module-hmac.html">15.1 hmac </A>
46<b class="navlabel">Up:</b>
47<a class="sectref" rel="parent" href="crypto.html">15. Cryptographic Services</A>
48<b class="navlabel">Next:</b>
49<a class="sectref" rel="next" href="module-sha.html">15.3 sha </A>
50</div>
51<hr /></div>
52</DIV>
53<!--End of Navigation Panel-->
54
55<H1><A NAME="SECTION0017200000000000000000">
5615.2 <tt class="module">md5</tt> --
57 MD5 message digest algorithm</A>
58</H1>
59
60<P>
61<A NAME="module-md5"></A>
62
63<P>
64This module implements the interface to RSA's MD5 message digest
65<a id='l2h-4820' xml:id='l2h-4820'></a>
66algorithm (see also Internet <a class="rfc" id='rfcref-92073' xml:id='rfcref-92073'
67href="http://www.faqs.org/rfcs/rfc1321.html">RFC 1321</a>). Its use is quite
68straightforward: use <tt class="function">new()</tt> to create an md5 object.
69You can now feed this object with arbitrary strings using the
70<tt class="method">update()</tt> method, and at any point you can ask it for the
71<i class="dfn">digest</i> (a strong kind of 128-bit checksum,
72a.k.a. ``fingerprint'') of the concatenation of the strings fed to it
73so far using the <tt class="method">digest()</tt> method.
74<a id='l2h-4821' xml:id='l2h-4821'></a>
75
76<P>
77For example, to obtain the digest of the string <code>'Nobody inspects
78the spammish repetition'</code>:
79
80<P>
81<div class="verbatim"><pre>
82&gt;&gt;&gt; import md5
83&gt;&gt;&gt; m = md5.new()
84&gt;&gt;&gt; m.update("Nobody inspects")
85&gt;&gt;&gt; m.update(" the spammish repetition")
86&gt;&gt;&gt; m.digest()
87'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
88</pre></div>
89
90<P>
91More condensed:
92
93<P>
94<div class="verbatim"><pre>
95&gt;&gt;&gt; md5.new("Nobody inspects the spammish repetition").digest()
96'\xbbd\x9c\x83\xdd\x1e\xa5\xc9\xd9\xde\xc9\xa1\x8d\xf0\xff\xe9'
97</pre></div>
98
99<P>
100The following values are provided as constants in the module and as
101attributes of the md5 objects returned by <tt class="function">new()</tt>:
102
103<P>
104<dl><dt><b><tt id='l2h-4813' xml:id='l2h-4813'>digest_size</tt></b></dt>
105<dd>
106 The size of the resulting digest in bytes. This is always
107 <code>16</code>.
108</dd></dl>
109
110<P>
111md5 objects support the following methods:
112
113<P>
114<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
115 <td><nobr><b><tt id='l2h-4814' xml:id='l2h-4814' class="function">new</tt></b>(</nobr></td>
116 <td><var></var><big>[</big><var>arg</var><big>]</big><var></var>)</td></tr></table></dt>
117<dd>
118Return a new md5 object. If <var>arg</var> is present, the method call
119<code>update(<var>arg</var>)</code> is made.
120</dl>
121
122<P>
123<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
124 <td><nobr><b><tt id='l2h-4815' xml:id='l2h-4815' class="function">md5</tt></b>(</nobr></td>
125 <td><var></var><big>[</big><var>arg</var><big>]</big><var></var>)</td></tr></table></dt>
126<dd>
127For backward compatibility reasons, this is an alternative name for the
128<tt class="function">new()</tt> function.
129</dl>
130
131<P>
132An md5 object has the following methods:
133
134<P>
135<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
136 <td><nobr><b><tt id='l2h-4816' xml:id='l2h-4816' class="method">update</tt></b>(</nobr></td>
137 <td><var>arg</var>)</td></tr></table></dt>
138<dd>
139Update the md5 object with the string <var>arg</var>. Repeated calls are
140equivalent to a single call with the concatenation of all the
141arguments: <code>m.update(a); m.update(b)</code> is equivalent to
142<code>m.update(a+b)</code>.
143</dl>
144
145<P>
146<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
147 <td><nobr><b><tt id='l2h-4817' xml:id='l2h-4817' class="method">digest</tt></b>(</nobr></td>
148 <td><var></var>)</td></tr></table></dt>
149<dd>
150Return the digest of the strings passed to the <tt class="method">update()</tt>
151method so far. This is a 16-byte string which may contain
152non-ASCII characters, including null bytes.
153</dl>
154
155<P>
156<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
157 <td><nobr><b><tt id='l2h-4818' xml:id='l2h-4818' class="method">hexdigest</tt></b>(</nobr></td>
158 <td><var></var>)</td></tr></table></dt>
159<dd>
160Like <tt class="method">digest()</tt> except the digest is returned as a string of
161length 32, containing only hexadecimal digits. This may
162be used to exchange the value safely in email or other non-binary
163environments.
164</dl>
165
166<P>
167<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
168 <td><nobr><b><tt id='l2h-4819' xml:id='l2h-4819' class="method">copy</tt></b>(</nobr></td>
169 <td><var></var>)</td></tr></table></dt>
170<dd>
171Return a copy (``clone'') of the md5 object. This can be used to
172efficiently compute the digests of strings that share a common initial
173substring.
174</dl>
175
176<P>
177<div class="seealso">
178 <p class="heading">See Also:</p>
179
180 <dl compact="compact" class="seemodule">
181 <dt>Module <b><tt class="module"><a href="module-sha.html">sha</a></tt>:</b>
182 <dd>Similar module implementing the Secure Hash
183 Algorithm (SHA). The SHA algorithm is considered a
184 more secure hash.
185 </dl>
186</div>
187
188<DIV CLASS="navigation">
189<div class='online-navigation'>
190<p></p><hr />
191<table align="center" width="100%" cellpadding="0" cellspacing="2">
192<tr>
193<td class='online-navigation'><a rel="prev" title="15.1 hmac "
194 href="module-hmac.html"><img src='../icons/previous.png'
195 border='0' height='32' alt='Previous Page' width='32' /></A></td>
196<td class='online-navigation'><a rel="parent" title="15. Cryptographic Services"
197 href="crypto.html"><img src='../icons/up.png'
198 border='0' height='32' alt='Up One Level' width='32' /></A></td>
199<td class='online-navigation'><a rel="next" title="15.3 sha "
200 href="module-sha.html"><img src='../icons/next.png'
201 border='0' height='32' alt='Next Page' width='32' /></A></td>
202<td align="center" width="100%">Python Library Reference</td>
203<td class='online-navigation'><a rel="contents" title="Table of Contents"
204 href="contents.html"><img src='../icons/contents.png'
205 border='0' height='32' alt='Contents' width='32' /></A></td>
206<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
207 border='0' height='32' alt='Module Index' width='32' /></a></td>
208<td class='online-navigation'><a rel="index" title="Index"
209 href="genindex.html"><img src='../icons/index.png'
210 border='0' height='32' alt='Index' width='32' /></A></td>
211</tr></table>
212<div class='online-navigation'>
213<b class="navlabel">Previous:</b>
214<a class="sectref" rel="prev" href="module-hmac.html">15.1 hmac </A>
215<b class="navlabel">Up:</b>
216<a class="sectref" rel="parent" href="crypto.html">15. Cryptographic Services</A>
217<b class="navlabel">Next:</b>
218<a class="sectref" rel="next" href="module-sha.html">15.3 sha </A>
219</div>
220</div>
221<hr />
222<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
223</DIV>
224<!--End of Navigation Panel-->
225<ADDRESS>
226See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
227</ADDRESS>
228</BODY>
229</HTML>