ó
BwLc           @   sÐ   d  Z  d Z d d l Td d l Z d d l Z d d l m Z m Z m Z d „  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.DSAs   $Id$iÿÿÿÿ(   t   *N(   t   list_test_casest   a2b_hext   b2a_hexc         C   sA   |  j  t j t j d t t j ƒ ƒ ƒ }  |  j d d ƒ }  |  S(   s   Strip whitespacet    t    (   t	   translatet   stringt	   maketranst
   whitespacet   lent   replace(   t   s(    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   _sws#   s    +t   DSATestc           B   sÝ   e  Z e d  ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z e d ƒ Z	 e
 d ƒ Z e d ƒ Z e d	 ƒ Z e d
 ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s¯   19131871 d75b1612 a819f29d 78d1b0d7 346f7aa7 7bb62a85
                9bfd6c56 75da9d21 2d3a36ef 1672ef66 0b8c7c25 5cc0ec74
                858fba33 f44c0669 9630a76b 030ee333s¯   626d0278 39ea0a13 413163a5 5b4cb500 299d5522 956cefcb
                3bff10f3 99ce2c2e 71cb9de5 fa24babf 58e5b795 21925c9c
                c42e9f6f 464b088c c572af53 e6d78802s¯   8df2a494 492276aa 3d25759b b06869cb eac0d83a fb8d0cf7
                cbb8324f 0d7882e5 d0762fc5 b7210eaf c2e9adac 32ab7aac
                49693dfb f83724c2 ec0736ee 31c80291s,   c773218c 737ec8ee 993b4f2d ed30f48e dace915fs,   2070b322 3dba372f de1c0ffc 7b2e3b49 8b260614s,   358dad57 1462710f 50e254cf 1a376b2b deaadfbfs,   0d516729 8202e49b 4116ac10 4fc3f415 ae52f917t   abcs,   a9993e36 4706816a ba3e2571 7850c26c 9cd0d89ds,   8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0s,   41e2345f 1f56df24 58f426d1 55b4ba2d b6dcd8c8c         C   sI   d d l  m a d d l m a d d l m a m } m a t |  _ d  S(   Niÿÿÿÿ(   t   DSA(   t   Random(   t   bytes_to_longt   inverset   size(	   t   Crypto.PublicKeyR   t   CryptoR   t   Crypto.Util.numberR   R   R   t   dsa(   t   selfR   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   setUpG   s    c         C   s<   |  j  j d ƒ } |  j | ƒ | j ƒ  } |  j | ƒ d S(   s7   DSA (default implementation) generated key (1 argument)i   N(   R   t   generatet   _check_private_keyt	   publickeyt   _check_public_key(   R   t   dsaObjt   pub(    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   test_generate_1argO   s    c         C   sH   |  j  j d t j ƒ  j ƒ } |  j | ƒ | j ƒ  } |  j | ƒ d S(   s8   DSA (default implementation) generated key (2 arguments)i   N(   R   R   R   t   newt   readR   R   R   (   R   R   R    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   test_generate_2argV   s    c         C   sx   g  |  j  |  j |  j |  j f D] } t t | ƒ ƒ ^ q \ } } } } |  j j | | | | f ƒ } |  j | ƒ d S(   s6   DSA (default implementation) constructed key (4-tuple)N(	   t   yt   gt   pt   qR   R   R   t	   constructt   _test_verification(   R   t   paramR%   R&   R'   R(   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   test_construct_4tuple]   s    Ic         C   s‘   g  |  j  |  j |  j |  j |  j f D] } t t | ƒ ƒ ^ q% \ } } } } } |  j j | | | | | f ƒ } |  j	 | ƒ |  j
 | ƒ d S(   s6   DSA (default implementation) constructed key (5-tuple)N(   R%   R&   R'   R(   t   xR   R   R   R)   t   _test_signingR*   (   R   R+   R%   R&   R'   R(   R-   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   test_construct_5tuplec   s    R!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  d | j | j	 k ƒ |  j  d t | j	 ƒ ƒ |  j  d | j d | j	 ƒ |  j  | j t | j | j
 | j ƒ ƒ |  j  d d | j
 k  ov| j	 k  n ƒ d  S(   Ni   i    i    (   t   assertEqualt   has_privatet   can_signt   can_encryptt	   can_blindR%   t   keyR&   R'   R(   R-   R   t   pow(   R   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR   j   s    (c         C   s¾  t  |  j ƒ } t  |  j ƒ } |  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 d t | d ƒ ƒ |  j d t | j	 d ƒ ƒ |  j d | j | j k ƒ |  j d t | j ƒ ƒ |  j d | j d | j ƒ |  j t | j | | ƒ |  j | j ƒ  | j ƒ  k ƒ |  j | j ƒ  | j ƒ  k ƒ d  S(   Ni    i   R-   i    (   R   t   kt   m_hashR0   R1   R2   R3   R4   R%   R5   R&   R'   R(   t   hasattrR   t   assertRaisest	   TypeErrort   signt   assert_R   (   R   R   R7   R8   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR      s$    c         C   s€   t  |  j ƒ } t  |  j ƒ } t t  |  j ƒ ƒ } t t  |  j ƒ ƒ } | j | | ƒ \ } } |  j | | f | | f ƒ d  S(   N(   R   R7   R8   R   t   rR   R<   R0   (   R   R   R7   R8   R>   R   t   r_outt   s_out(    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR.   Ÿ   s    c         C   s…   t  |  j ƒ } t t  |  j ƒ ƒ } t t  |  j ƒ ƒ } |  j d | j | | | f ƒ ƒ |  j d | j | d | | f ƒ ƒ d  S(   Ni   i    t    (   R   R8   R   R>   R   R0   t   verify(   R   R   R8   R>   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR*   §   s
    "(   t   __name__t
   __module__R   R%   R&   R'   R(   R-   R7   t	   k_inverseR   t   mR8   R>   R   R   R!   R$   R,   R/   R   R   R.   R*   (    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR   )   s.   										 	t   DSAFastMathTestc           B   s5   e  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   DSAImplementationt   TrueR   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR   ¯   s    c         C   s   t  j |  ƒ d S(   s9   DSA (_fastmath implementation) generated key (1 argument)N(   R   R!   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR!   ³   s    c         C   s   t  j |  ƒ d S(   s:   DSA (_fastmath implementation) generated key (2 arguments)N(   R   R$   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR$   ·   s    c         C   s   t  j |  ƒ d S(   s8   DSA (_fastmath implementation) constructed key (4-tuple)N(   R   R,   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR,   »   s    c         C   s   t  j |  ƒ d S(   s8   DSA (_fastmath implementation) constructed key (5-tuple)N(   R   R/   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR/   ¿   s    (   RC   RD   R   R!   R$   R,   R/   (    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyRG   ®   s
   				t   DSASlowMathTestc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s&   t  j |  ƒ t j d t ƒ |  _ d  S(   NRH   (   R   R   R   RI   t   FalseR   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR   Ä   s    c         C   s   t  j |  ƒ d S(   s9   DSA (_slowmath implementation) generated key (1 argument)N(   R   R!   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR!   È   s    c         C   s   t  j |  ƒ d S(   s:   DSA (_slowmath implementation) generated key (2 arguments)N(   R   R$   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR$   Ì   s    c         C   s   t  j |  ƒ d S(   s8   DSA (_slowmath implementation) constructed key (4-tuple)N(   R   R,   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR,   Ð   s    c         C   s   t  j |  ƒ d S(   s8   DSA (_slowmath implementation) constructed key (5-tuple)N(   R   R/   (   R   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR/   Ô   s    (   RC   RD   R   R!   R$   R,   R/   (    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyRK   Ã   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   RM   RG   t   ImportErrorRK   (   t   configt   testsRM   (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt	   get_testsÙ   s    t   __main__c           C   s   t  j t ƒ  ƒ S(   N(   t   unittestt	   TestSuiteRQ   (    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   <lambda>å   s    t   defaultTestt   suite(   t   __doc__t   __revision__t   Crypto.Util.python_compatRS   R   t   Crypto.SelfTest.st_commonR   R   R   R   t   TestCaseR   RG   RK   RQ   RC   RW   t   main(    (    (    sF   /usr/lib/python2.7/dist-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   <module>   s   
	…	