[Patches] [ python-Patches-1182394 ] HMAC hexdigest and general review

SourceForge.net noreply at sourceforge.net
Wed Apr 13 20:01:05 CEST 2005


Patches item #1182394, was opened at 2005-04-13 09:08
Message generated for change (Comment added) made by alouko
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1182394&group_id=5470

Category: Library (Lib)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Shane Holloway (shane_holloway)
Assigned to: Nobody/Anonymous (nobody)
Summary: HMAC hexdigest and general review

Initial Comment:
This patch is primarily aimed at speeding up the
HMAC.hexdigest method.  The current implementation is::

        return "".join([hex(ord(x))[2:].zfill(2)
                        for x in tuple(self.digest())])

Which is correct, but a little too clever.  Especially
when other tools are available.  The attached patch
adds HMAC._current that returns the hash object
combined from self.inner and self.outter to be used by
HMAC.digest and HMAC.hexdigest.  This results in an 11
fold speed improvement for md5 and sha digestmod's
while also making the code a little easier.


Other review points for the HMAC module include
removing "_secret_backdoor_key" in favor of using
"None" as the sentinel.  In this case, it makes sense
to use None because it is an invalid key, avoids a
global lookup in py2.4 and beyond, and is just as
readable.  

I also moved blocksize to a class level constant.  This
allows implementations to create different blocksize
hashes by inheriting and changing this value.  This
also involved a change to copy() to use
self.__class__(None) instead of directly calling
HMAC(None).

The final comment is that it would be nice to have a
C-level implementation of _strxor in binascii for this
module and possibly other uses.  However, I don't
really know a significantly faster way of implementing
this method in python.

Thanks,
-Shane Holloway

----------------------------------------------------------------------

Comment By: Antti Louko (alouko)
Date: 2005-04-13 10:01

Message:
Logged In: YES 
user_id=116402

This seems good.

I would also need strxor.  Should we add it to the string
type? ^ operator is not currently defined for strings.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1182394&group_id=5470


More information about the Patches mailing list