ó J(Zc@sØdZddlZejddkrEejddkrEddlTnddlTddlmZddlZddlZddl m Z ddl Z ddl Z d e fd „ƒYZd „Zd e fd „ƒYZdS(s$Id$iÿÿÿÿNiii(t*(tb2a_hex(tClockRewindWarningt FortunaPoolcBsDeZdZejZd„Zd„Zd„Zd„Zd„Z RS(sgFortuna pool type This object acts like a hash object, with the following differences: - It keeps a count (the .length attribute) of the number of bytes that have been added to the pool - It supports a .reset() method for in-place reinitialization - The method to add bytes to the pool is .append(), not .update(). cCs|jƒdS(N(treset(tself((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyt__init__6scCs)|jj|ƒ|jt|ƒ7_dS(N(t_htupdatetlengthtlen(Rtdata((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pytappend9scCs |jjƒS(N(Rtdigest(R((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyR =scCs=tjddkr#t|jƒƒSt|jƒƒjƒSdS(Nii(tsyst version_infoRR tdecode(R((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyt hexdigest@scCstjƒ|_d|_dS(Ni(tSHAd256tnewRR (R((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyRFs( t__name__t __module__t__doc__Rt digest_sizeRR R RR(((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyR)s      cCsh|dkst‚g}d}xCtdƒD]5}||@dkrQ|j|ƒnP|d>dB}q+W|S(s?Return a list of pools indexes (in range(32)) that are to be included during reseed number r. According to _Practical Cryptography_, chapter 10.5.2 "Pools": "Pool P_i is included if 2**i is a divisor of r. Thus P_0 is used every reseed, P_1 every other reseed, P_2 every fourth reseed, etc." iii l(tAssertionErrortrangeR (trtretvaltmaskti((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyt which_poolsJs tFortunaAccumulatorcBsDeZdZdZd„Zd„Zd„Zdd„Zd„Z RS(i@gš™™™™™¹?cCsjd|_tjƒ|_d|_gtdƒD]}tƒ^q.|_|jd|jdk sft ‚dS(Nii i( t reseed_counttFortunaGeneratort AESGeneratort generatortNonet last_reseedRRtpoolsR(RR((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyRus   %cCs d|_dS(N(R$R%(R((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyt_forget_last_reseedscCs¤tjƒ}|jdk rF|j|krFtjdtƒd|_n|jdj|jkr”|jdks„||j|j kr”|j |ƒn|j j |ƒS(Ns-Clock rewind detected. Resetting last_reseed.i( ttimeR%R$twarningstwarnRR&R t min_pool_sizetreseed_intervalt_reseedR#tpseudo_random_data(Rtbytest current_time((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyt random_dataŠs  cCs§|dkrtjƒ}ng}|jd7_||_xBt|jƒD]1}|j|j|jƒƒ|j|jƒqIWt dƒj |ƒ}|j j |ƒdS(Nit( R$R(R R%RR R&R RtbtjoinR#treseed(RR0tseedR((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyR-–s  cCs¾dt|ƒkodkns(t‚d|ko?dknsJt‚d|koadknslt‚|j|jt|ƒƒ|j|jtt|ƒƒƒ|j|j|ƒdS(Nii iiÿi(R RR&R tbchr(Rt source_numbert pool_numberR ((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pytadd_random_event£s ("" N( RRR+R,RR'R1R$R-R:(((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyR_s  (t __revision__RRtCrypto.Util.py21compattCrypto.Util.py3compattbinasciiRR(R)tCrypto.pct_warningsRRR!tobjectRRR(((sJ/tmp/pip-build-LvEk9W/pycrypto/Crypto/Random/Fortuna/FortunaAccumulator.pyts &      !