ó
j4Vdc           @   s  d  Z  d Z d d l Z d d l Z e j d d k rW 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	 „  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ÿÿÿÿNi    i   i   (   t   *(   t   list_test_casest   a2b_hext   b2a_hexc         C   s?   t  |  t ƒ r" d j |  j ƒ  ƒ St d ƒ j |  j ƒ  ƒ Sd S(   s,   Remove whitespace from a text or byte stringt    N(   t
   isinstancet   strt   joint   splitt   b(   t   s(    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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
 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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   setUpK   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(    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   test_generate_1argS   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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   test_generate_2argZ   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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   test_construct_4tuplea   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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   test_construct_5tupleg   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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR   n   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 t ƒ |  j | j ƒ  | j ƒ  k t ƒ d  S(   Ni    i   R+   i    (   R   t   kt   m_hashR.   R/   R0   R1   R2   R#   R3   R$   R%   R&   t   hasattrR   t   assertRaisest	   TypeErrort   signR   t   Truet   False(   R   R   R5   R6   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   R5   R6   R   t   rR
   R:   R.   (   R   R   R5   R6   R=   R
   t   r_outt   s_out(    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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 | t d ƒ | | f ƒ ƒ d  S(   Ni   i    s    (   R   R6   R   R=   R
   R.   t   verifyR	   (   R   R   R6   R=   R
   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR(   «   s
    "(   t   __name__t
   __module__R   R#   R$   R%   R&   R+   R5   t	   k_inverseR   R	   t   mR6   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_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   DSAImplementationR;   R   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR-   Ã   s    (   RA   RB   R   R   R"   R*   R-   (    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyRE   ²   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(   NRF   (   R   R   R   RG   R<   R   (   R   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-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   (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyR-   Ø   s    (   RA   RB   R   R   R"   R*   R-   (    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyRH   Ç   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| t  t ƒ 7} | 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 (   R   R   R   RI   RE   t   ImportErrort   distutils.sysconfigRJ   t   inspectt   ost   patht   normpatht   dirnamet   abspatht   getfilet   currentframet   existsRH   (   t   configt   testsRI   RJ   RN   t   _fm_path(    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt	   get_testsÝ   s    	>t   __main__c           C   s   t  j t ƒ  ƒ S(   N(   t   unittestt	   TestSuiteRZ   (    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   <lambda>ñ   R   t   defaultTestt   suite(   t   __doc__t   __revision__t   sysRO   t   version_infot   Crypto.Util.py21compatt   Crypto.Util.py3compatR\   t   Crypto.SelfTest.st_commonR   R   R   R   t   TestCaseR   RE   RH   RZ   RA   R`   t   main(    (    (    sp   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/Crypto/SelfTest/PublicKey/test_DSA.pyt   <module>   s    &
	…	