diff --git a/python-crypto-2.6.1-python3.12.patch b/python-crypto-2.6.1-python3.12.patch index 914c638..1892f42 100644 --- a/python-crypto-2.6.1-python3.12.patch +++ b/python-crypto-2.6.1-python3.12.patch @@ -1,21 +1,55 @@ --- src/_fastmath.c +++ src/_fastmath.c -@@ -70,11 +70,11 @@ longObjToMPZ (mpz_t m, PyLongObject * p) +@@ -58,6 +58,20 @@ + #define INLINE inline + #endif + ++#if PY_VERSION_HEX >= 0x030C0000 ++/* Code cribbed from python's internal/pycore_long.h */ ++/* Long value tag bits: ++ * * 0-1: Sign bits value = (1-sign), ie. negative=2, positive=0, zero=1. ++ * * 2: Reserved for immortality bit ++ * * 3+ Unsigned digit count ++ * */ ++#define SIGN_MASK 3 ++#define SIGN_ZERO 1 ++#define SIGN_NEGATIVE 2 ++#define NON_SIZE_BITS 3 ++#define TAG_FROM_SIGN_AND_SIZE(sign, size) ((1 - (sign)) | ((size) << NON_SIZE_BITS)) ++#endif ++ + static unsigned int sieve_base[10000]; + static int rabinMillerTest (mpz_t n, int rounds, PyObject *randfunc); + +@@ -70,13 +84,24 @@ longObjToMPZ (mpz_t m, PyLongObject * p) mpz_init (temp); mpz_init (temp2); #ifdef IS_PY3K - if (p->ob_base.ob_size > 0) { - size = p->ob_base.ob_size; ++#if PY_VERSION_HEX < 0x030C0000 + if (Py_SIZE(p) > 0) { + size = Py_SIZE(p); negative = 1; } else { - size = -p->ob_base.ob_size; + size = -Py_SIZE(p); ++ negative = -1; ++ } ++#else ++ size = p->long_value.lv_tag >> NON_SIZE_BITS; ++ if ((p->long_value.lv_tag & SIGN_MASK) == SIGN_NEGATIVE) { negative = -1; ++ } else if ((p->long_value.lv_tag & SIGN_MASK) == SIGN_ZERO) { ++ negative = 0; ++ } else { ++ negative = 1; } ++#endif #else -@@ -89,7 +89,11 @@ longObjToMPZ (mpz_t m, PyLongObject * p) + if (p->ob_size > 0) { + size = p->ob_size; +@@ -89,7 +114,11 @@ longObjToMPZ (mpz_t m, PyLongObject * p) mpz_set_ui (m, 0); for (i = 0; i < size; i++) { @@ -27,7 +61,7 @@ #ifdef IS_PY3K mpz_mul_2exp (temp2, temp, PyLong_SHIFT * i); #else -@@ -123,7 +127,11 @@ mpzToLongObj (mpz_t m) +@@ -123,7 +152,11 @@ mpzToLongObj (mpz_t m) for (i = 0; i < size; i++) { #ifdef IS_PY3K @@ -39,7 +73,7 @@ mpz_fdiv_q_2exp (temp, temp, PyLong_SHIFT); #else l->ob_digit[i] = (digit) (mpz_get_ui (temp) & MASK); -@@ -131,11 +139,19 @@ mpzToLongObj (mpz_t m) +@@ -131,11 +164,19 @@ mpzToLongObj (mpz_t m) #endif } i = size; @@ -50,10 +84,10 @@ +#endif i--; #ifdef IS_PY3K -+#if PY_VERSION_HEX < 0x03090000 ++#if PY_VERSION_HEX < 0x030C0000 l->ob_base.ob_size = i * sgn; #else -+ Py_SET_SIZE(l, (Py_ssize_t)(i * sgn)); ++ l->long_value.lv_tag = TAG_FROM_SIGN_AND_SIZE(sgn, (size_t)i); +#endif +#else l->ob_size = i * sgn; diff --git a/python-crypto.rpmlintrc b/python-crypto.rpmlintrc index 5c3b4dc..991b97b 100644 --- a/python-crypto.rpmlintrc +++ b/python-crypto.rpmlintrc @@ -1,5 +1,5 @@ -from Config import * - # LICENSE.orig is not a backup file addFilter("backup-file-in-package /usr/share/licenses/python-crypto/LEGAL/copy/LICENSE.orig") +# This is a long-unmaintained codebase that has never heard of modern tooling +addFilter("python-setup-test %{__python3} setup.py test") diff --git a/python-crypto.spec b/python-crypto.spec index 1ca9648..30429af 100644 --- a/python-crypto.spec +++ b/python-crypto.spec @@ -7,7 +7,7 @@ Summary: Cryptography library for Python Name: python-crypto Version: 2.6.1 -Release: 43%{?dist} +Release: 44%{?dist} # Mostly Public Domain apart from parts of HMAC.py and setup.py, which are Python License: Public Domain and Python URL: http://www.pycrypto.org/ @@ -58,22 +58,22 @@ or PyCryptodome software instead. %setup -n pycrypto-%{version} -q # Use distribution compiler flags rather than upstream's -%patch0 -p1 +%patch -P 0 -p1 # Fix divisions within benchmarking suite: -%patch1 -p1 +%patch -P 1 -p1 # AES.new with invalid parameter crashes python # https://github.com/dlitz/pycrypto/issues/176 # CVE-2013-7459 -%patch2 -p1 +%patch -P 2 -p1 # Unbundle libtomcrypt (#1087557) rm -rf src/libtom -%patch3 +%patch -P 3 # log() not available in libgmp, need libm too -%patch4 +%patch -P 4 # When creating ElGamal keys, the generator wasn't a square residue: ElGamal # encryption done with those keys cannot be secure under the DDH assumption @@ -85,36 +85,36 @@ rm -rf src/libtom # https://github.com/Legrandin/pycryptodome/commit/99c27a3b # Converted to pull request for pycrypto: # https://github.com/dlitz/pycrypto/pull/256 -%patch5 +%patch -P 5 # Replace the user-space RNG with a thin wrapper to os.urandom # Based on https://github.com/Legrandin/pycryptodome/commit/afd6328f # Fixes compatibility with Python 3.8 (#1718332) -%patch6 +%patch -P 6 # We already require Python 2.4 or later, so drop support for Python 2.1 # in the code -%patch7 +%patch -P 7 # Fix Python 3.10 compatibility # https://bugzilla.redhat.com/show_bug.cgi?id=1897544 -%patch8 +%patch -P 8 # Fix Python 3.11 compatibility # https://bugzilla.redhat.com/show_bug.cgi?id=2021808 -%patch9 +%patch -P 9 # Convert all code to Python 3 before the ability to use 2to3 goes away -%patch10 +%patch -P 10 # Drop use of deprecated distutils, going away in Python 3.12 -%patch11 +%patch -P 11 # Get rid of a SyntaxWarning in test_random.py -%patch12 +%patch -P 12 # Fix Python 3.12 compatibility -%patch13 +%patch -P 13 %build %global optflags %{optflags} -fno-strict-aliasing @@ -139,6 +139,10 @@ PYTHONPATH=%{buildroot}%{python3_sitearch} %{__python3} pct-speedtest.py %{python3_sitearch}/pycrypto-%{version}-py3.*.egg-info %changelog +* Thu Apr 13 2023 Paul Howarth - 2.6.1-44 +- More Python 3.12 compatibility fixes (rhbz#2186406) +- Avoid deprecated patch syntax + * Mon Mar 13 2023 Paul Howarth - 2.6.1-43 - Fix Python 3.12 compatibility (rhbz#2177718)