ó
j4Vdc           @   s  d  Z  d Z d d l Z d d l Z e j d d k oG e j d d k rW d d l Tn  d d l Td d l Z d d l m	 Z	 m
 Z
 m Z d	 e j f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ i  d „ Z e d k rd „  Z e j d d ƒ n  d S(   s(   Self-test suite for Crypto.PublicKey.RSAs   $Id$iÿÿÿÿNi    i   i   (   t   *(   t   list_test_casest   a2b_hext   b2a_hext   RSATestc           B   sÈ   e  Z d  Z d Z d Z d Z d Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sÅ  
           eb 7a 19 ac e9 e3 00 63 50 e3 29 50 4b 45 e2
        ca 82 31 0b 26 dc d8 7d 5c 68 f1 ee a8 f5 52 67
        c3 1b 2e 8b b4 25 1f 84 d7 e0 b2 c0 46 26 f5 af
        f9 3e dc fb 25 c9 c2 b3 ff 8a e1 0e 83 9a 2d db
        4c dc fe 4f f4 77 28 b4 a1 b7 c1 36 2b aa d2 9a
        b4 8d 28 69 d5 02 41 21 43 58 11 59 1b e3 92 f9
        82 fb 3e 87 d0 95 ae b4 04 48 db 97 2f 3a c1 4f
        7b c2 75 19 52 81 ce 32 d2 f1 b7 6d 4d 35 3e 2d
    sÅ  
        12 53 e0 4d c0 a5 39 7b b4 4a 7a b8 7e 9b f2 a0
        39 a3 3d 1e 99 6f c8 2a 94 cc d3 00 74 c9 5d f7
        63 72 20 17 06 9e 52 68 da 5d 1c 0b 4f 87 2c f6
        53 c1 1d f8 23 14 a6 79 68 df ea e2 8d ef 04 bb
        6d 84 b1 c3 1d 65 4a 19 70 e5 78 3b d6 eb 96 a0
        24 c2 ca 2f 4a 90 fe 9f 2e f5 c9 c1 40 e5 bb 48
        da 95 36 ad 87 00 c8 4f c9 13 0a de a7 4e 55 8d
        51 a7 4d df 85 d8 b5 0d e9 68 38 d6 06 3e 09 55
    sÅ  
        bb f8 2f 09 06 82 ce 9c 23 38 ac 2b 9d a8 71 f7
        36 8d 07 ee d4 10 43 a4 40 d6 b6 f0 74 54 f5 1f
        b8 df ba af 03 5c 02 ab 61 ea 48 ce eb 6f cd 48
        76 ed 52 0d 60 e1 ec 46 19 71 9d 8a 5b 8b 80 7f
        af b8 e0 a3 df c7 37 72 3e e6 b4 b7 d9 3a 25 84
        ee 6a 64 9d 06 09 53 74 88 34 b2 45 45 98 39 4e
        e0 aa b1 2d 7b 61 a5 1f 52 7a 9a 41 f6 c1 68 7f
        e2 53 72 98 ca 2a 8f 59 46 f8 e5 fd 09 1d bd cb
    l    så   
        c9 7f b1 f0 27 f4 53 f6 34 12 33 ea aa d1 d9 35
        3f 6c 42 d0 88 66 b1 d0 5a 0f 20 35 02 8b 9d 86
        98 40 b4 16 66 b4 2e 92 ea 0d a3 b4 32 04 b5 cf
        ce 33 52 52 4d 04 16 a5 a4 41 e7 00 af 46 15 03
    c         C   sÎ   d d l  m a d d l m a d d l m a m } t t |  j ƒ ƒ |  _	 t t |  j
 ƒ ƒ |  _ t |  j	 |  j ƒ d |  _ | |  j |  j d |  j d ƒ |  _ | |  j |  j ƒ |  _ t |  _ d  S(   Niÿÿÿÿ(   t   RSA(   t   Random(   t   bytes_to_longt   inversei    i   (   t   Crypto.PublicKeyR   t   CryptoR   t   Crypto.Util.numberR   R   R   t   modulust   nt   prime_factort   pt   divmodt   qt   et   dt   ut   rsa(   t   selfR   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   setUpZ   s    'c         C   sV   |  j  j d ƒ } |  j | ƒ |  j | ƒ | j ƒ  } |  j | ƒ |  j | ƒ d S(   s7   RSA (default implementation) generated key (1 argument)i   N(   R   t   generatet   _check_private_keyt   _exercise_primitivet	   publickeyt   _check_public_keyt   _exercise_public_primitive(   R   t   rsaObjt   pub(    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_generate_1argi   s    c         C   sb   |  j  j d t j ƒ  j ƒ } |  j | ƒ |  j | ƒ | j ƒ  } |  j | ƒ |  j	 | ƒ d S(   s8   RSA (default implementation) generated key (2 arguments)i   N(
   R   R   R   t   newt   readR   R   R   R   R   (   R   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_generate_2argr   s    c         C   s{   |  j  j d t j ƒ  j d d ƒ} |  j | ƒ |  j | ƒ | j ƒ  } |  j | ƒ |  j	 | ƒ |  j
 d | j ƒ d  S(   Ni   R   i  (   R   R   R   R!   R"   R   R   R   R   R   t   assertEqualR   (   R   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_generate_3args{   s    $c         C   sI   |  j  j |  j |  j f ƒ } |  j | ƒ |  j | ƒ |  j | ƒ d S(   s6   RSA (default implementation) constructed key (2-tuple)N(   R   t	   constructR   R   R   t   _check_encryptiont   _check_verification(   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_construct_2tuple„   s    c         C   s\   |  j  j |  j |  j |  j f ƒ } |  j | ƒ |  j | ƒ |  j | ƒ |  j | ƒ d S(   s6   RSA (default implementation) constructed key (3-tuple)N(	   R   R&   R   R   R   R'   t   _check_decryptiont   _check_signingR(   (   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_construct_3tuple‹   s
    $c         C   sb   |  j  j |  j |  j |  j |  j f ƒ } |  j | ƒ |  j | ƒ |  j | ƒ |  j	 | ƒ d S(   s6   RSA (default implementation) constructed key (4-tuple)N(
   R   R&   R   R   R   R   R'   R*   R+   R(   (   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_construct_4tuple“   s
    *c         C   su   |  j  j |  j |  j |  j |  j |  j f ƒ } |  j | ƒ |  j | ƒ |  j	 | ƒ |  j
 | ƒ |  j | ƒ d S(   s6   RSA (default implementation) constructed key (5-tuple)N(   R   R&   R   R   R   R   R   R   R'   R*   R+   R(   (   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_construct_5tuple›   s    0c         C   s{   |  j  j |  j |  j |  j |  j |  j |  j f ƒ } |  j | ƒ |  j	 | ƒ |  j
 | ƒ |  j | ƒ |  j | ƒ d S(   s6   RSA (default implementation) constructed key (6-tuple)N(   R   R&   R   R   R   R   R   R   R   R'   R*   R+   R(   (   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_construct_6tuple¤   s    6c         C   sÍ   |  j  j |  j |  j |  j g ƒ } |  j | j |  j k pK | j |  j k ƒ |  j | j |  j k pv | j |  j k ƒ |  j | j | j |  j k ƒ |  j t	 |  j  j |  j |  j |  j d g ƒ d  S(   Ni   (
   R   R&   R   R   R   t
   failUnlessR   R   t   assertRaisest
   ValueError(   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_factoring­   s
    $++ c         C   sÄ  |  j  d | j ƒ  ƒ |  j  d | j ƒ  ƒ |  j  d | j ƒ  ƒ |  j  d | j ƒ  ƒ |  j  | j | j j ƒ |  j  | j | j j ƒ |  j  | j | j j ƒ |  j  | j	 | j j	 ƒ |  j  | j
 | j j
 ƒ |  j  | j | j j ƒ |  j  | j | j	 | j
 ƒ |  j  d | j | j | j	 d | j
 d ƒ |  j  d | j	 | j | j
 ƒ |  j  d | j	 d k ƒ |  j  d | j
 d k ƒ |  j  d | j d k ƒ |  j  d | j d k ƒ d  S(   Ni   (   R$   t   has_privatet   can_signt   can_encryptt	   can_blindR   t   keyR   R   R   R   R   (   R   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   µ   s"    0!c         C   s  t  |  j ƒ } |  j d | j ƒ  ƒ |  j d | j ƒ  ƒ |  j d | j ƒ  ƒ |  j d | j ƒ  ƒ |  j | j | j j ƒ |  j | j	 | j j	 ƒ |  j d t
 | d ƒ ƒ |  j d t
 | d ƒ ƒ |  j d t
 | d ƒ ƒ |  j d t
 | d ƒ ƒ |  j d t
 | j d ƒ ƒ |  j d t
 | j d ƒ ƒ |  j d t
 | j d ƒ ƒ |  j d t
 | j d ƒ ƒ |  j d | j	 d k ƒ |  j t | j | t d ƒ ƒ |  j t | j | ƒ |  j | j ƒ  | j ƒ  k t ƒ |  j | j ƒ  | j ƒ  k t ƒ d  S(   Ni    i   R   R   R   R   t    (   R   t
   ciphertextR$   R4   R5   R6   R7   R   R8   R   t   hasattrR1   t	   TypeErrort   signt   bt   decryptR   t   Truet   False(   R   R   R:   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   Í   s(    "c   
      C   s#  t  |  j ƒ } | j | f ƒ } | j | t d ƒ ƒ \ } |  j t | ƒ t | ƒ ƒ t j ƒ  j	 t
 | ƒ d ƒ } | j | | ƒ } | j | f ƒ } | j | | ƒ } |  j t | ƒ t | ƒ ƒ | j | t d ƒ ƒ }	 |  j t | ƒ f |	 ƒ |  j d | j | t | ƒ f ƒ ƒ d  S(   NR9   i   (   R   R:   R?   t   encryptR>   R$   R   R   R!   R"   t   lent   blindt   unblindR=   R   t   verify(
   R   R   R:   t	   plaintextt   new_ciphertext2t   blinding_factort   blinded_ctextt   blinded_ptextt   unblinded_plaintextt
   signature2(    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   ï   s    c         C   sG   t  |  j ƒ } | j | t d ƒ ƒ \ } | j | t | ƒ f ƒ d  S(   NR9   (   R   RG   RB   R>   RF   R   (   R   R   RG   RH   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   
  s    c         C   sY   t  |  j ƒ } t  |  j ƒ } | j | t d ƒ ƒ \ } |  j t | ƒ t | ƒ ƒ d  S(   NR9   (   R   RG   R:   RB   R>   R$   R   (   R   R   RG   R:   RH   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR'     s    c   	      C   sÁ   t  |  j ƒ } t  |  j ƒ } | j | f ƒ } |  j t | ƒ t | ƒ ƒ t j ƒ  j t	 | ƒ d ƒ } | j
 | | ƒ } | j | f ƒ } | j | | ƒ } |  j t | ƒ t | ƒ ƒ d  S(   Ni   (   R   RG   R:   R?   R$   R   R   R!   R"   RC   RD   RE   (	   R   R   RG   R:   t   new_plaintextRI   RJ   RK   RL   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR*     s    c         C   su   t  t |  j ƒ ƒ } t |  j ƒ } | f } |  j d | j | | ƒ ƒ | d f } |  j d | j | | ƒ ƒ d  S(   Ni   R9   (   R   R   RG   R:   R$   RF   (   R   R   t	   signaturet   messaget   tt   t2(    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR(   *  s    	c         C   sM   t  t |  j ƒ ƒ } t |  j ƒ } |  j | f | j | t d ƒ ƒ ƒ d  S(   NR9   (   R   R   RG   R:   R$   R=   R>   (   R   R   RO   RP   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR+   8  s    (   t   __name__t
   __module__RG   R:   R   R   R   R   R    R#   R%   R)   R,   R-   R.   R/   R3   R   R   R   R   R'   R*   R(   R+   (    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   &   s.   																	"						t   RSAFastMathTestc           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   s&   t  j |  ƒ t j d t ƒ |  _ d  S(   Nt   use_fast_math(   R   R   R   t   RSAImplementationR@   R   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   @  s    c         C   s   t  j |  ƒ d S(   s9   RSA (_fastmath implementation) generated key (1 argument)N(   R   R    (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR    D  s    c         C   s   t  j |  ƒ d S(   s:   RSA (_fastmath implementation) generated key (2 arguments)N(   R   R#   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR#   H  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (2-tuple)N(   R   R)   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR)   L  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (3-tuple)N(   R   R,   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR,   P  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (4-tuple)N(   R   R-   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR-   T  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (5-tuple)N(   R   R.   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR.   X  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (6-tuple)N(   R   R/   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR/   \  s    c         C   s   t  j |  ƒ d  S(   N(   R   R3   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR3   `  s    (   RS   RT   R   R    R#   R)   R,   R-   R.   R/   R3   (    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyRU   ?  s   								t   RSASlowMathTestc           B   sY   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   s&   t  j |  ƒ t j d t ƒ |  _ d  S(   NRV   (   R   R   R   RW   RA   R   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   d  s    c         C   s   t  j |  ƒ d S(   s9   RSA (_slowmath implementation) generated key (1 argument)N(   R   R    (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR    h  s    c         C   s   t  j |  ƒ d S(   s:   RSA (_slowmath implementation) generated key (2 arguments)N(   R   R#   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR#   l  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (2-tuple)N(   R   R)   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR)   p  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (3-tuple)N(   R   R,   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR,   t  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (4-tuple)N(   R   R-   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR-   x  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (5-tuple)N(   R   R.   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR.   |  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (6-tuple)N(   R   R/   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR/   €  s    c         C   s   t  j |  ƒ d  S(   N(   R   R3   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR3   „  s    (   RS   RT   R   R    R#   R)   R,   R-   R.   R/   R3   (    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyRX   c  s   								c         C   s  g  } | t  t ƒ 7} y$ d d l m } | t  t ƒ 7} Wn¡ t k
 rÝ d d l m } d d  l } t	 j
 j t	 j
 j t	 j
 j | j | j ƒ  ƒ ƒ ƒ d | d ƒ ƒ } t	 j
 j | ƒ rÞ t d d d | ƒ ‚ qÞ n X|  j d	 d
 ƒ r| t  t ƒ 7} n  | S(   Niÿÿÿÿ(   t	   _fastmath(   t   get_config_vars   /../../PublicKey/_fastmatht   SOs-   While the _fastmath module exists, importing s<   it failed. This may point to the gmp or mpir shared library s.   not being in the path. _fastmath was found at t
   slow_testsi   (   R   R   R	   RY   RU   t   ImportErrort   distutils.sysconfigRZ   t   inspectt   ost   patht   normpatht   dirnamet   abspatht   getfilet   currentframet   existst   getRX   (   t   configt   testsRY   RZ   R_   t   _fm_path(    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt	   get_tests‡  s     	>t   __main__c           C   s   t  j t ƒ  ƒ S(   N(   t   unittestt	   TestSuiteRl   (    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   <lambda>œ  R9   t   defaultTestt   suite(   t   __doc__t   __revision__t   sysR`   t   version_infot   Crypto.Util.py21compatt   Crypto.Util.py3compatRn   t   Crypto.SelfTest.st_commonR   R   R   t   TestCaseR   RU   RX   Rl   RS   Rr   t   main(    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   <module>   s    &
ÿ $$	