This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: hmac.HMAC.copy() speedup
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: tim.peters, trevp
Priority: normal Keywords: patch

Created on 2004-02-12 05:28 by trevp, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
hmac.diff trevp, 2004-02-12 06:02 diff for hmac.py
Messages (3)
msg45380 - (view) Author: Trevor Perrin (trevp) Date: 2004-02-12 05:28
Hi,

I'm using python 2.3.2, on WinXP.  This is my first 
submitted patch, let me know if I'm doing anything 
wrong..

The current hmac.HMAC.copy() constructs a new 
instance first, then overwrites it.  The hmac._strxor() 
function called in the constructor is slow.  

HMAC is used in protocols like TLS & IPSEC where you 
want to MAC each packet or record sent, so you'd want 
to construct an HMAC object once, then copy() it for 
each record.  I'm writing a TLS implementation, and the 
patch here gives me ~30% increase in throughput.

Trevor




msg45381 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-03-20 20:24
Logged In: YES 
user_id=31435

It's a decent idea -- thanks!  The mechanics of the patch 
were fine.  It's not good to use None as a secret backdoor 
argument, since passing a computed None by mistake is a 
common program flaw, and getting back an insane HMAC 
object then is a poor outcome.  So the patch I checked in 
uses a different gimmick (a unique module-private object -- 
such a thing cannot be passed by mistake).

Lib/hmac.py; new revision: 1.8
msg45382 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-03-20 20:52
Logged In: YES 
user_id=31435

It's a decent idea -- thanks!  The mechanics of the patch 
were fine.  It's not good to use None as a secret backdoor 
argument, since passing a computed None by mistake is a 
common program flaw, and getting back an insane HMAC 
object then is a poor outcome.  So the patch I checked in 
uses a different gimmick (a unique module-private object -- 
such a thing cannot be passed by mistake).

Lib/hmac.py; new revision: 1.8
History
Date User Action Args
2022-04-11 14:56:02adminsetgithub: 39927
2004-02-12 05:28:35trevpcreate