[Python-checkins] python/dist/src/Lib hmac.py,1.7,1.8
tim_one at users.sourceforge.net
tim_one at users.sourceforge.net
Sat Mar 20 15:11:31 EST 2004
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20234/Lib
Modified Files:
hmac.py
Log Message:
Speed HMAC.copy() by installing a secret backdoor argument to
HMAC.__init__(). Adapted from SF patch 895445 "hmac.HMAC.copy() speedup"
by Trevor Perrin, who reported that this approach increased throughput
of his hmac-intensive app by 30%.
Index: hmac.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/hmac.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** hmac.py 3 Jun 2002 15:58:31 -0000 1.7
--- hmac.py 20 Mar 2004 20:11:29 -0000 1.8
***************
*** 13,16 ****
--- 13,21 ----
digest_size = None
+ # A unique object passed by HMAC.copy() to the HMAC constructor, in order
+ # that the latter return very quickly. HMAC("") in contrast is quite
+ # expensive.
+ _secret_backdoor_key = []
+
class HMAC:
"""RFC2104 HMAC class.
***************
*** 26,29 ****
--- 31,38 ----
digestmod: A module supporting PEP 247. Defaults to the md5 module.
"""
+
+ if key is _secret_backdoor_key: # cheap
+ return
+
if digestmod is None:
import md5
***************
*** 61,66 ****
An update to this copy won't affect the original object.
"""
! other = HMAC("")
other.digestmod = self.digestmod
other.inner = self.inner.copy()
other.outer = self.outer.copy()
--- 70,76 ----
An update to this copy won't affect the original object.
"""
! other = HMAC(_secret_backdoor_key)
other.digestmod = self.digestmod
+ other.digest_size = self.digest_size
other.inner = self.inner.copy()
other.outer = self.outer.copy()
More information about the Python-checkins
mailing list