ó
j4Vdc           @   sV  d  Z  d d l m Z d Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 e	 j
 d d k r— e	 j
 d d k r— d d l Tn  d d l Ty d d l Z Wn e k
 rÊ d Z n Xd d l Z d d l Z d	 e j f d
 „  ƒ  YZ d „  Z d e j f d „  ƒ  YZ i  d „ Z e d k rRd „  Z e j d d ƒ n  d S(   s0   Self-test suite for generic Crypto.Random stuff iÿÿÿÿ(   t   nested_scopess   $Id$Ni    i   i   (   t   *t   RNGForkTestc           B   s   e  Z d  „  Z d „  Z RS(   c         C   sB   t  j j j ƒ  } | j j ƒ  z | j j SWd | j j ƒ  Xd S(   s‰   
        Get `FortunaAccumulator.reseed_count`, the global count of the
        number of times that the PRNG has been reseeded.
        N(	   t   Cryptot   Randomt   _UserFriendlyRNGt   _get_singletont   _lockt   acquiret   _fat   reseed_countt   release(   t   selft   rng_singleton(    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyt   _get_reseed_count2   s
    c         C   sä  t  j j d ƒ r, t t d ƒ s( t ‚ d  St j d ƒ |  j ƒ  } t	 j
 j j ƒ  j ƒ  t	 j
 j d ƒ |  j ƒ  } |  j | | ƒ g  } xÃ t d ƒ D]µ } t j ƒ  \ } } t j ƒ  d k r)t j | ƒ t j | d ƒ } t	 j
 j ƒ  t	 j
 j d ƒ } | j | ƒ | j ƒ  t j d ƒ n  t j | ƒ | j t j | d	 ƒ ƒ qš Wg  }	 i  }
 xD | D]< } t j | j ƒ  ƒ } |	 j | ƒ d |
 | <| j ƒ  qfWt |	 ƒ t |
 j ƒ  ƒ k ràt d
 t j |	 ƒ ƒ ‚ n  d  S(   Nt   wint   forkg333333Ã?i   i
   i    t   wbi   t   rbs'   RNG output duplicated across fork():
%s(    t   syst   platformt
   startswitht   hasattrt   ost   AssertionErrort   timet   sleepR   R   R   R   R   t   reinitt   get_random_bytest   assertNotEqualt   ranget   pipeR   t   closet   fdopent   atforkt   writet   _exitt   appendt   binasciit   hexlifyt   readt   lent   keyst   pprintt   pformat(   R   t   reseed_count_beforet   reseed_count_aftert   rfilest   it   rfdt   wfdt   ft   datat   resultst   results_dict(    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyt   runTest>   s@    

(   t   __name__t
   __module__R   R7   (    (    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyR   0   s   	c         C   sn   t  j j d ƒ } t j d ƒ t  j j d ƒ } |  j t j | ƒ ƒ |  j t j | ƒ ƒ |  j d  ƒ d  S(   Ni   gš™™™™™¹?(	   R   R   R   R   R   t   putR&   t   b2a_hext   None(   t   qt   at   b(    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyt
   _task_mains   s    t   RNGMultiprocessingForkTestc           B   s   e  Z d  „  Z RS(   c   
      C   sŠ  d } t  j ƒ  } g  t | ƒ D] } | j d ƒ ^ q } t j d ƒ t j j j	 ƒ  j
 ƒ  t j j d ƒ t  j d | d t j j ƒ } | j t | ƒ } g  t | ƒ D] } | | j d ƒ ^ qª } g  t | ƒ D] } | | j d ƒ ^ qÖ } t t | | ƒ ƒ }	 | j d ƒ | j ƒ  | j ƒ  t t | ƒ ƒ t | ƒ k sgt t |	 ƒ ƒ t |	 ƒ k r†t d t j |	 ƒ f ƒ ‚ n  d  S(   Ni   i   g333333Ã?t	   processest   initializeri   s'   RNG output duplicated across fork():
%s(   t   multiprocessingt   ManagerR   t   QueueR   R   R   R   R   R   R   R   t   PoolR"   t	   map_asyncR@   t   gett   listt   zipR    t   joinR)   t   setR   R+   R,   (
   R   t   n_procst   managerR0   t   queuest   poolt
   map_resultt   aat   bbt   res(    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyR7   ~   s"    (,,

<(   R8   R9   R7   (    (    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyRA   |   s   c         C   s9   g  } | t  ƒ  g 7} t d  k	 r5 | t ƒ  g 7} n  | S(   N(   R   RD   R<   RA   (   t   configt   tests(    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyt	   get_tests    s
    t   __main__c           C   s   t  j t ƒ  ƒ S(   N(   t   unittestt	   TestSuiteRX   (    (    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyt   <lambda>¨   t    t   defaultTestt   suite(   t   __doc__t
   __future__R    t   __revision__R&   R+   RZ   R   R   R   t   version_infot   Crypto.Util.py21compatt   Crypto.Util.py3compatRD   t   ImportErrorR<   t   Crypto.Random._UserFriendlyRNGR   t   Crypto.Random.randomt   TestCaseR   R@   RA   RX   R8   R_   t   main(    (    (    sz   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/Random/test__UserFriendlyRNG.pyt   <module>   s0   &

C		$	