[python-crypto] Add python3-crypto subpackage (#748529)

Paul Howarth pghmcfc at fedoraproject.org
Tue Oct 25 15:26:18 UTC 2011


commit 5067373cd3bd7938fa5324f8719cdd0cc280237d
Author: Paul Howarth <paul at city-fan.org>
Date:   Tue Oct 25 16:25:16 2011 +0100

    Add python3-crypto subpackage (#748529)
    
    - Add python3-crypto subpackage (based on patch from Dave Malcolm - #748529)

 python-crypto-2.4-fix-pubkey-size-divisions.patch |   46 ++++++++++++++
 python-crypto.spec                                |   70 ++++++++++++++++++++-
 2 files changed, 114 insertions(+), 2 deletions(-)
---
diff --git a/python-crypto-2.4-fix-pubkey-size-divisions.patch b/python-crypto-2.4-fix-pubkey-size-divisions.patch
new file mode 100644
index 0000000..9f3323b
--- /dev/null
+++ b/python-crypto-2.4-fix-pubkey-size-divisions.patch
@@ -0,0 +1,46 @@
+setup.py for Python 3 doesn't invoke 2to3 on pct-speedtest.py, which runs
+into problems:
+
+Traceback (most recent call last):
+  File "pct-speedtest.py", line 218, in <module>
+    Benchmark().run()
+  File "pct-speedtest.py", line 200, in run
+    self.test_pubkey_setup(pubkey_name, module, key_bytes)
+  File "pct-speedtest.py", line 85, in test_pubkey_setup
+    keys = self.random_keys(key_bytes)[:5]
+  File "pct-speedtest.py", line 49, in random_keys
+    return self.random_blocks(bytes, 10**5)     # 100k
+  File "pct-speedtest.py", line 53, in random_blocks
+    data = self.random_data(bytes)
+  File "pct-speedtest.py", line 62, in random_data
+    self.__random_data = self._random_bytes(bytes)
+  File "pct-speedtest.py", line 73, in _random_bytes
+    return os.urandom(b)
+  File "/usr/lib64/python3.2/os.py", line 777, in urandom
+    bs += read(_urandomfd, n - len(bs))
+TypeError: integer argument expected, got float
+
+This is due to the divisions in the pubkey_specs table, which in Python 3 is
+true division, returning a float.
+
+As it happens, 2to3 can't convert these divisions, see:
+http://bugs.python.org/issue12831
+
+Change them to explicitly be floor divisions (supported in Python 2.2
+onwards; see PEP 0238)
+
+--- pycrypto/pct-speedtest.py
++++ pycrypto/pct-speedtest.py
+@@ -165,9 +165,9 @@
+ 
+     def run(self):
+         pubkey_specs = [
+-            ("RSA(1024)", RSA, 1024/8),
+-            ("RSA(2048)", RSA, 2048/8),
+-            ("RSA(4096)", RSA, 4096/8),
++            ("RSA(1024)", RSA, 1024//8),
++            ("RSA(2048)", RSA, 2048//8),
++            ("RSA(4096)", RSA, 4096//8),
+             ]
+         block_specs = [
+             ("DES", DES, 8),
diff --git a/python-crypto.spec b/python-crypto.spec
index e766bcc..22901aa 100644
--- a/python-crypto.spec
+++ b/python-crypto.spec
@@ -1,37 +1,75 @@
 %global pythonver %(%{__python} -c "import sys; print sys.version[:3]" 2>/dev/null || echo 0.0)
 %{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)" 2>/dev/null)}
 
+# Python3 introduced in Fedora 13
+%global with_python3 %([ 0%{?fedora} -gt 12 -o 0%{?rhel} -gt 6 ] && echo 1 || echo 0)
+
 Summary:	Cryptography library for Python
 Name:		python-crypto
 Version:	2.4
-Release:	1%{?dist}
+Release:	2%{?dist}
 # Mostly Public Domain apart from parts of HMAC.py and setup.py, which are Python
 License:	Public Domain and Python
 Group:		Development/Libraries
 URL:		http://www.pycrypto.org/
 Source0:	http://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-%{version}.tar.gz
 Patch0:		python-crypto-2.4-optflags.patch
+Patch1:		python-crypto-2.4-fix-pubkey-size-divisions.patch
 Provides:	pycrypto = %{version}-%{release}
 BuildRequires:	python2-devel >= 2.2, gmp-devel >= 4.1
+%if %{with_python3}
+BuildRequires:	python-tools
+BuildRequires:	python3-devel
+%endif
 BuildRoot:	%{_tmppath}/%{name}-%{version}-buildroot-%(id -nu)
 
 # Don't want provides for python shared objects
 %{?filter_provides_in: %filter_provides_in %{python_sitearch}/Crypto/.*\.so}
+%if %{with_python3}
+%{?filter_provides_in: %filter_provides_in %{python3_sitearch}/Crypto/.*\.so}
+%endif
 %{?filter_setup}
 
 %description
-Python-crypto is a collection of both secure hash functions (such as MD5 and
+PyCrypto is a collection of both secure hash functions (such as MD5 and
+SHA), and various encryption algorithms (AES, DES, RSA, ElGamal, etc.).
+
+%if %{with_python3}
+%package -n python3-crypto
+Summary:	Cryptography library for Python 3
+Group:		Development/Libraries
+
+%description -n python3-crypto
+PyCrypto is a collection of both secure hash functions (such as MD5 and
 SHA), and various encryption algorithms (AES, DES, RSA, ElGamal, etc.).
 
+This is the Python 3 build of the package.
+%endif
+
 %prep
 %setup -n pycrypto-%{version} -q
 
 # Use distribution compiler flags rather than upstream's
 %patch0 -p1
 
+# Fix divisions within benchmarking suite:
+%patch1 -p1
+
+# Prepare python3 build (setup.py doesn't run 2to3 on pct-speedtest.py)
+%if %{with_python3}
+cp -a . %{py3dir}
+2to3 -wn %{py3dir}/pct-speedtest.py
+%endif
+
 %build
 CFLAGS="%{optflags} -fno-strict-aliasing" %{__python} setup.py build
 
+%if %{with_python3}
+cd %{py3dir}
+CFLAGS="%{optflags} -fno-strict-aliasing" %{__python3} setup.py build
+cd -
+%endif
+
 %install
 rm -rf %{buildroot}
 %{__python} setup.py install -O1 --skip-build --root %{buildroot}
@@ -39,6 +77,14 @@ rm -rf %{buildroot}
 # Remove group write permissions on shared objects
 find %{buildroot}%{python_sitearch} -name '*.so' -exec chmod -c g-w {} \;
 
+# Build for python3 too
+%if %{with_python3}
+cd %{py3dir}
+%{__python3} setup.py install -O1 --skip-build --root %{buildroot}
+cd -
+find %{buildroot}%{python3_sitearch} -name '*.so' -exec chmod -c g-w {} \;
+%endif
+
 # See if there's any egg-info
 if [ -f %{buildroot}%{python_sitearch}/pycrypto-%{version}-py%{pythonver}.egg-info ]; then
 	echo %{python_sitearch}/pycrypto-%{version}-py%{pythonver}.egg-info
@@ -52,6 +98,14 @@ fi > egg-info
 PYTHONPATH=%{buildroot}%{python_sitearch} %{__python} pct-speedtest.py
 %endif
 
+# Test the python3 build too
+%if %{with_python3}
+cd %{py3dir}
+%{__python3} setup.py test
+PYTHONPATH=%{buildroot}%{python3_sitearch} %{__python3} pct-speedtest.py
+cd -
+%endif
+
 %clean
 rm -rf %{buildroot}
 
@@ -61,7 +115,19 @@ rm -rf %{buildroot}
 %doc python-3-changes.txt
 %{python_sitearch}/Crypto/
 
+%if %{with_python3}
+%files -n python3-crypto
+%defattr(-,root,root,-)
+%doc README TODO ACKS ChangeLog LEGAL/ COPYRIGHT Doc/
+%doc python-3-changes.txt
+%{python3_sitearch}/Crypto/
+%{python3_sitearch}/pycrypto-*py3.*.egg-info
+%endif
+
 %changelog
+* Tue Oct 25 2011 Paul Howarth <paul at city-fan.org> - 2.4-2
+- Add python3-crypto subpackage (based on patch from Dave Malcolm - #748529)
+
 * Mon Oct 24 2011 Paul Howarth <paul at city-fan.org> - 2.4-1
 - Update to 2.4
   - Python 3 support! PyCrypto now supports every version of Python from 2.1


More information about the scm-commits mailing list