%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}

Summary:	Cryptography library for Python
Summary(ja):	Python 用 Cryptography ライブラリ
Name:		python-crypto
Version:	2.6.1
Release:	2%{?_dist_release}
License:	Public Domain and Python
Group:		Development/Libraries
URL:		http://www.dlitz.net/software/pycrypto/
Source:		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
Patch2:         pycrypto-2.6.1-CVE-2013-7459.patch
Patch4:         python-crypto-2.6.1-link.patch
Patch5:         pycrypto-2.6.1-CVE-2018-6594.patch

BuildRequires:	python >= 2.2
BuildRequires:	python-devel >= 2.2
BuildRequires:	python-rpm-macros
BuildRequires:	python3
BuildRequires:	python3-devel
BuildRequires:	python3-rpm-macros
BuildRequires:	libxcrypt-devel
BuildRequires:	gmp-devel >= 5
BuildRoot:	%{_tmppath}/%{name}-%{version}-root

Vendor: Project Vine
Distribution: Vine Linux

%description
Python-crypto is a collection of both secure hash functions 
(such as MD5 and SHA), and various encryption algorithms
(AES, DES, IDEA, RSA, ElGamal, etc.).


%package -n python3-crypto
Summary:        Cryptography library for Python 3
%{?python_provide:%python_provide python3-crypto}

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

%prep
%setup -n pycrypto-%{version} -q

# Use distribution compiler flags rather than upstream's
%patch0 -p1

# Fix divisions within benchmarking suite:
%patch1 -p1

# AES.new with invalid parameter crashes python
# https://github.com/dlitz/pycrypto/issues/176
# CVE-2013-7459
%patch2 -p1

# log() not available in libgmp, need libm too
%patch4

# When creating ElGamal keys, the generator wasn't a square residue: ElGamal
# encryption done with those keys cannot be secure under the DDH assumption
# https://bugzilla.redhat.com/show_bug.cgi?id=1542313 (CVE-2018-6594)
# https://github.com/TElgamal/attack-on-pycrypto-elgamal
# https://github.com/Legrandin/pycryptodome/issues/90
# https://github.com/dlitz/pycrypto/issues/253
# Patch based on this commit from cryptodome:
# https://github.com/Legrandin/pycryptodome/commit/99c27a3b
# Converted to pull request for pycrypto:
# https://github.com/dlitz/pycrypto/pull/256
%patch5

# Remove spurious shellbangs
%{__sed} -i -e '\|^#!/usr/local/bin/python| d' lib/Crypto/Util/RFC1751.py

%build
%global optflags %{optflags} -fno-strict-aliasing
%py_build
%py3_build

%install
%{__rm} -rf %{buildroot}
%py_install
%py3_install

# Remove group write permissions on shared objects
find %{buildroot}%{python_sitearch} -name '*.so' -exec chmod -c g-w {} \;
find %{buildroot}%{python3_sitearch} -name '*.so' -exec chmod -c g-w {} \;

%check
%{__python} setup.py test
%{__python3} setup.py test

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%license COPYRIGHT LEGAL/
%doc README TODO ACKS ChangeLog Doc/
%{python_sitearch}/Crypto/
%{python_sitearch}/pycrypto-%{version}-py2.*.egg-info

%files -n python3-crypto
%defattr(-,root,root,-)
%license COPYRIGHT LEGAL/
%doc README TODO ACKS ChangeLog Doc/
%{python3_sitearch}/Crypto/
%{python3_sitearch}/pycrypto-%{version}-py3.*.egg-info

%changelog
* Tue May 14 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 2.6.1-2
- dropped all patches.
- import patched from rawhide.
- added BR:libxcrypt-devel.
- added python3 support.

* Sun Dec 15 2013 NAKAMURA Kenta <kenta@vinelinux.org> 2.6.1-1
- new upstream release
- drop Patch3: doc.patch

* Sat May 26 2012 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.6-1
- new upstream release

* Sun Feb 19 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.5-2
- rebuild with python-2.7.2

* Mon Jan 16 2012 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.5-1
- new upstream release
- added patches(1,2,3) from Debian

* Sun Nov 13 2011 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.4.1-1
- new upstream release
- dropt patch1

* Sun Oct 3 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.3-2
- rebuilt with rpm-4.8.1 for pkg-config

* Sat Aug 28 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.3-1
- new upstream release
- changed %%files

* Sun Aug 22 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 2.2-2
- fix %files (change directory from %{python_sitelib} to %{python_sitearch})

* Sun Aug 22 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.2-1
- new upstream release

* Wed Jul 7 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.1.0-1
- new upstream release
- changed URL and SOURCE to new upstream
- dropt patch0,2
- replaced patch1 from Debian newer
- added pacth3 from Debian
- changed document files dir in %%files

* Tue Feb 02 2010 Shu KONNO <owa@bg.wakwak.com> 2.0.1-3
- rebuild with python-2.6

* Fri Oct 23 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.0.1-2
- added Patch0,1,2 from Debian to fix some problem

* Wed Jul 29 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> 2.0.1-1
- initial build for VineSeed

* Mon Jun 04 2007 David Woodhouse <dwmw2@infradead.org> - 2.0.1-7.1
- Fix libdir handling so it works on more arches than x86_64

* Wed Apr 18 2007 Thorsten Leemhuis <fedora[AT]leemhuis.info> - 2.0.1-7
- Fix typo

* Wed Apr 18 2007 Thorsten Leemhuis <fedora[AT]leemhuis.info> - 2.0.1-6
- Remove dist
- rebuild, because the older version was much bigger, as it was build when
  distutils was doing static links of libpython

* Sat Dec 09 2006 Thorsten Leemhuis <fedora[AT]leemhuis.info> - 2.0.1-5
- Rebuild for python 2.5

* Thu Sep 07 2006 Thorsten Leemhuis <fedora[AT]leemhuis.info> - 2.0.1-4
- Don't ghost pyo files (#205408)

* Tue Aug 29 2006 Thorsten Leemhuis <fedora[AT]leemhuis.info> - 2.0.1-3
- Rebuild for Fedora Extras 6

* Mon Feb 13 2006 Thorsten Leemhuis <fedora[AT]leemhuis.info> - 2.0.1-2
- Rebuild for Fedora Extras 5

* Wed Aug 17 2005 Thorsten Leemhuis <fedora at leemhuis dot info> - 0:2.0.1-1
- Update to 2.0.1
- Use Dist
- Drop python-crypto-64bit-unclean.patch, similar patch was applied 
  upstream

* Thu May 05 2005 Thorsten Leemhuis <fedora at leemhuis dot info> - 0:2.0-4
- add python-crypto-64bit-unclean.patch (#156173)

* Mon Mar 21 2005 Seth Vidal <skvidal at phy.duke.edu> - 0:2.0-3
- iterate release for build on python 2.4 based systems

* Sat Dec 18 2004 Thorsten Leemhuis <fedora at leemhuis dot info> - 0:2.0-2
- Fix build on x86_64: use python_sitearch for files and patch source
  to find gmp

* Thu Aug 26 2004 Thorsten Leemhuis <fedora at leemhuis dot info> - 0:2.0-0.fdr.1
- Update to 2.00

* Fri Aug 13 2004 Ville Skytta <ville.skytta at iki.fi> - 0:1.9-0.fdr.6.a6
- Don't use get_python_version(), it's available in Python >= 2.3 only.

* Thu Aug 12 2004 Thorsten Leemhuis <fedora at leemhuis dot info> 0:1.9-0.fdr.5.a6
- Own dir python_sitearch/Crypto/

* Wed Aug 11 2004 Thorsten Leemhuis <fedora at leemhuis dot info> 0:1.9-0.fdr.4.a6
- Match python spec template more

* Sat Jul 17 2004 Thorsten Leemhuis <fedora at leemhuis dot info> 0:1.9-0.fdr.3.a6
- Own _libdir/python/site-packages/Crypto/

* Wed Mar 24 2004 Panu Matilainen <pmatilai@welho.com> 0.3.2-0.fdr.2.a6
- generate .pyo files during install
- require exact version of python used to build the package
- include more docs + demos
- fix dependency on /usr/local/bin/python
- use fedora.us style buildroot
- buildrequires gmp-devel
- use description from README

* Sun Jan 11 2004 Ryan Boder <icanoop@bitwiser.org>  0.3.2-0.fdr.1.a6
- Initial build.

