U
    ʹh^"                     @   s  d dl Z zd dlZW n ek
r0   d dlZY nX d dlmZmZ d dlmZ	 zd dlm
Z
 dZW n ek
rz   dZY nX ddlmZ ddlmZmZmZmZ i Zere
jged	< d
ed< dZdZdZdZdZeedeZeeeeeZedddZeedddZeeZded< ef eee	j ded ddd Z!dd Z"e j#j$ddd e%e"edD d d e&d!D d"d#d$ Z'G d%d& d&ej(Z)G d'd( d(ej(Z*G d)d* d*ej(Z+dS )+    N)givensettings)HealthCheckTF   )inverse_mod)CurveFpINFINITYPoint	CurveEdTwZsuppress_health_checki  Zdeadline      1(i&^#a;   9{uDjSg9g(B   +' 1t:_|v!a:@m   H<^W]dZ{cxW\Iq             Zmax_examples)Z	min_valueZ	max_valuec                 C   s&   t | t}t|  }|| tks"td S N)r   rp192AssertionError)ZmultipleZinv_mp1 r   >./venv/lib/python3.8/site-packages/ecdsa/test_ellipticcurve.pytest_p192_mult_tests.   s    
r   c                 c   s,   t }d}||kr(|V  ||  }|d7 }qd S )Nr   r   )r   )Zpointnretir   r   r   add_n_times7   s    r    zp, m, checkc                 C   s   g | ]\}}t ||fqS r   )g_23).0r   Zexpr   r   r   
<listcomp>C   s     r#      c                 C   s   g | ]}d  |qS )zg_23 test with mult {0})format)r"   r   r   r   r   r#   D   s     	   )Zidsc                 C   s   | | |kst d S r   )r   )pmcheckr   r   r   test_add_and_mult_equivalenceA   s    r*   c                   @   sX   e Zd Zedd Zdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd ZdS )	TestCurvec                 C   s   t ddd| _d S Nr   r   )r   c_23clsr   r   r   
setUpClassK   s    zTestCurve.setUpClassc                 C   s   |  | jtddd d S r,   )assertEqualr-   r   selfr   r   r   test_equality_curvesO   s    zTestCurve.test_equality_curvesc                 C   s   t tdt}| | j| d S )Nr   )r   r'   bassertNotEqualr-   )r3   c192r   r   r   test_inequality_curvesR   s    z TestCurve.test_inequality_curvesc                 C   s(   t ddd}t ddd}| || d S )Nr   r   r   )r   r6   )r3   ar5   r   r   r    test_inequality_curves_by_b_onlyV   s    z*TestCurve.test_inequality_curves_by_b_onlyc                 C   s   | j d i d S r   r-   r2   r   r   r   ,test_usability_in_a_hashed_collection_curves[   s    z6TestCurve.test_usability_in_a_hashed_collection_curvesc                 C   s   t | j d S r   hashr-   r2   r   r   r   test_hashability_curves^   s    z!TestCurve.test_hashability_curvesc                 C   s   t dddt dddt ddd  }}}t dddt ddd| j  }}}| ttt|||fd | ttt|||fd | td i|d i | ||d i d S )N   r   r   r      )r   r-   r1   lensetZassertDictEqualZassertIn)r3   Zne1Zne2Zne3Zeq1Zeq2Zeq3r   r   r   test_conflation_curvesa   s    ("z TestCurve.test_conflation_curvesc                 C   s   |  t| jd d S )NzCurveFp(p=23, a=1, b=1)r1   strr-   r2   r   r   r   test___str__i   s    zTestCurve.test___str__c                 C   s"   t dddd}| t|d d S )Nr   r   rA   zCurveFp(p=23, a=1, b=1, h=4))r   r1   rF   r3   cr   r   r   test___str___with_cofactorl   s    z$TestCurve.test___str___with_cofactorN)__name__
__module____qualname__classmethodr0   r4   r8   r:   r<   r?   rD   rG   rJ   r   r   r   r   r+   J   s   
r+   c                   @   s8   e Zd Zedd Zdd Zdd Zdd Zd	d
 ZdS )TestCurveEdTwc                 C   s   t ddd| _d S r,   )r
   r-   r.   r   r   r   r0   r   s    zTestCurveEdTw.setUpClassc                 C   s   |  t| jd d S )NzCurveEdTw(p=23, a=1, d=1)rE   r2   r   r   r   rG   v   s    zTestCurveEdTw.test___str__c                 C   s"   t dddd}| t|d d S )Nr   r   rA   zCurveEdTw(p=23, a=1, d=1, h=4))r
   r1   rF   rH   r   r   r   rJ   y   s    z(TestCurveEdTw.test___str___with_cofactorc                 C   s   | j d i d S r   r;   r2   r   r   r   r<   }   s    z:TestCurveEdTw.test_usability_in_a_hashed_collection_curvesc                 C   s   t | j d S r   r=   r2   r   r   r   r?      s    z%TestCurveEdTw.test_hashability_curvesN)	rK   rL   rM   rN   r0   rG   rJ   r<   r?   r   r   r   r   rO   q   s   
rO   c                   @   s   e Zd Zedd Zdd Zdd Zdd Zd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+S ),	TestPointc                 C   sX   t ddd| _t| jddd| _d}d}d}d}d	}t |d
|| _t| j|||| _d S )Nr   r   r   r   r   r   r   r   r   r   )r   r-   r	   r!   r7   r   )r/   r'   r   r5   GxGyr   r   r   r0      s    zTestPoint.setUpClassc                 C   s   d}|| j  }| | d d}|| j  }| | d | | d d}d}|| j  ||  }| | d | | d d S )Nl   uH=.t.#",W}7?jl   Z`uSG;R-]]0sk	+l   N/vZL_~XXw]ol   ~n&DJ,6'1a47b?`l   5XD+8n#w}rO	l   WTY>n+BtC*Yql   !M_JT96wfF[,z=)r   r1   xy)r3   dQkRZu1Zu2Ztempr   r   r   	test_p192   s6    
 
    zTestPoint.test_p192c                 C   sD   t }| }| || | | |  | | |  d S r   )r   doubler1   rS   rT   )r3   r   p3r   r   r   test_double_infinity   s
    zTestPoint.test_double_infinityc                 C   sF   d\}}}}t | j||}| }| | | | | | d S )N)   
   r      )r	   r-   rZ   r1   rS   rT   )r3   x1y1x3y3r   r[   r   r   r   test_double   s
    zTestPoint.test_doublec                 C   s^   t | jdd}| }| | | fd | |t | }| |t | |t d S N      rA   r   )	r	   r-   rZ   r1   rS   rT   r6   r   assertIsr3   r   p2r[   r   r   r   test_double_to_infinity   s    z!TestPoint.test_double_to_infinityc                 C   s^   t | jdd}|| }| | | fd | |t || }| |t | |t d S re   r	   r-   r1   rS   rT   r6   r   ri   rj   r   r   r   test_add_self_to_infinity   s    z#TestPoint.test_add_self_to_infinityc                 C   s^   t | jdd}|d }| | | fd | |t |d }| |t | |t d S )Nrf   rg   r   rh   rm   rj   r   r   r   test_mul_to_infinity   s    zTestPoint.test_mul_to_infinityc                 C   sH   d\}}}}}t | j||}|| }| | | | | | d S )N)r]   r^   r   r   r_   r	   r-   r1   rS   rT   )r3   r`   ra   r(   rb   rc   r   r[   r   r   r   test_multiply   s
    zTestPoint.test_multiplyc           
      C   sX   d\}}}}}}t | j||}t | j||}|| }	| |	 | | |	 | dS ):We expect that on curve c, (x1,y1) + (x2, y2 ) = (x3, y3).)r]   r^   r&   r      rg   Nrp   
r3   r`   ra   Zx2Zy2rb   rc   r   rk   r[   r   r   r   test_add   s    zTestPoint.test_addc           
      C   sX   d\}}}}}}t | j||}t | j||}|| }	| |	 | | |	 | dS )rr   )r]   r^   r]   r^   r   r_   Nrp   rt   r   r   r   test_add_as_double   s    zTestPoint.test_add_as_doublec                 C   s   |  | jt| jddd d S )Nr   r   )r1   r!   r	   r-   r2   r   r   r   test_equality_points   s    zTestPoint.test_equality_pointsc                 C   s,   t ddd}t|ddd}| | j| d S Nd   r   )r   r	   r6   r!   )r3   rI   r'   r   r   r   test_inequality_points   s    z TestPoint.test_inequality_pointsc                 C   s   t ddd}| | j| d S rx   )r   r6   r!   rH   r   r   r   !test_inequality_points_diff_types   s    z+TestPoint.test_inequality_points_diff_typesc                 C   s,   t | jdd}t | jdd}| || d S )N   rA      )r	   r-   r6   )r3   r   rk   r   r   r   test_inequality_diff_y  s    z TestPoint.test_inequality_diff_yc                 C   s,   t | jdd}| |t | j|  d S Nr]   r^   )r	   r-   r1   
from_bytesto_bytesr3   r'   r   r   r   test_to_bytes_from_bytes	  s    z"TestPoint.test_to_bytes_from_bytesc                 C   s$   t | jdd}| t||   d S r   )r	   r-   r1   r   r   r   r   r   test_add_to_neg_self  s    zTestPoint.test_add_to_neg_selfc                 C   s"   t | jdd}| ||t  d S r   )r	   r-   ri   r   r   r   r   r   test_add_to_infinity  s    zTestPoint.test_add_to_infinityc                 C   s   |  ttd  d S )Nr^   )ri   r   r2   r   r   r   test_mul_infinity_by_scalar  s    z%TestPoint.test_mul_infinity_by_scalarc                 C   s(   t | jdd}| |d | d  d S )Nr]   r^      )r	   r-   r1   r   r   r   r   test_mul_by_negative  s    zTestPoint.test_mul_by_negativec                 C   s   |  ttd d S )NZinfinity)r1   rF   r   r2   r   r   r   test_str_infinity   s    zTestPoint.test_str_infinityc                 C   s"   t | jdd}| t|d d S )Nr]   r^   z(3,10))r	   r-   r1   rF   r   r   r   r   test_str_point#  s    zTestPoint.test_str_pointN)rK   rL   rM   rN   r0   rY   r\   rd   rl   rn   ro   rq   ru   rv   rw   rz   r{   r~   r   r   r   r   r   r   r   r   r   r   r   rP      s,   
			

rP   ),ZpytestZ	unittest2ZunittestImportErrorZ
hypothesisr   r   Zhypothesis.strategiesZ
strategiesstr   Z
HC_PRESENTZnumbertheoryr   Zellipticcurver   r   r	   r
   ZHYP_SETTINGSZtoo_slowr'   r   r5   rQ   rR   r7   r   r-   r!   dictZHYP_SLOW_SETTINGSZintegersr   r    ZmarkZparametrize	enumerateranger*   ZTestCaser+   rO   rP   r   r   r   r   <module>   sR   


'