実際、_sha モジュールは shamodule.c によって提供され、_md5 は md5module.c および md5.c によって提供され、どちらも Python がデフォルトで OpenSSL でコンパイルされていない場合にのみビルドされます。
詳細はsetup.py
、Python ソース tarball で確認できます。
if COMPILED_WITH_PYDEBUG or not have_usable_openssl:
# The _sha module implements the SHA1 hash algorithm.
exts.append( Extension('_sha', ['shamodule.c']) )
# The _md5 module implements the RSA Data Security, Inc. MD5
# Message-Digest Algorithm, described in RFC 1321. The
# necessary files md5.c and md5.h are included here.
exts.append( Extension('_md5',
sources = ['md5module.c', 'md5.c'],
depends = ['md5.h']) )
ほとんどの場合、Python は Openssl ライブラリを使用して構築されており、その場合、これらの関数は OpenSSL ライブラリ自体によって提供されます。
個別に必要な場合は、OpenSSL を使用せずに Python をビルドできます。さらに良いのは、pydebug オプションを使用してビルドし、それらを使用することです。
Python ソース tarball から:
./configure --with-pydebug
make
そして、そこに行きます:
>>> import _sha
[38571 refs]
>>> _sha.__file__
'/home/senthil/python/release27-maint/build/lib.linux-i686-2.7-pydebug/_sha.so'
[38573 refs]