Blob Blame Raw
%global srcname pycryptodomex
%global common_description PyCryptodome is a self-contained Python package of low-level cryptographic\
primitives. It's a fork of PyCrypto. It brings several enhancements with respect\
to the last official version of PyCrypto (2.6.1), for instance:\
\
  * Authenticated encryption modes (GCM, CCM, EAX, SIV, OCB)\
  * Accelerated AES on Intel platforms via AES-NI\
  * Elliptic curves cryptography (NIST P-256 curve only)\
  * Better and more compact API (nonce and iv attributes for ciphers, automatic\
    generation of random nonces and IVs, simplified CTR cipher mode, and more)\
  * SHA-3 (including SHAKE XOFs) and BLAKE2 hash algorithms\
  * Salsa20 and ChaCha20 stream ciphers\
  * scrypt and HKDF\
  * Deterministic (EC)DSA\
  * Password-protected PKCS#8 key containers\
  * Shamir's Secret Sharing scheme\
  * Random numbers get sourced directly from the OS (and not from a CSPRNG in\
    userspace)\
  * Cleaner RSA and DSA key generation (largely based on FIPS 186-4)\
  * Major clean ups and simplification of the code base\
\
PyCryptodome is not a wrapper to a separate C library like OpenSSL. To the\
largest possible extent, algorithms are implemented in pure Python. Only the\
pieces that are extremely critical to performance (e.g. block ciphers) are\
implemented as C extensions.\
\
Note: all modules are installed under the Cryptodome package to avoid conflicts\
with the PyCrypto library.

%global _with_python2 0%{?rhel} || 0%{?fedora}
%global _with_python3_other 0%{?rhel}
# Tests fail on 32-bit architectures
# TODO: report issue
%global _with_tests 0%{?fedora} <= 29 || 0%{?rhel}
%global python_sphinx_pkg %{?rhel:python2}%{?fedora:python%{python3_pkgversion}}-sphinx
%global sphinx_build sphinx-build%{?fedora:-%{python3_version}}

Name:           python-%{srcname}
Version:        3.8.2
Release:        2%{?dist}
Summary:        A self-contained cryptographic library for Python

# PyCrypto-based code is public domain, further PyCryptodome contributions are
# BSD
License:        BSD and Public Domain
URL:            http://www.pycryptodome.org/
Source0:        https://github.com/Legrandin/pycryptodome/archive/v%{version}/%{srcname}-%{version}.tar.gz
# Use external libtomcrypt library
Patch0:         %{name}-3.7.3-use_external_libtomcrypt.patch
# Fix documentation build with Sphinx <= 1.2, especially on EL
Patch1:         %{name}-3.7.0-sphinx.patch
# Fix compilation flags
Patch2:         %{name}-3.7.3-cflags.patch

BuildRequires:  gcc
BuildRequires:  libtomcrypt-devel
%if 0%{?_with_python2}
BuildRequires:  python2-devel
BuildRequires:  python2-setuptools
%endif
BuildRequires:  python%{python3_pkgversion}-devel
BuildRequires:  python%{python3_pkgversion}-setuptools
%if 0%{_with_python3_other}
BuildRequires:  python%{python3_other_pkgversion}-devel
BuildRequires:  python%{python3_other_pkgversion}-setuptools
%endif
# Needed for documentation
BuildRequires:  %{python_sphinx_pkg}
%if 0%{?rhel}
BuildRequires:  python-sphinxcontrib-napoleon
%endif

%description
%{common_description}


%if 0%{?_with_python2}
%package -n python2-%{srcname}
Summary:        %{summary}
# GMP library is dl-opened
Requires:       gmp%{?_isa}
%{?python_provide:%python_provide python2-%{srcname}}

%description -n python2-%{srcname}
%{common_description}
%endif


%package -n python%{python3_pkgversion}-%{srcname}
Summary:        %{summary}
# GMP library is dl-opened
Requires:       gmp%{?_isa}
%{?python_provide:%python_provide python%{python3_pkgversion}-%{srcname}}

%description -n python%{python3_pkgversion}-%{srcname}
%{common_description}


%if 0%{?_with_python3_other}
%package -n python%{python3_other_pkgversion}-%{srcname}
Summary:        %{summary}
# GMP library is dl-opened
Requires:       gmp%{?_isa}
%{?python_provide:%python_provide python%{python3_other_pkgversion}-%{srcname}}

%description -n python%{python3_other_pkgversion}-%{srcname}
%{common_description}
%endif


%prep
%autosetup -n pycryptodome-%{version} -p0

# Drop bundled libraries
rm -r src/libtom/

# Remove shebang
sed '1{\@^#! /usr/bin/env python@d}' lib/Crypto/SelfTest/__main__.py >lib/Crypto/SelfTest/__main__.py.new && \
touch -r lib/Crypto/SelfTest/__main__.py lib/Crypto/SelfTest/__main__.py.new && \
mv lib/Crypto/SelfTest/__main__.py.new lib/Crypto/SelfTest/__main__.py


%build
touch .separate_namespace
%if 0%{?_with_python2}
%py2_build
%endif
%py3_build
%if 0%{?_with_python3_other}
%py3_other_build
%endif


# Build documentation
%make_build -C Doc/ man SPHINXBUILD=%{sphinx_build}


%install
%if 0%{?_with_python2}
%py2_install
%endif
%py3_install
%if 0%{?_with_python3_other}
%py3_other_install
%endif


# Install man pages
install -Dpm 0644 Doc/_build/man/pycryptodome.1 $RPM_BUILD_ROOT%{_mandir}/man1/pycryptodome.1

# Fix permissions
%if 0%{_with_python2}
chmod 0755 $RPM_BUILD_ROOT%{python2_sitearch}/Cryptodome/SelfTest/PublicKey/test_vectors/ECC/gen_ecc_p256.sh
%endif
chmod 0755 $RPM_BUILD_ROOT%{python3_sitearch}/Cryptodome/SelfTest/PublicKey/test_vectors/ECC/gen_ecc_p256.sh
%if 0%{_with_python3_other}
chmod 0755 $RPM_BUILD_ROOT%{python3_other_sitearch}/Cryptodome/SelfTest/PublicKey/test_vectors/ECC/gen_ecc_p256.sh
%endif


%check
%if 0%{?_with_tests}
%if 0%{?_with_python2}
%{__python2} setup.py test
%endif
%{__python3} setup.py test
%if 0%{?_with_python3_other}
%{__python3_other} setup.py test
%endif
%endif


%if 0%{?_with_python2}
%files -n python2-%{srcname}
%doc AUTHORS.rst Changelog.rst README.rst
%license LICENSE.rst
%{python2_sitearch}/Cryptodome/
%{python2_sitearch}/%{srcname}-*.egg-info/
%{_mandir}/man1/pycryptodome.1.*
%endif


%files -n python%{python3_pkgversion}-%{srcname}
%doc AUTHORS.rst Changelog.rst README.rst
%license LICENSE.rst
%{python3_sitearch}/Cryptodome/
%{python3_sitearch}/%{srcname}-*.egg-info/
%{_mandir}/man1/pycryptodome.1.*



%if 0%{?_with_python3_other}
%files -n python%{python3_other_pkgversion}-%{srcname}
%doc AUTHORS.rst Changelog.rst README.rst
%license LICENSE.rst
%{python3_other_sitearch}/Cryptodome/
%{python3_other_sitearch}/%{srcname}-*.egg-info/
%{_mandir}/man1/pycryptodome.1.*
%endif


%changelog
* Mon Aug 19 2019 Miro Hrončok <mhroncok@redhat.com> - 3.8.2-2
- Rebuilt for Python 3.8

* Fri Aug 09 2019 Mohamed El Morabity <melmorabity@fedoraproject.org> - 3.8.2-1
- Update to 3.8.2

* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 3.8.1-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Tue Apr 09 2019 Miro Hrončok <mhroncok@redhat.com> - 3.8.1-2
- Readd python2-pycryptodomex (#1672052)

* Fri Apr 05 2019 Mohamed El Morabity <melmorabity@fedoraproject.org> - 3.8.1-1
- Update to 3.8.1

* Fri Mar 29 2019 Mohamed El Morabity <melmorabity@fedoraproject.org> - 3.8.0-1
- Update to 3.8.0

* Fri Feb 15 2019 Mohamed El Morabity <melmorabity@fedoraproject.org> - 3.7.3-1
- Update to 3.7.3

* Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 3.7.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Mon Nov 19 2018 Mohamed El Morabity <melmorabity@fedoraproject.org> - 3.7.0-1
- Update to 3.7.0
- Use the same .spec file for all supported releases of Fedora and EL