[PYTHON-CRYPTO] Hashing API

Bryan Mongeau bryan at EEVOLVED.COM
Wed Feb 14 15:34:44 CET 2001


I've been hacking through some of my crypto modules, seeing how they fit with
the proposed API PC Drew has produced. I've come across something of
interest, pertaining to the hashing API:

The old way of using hash modules was to call .new() all the time to get new
hashing contexts.

The proposed way, better in my opinion, is to simply create new hashing
objects, discarding them when no longer needed.

The best way, in my opinion, would be as mentioned above, but passing an
additional parameter to .digest() will clear the hashing context. For example:

# Create an instance of a hashing class
hasher = sha256("hash this now")

# Get the digest without clearing the context
hash = hasher.digest()

# Add a string to the running context
hasher.update("another hash string")

# Get the digest and clear the context
hash = hasher.digest(1)  # Any true boolean value should suffice here

# Add a string to a brand new hashing context
hasher.update("fresh hash again!")

I think this is more efficient than deleting and creating objects to clear
the hashing context, don't you? I've already implemented this for SHA256.
Add to the API?

Regards,
--
<==================================>
Bryan Mongeau
Lead Developer, Director
eEvolved Real-Time Technologies Inc.
http://www.eevolved.com
<==================================>

"The universe we observe has precisely the properties we should expect if
there is, at bottom, no design, no purpose, no evil and no good, nothing but
blind pitiless indifference." -- Richard Dawkins





More information about the python-crypto mailing list