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 |
|
---|
11 | This module implements the interface to NIST's\index{NIST} secure hash
|
---|
12 | algorithm,\index{Secure Hash Algorithm} known as SHA-1. SHA-1 is an
|
---|
13 | improved version of the original SHA hash algorithm. It is used in
|
---|
14 | the same way as the \refmodule{md5} module:\ use \function{new()}
|
---|
15 | to create an sha object, then feed this object with arbitrary strings
|
---|
16 | using the \method{update()} method, and at any point you can ask it
|
---|
17 | for the \dfn{digest} of the concatenation of the strings fed to it
|
---|
18 | so far.\index{checksum!SHA} SHA-1 digests are 160 bits instead of
|
---|
19 | MD5'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 |
|
---|
28 | The following values are provided as constants in the module and as
|
---|
29 | attributes 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 |
|
---|
43 | An sha object has the same methods as md5 objects:
|
---|
44 |
|
---|
45 | \begin{methoddesc}[sha]{update}{arg}
|
---|
46 | Update the sha object with the string \var{arg}. Repeated calls are
|
---|
47 | equivalent to a single call with the concatenation of all the
|
---|
48 | arguments: \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}{}
|
---|
53 | Return the digest of the strings passed to the \method{update()}
|
---|
54 | method so far. This is a 20-byte string which may contain
|
---|
55 | non-\ASCII{} characters, including null bytes.
|
---|
56 | \end{methoddesc}
|
---|
57 |
|
---|
58 | \begin{methoddesc}[sha]{hexdigest}{}
|
---|
59 | Like \method{digest()} except the digest is returned as a string of
|
---|
60 | length 40, containing only hexadecimal digits. This may
|
---|
61 | be used to exchange the value safely in email or other non-binary
|
---|
62 | environments.
|
---|
63 | \end{methoddesc}
|
---|
64 |
|
---|
65 | \begin{methoddesc}[sha]{copy}{}
|
---|
66 | Return a copy (``clone'') of the sha object. This can be used to
|
---|
67 | efficiently compute the digests of strings that share a common initial
|
---|
68 | substring.
|
---|
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 |
|
---|