Current File : //usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyo |
�
�/�Oc @ sa d Z d Z d d d g Z d d l m Z d d l Td
Z d d d � � YZ d
d
d � Z d
S( s� HMAC (Hash-based Message Authentication Code) algorithm
HMAC is a MAC defined in RFC2104_ and FIPS-198_ and constructed using
a cryptograpic hash algorithm.
It is usually named *HMAC-X*, where *X* is the hash algorithm; for
instance *HMAC-SHA1* or *HMAC-MD5*.
The strength of an HMAC depends on:
- the strength of the hash algorithm
- the length and entropy of the secret key
An example of possible usage is the following:
>>> from Crypto.Hash import HMAC
>>>
>>> secret = b'Swordfish'
>>> h = HMAC.new(secret)
>>> h.update(b'Hello')
>>> print h.hexdigest()
.. _RFC2104: http://www.ietf.org/rfc/rfc2104.txt
.. _FIPS-198: http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf
s $Id$t newt digest_sizet HMACi����( t strxor_c( t *c B sG e Z d Z d Z d d d � Z d � Z d � Z d � Z d � Z RS( s Class that implements HMACc C sK | d k r! d d l } | } n | | _ | j � | _ | j � | _ y | j | _ Wn) t k
r� t | j j � � | _ n Xy
| j
} Wn t k
r� d } n Xd } d } t | � | k r� | j | � j � } n | t d � | t | � } | j j t
| | � � | j j t
| | � � | rG| j | � n d S( s� Create a new HMAC object.
:Parameters:
key : byte string
secret key for the MAC object.
It must be long enough to match the expected security level of the
MAC. However, there is no benefit in using keys longer than the
`digest_size` of the underlying hash algorithm.
msg : byte string
The very first chunk of the message to authenticate.
It is equivalent to an early call to `update()`. Optional.
:Parameter digestmod:
The hash algorithm the HMAC is based on.
Default is `Crypto.Hash.MD5`.
:Type digestmod:
A hash module or object instantiated from `Crypto.Hash`
i����Ni@ i6 i\ i ( t Nonet MD5t digestmodR t outert innerR t AttributeErrort lent digestt
block_sizet bchrt updateR ( t selft keyt msgR R t blocksizet ipadt opad( ( s6 /usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyt __init__R s.
c C s | j j | � d S( s� Continue authentication of a message by consuming the next chunk of data.
Repeated calls are equivalent to a single call with the concatenation
of all the arguments. In other words:
>>> m.update(a); m.update(b)
is equivalent to:
>>> m.update(a+b)
:Parameters:
msg : byte string
The next chunk of the message being authenticated
N( R R ( R R ( ( s6 /usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR � s c C sF t t d � � } | j | _ | j j � | _ | j j � | _ | S( s! Return a copy ("clone") of the MAC object.
The copy will have the same internal state as the original MAC
object.
This can be used to efficiently compute the MAC of strings that
share a common initial substring.
:Returns: An `HMAC` object
t ( R t bR R t copyR ( R t other( ( s6 /usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR � s
c C s/ | j j � } | j | j j � � | j � S( s} Return the **binary** (non-printable) MAC of the message that has
been authenticated so far.
This method does not change the state of the MAC object.
You can continue updating the object after calling this function.
:Return: A byte string of `digest_size` bytes. It may contain non-ASCII
characters, including null bytes.
( R R R R R ( R t h( ( s6 /usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR � s
c C s6 d j g t | j � � D] } d t | � ^ q � S( s Return the **printable** MAC of the message that has been
authenticated so far.
This method does not change the state of the MAC object.
:Return: A string of 2* `digest_size` bytes. It contains only
hexadecimal ASCII digits.
R s %02x( t joint tupleR t bord( R t x( ( s6 /usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyt hexdigest� s N(
t __name__t
__module__t __doc__R R R R R R R ( ( ( s6 /usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR J s 1 c C s t | | | � S( s� Create a new HMAC object.
:Parameters:
key : byte string
key for the MAC object.
It must be long enough to match the expected security level of the
MAC. However, there is no benefit in using keys longer than the
`digest_size` of the underlying hash algorithm.
msg : byte string
The very first chunk of the message to authenticate.
It is equivalent to an early call to `HMAC.update()`.
Optional.
:Parameter digestmod:
The hash to use to implement the HMAC. Default is `Crypto.Hash.MD5`.
:Type digestmod:
A hash module or instantiated object from `Crypto.Hash`
:Returns: An `HMAC` object
( R ( R R R ( ( s6 /usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyR � s N( (
R# t __revision__t __all__t Crypto.Util.strxorR t Crypto.Util.py3compatR R R R ( ( ( s6 /usr/lib64/python2.7/site-packages/Crypto/Hash/HMAC.pyt <module>9 s
v