<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/python-packages/pycrypto.git/lib/Crypto/Random, branch master</title>
<subtitle>github.com: dlitz/pycrypto.git
</subtitle>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/'/>
<entry>
<title>Merge tag 'v2.6.1' (fix CVE-2013-1445)</title>
<updated>2013-10-20T20:28:46+00:00</updated>
<author>
<name>Dwayne Litzenberger</name>
<email>dlitz@dlitz.net</email>
</author>
<published>2013-10-20T20:28:46+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=d044a478332682c253c379db87d444b056e4ab37'/>
<id>d044a478332682c253c379db87d444b056e4ab37</id>
<content type='text'>
This is the PyCrypto 2.6.1 release.

Dwayne Litzenberger (4):
      Random: Make Crypto.Random.atfork() set last_reseed=None (CVE-2013-1445)
      Fortuna: Add comments for reseed_interval and min_pool_size to FortunaAccumulator
      Update the ChangeLog
      Release v2.6.1
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is the PyCrypto 2.6.1 release.

Dwayne Litzenberger (4):
      Random: Make Crypto.Random.atfork() set last_reseed=None (CVE-2013-1445)
      Fortuna: Add comments for reseed_interval and min_pool_size to FortunaAccumulator
      Update the ChangeLog
      Release v2.6.1
</pre>
</div>
</content>
</entry>
<entry>
<title>Fortuna: Add comments for reseed_interval and min_pool_size to FortunaAccumulator</title>
<updated>2013-10-14T21:37:36+00:00</updated>
<author>
<name>Dwayne Litzenberger</name>
<email>dlitz@dlitz.net</email>
</author>
<published>2013-10-14T21:37:36+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=fa06af7feaf37e7dc2d66a1e028fe9afc8ffd585'/>
<id>fa06af7feaf37e7dc2d66a1e028fe9afc8ffd585</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Random: Make Crypto.Random.atfork() set last_reseed=None (CVE-2013-1445)</title>
<updated>2013-10-14T21:37:35+00:00</updated>
<author>
<name>Dwayne Litzenberger</name>
<email>dlitz@dlitz.net</email>
</author>
<published>2013-10-14T21:37:35+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=19dcf7b15d61b7dc1a125a367151de40df6ef175'/>
<id>19dcf7b15d61b7dc1a125a367151de40df6ef175</id>
<content type='text'>
== Summary ==

In PyCrypto before v2.6.1, the Crypto.Random pseudo-random number
generator (PRNG) exhibits a race condition that may cause it to generate
the same 'random' output in multiple processes that are forked from each
other.  Depending on the application, this could reveal sensitive
information or cryptographic keys to remote attackers.

An application may be affected if, within 100 milliseconds, it performs
the following steps (which may be summarized as "read-fork-read-read"):

1. Read from the Crypto.Random PRNG, causing an internal reseed;
2. Fork the process and invoke Crypto.Random.atfork() in the child;
3. Read from the Crypto.Random PRNG again, in at least two different
   processes (parent and child, or multiple children).

Only applications that invoke Crypto.Random.atfork() and perform the
above steps are affected by this issue.  Other applications are
unaffected.

Note: Some PyCrypto functions, such as key generation and PKCS#1-related
functions, implicitly read from the Crypto.Random PRNG.

== Technical details ==

Crypto.Random uses Fortuna[1] to generate random numbers.  The flow of
entropy looks something like this:

    /dev/urandom  -\
                    +-&gt; "accumulator" --&gt; "generator" --&gt; output
    other sources -/   (entropy pools)     (AES-CTR)

- The "accumulator" maintains several pools that collect entropy from
  the environment.

- The "generator" is a deterministic PRNG that is reseeded by the
  accumulator.  Reseeding normally occurs during each request for random
  numbers, but never more than once every 100 ms (the "minimum reseed
  interval").

When a process is forked, the parent's state is duplicated in the child.
In order to continue using the PRNG, the child process must invoke
Crypto.Random.atfork(), which collects new entropy from /dev/urandom and
adds it to the accumulator.  When new PRNG output is subsequently
requested, some of the new entropy in the accumulator is used to reseed
the generator, causing the output of the child to diverge from its
parent.

However, in previous versions of PyCrypto, Crypto.Random.atfork() did
not explicitly reset the child's rate-limiter, so if the child requested
PRNG output before the minimum reseed interval of 100 ms had elapsed, it
would generate its output using state inherited from its parent.

This created a race condition between the parent process and its forked
children that could cause them to produce identical PRNG output for the
duration of the 100 ms minimum reseed interval.

== Demonstration ==

Here is some sample code that illustrates the problem:

    from binascii import hexlify
    import multiprocessing, pprint, time
    import Crypto.Random

    def task_main(arg):
        a = Crypto.Random.get_random_bytes(8)
        time.sleep(0.1)
        b = Crypto.Random.get_random_bytes(8)
        rdy, ack = arg
        rdy.set()
        ack.wait()
        return "%s,%s" % (hexlify(a).decode(),
                          hexlify(b).decode())

    n_procs = 4
    manager = multiprocessing.Manager()
    rdys = [manager.Event() for i in range(n_procs)]
    acks = [manager.Event() for i in range(n_procs)]
    Crypto.Random.get_random_bytes(1)
    pool = multiprocessing.Pool(processes=n_procs,
                                initializer=Crypto.Random.atfork)
    res_async = pool.map_async(task_main, zip(rdys, acks))
    pool.close()
    [rdy.wait() for rdy in rdys]
    [ack.set() for ack in acks]
    res = res_async.get()
    pprint.pprint(sorted(res))
    pool.join()

The output should be random, but it looked like this:

    ['c607803ae01aa8c0,2e4de6457a304b34',
     'c607803ae01aa8c0,af80d08942b4c987',
     'c607803ae01aa8c0,b0e4c0853de927c4',
     'c607803ae01aa8c0,f0362585b3fceba4']

== Solution ==

The solution is to upgrade to PyCrypto v2.6.1 or later, which properly
resets the rate-limiter when Crypto.Random.atfork() is invoked in the
child.

== References ==

[1] N. Ferguson and B. Schneier, _Practical Cryptography_,
    Indianapolis: Wiley, 2003, pp. 155-184.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
== Summary ==

In PyCrypto before v2.6.1, the Crypto.Random pseudo-random number
generator (PRNG) exhibits a race condition that may cause it to generate
the same 'random' output in multiple processes that are forked from each
other.  Depending on the application, this could reveal sensitive
information or cryptographic keys to remote attackers.

An application may be affected if, within 100 milliseconds, it performs
the following steps (which may be summarized as "read-fork-read-read"):

1. Read from the Crypto.Random PRNG, causing an internal reseed;
2. Fork the process and invoke Crypto.Random.atfork() in the child;
3. Read from the Crypto.Random PRNG again, in at least two different
   processes (parent and child, or multiple children).

Only applications that invoke Crypto.Random.atfork() and perform the
above steps are affected by this issue.  Other applications are
unaffected.

Note: Some PyCrypto functions, such as key generation and PKCS#1-related
functions, implicitly read from the Crypto.Random PRNG.

== Technical details ==

Crypto.Random uses Fortuna[1] to generate random numbers.  The flow of
entropy looks something like this:

    /dev/urandom  -\
                    +-&gt; "accumulator" --&gt; "generator" --&gt; output
    other sources -/   (entropy pools)     (AES-CTR)

- The "accumulator" maintains several pools that collect entropy from
  the environment.

- The "generator" is a deterministic PRNG that is reseeded by the
  accumulator.  Reseeding normally occurs during each request for random
  numbers, but never more than once every 100 ms (the "minimum reseed
  interval").

When a process is forked, the parent's state is duplicated in the child.
In order to continue using the PRNG, the child process must invoke
Crypto.Random.atfork(), which collects new entropy from /dev/urandom and
adds it to the accumulator.  When new PRNG output is subsequently
requested, some of the new entropy in the accumulator is used to reseed
the generator, causing the output of the child to diverge from its
parent.

However, in previous versions of PyCrypto, Crypto.Random.atfork() did
not explicitly reset the child's rate-limiter, so if the child requested
PRNG output before the minimum reseed interval of 100 ms had elapsed, it
would generate its output using state inherited from its parent.

This created a race condition between the parent process and its forked
children that could cause them to produce identical PRNG output for the
duration of the 100 ms minimum reseed interval.

== Demonstration ==

Here is some sample code that illustrates the problem:

    from binascii import hexlify
    import multiprocessing, pprint, time
    import Crypto.Random

    def task_main(arg):
        a = Crypto.Random.get_random_bytes(8)
        time.sleep(0.1)
        b = Crypto.Random.get_random_bytes(8)
        rdy, ack = arg
        rdy.set()
        ack.wait()
        return "%s,%s" % (hexlify(a).decode(),
                          hexlify(b).decode())

    n_procs = 4
    manager = multiprocessing.Manager()
    rdys = [manager.Event() for i in range(n_procs)]
    acks = [manager.Event() for i in range(n_procs)]
    Crypto.Random.get_random_bytes(1)
    pool = multiprocessing.Pool(processes=n_procs,
                                initializer=Crypto.Random.atfork)
    res_async = pool.map_async(task_main, zip(rdys, acks))
    pool.close()
    [rdy.wait() for rdy in rdys]
    [ack.set() for ack in acks]
    res = res_async.get()
    pprint.pprint(sorted(res))
    pool.join()

The output should be random, but it looked like this:

    ['c607803ae01aa8c0,2e4de6457a304b34',
     'c607803ae01aa8c0,af80d08942b4c987',
     'c607803ae01aa8c0,b0e4c0853de927c4',
     'c607803ae01aa8c0,f0362585b3fceba4']

== Solution ==

The solution is to upgrade to PyCrypto v2.6.1 or later, which properly
resets the rate-limiter when Crypto.Random.atfork() is invoked in the
child.

== References ==

[1] N. Ferguson and B. Schneier, _Practical Cryptography_,
    Indianapolis: Wiley, 2003, pp. 155-184.
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix error importing winrandom on Python 3</title>
<updated>2013-05-25T04:22:15+00:00</updated>
<author>
<name>Jason R. Coombs</name>
<email>jaraco@jaraco.com</email>
</author>
<published>2013-05-25T04:22:15+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=10abfc8633bac653eda4d346fc051b2f07554dcd'/>
<id>10abfc8633bac653eda4d346fc051b2f07554dcd</id>
<content type='text'>
On Python 3, 'import winrandom' cannot be automatically converted to the relative import, so fails. This change fixes that behavior.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
On Python 3, 'import winrandom' cannot be automatically converted to the relative import, so fails. This change fixes that behavior.</pre>
</div>
</content>
</entry>
<entry>
<title>FortunaAccumulator: Use time.monotonic if available (i.e. Python 3.3 and later)</title>
<updated>2013-04-22T06:24:23+00:00</updated>
<author>
<name>Dwayne Litzenberger</name>
<email>dlitz@dlitz.net</email>
</author>
<published>2013-04-22T06:24:23+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=22d7760ae7346d80a6c54b1549e9a1d560c239bc'/>
<id>22d7760ae7346d80a6c54b1549e9a1d560c239bc</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix dumb typo: "is 2" should be "== 2"</title>
<updated>2013-02-18T03:00:50+00:00</updated>
<author>
<name>Dwayne Litzenberger</name>
<email>dlitz@dlitz.net</email>
</author>
<published>2013-02-18T03:00:43+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=4e4cc0beefbb316db2a8750e747e697df0b754d7'/>
<id>4e4cc0beefbb316db2a8750e747e697df0b754d7</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix LP#1061217: random.shuffle takes O(n^2) time</title>
<updated>2013-02-16T18:50:03+00:00</updated>
<author>
<name>Dwayne Litzenberger</name>
<email>dlitz@dlitz.net</email>
</author>
<published>2013-02-16T18:50:03+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=14ef4933c9c0b21c7bfba3556e1aa13f3f9ef6ff'/>
<id>14ef4933c9c0b21c7bfba3556e1aa13f3f9ef6ff</id>
<content type='text'>
The previous implementation took O(n**2) time and O(n) auxiliary space.
We now use the Fisher-Yates algorithm, which takes O(n) time and O(1)
space.

Thanks to Sujay Jayakar and Andrew Cooke for pointing this out and
suggesting a solution.

Bug report: https://bugs.launchpad.net/pycrypto/+bug/1061217
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The previous implementation took O(n**2) time and O(n) auxiliary space.
We now use the Fisher-Yates algorithm, which takes O(n) time and O(1)
space.

Thanks to Sujay Jayakar and Andrew Cooke for pointing this out and
suggesting a solution.

Bug report: https://bugs.launchpad.net/pycrypto/+bug/1061217
</pre>
</div>
</content>
</entry>
<entry>
<title>Fix DevURandomRNG to work with Python3's new I/O stack.</title>
<updated>2012-04-21T16:59:49+00:00</updated>
<author>
<name>Sebastian Ramacher</name>
<email>s.ramacher@gmx.at</email>
</author>
<published>2012-02-03T14:26:27+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=95d65366e9ac7e194bf8317d69785c9a5b877790'/>
<id>95d65366e9ac7e194bf8317d69785c9a5b877790</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge from upstream</title>
<updated>2011-12-22T13:55:40+00:00</updated>
<author>
<name>Legrandin</name>
<email>gooksankoo@hoiptorrow.mailexpire.com</email>
</author>
<published>2011-12-22T13:55:40+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=114ca5b4d467617489817eee77ed0621665ee362'/>
<id>114ca5b4d467617489817eee77ed0621665ee362</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Python 3.x fixes:</title>
<updated>2011-10-22T19:07:47+00:00</updated>
<author>
<name>Dwayne C. Litzenberger</name>
<email>dlitz@dlitz.net</email>
</author>
<published>2011-10-22T19:07:47+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/python-packages/pycrypto.git/commit/?id=094d70b64d6b575841c6d340f2391b977bc61694'/>
<id>094d70b64d6b575841c6d340f2391b977bc61694</id>
<content type='text'>
- Use absolute imports
- Fix StringIO import so that 2to3 can translate it
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
- Use absolute imports
- Fix StringIO import so that 2to3 can translate it
</pre>
</div>
</content>
</entry>
</feed>
