Ñò
BwLc        
   @   s™   d  Z  d d k Td d k l Z d d k Z d d k Z d d k l Z d d k Z d d k	 Z	 d e
 f d „  ƒ  YZ d „  Z d	 e
 f d
 „  ƒ  YZ d S(   s   $Id$iÿÿÿÿ(   t   *(   t   b2a_hexN(   t   ClockRewindWarningt   FortunaPoolc           B   sD   e  Z d  Z e i Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sg  Fortuna 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().
    c         C   s   |  i  ƒ  d  S(   N(   t   reset(   t   self(    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyt   __init__3   s    c         C   s)   |  i  i | ƒ |  i t | ƒ 7_ d  S(   N(   t   _ht   updatet   lengtht   len(   R   t   data(    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyt   append6   s    c         C   s   |  i  i ƒ  S(   N(   R   t   digest(   R   (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyR   :   s    c         C   s   t  |  i ƒ  ƒ S(   N(   R   R   (   R   (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyt	   hexdigest=   s    c         C   s   t  i ƒ  |  _ d |  _ d  S(   Ni    (   t   SHAd256t   newR   R	   (   R   (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyR   @   s    (
   t   __name__t
   __module__t   __doc__R   t   digest_sizeR   R   R   R   R   (    (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyR   &   s   						c         C   sl   |  d j p t  ‚ g  } d } xE t d ƒ D]7 } |  | @d j o | i | ƒ n P| d >d B} 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."
    i   i    i    l    (   t   AssertionErrort   rangeR   (   t   rt   retvalt   maskt   i(    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyt   which_poolsD   s    	 t   FortunaAccumulatorc           B   s;   e  Z d  Z d Z d „  Z d „  Z d d „ Z d „  Z RS(   i@   gš™™™™™¹?c         C   st   d |  _  t i ƒ  |  _ d  |  _ g  } t d ƒ D] } | t ƒ  q2 ~ |  _ |  i d |  i d j	 p t	 ‚ d  S(   Ni    i    i   (
   t   reseed_countt   FortunaGeneratort   AESGeneratort	   generatort   Nonet   last_reseedR   R   t   poolsR   (   R   t   _[1]R   (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyR   ^   s
    		-c         C   s›   t  i  ƒ  } |  i | j o t i d t ƒ d  |  _ n |  i d i |  i j o8 |  i d  j p | |  i |  i	 j o |  i
 | ƒ n |  i i | ƒ S(   Ns-   Clock rewind detected. Resetting last_reseed.i    (   t   timeR"   t   warningst   warnR   R!   R#   R	   t   min_pool_sizet   reseed_intervalt   _reseedR    t   pseudo_random_data(   R   t   bytest   current_time(    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyt   random_dataj   s    c         C   s£   | d  j o t i ƒ  } n g  } |  i d 7_ | |  _ xB t |  i ƒ D]1 } | i |  i | i ƒ  ƒ |  i | i ƒ  qK Wd i	 | ƒ } |  i
 i | ƒ d  S(   Ni   t    (   R!   R%   R   R"   R   R   R#   R   R   t   joinR    t   reseed(   R   R-   t   seedR   (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyR*   v   s    	 c         C   sÇ   d t  | ƒ j o
 d j n p t ‚ d | j o
 d j n p t ‚ d | j o
 d j n p t ‚ |  i | i t | ƒ ƒ |  i | i t t  | ƒ ƒ ƒ |  i | i | ƒ d  S(   Ni   i    i    iÿ   i   (   R
   R   R#   R   t   chr(   R   t   source_numbert   pool_numberR   (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyt   add_random_eventƒ   s    +%% N(	   R   R   R(   R)   R   R.   R!   R*   R6   (    (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyR   Y   s   		(   t   __revision__t   Crypto.Util.python_compatt   binasciiR   R%   R&   t   Crypto.pct_warningsR   R   R   t   objectR   R   R   (    (    (    sg   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaAccumulator.pyt   <module>   s   
	