blob: f7732dc4eddf6bf646b669b71fb6e52c1be8cc5a [file] [log] [blame]
Fred Drake957ac3f1999-04-23 21:52:18 +00001\section{\module{sha} ---
Raymond Hettinger1e4cf672003-09-15 18:20:52 +00002 SHA-1 message digest algorithm}
Fred Drake957ac3f1999-04-23 21:52:18 +00003
4\declaremodule{builtin}{sha}
5\modulesynopsis{NIST's secure hash algorithm, SHA.}
6\sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org}
7
8
9This module implements the interface to NIST's\index{NIST} secure hash
Raymond Hettinger1e4cf672003-09-15 18:20:52 +000010algorithm,\index{Secure Hash Algorithm} known as SHA-1. SHA-1 is an
11improved version of the original SHA hash algorithm. It is used in
Tim Peters1de80982000-09-18 15:34:57 +000012the same way as the \refmodule{md5} module:\ use \function{new()}
Fred Drake957ac3f1999-04-23 21:52:18 +000013to create an sha object, then feed this object with arbitrary strings
14using the \method{update()} method, and at any point you can ask it
Thomas Woutersf8316632000-07-16 19:01:10 +000015for the \dfn{digest} of the concatenation of the strings fed to it
Raymond Hettinger1e4cf672003-09-15 18:20:52 +000016so far.\index{checksum!SHA} SHA-1 digests are 160 bits instead of
Tim Peters1de80982000-09-18 15:34:57 +000017MD5's 128 bits.
Fred Drake957ac3f1999-04-23 21:52:18 +000018
19
20\begin{funcdesc}{new}{\optional{string}}
21 Return a new sha object. If \var{string} is present, the method
22 call \code{update(\var{string})} is made.
23\end{funcdesc}
24
25
26The following values are provided as constants in the module and as
27attributes of the sha objects returned by \function{new()}:
28
29\begin{datadesc}{blocksize}
30 Size of the blocks fed into the hash function; this is always
31 \code{1}. This size is used to allow an arbitrary string to be
32 hashed.
33\end{datadesc}
34
Andrew M. Kuchlingbc4a1c22001-11-02 21:44:09 +000035\begin{datadesc}{digest_size}
Fred Drake957ac3f1999-04-23 21:52:18 +000036 The size of the resulting digest in bytes. This is always
37 \code{20}.
38\end{datadesc}
39
40
Tim Peters1de80982000-09-18 15:34:57 +000041An sha object has the same methods as md5 objects:
Fred Drake957ac3f1999-04-23 21:52:18 +000042
Tim Peters1de80982000-09-18 15:34:57 +000043\begin{methoddesc}[sha]{update}{arg}
44Update the sha object with the string \var{arg}. Repeated calls are
45equivalent to a single call with the concatenation of all the
Fred Drake907e76b2001-07-06 20:30:11 +000046arguments: \code{m.update(a); m.update(b)} is equivalent to
Tim Peters1de80982000-09-18 15:34:57 +000047\code{m.update(a+b)}.
Fred Drake957ac3f1999-04-23 21:52:18 +000048\end{methoddesc}
49
Tim Peters1de80982000-09-18 15:34:57 +000050\begin{methoddesc}[sha]{digest}{}
51Return the digest of the strings passed to the \method{update()}
52method so far. This is a 20-byte string which may contain
53non-\ASCII{} characters, including null bytes.
54\end{methoddesc}
55
56\begin{methoddesc}[sha]{hexdigest}{}
57Like \method{digest()} except the digest is returned as a string of
58length 40, containing only hexadecimal digits. This may
59be used to exchange the value safely in email or other non-binary
60environments.
61\end{methoddesc}
62
63\begin{methoddesc}[sha]{copy}{}
64Return a copy (``clone'') of the sha object. This can be used to
65efficiently compute the digests of strings that share a common initial
66substring.
67\end{methoddesc}
Fred Drake957ac3f1999-04-23 21:52:18 +000068
69\begin{seealso}
Fred Drake3c0fc842001-08-30 14:42:40 +000070 \seetitle[http://csrc.nist.gov/publications/fips/fips180-1/fip180-1.txt]
71 {Secure Hash Standard}
72 {The Secure Hash Algorithm is defined by NIST document FIPS
73 PUB 180-1:
74 \citetitle[http://csrc.nist.gov/publications/fips/fips180-1/fip180-1.txt]
75 {Secure Hash Standard}, published in April of 1995. It is
76 available online as plain text (at least one diagram was
77 omitted) and as PDF at
78 \url{http://csrc.nist.gov/publications/fips/fips180-1/fip180-1.pdf}.}
Fred Drakea20c2652001-09-06 18:59:43 +000079
80 \seetitle[http://csrc.nist.gov/encryption/tkhash.html]
81 {Cryptographic Toolkit (Secure Hashing)}
82 {Links from NIST to various information on secure hashing.}
Fred Drake957ac3f1999-04-23 21:52:18 +000083\end{seealso}