[IronPython] hashlib for IronPython

Sanghyeon Seo sanxiyn at gmail.com
Wed Oct 11 10:36:54 CEST 2006

hashlib is a new module using C extension added in CPython 2.5.

This is now implemented in FePy:

In CPython 2.5, md5 and sha modules are implemented as a thin wrapper
around this module. The same is true for FePy now:

You can read the source, but here are some technical details:

In CPython, hashlib is backed by OpenSSL. hashlib.new can create hash
object by name, in contrast to static constructors like hashlib.md5.
This is implemented by OpenSSL function EVP_get_digestbyname.

I have mapped this to HashAlgorithm.Create, which was an obvious
choice. This can be used, for example, to load RIPEMD160 which doesn't
have static constructor in hashlib.

Oh, by the way, I updated hash_test.py too, and you can see the usage
there. hashlib import is conditionalized to make it run on CPython 2.4

There were two problems:

1. .NET framework doesn't provide SHA224 hash algorithm, but it is
always present in CPython hashlib. I raise NotImplementedError for
this case.

2. Mono's HashAlgorithm.Create doesn't accept lowercased algorithm
names, while both MS.NET and CPython do. I convert the name to the
uppercase myself.

There's also more difficult problem which I will write about in the next post.

Seo Sanghyeon

More information about the Ironpython-users mailing list