Commit | Line | Data |
---|---|---|
920dae64 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="prev" href="module-md5.html" /> | |
13 | <link rel="parent" href="crypto.html" /> | |
14 | <link rel="next" href="tkinter.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>15.3 sha -- SHA-1 message digest algorithm</title> | |
17 | </head> | |
18 | <body> | |
19 | <DIV CLASS="navigation"> | |
20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
22 | <tr> | |
23 | <td class='online-navigation'><a rel="prev" title="15.2 md5 " | |
24 | href="module-md5.html"><img src='../icons/previous.png' | |
25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
26 | <td class='online-navigation'><a rel="parent" title="15. Cryptographic Services" | |
27 | href="crypto.html"><img src='../icons/up.png' | |
28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
29 | <td class='online-navigation'><a rel="next" title="16. Graphical User Interfaces" | |
30 | href="tkinter.html"><img src='../icons/next.png' | |
31 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
32 | <td align="center" width="100%">Python Library Reference</td> | |
33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
34 | href="contents.html"><img src='../icons/contents.png' | |
35 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
36 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
37 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
38 | <td class='online-navigation'><a rel="index" title="Index" | |
39 | href="genindex.html"><img src='../icons/index.png' | |
40 | border='0' height='32' alt='Index' width='32' /></A></td> | |
41 | </tr></table> | |
42 | <div class='online-navigation'> | |
43 | <b class="navlabel">Previous:</b> | |
44 | <a class="sectref" rel="prev" href="module-md5.html">15.2 md5 </A> | |
45 | <b class="navlabel">Up:</b> | |
46 | <a class="sectref" rel="parent" href="crypto.html">15. Cryptographic Services</A> | |
47 | <b class="navlabel">Next:</b> | |
48 | <a class="sectref" rel="next" href="tkinter.html">16. Graphical User Interfaces</A> | |
49 | </div> | |
50 | <hr /></div> | |
51 | </DIV> | |
52 | <!--End of Navigation Panel--> | |
53 | ||
54 | <H1><A NAME="SECTION0017300000000000000000"> | |
55 | 15.3 <tt class="module">sha</tt> -- | |
56 | SHA-1 message digest algorithm</A> | |
57 | </H1> | |
58 | ||
59 | <P> | |
60 | <A NAME="module-sha"></A> | |
61 | ||
62 | <P> | |
63 | This module implements the interface to NIST's<a id='l2h-4830' xml:id='l2h-4830'></a> secure hash | |
64 | algorithm,<a id='l2h-4831' xml:id='l2h-4831'></a> known as SHA-1. SHA-1 is an | |
65 | improved version of the original SHA hash algorithm. It is used in | |
66 | the same way as the <tt class="module"><a href="module-md5.html">md5</a></tt> module: use <tt class="function">new()</tt> | |
67 | to create an sha object, then feed this object with arbitrary strings | |
68 | using the <tt class="method">update()</tt> method, and at any point you can ask it | |
69 | for the <i class="dfn">digest</i> of the concatenation of the strings fed to it | |
70 | so far.<a id='l2h-4832' xml:id='l2h-4832'></a> SHA-1 digests are 160 bits instead of | |
71 | MD5's 128 bits. | |
72 | ||
73 | <P> | |
74 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
75 | <td><nobr><b><tt id='l2h-4823' xml:id='l2h-4823' class="function">new</tt></b>(</nobr></td> | |
76 | <td><var></var><big>[</big><var>string</var><big>]</big><var></var>)</td></tr></table></dt> | |
77 | <dd> | |
78 | Return a new sha object. If <var>string</var> is present, the method | |
79 | call <code>update(<var>string</var>)</code> is made. | |
80 | </dl> | |
81 | ||
82 | <P> | |
83 | The following values are provided as constants in the module and as | |
84 | attributes of the sha objects returned by <tt class="function">new()</tt>: | |
85 | ||
86 | <P> | |
87 | <dl><dt><b><tt id='l2h-4824' xml:id='l2h-4824'>blocksize</tt></b></dt> | |
88 | <dd> | |
89 | Size of the blocks fed into the hash function; this is always | |
90 | <code>1</code>. This size is used to allow an arbitrary string to be | |
91 | hashed. | |
92 | </dd></dl> | |
93 | ||
94 | <P> | |
95 | <dl><dt><b><tt id='l2h-4825' xml:id='l2h-4825'>digest_size</tt></b></dt> | |
96 | <dd> | |
97 | The size of the resulting digest in bytes. This is always | |
98 | <code>20</code>. | |
99 | </dd></dl> | |
100 | ||
101 | <P> | |
102 | An sha object has the same methods as md5 objects: | |
103 | ||
104 | <P> | |
105 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
106 | <td><nobr><b><tt id='l2h-4826' xml:id='l2h-4826' class="method">update</tt></b>(</nobr></td> | |
107 | <td><var>arg</var>)</td></tr></table></dt> | |
108 | <dd> | |
109 | Update the sha object with the string <var>arg</var>. Repeated calls are | |
110 | equivalent to a single call with the concatenation of all the | |
111 | arguments: <code>m.update(a); m.update(b)</code> is equivalent to | |
112 | <code>m.update(a+b)</code>. | |
113 | </dl> | |
114 | ||
115 | <P> | |
116 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
117 | <td><nobr><b><tt id='l2h-4827' xml:id='l2h-4827' class="method">digest</tt></b>(</nobr></td> | |
118 | <td><var></var>)</td></tr></table></dt> | |
119 | <dd> | |
120 | Return the digest of the strings passed to the <tt class="method">update()</tt> | |
121 | method so far. This is a 20-byte string which may contain | |
122 | non-ASCII characters, including null bytes. | |
123 | </dl> | |
124 | ||
125 | <P> | |
126 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
127 | <td><nobr><b><tt id='l2h-4828' xml:id='l2h-4828' class="method">hexdigest</tt></b>(</nobr></td> | |
128 | <td><var></var>)</td></tr></table></dt> | |
129 | <dd> | |
130 | Like <tt class="method">digest()</tt> except the digest is returned as a string of | |
131 | length 40, containing only hexadecimal digits. This may | |
132 | be used to exchange the value safely in email or other non-binary | |
133 | environments. | |
134 | </dl> | |
135 | ||
136 | <P> | |
137 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
138 | <td><nobr><b><tt id='l2h-4829' xml:id='l2h-4829' class="method">copy</tt></b>(</nobr></td> | |
139 | <td><var></var>)</td></tr></table></dt> | |
140 | <dd> | |
141 | Return a copy (``clone'') of the sha object. This can be used to | |
142 | efficiently compute the digests of strings that share a common initial | |
143 | substring. | |
144 | </dl> | |
145 | ||
146 | <P> | |
147 | <div class="seealso"> | |
148 | <p class="heading">See Also:</p> | |
149 | ||
150 | <dl compact="compact" class="seetitle"> | |
151 | <dt><em class="citetitle"><a href="http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf" | |
152 | >Secure Hash Standard</a></em></dt> | |
153 | <dd>The Secure Hash Algorithm is defined by NIST document FIPS | |
154 | PUB 180-2: | |
155 | <em class="citetitle"><a | |
156 | href="http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf" | |
157 | title="Secure Hash Standard" | |
158 | >Secure Hash Standard</a></em>, published in August 2002.</dd> | |
159 | </dl> | |
160 | ||
161 | <P> | |
162 | <dl compact="compact" class="seetitle"> | |
163 | <dt><em class="citetitle"><a href="http://csrc.nist.gov/encryption/tkhash.html" | |
164 | >Cryptographic Toolkit (Secure Hashing)</a></em></dt> | |
165 | <dd>Links from NIST to various information on secure hashing.</dd> | |
166 | </dl> | |
167 | </div> | |
168 | ||
169 | <P> | |
170 | ||
171 | <DIV CLASS="navigation"> | |
172 | <div class='online-navigation'> | |
173 | <p></p><hr /> | |
174 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
175 | <tr> | |
176 | <td class='online-navigation'><a rel="prev" title="15.2 md5 " | |
177 | href="module-md5.html"><img src='../icons/previous.png' | |
178 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
179 | <td class='online-navigation'><a rel="parent" title="15. Cryptographic Services" | |
180 | href="crypto.html"><img src='../icons/up.png' | |
181 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
182 | <td class='online-navigation'><a rel="next" title="16. Graphical User Interfaces" | |
183 | href="tkinter.html"><img src='../icons/next.png' | |
184 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
185 | <td align="center" width="100%">Python Library Reference</td> | |
186 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
187 | href="contents.html"><img src='../icons/contents.png' | |
188 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
189 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
190 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
191 | <td class='online-navigation'><a rel="index" title="Index" | |
192 | href="genindex.html"><img src='../icons/index.png' | |
193 | border='0' height='32' alt='Index' width='32' /></A></td> | |
194 | </tr></table> | |
195 | <div class='online-navigation'> | |
196 | <b class="navlabel">Previous:</b> | |
197 | <a class="sectref" rel="prev" href="module-md5.html">15.2 md5 </A> | |
198 | <b class="navlabel">Up:</b> | |
199 | <a class="sectref" rel="parent" href="crypto.html">15. Cryptographic Services</A> | |
200 | <b class="navlabel">Next:</b> | |
201 | <a class="sectref" rel="next" href="tkinter.html">16. Graphical User Interfaces</A> | |
202 | </div> | |
203 | </div> | |
204 | <hr /> | |
205 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
206 | </DIV> | |
207 | <!--End of Navigation Panel--> | |
208 | <ADDRESS> | |
209 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
210 | </ADDRESS> | |
211 | </BODY> | |
212 | </HTML> |