ó
æ¨[Qc           @   sì  d  d l  Z  d  d l Z d  d l m Z d  d l m Z m Z m Z m Z i e d ƒ d 6e d ƒ d 6e d ƒ d	 6e d
 ƒ d 6e d ƒ d 6Z	 i e  j
 d 6e  j d 6e  j d	 6e  j d 6e  j d 6Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d d d d d g Z e d  k rèd! GHd  d l Z xR e d" ƒ D]D Z  e j! ƒ  \ Z" Z# e" rºPn  e  r˜e  d# d$ k r˜d% e  GHq˜q˜Wd& GHn  d S('   iÿÿÿÿN(   t   b(   t   commont	   transformt   coret   varblocks   0 0*†H†÷ t   MD5s   0!0	+ s   SHA-1s   010	`†He  s   SHA-256s   0A0	`†He 0s   SHA-384s   0Q0	`†He @s   SHA-512t   CryptoErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyR   6   s   t   DecryptionErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyR	   9   s   t   VerificationErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyR
   <   s   c         C   sè   | d } t  |  ƒ } | | k r; t d | | f ƒ ‚ n  t d ƒ } | | d } xe t  | ƒ | k  r¼ | t  | ƒ } t j | d ƒ } | j t d ƒ t d ƒ ƒ } | | |  } qX Wt d ƒ j t d ƒ | t d ƒ |  g ƒ S(   Ni   s;   %i bytes needed for message, but there is only space for %it    i   i   t    t    (   t   lent   OverflowErrorR    t   ost   urandomt   replacet   join(   t   messaget   target_lengtht   max_msglengtht	   msglengtht   paddingt   padding_lengtht   needed_bytest   new_padding(    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyt   _pad_for_encryption?   s     
	c         C   s~   | d } t  |  ƒ } | | k r; t d | | f ƒ ‚ n  | | d } t d ƒ j t d ƒ | t d ƒ t d ƒ |  g ƒ S(   Ni   s;   %i bytes needed for message, but there is only space for %ii   R   t    s   ÿR   (   R   R   R    R   (   R   R   R   R   R   (    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyt   _pad_for_signingm   s    
	c         C   sa   t  j | j ƒ } t |  | ƒ } t j | ƒ } t j | | j | j ƒ } t j	 | | ƒ } | S(   N(
   R   t	   byte_sizet   nR   R   t	   bytes2intR   t   encrypt_intt   et	   int2bytes(   R   t   pub_keyt	   keylengtht   paddedt   payloadt	   encryptedt   block(    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyt   encrypt   s    c         C   s¾   t  j | j ƒ } t j |  ƒ } t j | | j | j ƒ } t j | | ƒ } | d d !t	 d ƒ k rv t
 d ƒ ‚ n  y | j t	 d ƒ d ƒ } Wn t k
 r± t
 d ƒ ‚ n X| | d S(   Ni    i   R   s   Decryption failedR   i   (   R   R   R    R   R!   R   t   decrypt_intt   dR$   R    R	   t   indext
   ValueError(   t   cryptot   priv_keyt	   blocksizeR)   t	   decryptedt	   cleartextt   sep_idx(    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyt   decrypt®   s    3c   
      C   s£   | t  k r t d | ƒ ‚ n  t  | } t |  | ƒ } | | } t j | j ƒ } t | | ƒ } t j | ƒ } t	 j
 | | j | j ƒ } t j | | ƒ }	 |	 S(   Ns   Invalid hash method: %s(   t	   HASH_ASN1R/   t   _hashR   R   R    R   R   R!   R   R"   R-   R$   (
   R   R1   t   hasht   asn1codeR4   R&   R'   R(   R)   R*   (    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyt   signò   s    

c         C   sú   t  j | j ƒ } t j | ƒ } t j | | j | j ƒ } t j | | ƒ } | d d !t	 d ƒ k rv t
 d ƒ ‚ n  y | j t	 d ƒ d ƒ } Wn t k
 r± t
 d ƒ ‚ n Xt | | d ƒ \ } }	 t |  | ƒ }
 |
 |	 k rö t
 d ƒ ‚ n  d  S(   Ni    i   R   s   Verification failedR   i   (   R   R   R    R   R!   R   R,   R#   R$   R    R
   R.   R/   t   _find_method_hashR8   (   R   t	   signatureR%   R2   R)   R3   t   clearsigR5   t   method_namet   signature_hasht   message_hash(    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyt   verify  s    c         C   s—   | t  k r t d | ƒ ‚ n  t  | } | ƒ  } t |  d ƒ r€ t |  j d ƒ r€ x7 t j |  d ƒ D] } | j | ƒ qf Wn | j |  ƒ | j ƒ  S(   Ns   Invalid hash method: %st   readt   __call__i   (   t   HASH_METHODSR/   t   hasattrRC   R   t   yield_fixedblockst   updatet   digest(   R   R?   t   methodt   hasherR*   (    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyR8   D  s    
	!c         C   sS   x@ t  j ƒ  D]2 \ } } |  j | ƒ s. q n  | |  t | ƒ f SWt d ƒ ‚ d  S(   Ns   Verification failed(   R7   t   itemst
   startswithR   R
   (   t   method_hasht   hashnameR:   (    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyR<   `  s
    R+   R6   R;   RB   t   __main__s'   Running doctests 1000x or until failureiè  id   i    s   %i timess   Doctests done($   t   hashlibR   t   rsa._compatR    t   rsaR   R   R   R   R7   t   md5t   sha1t   sha256t   sha384t   sha512RE   t	   ExceptionR   R	   R
   R   R   R+   R6   R;   RB   R8   R<   t   __all__R   t   doctestt   ranget   countt   testmodt   failurest   tests(    (    (    s_   /home/tom/ab/x64lucid-deps/install/lib/python2.7/site-packages/rsa-3.1.1-py2.7.egg/rsa/pkcs1.pyt   <module>   sL   "



	.	"		D	%	-		