source: vendor/python/2.5/Doc/lib/libsha.tex

Last change on this file was 3225, checked in by bird, 18 years ago

Python 2.5

File size: 2.9 KB
Line 
1\section{\module{sha} ---
2 SHA-1 message digest algorithm}
3
4\declaremodule{builtin}{sha}
5\modulesynopsis{NIST's secure hash algorithm, SHA.}
6\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
7
8\deprecated{2.5}{Use the \refmodule{hashlib} module instead.}
9
10
11This module implements the interface to NIST's\index{NIST} secure hash
12algorithm,\index{Secure Hash Algorithm} known as SHA-1. SHA-1 is an
13improved version of the original SHA hash algorithm. It is used in
14the same way as the \refmodule{md5} module:\ use \function{new()}
15to create an sha object, then feed this object with arbitrary strings
16using the \method{update()} method, and at any point you can ask it
17for the \dfn{digest} of the concatenation of the strings fed to it
18so far.\index{checksum!SHA} SHA-1 digests are 160 bits instead of
19MD5's 128 bits.
20
21
22\begin{funcdesc}{new}{\optional{string}}
23 Return a new sha object. If \var{string} is present, the method
24 call \code{update(\var{string})} is made.
25\end{funcdesc}
26
27
28The following values are provided as constants in the module and as
29attributes of the sha objects returned by \function{new()}:
30
31\begin{datadesc}{blocksize}
32 Size of the blocks fed into the hash function; this is always
33 \code{1}. This size is used to allow an arbitrary string to be
34 hashed.
35\end{datadesc}
36
37\begin{datadesc}{digest_size}
38 The size of the resulting digest in bytes. This is always
39 \code{20}.
40\end{datadesc}
41
42
43An sha object has the same methods as md5 objects:
44
45\begin{methoddesc}[sha]{update}{arg}
46Update the sha object with the string \var{arg}. Repeated calls are
47equivalent to a single call with the concatenation of all the
48arguments: \code{m.update(a); m.update(b)} is equivalent to
49\code{m.update(a+b)}.
50\end{methoddesc}
51
52\begin{methoddesc}[sha]{digest}{}
53Return the digest of the strings passed to the \method{update()}
54method so far. This is a 20-byte string which may contain
55non-\ASCII{} characters, including null bytes.
56\end{methoddesc}
57
58\begin{methoddesc}[sha]{hexdigest}{}
59Like \method{digest()} except the digest is returned as a string of
60length 40, containing only hexadecimal digits. This may
61be used to exchange the value safely in email or other non-binary
62environments.
63\end{methoddesc}
64
65\begin{methoddesc}[sha]{copy}{}
66Return a copy (``clone'') of the sha object. This can be used to
67efficiently compute the digests of strings that share a common initial
68substring.
69\end{methoddesc}
70
71\begin{seealso}
72 \seetitle[http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf]
73 {Secure Hash Standard}
74 {The Secure Hash Algorithm is defined by NIST document FIPS
75 PUB 180-2:
76 \citetitle[http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf]
77 {Secure Hash Standard}, published in August 2002.}
78
79 \seetitle[http://csrc.nist.gov/encryption/tkhash.html]
80 {Cryptographic Toolkit (Secure Hashing)}
81 {Links from NIST to various information on secure hashing.}
82\end{seealso}
83
Note: See TracBrowser for help on using the repository browser.