[IronPython] Fwd: hashlib for IronPython

Sanghyeon Seo sanxiyn at gmail.com
Wed Oct 11 16:16:18 CEST 2006


---------- Forwarded message ----------
From: Sebastien Pouliot <sebastien at ximian.com>
Subject: Re: [IronPython] hashlib for IronPython
To: Sanghyeon Seo <sanxiyn at gmail.com>


[I'm not subscribed to the list, someone c.c. me this email. Feel free
to forward my answer to the list if it can help anybody]

On Wed, 2006-10-11 at 17:36 +0900, Sanghyeon Seo wrote:
> hashlib is a new module using C extension added in CPython 2.5.
> http://docs.python.org/lib/module-hashlib.html
> This is now implemented in FePy:
> https://svn.sourceforge.net/svnroot/fepy/trunk/lib/hashlib.py
> In CPython 2.5, md5 and sha modules are implemented as a thin wrapper
> around this module. The same is true for FePy now:
> https://svn.sourceforge.net/svnroot/fepy/trunk/lib/md5.py
> https://svn.sourceforge.net/svnroot/fepy/trunk/lib/sha.py
> 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
> too.
> https://svn.sourceforge.net/svnroot/fepy/trunk/example/hash_test.py
> 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.

Mono.Security.dll implements the SHA224 algorithm. This assembly is
always included with Mono (as many security tools depends on it). The
same assembly/binary can also be used on the MS runtime without any

Note that calling HashAlgorithm.Create("SHA224") will work only if the
machine.config file has been updated to add this mapping (as it is not
part of the default mappings supplied in .NET).

The implementation is also MIT X11 licensed so you should also be able
to reuse the (C#) source directly.

> 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.

Thanks for filling the bug into our bugzilla. It is now fixed in SVN and
should be part of our next release.

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

Sebastien Pouliot  <sebastien at ximian.com>
Blog: http://pages.infinit.net/ctech/

More information about the Ironpython-users mailing list