a
    _mg                     @   s  d dl Z zd dlZW n ey.   d dlZY n0 d dlmZmZ d dlmZ	 zd dlm
Z
 dZW n eyv   dZY n0 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 i 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  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"J d S N)r   rp192)multipleZinv_mp1 r   O/var/www/html/idle/venv/lib/python3.9/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   expr   r   r   
<listcomp>C       r%      c                 C   s   g | ]}d  |qS )zg_23 test with mult {0})format)r#   r    r   r   r   r%   D   r&   	   )idsc                 C   s   | | |ksJ d S r   r   )pmcheckr   r   r   test_add_and_mult_equivalenceA   s    r.   c                   @   sP   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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 r0   )assertEqualr1   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assertNotEqualr1   )r7   c192r   r   r   test_inequality_curvesR   s    z TestCurve.test_inequality_curvesc                 C   s   | j d i d S r   r1   r6   r   r   r   ,test_usability_in_a_hashed_collection_curvesV   s    z6TestCurve.test_usability_in_a_hashed_collection_curvesc                 C   s   t | j d S r   hashr1   r6   r   r   r   test_hashability_curvesY   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   r1   r5   lensetZassertDictEqualZassertIn)r7   Zne1Zne2Zne3Zeq1Zeq2Zeq3r   r   r   test_conflation_curves\   s    ("z TestCurve.test_conflation_curvesc                 C   s   |  t| jd d S )NzCurveFp(p=23, a=1, b=1)r5   strr1   r6   r   r   r   test___str__d   s    zTestCurve.test___str__c                 C   s"   t dddd}| t|d d S )Nr   r   rC   zCurveFp(p=23, a=1, b=1, h=4))r   r5   rH   r7   cr   r   r   test___str___with_cofactorg   s    z$TestCurve.test___str___with_cofactorN)__name__
__module____qualname__classmethodr4   r8   r<   r>   rA   rF   rI   rL   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 r0   )r
   r1   r2   r   r   r   r4   m   s    zTestCurveEdTw.setUpClassc                 C   s   |  t| jd d S )NzCurveEdTw(p=23, a=1, d=1)rG   r6   r   r   r   rI   q   s    zTestCurveEdTw.test___str__c                 C   s"   t dddd}| t|d d S )Nr   r   rC   zCurveEdTw(p=23, a=1, d=1, h=4))r
   r5   rH   rJ   r   r   r   rL   t   s    z(TestCurveEdTw.test___str___with_cofactorc                 C   s   | j d i d S r   r=   r6   r   r   r   r>   x   s    z:TestCurveEdTw.test_usability_in_a_hashed_collection_curvesc                 C   s   t | j d S r   r?   r6   r   r   r   rA   {   s    z%TestCurveEdTw.test_hashability_curvesN)	rM   rN   rO   rP   r4   rI   rL   r>   rA   r   r   r   r   rQ   l   s   
rQ   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#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   r1   r	   r"   r;   r   )r3   r+   r   r9   GxGyr   r   r   r4      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   r5   xy)r7   dQkRu1u2tempr   r   r   	test_p192   s,    

zTestPoint.test_p192c                 C   sD   t }| }| || | | |  | | |  d S r   )r   doubler5   rU   rV   )r7   r   p3r   r   r   test_double_infinity   s
    zTestPoint.test_double_infinityc                 C   sF   d\}}}}t | j||}| }| | | | | | d S )N)   
   r      )r	   r1   r_   r5   rU   rV   )r7   x1y1x3y3r   r`   r   r   r   test_double   s
    zTestPoint.test_doublec                 C   sH   d\}}}}}t | j||}|| }| | | | | | d S )N)rb   rc   r   r   rd   r	   r1   r5   rU   rV   )r7   re   rf   r,   rg   rh   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).)rb   rc   r)   r         Nrj   
r7   re   rf   Zx2y2rg   rh   r   p2r`   r   r   r   test_add   s    zTestPoint.test_addc           
      C   sX   d\}}}}}}t | j||}t | j||}|| }	| |	 | | |	 | dS )rl   )rb   rc   rb   rc   r   rd   Nrj   ro   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   )r5   r"   r	   r1   r6   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	   r:   r"   )r7   rK   r+   r   r   r   test_inequality_points   s    z TestPoint.test_inequality_pointsc                 C   s   t ddd}| | j| d S ru   )r   r:   r"   rJ   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 S Nrb   rc   )r	   r1   r5   
from_bytesto_bytesr7   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 ry   )r	   r1   r5   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 ry   )r	   r1   assertIsr   r|   r   r   r   test_add_to_infinity   s    zTestPoint.test_add_to_infinityc                 C   s   |  ttd  d S )Nrc   )r   r   r6   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 )Nrb   rc      )r	   r1   r5   r|   r   r   r   test_mul_by_negative   s    zTestPoint.test_mul_by_negativec                 C   s   |  ttd d S )NZinfinity)r5   rH   r   r6   r   r   r   test_str_infinity   s    zTestPoint.test_str_infinityc                 C   s"   t | jdd}| t|d d S )Nrb   rc   z(3,10))r	   r1   r5   rH   r|   r   r   r   test_str_point   s    zTestPoint.test_str_pointN)rM   rN   rO   rP   r4   r^   ra   ri   rk   rr   rs   rt   rw   rx   r}   r~   r   r   r   r   r   r   r   r   r   rR      s$   


rR   ),ZpytestZ	unittest2ZunittestImportErrorZ
hypothesisr   r   Zhypothesis.strategies
strategiesstr   Z
HC_PRESENTZnumbertheoryr   Zellipticcurver   r   r	   r
   ZHYP_SETTINGSZtoo_slowr+   r   r9   rS   rT   r;   r   r1   r"   dictZHYP_SLOW_SETTINGSZintegersr   r!   markZparametrize	enumerateranger.   ZTestCaser/   rQ   rR   r   r   r   r   <module>   sR   


"