wishlist: add support for larger message digests from SHA-2 family

Bug #544792 reported by dkg
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Python-Crypto
Fix Released
Wishlist
Unassigned
Nominated for Trunk by Legrandin

Bug Description

Currently, python-crypto appears to support SHA256 as its largest message digest. it would be good to be able to support other message digests from the SHA-2 family as well (sha-512, sha-384, and sha-224, in particular).

Revision history for this message
lorenz quack (lorenz.quack) wrote :

I went ahead and implemented SHA-512.
I based it on the existing SHA256.c implementation which made it pretty easy.
The patch also includes some unit tests.

Caveat: It depends on the header stdint.h which is only required by C99 and furthermore it depends on stdint.h defining a uint64-t type. even in C99 this is only optional.

P.S.: I took the liberty to add myself to the ACKS file in this patch.

Revision history for this message
lorenz quack (lorenz.quack) wrote :

Here are some more patches which should be applied in this order:

02_SHA2_unification.patch : Introduces generic template for SHA-2 family hashes. change SHA-256 and SHA-512 to use it.
03_SHA224_SHA384.patch : Implements SHA-224 and SHA-384 also using the generic template
04_SHA2_clean.patch : Cleans up the code and adds the Public Domain disclaimers where I previously forgot them

Hope this is useful and comments are welcome!

Revision history for this message
lorenz quack (lorenz.quack) wrote :
Revision history for this message
lorenz quack (lorenz.quack) wrote :
Revision history for this message
lorenz quack (lorenz.quack) wrote :

Not sure if there is any interest in these patches.
But for completeness I should point out a bug I noticed in my patches.

I changed the macro DIGEST_SIZE to mean the size of the digest in Bits and introduced a macro DIGEST_SIZE_BYTES to replace the old one but forgot to change the hash_template accordingly.

The fix seems pretty trivial: Either the macros need to be renamed or the hash_template needs to be adapted.

Should I send in new patches or is this comment sufficient?

Revision history for this message
dkg (dkg0) wrote :

I suspect you should leave the existing DIGEST_SIZE as bytes, and introduce a new DIGEST_SIZE_BITS.

That would avoid breaking the semantics of the API for people who use the macro, if it is exposed somewhere.

Revision history for this message
lorenz quack (lorenz.quack) wrote :

fixed the naming issue of the macros in the SHA2-family.
Also added unittests checking for the digest_size attribute at a module and instance level.

Changed in pycrypto:
importance: Undecided → Wishlist
status: New → Confirmed
Revision history for this message
Darsey Litzenberger (dlitz) wrote :

Fixed in v2.5

Changed in pycrypto:
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.