py-crypto + gmp

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

py-crypto + gmp

knitti
Hi,

perhaps someone can give me a pointer with my
following problem:
I try to use the _fastmath (which needs gmp) module
in py-crypto. I'm able to build it by including the following
in PCTBuildExt.build_extensions() in setup.py:

            Extension("Crypto.PublicKey._fastmath",
                    include_dirs=['src/', '/usr/local/include'],
                    sources=["src/_fastmath.c"]),

I get no errors:

# python setup.py build_ext
running build_ext
building 'Crypto.PublicKey._fastmath' extension
cc -pthread -fno-strict-aliasing -DNDEBUG -O2 -pipe \
-DTHREAD_STACK_SIZE=0x20000 -fPIC -fPIC -Isrc/ \
-I/usr/local/include -I/usr/local/include/python2.4 \
-c src/_fastmath.c \
-o build/temp.openbsd-3.8-i386-2.4/src/_fastmath.o
cc -pthread -shared -fPIC \
-L/usr/obj/i386/python-2.4.1p0/Python-2.4.1 \
build/temp.openbsd-3.8-i386-2.4/src/_fastmath.o \
-o build/lib.openbsd-3.8-i386-2.4/Crypto/PublicKey/_fastmath.so

so it _seems_ alright. But when I try to use it I get the following:

$ python
Python 2.4.1 (#1, Sep  3 2005, 13:08:59)
[GCC 3.3.5 (propolice)] on openbsd3
Type "help", "copyright", "credits" or "license" for more information.
>>> from Crypto.PublicKey import RSA
>>> from Crypto.Util.randpool import RandomPool
>>> rp = RandomPool()
>>> a = RSA.generate(3072, rp.get_bytes)
python:/usr/local/lib/python2.4/site-packages/Crypto/PublicKey/_fastmath.so:
undefined symbol '__gmpz_init'
lazy binding failed!
Segmentation fault (core dumped)

I'm not sure what to do now, I think it doesn't find libgmp,
symlinking libgmp into /usr/local/lib/python2.4/lib-dynload
doesn't help.

I use the python2.4.1p0 and gmp4.1.4 as packages on a
OpenBSD 3.8-stable. I build py-crypto (2.0.1) from source,
because the port doesn't have a flavor for building fastmath.

any ideas are welcome.

--knitti

Reply | Threaded
Open this post in threaded view
|

Re: py-crypto + gmp

Aleksander Piotrowski
knitti <[hidden email]> wrote:

> perhaps someone can give me a pointer with my
> following problem:
> I try to use the _fastmath (which needs gmp) module
> in py-crypto. I'm able to build it by including the following
> in PCTBuildExt.build_extensions() in setup.py:
>
>             Extension("Crypto.PublicKey._fastmath",
>                     include_dirs=['src/', '/usr/local/include'],
>                     sources=["src/_fastmath.c"]),

Following diff enables _fastmath module.  OK?

Index: Makefile
===================================================================
RCS file: /cvs/ports/security/py-crypto/Makefile,v
retrieving revision 1.4
diff -u -r1.4 Makefile
--- Makefile 27 Nov 2005 15:20:42 -0000 1.4
+++ Makefile 22 Jan 2006 12:48:48 -0000
@@ -6,7 +6,7 @@
 
 VERSION= 2.0.1
 DISTNAME= pycrypto-${VERSION}
-PKGNAME= py-crypto-${VERSION}
+PKGNAME= py-crypto-${VERSION}p0
 CATEGORIES=     security devel
 
 HOMEPAGE= http://www.amk.ca/python/code/crypto.html
@@ -22,8 +22,12 @@
 MASTER_SITES= http://www.amk.ca/files/python/crypto/
 
 MODULES= lang/python
+LIB_DEPENDS= gmp.6::devel/gmp
 
 DOCSDIR= ${PREFIX}/share/doc/py-crypto
+
+pre-build:
+ perl -pi -e 's,!!LOCALBASE!!,${LOCALBASE},g' ${WRKSRC}/setup.py
 
 post-install:
  ${INSTALL_DATA_DIR} ${DOCSDIR}
Index: patches/patch-setup_py
===================================================================
RCS file: /cvs/ports/security/py-crypto/patches/patch-setup_py,v
retrieving revision 1.1
diff -u -r1.1 patch-setup_py
--- patches/patch-setup_py 28 May 2005 05:39:45 -0000 1.1
+++ patches/patch-setup_py 22 Jan 2006 12:48:48 -0000
@@ -51,6 +51,26 @@
 
              # Stream ciphers
              Extension("Crypto.Cipher.ARC4",
+@@ -116,14 +122,12 @@ class PCTBuildExt (build_ext):
+         build_ext.build_extensions(self)
+
+     def detect_modules (self):
+-        lib_dirs = self.compiler.library_dirs + ['/lib', '/usr/lib']
+-        inc_dirs = self.compiler.include_dirs + ['/usr/include']
+         exts = []
+-        if (self.compiler.find_library_file(lib_dirs, 'gmp')):
+-            exts.append(Extension("Crypto.PublicKey._fastmath",
+-                                  include_dirs=['src/'],
+-                                  libraries=['gmp'],
+-                                  sources=["src/_fastmath.c"]))
++        exts.append(Extension("Crypto.PublicKey._fastmath",
++                              include_dirs=['src/', '!!LOCALBASE!!/include'],
++                              library_dirs=['!!LOCALBASE!!/lib'],
++                              libraries=['gmp'],
++                              sources=["src/_fastmath.c"]))
+         self.extensions += exts
+
+ kw = {'name':"pycrypto",
 @@ -139,9 +142,9 @@ kw = {'name':"pycrypto",
        'package_dir' : { "Crypto":"." },
        # One module is defined here, because build_ext won't be
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/security/py-crypto/pkg/PLIST,v
retrieving revision 1.4
diff -u -r1.4 PLIST
--- pkg/PLIST 27 Nov 2005 15:20:42 -0000 1.4
+++ pkg/PLIST 22 Jan 2006 12:48:48 -0000
@@ -38,6 +38,7 @@
 lib/python${MODPY_VERSION}/site-packages/Crypto/PublicKey/RSA.pyc
 lib/python${MODPY_VERSION}/site-packages/Crypto/PublicKey/__init__.py
 lib/python${MODPY_VERSION}/site-packages/Crypto/PublicKey/__init__.pyc
+lib/python${MODPY_VERSION}/site-packages/Crypto/PublicKey/_fastmath.so
 lib/python${MODPY_VERSION}/site-packages/Crypto/PublicKey/pubkey.py
 lib/python${MODPY_VERSION}/site-packages/Crypto/PublicKey/pubkey.pyc
 lib/python${MODPY_VERSION}/site-packages/Crypto/PublicKey/qNEW.py

Reply | Threaded
Open this post in threaded view
|

Re: py-crypto + gmp

knitti
On 1/22/06, Aleksander Piotrowski <[hidden email]> wrote:
> Following diff enables _fastmath module.  OK?
[...]
> ++                              library_dirs=['!!LOCALBASE!!/lib'],
> ++                              libraries=['gmp'],
yeah, that did it. thank you very much.
as I don't have a -current to test the port at the moment, I can't tell
whether the port is ok, but obviously it has already been committed.
thanks again, for unveiling another detail of distutils ;)

--knitti