ó
BwLc           @   s»   d  Z  d Z 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ÿÿÿÿ(   t   *N(   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 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   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   setUpV   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(    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_generate_1arge   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   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_generate_2argn   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   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_construct_2tuplew   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   (    (    sF   /usr/lib/python2.7/dist-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   (    (    sF   /usr/lib/python2.7/dist-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   (    (    sF   /usr/lib/python2.7/dist-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   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   test_construct_6tuple—   s    6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  d | j	 | j
 k  ƒ |  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   (   t   assertEqualt   has_privatet   can_signt   can_encryptt	   can_blindR   t   keyR   R   R   R   R   (   R   R   (    (    sF   /usr/lib/python2.7/dist-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 | d ƒ |  j t | j | ƒ |  j | j ƒ  | j ƒ  k ƒ |  j | j ƒ  | j ƒ  k ƒ d  S(   Ni    i   R   R   R   R   t    (   R   t
   ciphertextR.   R/   R0   R1   R2   R   R3   R   t   hasattrt   assertRaisest	   TypeErrort   signt   decryptt   assert_R   (   R   R   R5   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   ¹   s(    c   
      C   s  t  |  j ƒ } | j | f ƒ } | j | d ƒ \ } |  j t | ƒ t | ƒ ƒ t j ƒ  j t	 | ƒ d ƒ } | j
 | | ƒ } | j | f ƒ } | j | | ƒ } |  j t | ƒ t | ƒ ƒ | j | d ƒ }	 |  j t | ƒ f |	 ƒ |  j d | j | t | ƒ f ƒ ƒ d  S(   NR4   i   (   R   R5   R:   t   encryptR.   R   R   R!   R"   t   lent   blindt   unblindR9   R   t   verify(
   R   R   R5   t	   plaintextt   new_ciphertext2t   blinding_factort   blinded_ctextt   blinded_ptextt   unblinded_plaintextt
   signature2(    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   Û   s    c         C   sA   t  |  j ƒ } | j | d ƒ \ } | j | t | ƒ f ƒ d  S(   NR4   (   R   RA   R<   R@   R   (   R   R   RA   RB   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   ö   s    c         C   sS   t  |  j ƒ } t  |  j ƒ } | j | d ƒ \ } |  j t | ƒ t | ƒ ƒ d  S(   NR4   (   R   RA   R5   R<   R.   R   (   R   R   RA   R5   RB   (    (    sF   /usr/lib/python2.7/dist-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   RA   R5   R:   R.   R   R   R!   R"   R=   R>   R?   (	   R   R   RA   R5   t   new_plaintextRC   RD   RE   RF   (    (    sF   /usr/lib/python2.7/dist-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   R4   (   R   R   RA   R5   R.   R@   (   R   R   t	   signaturet   messaget   tt   t2(    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR&     s    	c         C   sG   t  t |  j ƒ ƒ } t |  j ƒ } |  j | f | j | d ƒ ƒ d  S(   NR4   (   R   R   RA   R5   R.   R9   (   R   R   RI   RJ   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR)   $  s    (   t   __name__t
   __module__RA   R5   R   R   R   R   R    R#   R'   R*   R+   R,   R-   R   R   R   R   R%   R(   R&   R)   (    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   "   s*   														"						t   RSAFastMathTestc           B   sP   e  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   RSAImplementationt   TrueR   (   R   (    (    sF   /usr/lib/python2.7/dist-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   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR    0  s    c         C   s   t  j |  ƒ d S(   s:   RSA (_fastmath implementation) generated key (2 arguments)N(   R   R#   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR#   4  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (2-tuple)N(   R   R'   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR'   8  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (3-tuple)N(   R   R*   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR*   <  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (4-tuple)N(   R   R+   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR+   @  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (5-tuple)N(   R   R,   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR,   D  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_fastmath implementation) constructed key (6-tuple)N(   R   R-   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR-   H  s    (
   RM   RN   R   R    R#   R'   R*   R+   R,   R-   (    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyRO   +  s   							t   RSASlowMathTestc           B   sP   e  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(   NRP   (   R   R   R   RQ   t   FalseR   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR   M  s    c         C   s   t  j |  ƒ d S(   s9   RSA (_slowmath implementation) generated key (1 argument)N(   R   R    (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR    Q  s    c         C   s   t  j |  ƒ d S(   s:   RSA (_slowmath implementation) generated key (2 arguments)N(   R   R#   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR#   U  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (2-tuple)N(   R   R'   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR'   Y  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (3-tuple)N(   R   R*   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR*   ]  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (4-tuple)N(   R   R+   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR+   a  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (5-tuple)N(   R   R,   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR,   e  s    c         C   s   t  j |  ƒ d S(   s8   RSA (_slowmath implementation) constructed key (6-tuple)N(   R   R-   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyR-   i  s    (
   RM   RN   R   R    R#   R'   R*   R+   R,   R-   (    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyRS   L  s   							c         C   sb   g  } | t  t ƒ 7} y$ d d l m } | t  t ƒ 7} Wn t k
 rM n X| t  t ƒ 7} | S(   Niÿÿÿÿ(   t	   _fastmath(   R   R   R	   RU   RO   t   ImportErrorRS   (   t   configt   testsRU   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt	   get_testsn  s    t   __main__c           C   s   t  j t ƒ  ƒ S(   N(   t   unittestt	   TestSuiteRY   (    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   <lambda>z  s    t   defaultTestt   suite(   t   __doc__t   __revision__t   Crypto.Util.python_compatR[   t   Crypto.SelfTest.st_commonR   R   R   t   TestCaseR   RO   RS   RY   RM   R_   t   main(    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_RSA.pyt   <module>   s   
ÿ 
!"	