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