~ubuntu-branches/ubuntu/wily/python-crypto/wily-proposed

« back to all changes in this revision

Viewing changes to lib/Crypto/Random/Fortuna/FortunaAccumulator.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Ramacher, Jakub Wilk, Sebastian Ramacher
  • Date: 2013-10-17 18:24:51 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20131017182451-3zdvbd6pnum0anrm
Tags: 2.6.1-1
[ Jakub Wilk ]
* Drop obsolete Conflicts/Replaces with python2.3-crypto and
  python2.4-crypto.

[ Sebastian Ramacher ]
* New upstream release.
  - Fixes CVE-2013-1445: PRNG not correctly reseeded in some situations.
* Set urgency to high since this upload fixes a security issue.
* debian/python3-crypto.install: Fix lintian warning
  brace-expansion-in-debhelper-config-file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
 
95
95
class FortunaAccumulator(object):
96
96
 
97
 
    min_pool_size = 64      # TODO: explain why
98
 
    reseed_interval = 0.100   # 100 ms    TODO: explain why
 
97
    # An estimate of how many bytes we must append to pool 0 before it will
 
98
    # contain 128 bits of entropy (with respect to an attack).  We reseed the
 
99
    # generator only after pool 0 contains `min_pool_size` bytes.  Note that
 
100
    # unlike with some other PRNGs, Fortuna's security does not rely on the
 
101
    # accuracy of this estimate---we can accord to be optimistic here.
 
102
    min_pool_size = 64  # size in bytes
 
103
 
 
104
    # If an attacker can predict some (but not all) of our entropy sources, the
 
105
    # `min_pool_size` check may not be sufficient to prevent a successful state
 
106
    # compromise extension attack.  To resist this attack, Fortuna spreads the
 
107
    # input across 32 pools, which are then consumed (to reseed the output
 
108
    # generator) with exponentially decreasing frequency.
 
109
    #
 
110
    # In order to prevent an attacker from gaining knowledge of all 32 pools
 
111
    # before we have a chance to fill them with enough information that the
 
112
    # attacker cannot predict, we impose a rate limit of 10 reseeds/second (one
 
113
    # per 100 ms).  This ensures that a hypothetical 33rd pool would only be
 
114
    # needed after a minimum of 13 years of sustained attack.
 
115
    reseed_interval = 0.100     # time in seconds
99
116
 
100
117
    def __init__(self):
101
118
        self.reseed_count = 0
109
126
        self.pools = [FortunaPool() for i in range(32)]     # 32 pools
110
127
        assert(self.pools[0] is not self.pools[1])
111
128
 
 
129
    def _forget_last_reseed(self):
 
130
        # This is not part of the standard Fortuna definition, and using this
 
131
        # function frequently can weaken Fortuna's ability to resist a state
 
132
        # compromise extension attack, but we need this in order to properly
 
133
        # implement Crypto.Random.atfork().  Otherwise, forked child processes
 
134
        # might continue to use their parent's PRNG state for up to 100ms in
 
135
        # some cases. (e.g. CVE-2013-1445)
 
136
        self.last_reseed = None
 
137
 
112
138
    def random_data(self, bytes):
113
139
        current_time = time.time()
114
140
        if (self.last_reseed is not None and self.last_reseed > current_time): # Avoid float comparison to None to make Py3k happy