Ņō
BwLc        	   @   s~   d  Z  d d k Td d k Z d d k l Z l Z l Z d d k l Z d d k	 l
 Z
 d d k Z d e f d     YZ d S(	   s   $Id$iĸĸĸĸ(   t   *N(   t
   ceil_shiftt
   exact_log2t	   exact_div(   t   Counter(   t   AESt   AESGeneratorc           B   sg   e  Z d  Z e i Z d Z d Z d e d Z d   Z d   Z	 d   Z
 d	   Z d
   Z d   Z RS(   s)  The Fortuna "generator"

    This is used internally by the Fortuna PRNG to generate arbitrary amounts
    of pseudorandom data from a smaller amount of seed data.

    The output is generated by running AES-256 in counter mode and re-keying
    after every mebibyte (2**16 blocks) of output.
    i    i   i   t    i   c         C   są   t  i d |  i d d d d t  |  _ d  |  _ t |  i  |  _ d |  i >|  i j p t	  t
 |  i |  i  |  _ |  i |  i |  i j p t	  |  i |  i |  _ d  S(   Nt   nbitsi   t   initial_valuei    t   little_endiani   (   R   t   newt
   block_sizet   Truet   countert   Nonet   keyR   t   block_size_shiftt   AssertionErrorR   t   key_sizet   blocks_per_keyt   max_blocks_per_requestt   max_bytes_per_request(   t   self(    (    se   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaGenerator.pyt   __init__>   s    (	!c         C   su   |  i  d  j o d |  i |  _  n |  i t i |  i  |  i    |  i   t |  i   |  i j p t	  d  S(   NR   (
   R   R   R   t   _set_keyt   SHAd256R   t   digestR   t   lenR   (   R   t   seed(    (    se   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaGenerator.pyt   reseedK   s
    #
c         C   s~   | d j p t   | d ?} | d @} g  } x* t |  D] } | i |  i d   q; W| i |  i |   d i |  S(   Ni    i   i   t    i   iĸĸ i   (   R   t   xranget   appendt   _pseudo_random_datat   join(   R   t   bytest   num_full_blockst	   remaindert   retvalt   i(    (    se   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaGenerator.pyt   pseudo_random_dataR   s    

 c         C   s.   | |  _  t i | t i d |  i |  _ d  S(   NR   (   R   R   R   t   MODE_CTRR   t   _cipher(   R   R   (    (    se   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaGenerator.pyR   _   s    	c         C   s­   d | j o |  i  j n p t d   n t | |  i  } |  i |  |  } |  i |  i |  i   t |  | j p t  t |  i  |  i	 j p t  | S(   Ni    s6   You cannot ask for more than 1 MiB of data per request(
   R   R   R   R   t   _generate_blocksR   R   R   R   R   (   R   R$   t
   num_blocksR'   (    (    se   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaGenerator.pyR"   c   s    ! c         C   sÃ   |  i  d  j o t d   n d | j o |  i j n p t  g  } x4 t | d ? D]" } | i |  i i |  i   q_ W| d @|  i	 >} | i |  i i |  i |    d i
 |  S(   Ns#   generator must be seeded before usei    i   iĸ  R   (   R   R   R   R   R    R!   R+   t   encryptt   _four_kiblocks_of_zerosR   R#   (   R   R-   R'   R(   t   remaining_bytes(    (    se   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaGenerator.pyR,   u   s    (   i   (   t   __name__t
   __module__t   __doc__R   R   R   R   R/   R   R   R)   R   R"   R,   (    (    (    se   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaGenerator.pyR   %   s   	
					(   t   __revision__t   Crypto.Util.python_compatt   structt   Crypto.Util.numberR   R   R   t   Crypto.UtilR   t   Crypto.CipherR   R   t   objectR   (    (    (    se   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\Crypto\Random\Fortuna\FortunaGenerator.pyt   <module>   s   
