ó
Q'—^c           @   sØ   d  Z  d d l Z e j d d k rE e j d d k rE d d l Tn  d d l Td d l m Z d d l Z d d l Z d d l	 m
 Z
 d d l Z d d l Z d	 e f d
 „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d S(   s   $Id$iÿÿÿÿNi    i   i   (   t   *(   t   b2a_hex(   t   ClockRewindWarningt   FortunaPoolc           B   sD   e  Z d  Z e j 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   |  j  ƒ  d  S(   N(   t   reset(   t   self(    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyt   __init__6   s    c         C   s)   |  j  j | ƒ |  j t | ƒ 7_ d  S(   N(   t   _ht   updatet   lengtht   len(   R   t   data(    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyt   append9   s    c         C   s   |  j  j ƒ  S(   N(   R   t   digest(   R   (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyR   =   s    c         C   s=   t  j d d k r# t |  j ƒ  ƒ St |  j ƒ  ƒ j ƒ  Sd  S(   Ni    i   (   t   syst   version_infoR   R   t   decode(   R   (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyt	   hexdigest@   s    c         C   s   t  j ƒ  |  _ d |  _ d  S(   Ni    (   t   SHAd256t   newR   R	   (   R   (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyR   F   s    (
   t   __name__t
   __module__t   __doc__R   t   digest_sizeR   R   R   R   R   (    (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyR   )   s   						c         C   sh   |  d k s t  ‚ g  } d } xC t d ƒ D]5 } |  | @d k rQ | j | ƒ 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(    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyt   which_poolsJ   s    	t   FortunaAccumulatorc           B   sD   e  Z d  Z d Z d „  Z d „  Z d „  Z d d „ Z d „  Z	 RS(   i@   gš™™™™™¹?c         C   sj   d |  _  t j ƒ  |  _ d  |  _ g  t d ƒ D] } t ƒ  ^ q. |  _ |  j d |  j d k	 sf t	 ‚ d  S(   Ni    i    i   (
   t   reseed_countt   FortunaGeneratort   AESGeneratort	   generatort   Nonet   last_reseedR   R   t   poolsR   (   R   R   (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyR   u   s
    		%c         C   s   d  |  _ d  S(   N(   R$   R%   (   R   (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyt   _forget_last_reseed   s    c         C   s¤   t  j  ƒ  } |  j d  k	 rF |  j | k rF t j d t ƒ d  |  _ n  |  j d j |  j k r” |  j d  k s„ | |  j |  j	 k r” |  j
 | ƒ n  |  j j | ƒ S(   Ns-   Clock rewind detected. Resetting last_reseed.i    (   t   timeR%   R$   t   warningst   warnR   R&   R	   t   min_pool_sizet   reseed_intervalt   _reseedR#   t   pseudo_random_data(   R   t   bytest   current_time(    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyt   random_dataŠ   s    c         C   s§   | d  k r t j ƒ  } n  g  } |  j d 7_ | |  _ xB t |  j ƒ D]1 } | j |  j | j ƒ  ƒ |  j | j ƒ  qI Wt	 d ƒ j
 | ƒ } |  j j | ƒ d  S(   Ni   t    (   R$   R(   R    R%   R   R   R&   R   R   t   bt   joinR#   t   reseed(   R   R0   t   seedR   (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyR-   –   s    	c         C   s¾   d t  | ƒ k o d k n s( t ‚ d | k o? d k n sJ t ‚ d | k oa d k n sl t ‚ |  j | j t | ƒ ƒ |  j | j t t  | ƒ ƒ ƒ |  j | j | ƒ d  S(   Ni   i    i    iÿ   i   (   R
   R   R&   R   t   bchr(   R   t   source_numbert   pool_numberR   (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyt   add_random_event£   s    ("" N(
   R   R   R+   R,   R   R'   R1   R$   R-   R:   (    (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyR   _   s   				(   t   __revision__R   R   t   Crypto.Util.py21compatt   Crypto.Util.py3compatt   binasciiR   R(   R)   t   Crypto.pct_warningsR   R   R!   t   objectR   R   R   (    (    (    sJ   /tmp/pip-unpacked-wheel-owA23s/Crypto/Random/Fortuna/FortunaAccumulator.pyt   <module>   s   &
!	