This module implements HMAC, a method for message authentication
using cryptographic hash functions described in RFC 2104. It is a
slight improvement to an earlier version written by Barry Warsaw.
- HMAC (hashmodule)
-
Instances of the HMAC class implement HMAC for a specific hash
function. The constructor takes the hashmodule as an argument.
It must be a module that follows conforms to the interface of the
hashes in Crypto.Hash. This requires that the module have a
digestsize attribute and a new function.
HMAC provides the following method:
- hash (key, block)
-
Produce the HMAC hash for the given string, block. Key is
the shared secret authentication key, as a string. For best results
RFC 2104 recommends that the length of key should be at least as large
as the underlying hash's output block size, but this is not enforced.
If the key length is greater than the hash algorithm's basic
compression function's block size (typically 64 bytes), then it is
hashed to get the used key value. If it is less than this block
size, it is padded by appending enough zero bytes to the key.
- HMACSpecializer (hashmodule, key)
-
Instances of the HMACSpecializer class implement an HMAC for a
particular hash module and key. If many HMACs will be computed with
the same key, it is more efficient to use this class than
HMAC. There is no other reason to use this class.
HMACSpecializer provides the following method:
- hash (block)
-
Produce the HMAC hash for the given string, block. See
HMAC.hash for details.