blob: 5ca24d1c28968abb7e1c59559e68cedd590dcb32 [file] [log] [blame]
Fred Drake42706802001-09-11 16:56:09 +00001\section{\module{hmac} ---
2 Keyed-Hashing for Message Authentication}
3
4\declaremodule{standard}{hmac}
5\modulesynopsis{Keyed-Hashing for Message Authentication (HMAC)
6 implementation for Python.}
7\moduleauthor{Gerhard H{\"a}ring}{ghaering@users.sourceforge.net}
8\sectionauthor{Gerhard H{\"a}ring}{ghaering@users.sourceforge.net}
9
10\versionadded{2.2}
11
12This module implements the HMAC algorithm as described by \rfc{2104}.
13
14\begin{funcdesc}{new}{key\optional{, msg\optional{, digestmod}}}
15 Return a new hmac object. If \var{msg} is present, the method call
16 \code{update(\var{msg})} is made. \var{digestmod} is the digest
Gregory P. Smithf21a5f72005-08-21 18:45:59 +000017 constructor or module for the HMAC object to use. It defaults to
18 the \code{\refmodule{hashlib}.md5} constructor. \note{The md5 hash
19 has known weaknesses but remains the default for backwards compatibility.
20 Choose a better one for your application.}
Fred Drake42706802001-09-11 16:56:09 +000021\end{funcdesc}
22
23An HMAC object has the following methods:
24
25\begin{methoddesc}[hmac]{update}{msg}
26 Update the hmac object with the string \var{msg}. Repeated calls
27 are equivalent to a single call with the concatenation of all the
28 arguments: \code{m.update(a); m.update(b)} is equivalent to
29 \code{m.update(a + b)}.
30\end{methoddesc}
31
32\begin{methoddesc}[hmac]{digest}{}
33 Return the digest of the strings passed to the \method{update()}
Gregory P. Smithf21a5f72005-08-21 18:45:59 +000034 method so far. This string will be the same length as the
35 \var{digest_size} of the digest given to the constructor. It
36 may contain non-\ASCII{} characters, including NUL bytes.
Fred Drake42706802001-09-11 16:56:09 +000037\end{methoddesc}
38
39\begin{methoddesc}[hmac]{hexdigest}{}
Gregory P. Smithf21a5f72005-08-21 18:45:59 +000040 Like \method{digest()} except the digest is returned as a string
41 twice the length containing
Fred Drake42706802001-09-11 16:56:09 +000042 only hexadecimal digits. This may be used to exchange the value
43 safely in email or other non-binary environments.
44\end{methoddesc}
45
46\begin{methoddesc}[hmac]{copy}{}
47 Return a copy (``clone'') of the hmac object. This can be used to
48 efficiently compute the digests of strings that share a common
49 initial substring.
50\end{methoddesc}
Gregory P. Smithf21a5f72005-08-21 18:45:59 +000051
52\begin{seealso}
53 \seemodule{hashlib}{The python module providing secure hash functions.}
54\end{seealso}