[Python-Dev] SHA-256 module
Trevor Perrin
trevp at trevp.net
Fri Jul 2 10:54:05 CEST 2004
At 03:52 PM 6/30/2004 -0700, Gregory P. Smith wrote:
[...]
>The point about SSL being included is interesting. The OpenSSL library
>provides implementations of all of the important hash algorithms (and
>uses them in order to implement ssl!). Its hashing code is much better
>optimized on various architectures than the python module ever will
>be.
On my P4, OpenSSL SHA-1 looks around 25% faster (75 vs. 60 MB/s).
FWIW, I've changed the patch to support SHA224, 384, and 512. There are
"sha256" and "sha512" modules, with an extra function in each module for
the truncated algorithm:
>>> from sha256 import sha256, sha224
>>> from sha512 import sha512, sha384
>>>
>>> sha256("abc").hexdigest()
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
>>>
>>> sha384("abc").hexdigest()
'cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7'
http://sourceforge.net/tracker/index.php?func=detail&aid=935454&group_id=5470&atid=305470
Since there are some module-level functions and constants (new(),
digestsize, blocksize), I like using separate modules instead of sticking
everything in 'sha'.
We could also add some simple wrapper modules for sha224 and sha384 to make
them appear as top-level modules, like the other ones.
Trevor
More information about the Python-Dev
mailing list