Random number generator uses wrong API

Bug #1905524 reported by Arne Bachmann
This bug report is a duplicate of:  Bug #1830738: Deprecation Warning time.clock(). Edit Remove
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Python-Crypto
New
Undecided
Unassigned

Bug Description

The code tries to access `time.clock()` which doesn't exist (in my Python distribution).
On Unix there is `time.clock_gettime(key)` and `time.clock_gettime_ns(key)` or `time.perf_counter()` and `time.perf_counter_ns()`.

I tested with Miniforge3 (CPython) and Miniconda3, simply installed via `conda install pycrypto`.

```
        p = KeyPair()
      File "d:\forks\hace\autocook\autocook\encryption.py", line 33, in __init__
        _.key = key = RSA.generate(KEY_SIZE_BITS, Random.new().read) # using minimum allowed key length
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\PublicKey\RSA.py", line 508, in generate
        obj = _RSA.generate_py(bits, rf, progress_func, e) # TODO: Don't use legacy _RSA module
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\PublicKey\_RSA.py", line 50, in generate_py
        p = pubkey.getStrongPrime(bits>>1, obj.e, 1e-12, randfunc)
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\Util\number.py", line 282, in getStrongPrime
        X = getRandomRange (lower_bound, upper_bound, randfunc)
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\Util\number.py", line 123, in getRandomRange
        value = getRandomInteger(bits, randfunc)
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\Util\number.py", line 104, in getRandomInteger
        S = randfunc(N>>3)
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\Random\_UserFriendlyRNG.py", line 202, in read
        return self._singleton.read(bytes)
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\Random\_UserFriendlyRNG.py", line 178, in read
        return _UserFriendlyRNG.read(self, bytes)
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\Random\_UserFriendlyRNG.py", line 129, in read
        self._ec.collect()
      File "c:\programdata\Miniconda3\envs\py38\lib\site-packages\Crypto\Random\_UserFriendlyRNG.py", line 77, in collect
        t = time.clock()
    AttributeError: module 'time' has no attribute 'clock'
**********************************************************************
```

Tags: clock rng time
description: updated
Revision history for this message
Cardinal Kracker (launchpap-user) wrote :

time.process_time() seems to be the intended replacement.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.