Replace the user-space RNG with a thin wrapper to os.urandom

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)

- Drop support for Python 2.1
f38
Paul Howarth 6 years ago
parent eee44a9e50
commit a5fd7148fb

@ -0,0 +1,296 @@
--- lib/Crypto/Cipher/blockalgo.py
+++ lib/Crypto/Cipher/blockalgo.py
@@ -22,8 +22,6 @@
"""Module with definitions common to all block ciphers."""
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
#: *Electronic Code Book (ECB)*.
--- lib/Crypto/PublicKey/DSA.py
+++ lib/Crypto/PublicKey/DSA.py
@@ -82,8 +82,6 @@ __revision__ = "$Id$"
__all__ = ['generate', 'construct', 'error', 'DSAImplementation', '_DSAobj']
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.PublicKey import _DSA, _slowmath, pubkey
from Crypto import Random
--- lib/Crypto/PublicKey/RSA.py
+++ lib/Crypto/PublicKey/RSA.py
@@ -68,8 +68,6 @@ __revision__ = "$Id$"
__all__ = ['generate', 'construct', 'error', 'importKey', 'RSAImplementation', '_RSAobj']
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
#from Crypto.Util.python_compat import *
from Crypto.Util.number import getRandomRange, bytes_to_long, long_to_bytes
--- lib/Crypto/PublicKey/_slowmath.py
+++ lib/Crypto/PublicKey/_slowmath.py
@@ -30,8 +30,6 @@ __all__ = ['rsa_construct']
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.number import size, inverse, GCD
class error(Exception):
--- lib/Crypto/Random/Fortuna/FortunaAccumulator.py
+++ lib/Crypto/Random/Fortuna/FortunaAccumulator.py
@@ -25,8 +25,6 @@
__revision__ = "$Id$"
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
from binascii import b2a_hex
--- lib/Crypto/Random/Fortuna/FortunaGenerator.py
+++ lib/Crypto/Random/Fortuna/FortunaGenerator.py
@@ -25,8 +25,6 @@
__revision__ = "$Id$"
import sys
-if sys.version_info[0] is 2 and sys.version_info[1] is 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
import struct
--- lib/Crypto/Random/Fortuna/SHAd256.py
+++ lib/Crypto/Random/Fortuna/SHAd256.py
@@ -32,8 +32,6 @@ __revision__ = "$Id$"
__all__ = ['new', 'digest_size']
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
from binascii import b2a_hex
--- lib/Crypto/Random/random.py
+++ lib/Crypto/Random/random.py
@@ -29,8 +29,6 @@ __all__ = ['StrongRandom', 'getrandbits'
from Crypto import Random
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
class StrongRandom(object):
def __init__(self, rng=None, randfunc=None):
--- lib/Crypto/SelfTest/PublicKey/test_DSA.py
+++ lib/Crypto/SelfTest/PublicKey/test_DSA.py
@@ -28,8 +28,6 @@ __revision__ = "$Id$"
import sys
import os
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
import unittest
--- lib/Crypto/SelfTest/PublicKey/test_RSA.py
+++ lib/Crypto/SelfTest/PublicKey/test_RSA.py
@@ -28,8 +28,6 @@ __revision__ = "$Id$"
import sys
import os
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
import unittest
--- lib/Crypto/SelfTest/Random/Fortuna/test_FortunaAccumulator.py
+++ lib/Crypto/SelfTest/Random/Fortuna/test_FortunaAccumulator.py
@@ -27,8 +27,6 @@
__revision__ = "$Id$"
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
import unittest
--- lib/Crypto/SelfTest/Random/Fortuna/test_FortunaGenerator.py
+++ lib/Crypto/SelfTest/Random/Fortuna/test_FortunaGenerator.py
@@ -27,8 +27,6 @@
__revision__ = "$Id$"
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
import unittest
--- lib/Crypto/SelfTest/Random/test_random.py
+++ lib/Crypto/SelfTest/Random/test_random.py
@@ -28,8 +28,6 @@ __revision__ = "$Id$"
import unittest
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
class SimpleTest(unittest.TestCase):
--- lib/Crypto/SelfTest/st_common.py
+++ lib/Crypto/SelfTest/st_common.py
@@ -29,8 +29,6 @@ __revision__ = "$Id$"
import unittest
import binascii
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
class _list_testloader(unittest.TestLoader):
--- lib/Crypto/SelfTest/Util/test_Counter.py
+++ lib/Crypto/SelfTest/Util/test_Counter.py
@@ -27,8 +27,6 @@
__revision__ = "$Id$"
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
import unittest
--- lib/Crypto/SelfTest/Util/test_number.py
+++ lib/Crypto/SelfTest/Util/test_number.py
@@ -27,8 +27,6 @@
__revision__ = "$Id$"
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
import unittest
--- lib/Crypto/Signature/PKCS1_PSS.py
+++ lib/Crypto/Signature/PKCS1_PSS.py
@@ -67,8 +67,6 @@ __revision__ = "$Id$"
__all__ = [ 'new', 'PSS_SigScheme' ]
from Crypto.Util.py3compat import *
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
import Crypto.Util.number
from Crypto.Util.number import ceil_shift, ceil_div, long_to_bytes
from Crypto.Util.strxor import strxor
--- lib/Crypto/Util/Counter.py
+++ lib/Crypto/Util/Counter.py
@@ -52,8 +52,6 @@ An example of usage is the following:
:undocumented: __package__
"""
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
from Crypto.Util.py3compat import *
from Crypto.Util import _counter
--- lib/Crypto/Util/_number_new.py
+++ lib/Crypto/Util/_number_new.py
@@ -28,8 +28,6 @@ __revision__ = "$Id$"
__all__ = ['ceil_shift', 'ceil_div', 'floor_div', 'exact_log2', 'exact_div']
import sys
-if sys.version_info[0] == 2 and sys.version_info[1] == 1:
- from Crypto.Util.py21compat import *
def ceil_shift(n, b):
"""Return ceil(n / 2**b) without performing any floating-point or division operations.
--- lib/Crypto/Util/py21compat.py
+++ /dev/null
@@ -1,84 +0,0 @@
-# -*- coding: utf-8 -*-
-#
-# Util/py21compat.py : Compatibility code for Python 2.1
-#
-# Written in 2008 by Dwayne C. Litzenberger <dlitz@dlitz.net>
-#
-# ===================================================================
-# The contents of this file are dedicated to the public domain. To
-# the extent that dedication to the public domain is not available,
-# everyone is granted a worldwide, perpetual, royalty-free,
-# non-exclusive license to exercise all rights associated with the
-# contents of this file for any purpose whatsoever.
-# No rights are reserved.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
-# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
-# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-# ===================================================================
-
-"""Compatibility code for Python 2.1
-
-Currently, this just defines:
- - True and False
- - object
- - isinstance
-"""
-
-__revision__ = "$Id$"
-__all__ = []
-
-import sys
-import __builtin__
-
-# 'True' and 'False' aren't defined in Python 2.1. Define them.
-try:
- True, False
-except NameError:
- (True, False) = (1, 0)
- __all__ += ['True', 'False']
-
-# New-style classes were introduced in Python 2.2. Defining "object" in Python
-# 2.1 lets us use new-style classes in versions of Python that support them,
-# while still maintaining backward compatibility with old-style classes
-try:
- object
-except NameError:
- class object: pass
- __all__ += ['object']
-
-# Starting with Python 2.2, isinstance allows a tuple for the second argument.
-# Also, builtins like "tuple", "list", "str", "unicode", "int", and "long"
-# became first-class types, rather than functions. We want to support
-# constructs like:
-# isinstance(x, (int, long))
-# So we hack it for Python 2.1.
-try:
- isinstance(5, (int, long))
-except TypeError:
- __all__ += ['isinstance']
- _builtin_type_map = {
- tuple: type(()),
- list: type([]),
- str: type(""),
- unicode: type(u""),
- int: type(0),
- long: type(0L),
- }
- def isinstance(obj, t):
- if not __builtin__.isinstance(t, type(())):
- # t is not a tuple
- return __builtin__.isinstance(obj, _builtin_type_map.get(t, t))
- else:
- # t is a tuple
- for typ in t:
- if __builtin__.isinstance(obj, _builtin_type_map.get(typ, typ)):
- return True
- return False
-
-# vim:set ts=4 sw=4 sts=4 expandtab:

File diff suppressed because it is too large Load Diff

@ -10,7 +10,7 @@
Summary: Cryptography library for Python Summary: Cryptography library for Python
Name: python-crypto Name: python-crypto
Version: 2.6.1 Version: 2.6.1
Release: 25%{?dist} Release: 26%{?dist}
# Mostly Public Domain apart from parts of HMAC.py and setup.py, which are Python # Mostly Public Domain apart from parts of HMAC.py and setup.py, which are Python
License: Public Domain and Python License: Public Domain and Python
URL: http://www.pycrypto.org/ URL: http://www.pycrypto.org/
@ -21,6 +21,8 @@ Patch2: pycrypto-2.6.1-CVE-2013-7459.patch
Patch3: pycrypto-2.6.1-unbundle-libtomcrypt.patch Patch3: pycrypto-2.6.1-unbundle-libtomcrypt.patch
Patch4: python-crypto-2.6.1-link.patch Patch4: python-crypto-2.6.1-link.patch
Patch5: pycrypto-2.6.1-CVE-2018-6594.patch Patch5: pycrypto-2.6.1-CVE-2018-6594.patch
Patch6: pycrypto-2.6.1-use-os-random.patch
Patch7: pycrypto-2.6.1-drop-py2.1-support.patch
BuildRequires: coreutils BuildRequires: coreutils
BuildRequires: findutils BuildRequires: findutils
BuildRequires: gcc BuildRequires: gcc
@ -88,6 +90,15 @@ rm -rf src/libtom
# https://github.com/dlitz/pycrypto/pull/256 # https://github.com/dlitz/pycrypto/pull/256
%patch5 %patch5
# 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
# We already require Python 2.4 or later, so drop support for Python 2.1
# in the code
%patch7
# setup.py doesn't run 2to3 on pct-speedtest.py # setup.py doesn't run 2to3 on pct-speedtest.py
cp pct-speedtest.py pct-speedtest3.py cp pct-speedtest.py pct-speedtest3.py
2to3 -wn pct-speedtest3.py 2to3 -wn pct-speedtest3.py
@ -126,6 +137,12 @@ PYTHONPATH=%{buildroot}%{python3_sitearch} %{__python3} pct-speedtest3.py
%{python3_sitearch}/pycrypto-%{version}-py3.*.egg-info %{python3_sitearch}/pycrypto-%{version}-py3.*.egg-info
%changelog %changelog
* Fri Jun 7 2019 Paul Howarth <paul@city-fan.org> - 2.6.1-26
- 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)
- Drop support for Python 2.1
* Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 2.6.1-25 * Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 2.6.1-25
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild - Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

Loading…
Cancel
Save