o
    ϋiP                     @   s   d dl Z d dlZzd dlZW n ey   d dlZY nw d dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZmZmZmZ ddlmZmZmZ ddlmZmZmZmZmZmZmZ ddlmZ ddl m!Z! i Z"ej#dkrud	e"d
< i Z$dej%v rde$d< nde$d< G dd dej&Z'dS )    N)givenassumesettingsexample   )CurveFpPointJacobiINFINITY)generator_256	curve_256generator_224generator_brainpoolp160r1curve_brainpoolp160r1generator_112r2curve_112r2)inverse_mod)	randrange)      i  deadlinez--fastr   max_examples
   c                   @   s  e Z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)d* Zd+d, Zd-d. Zed}i eeejd/ee ! d0 d1d2d3 Z"ed}i eeejd/ee ! d0 d1e#d/e#ee ! d4d5 Z$ed}i eeejd0ee ! d0 d1ejd0ee ! d0 d1e#d6d6d7d8 Z%ed}i eeejd0ee ! d0 d1ejd0ee ! d0 d1ejd0ee&' d0 d1d9d: Z(e)j*j+ed}i eeejd0ee ! d0 d1ejd0ee ! d0 d1ejd0ee&' d0 d1e#d0d0d0e#d6d6d6e#d;ee ! d; d0e#d;ee ! d; d6d<d= Z,d>d? Z-e)j*j+ed}i eeejd0ee ! d0 d1ejd0ee ! d0 d1ej.ejd0ee&' d0 d1d;d;d@dAe#d;d;d;d0ge#d;d;d;d6ge#d;ee ! d; d;d6ge#d;ee ! d; d;d0gdBdC Z/dDdE Z0dFdG Z1dHdI Z2dJdK Z3dLdM Z4dNdO Z5dPdQ Z6dRdS Z7dTdU Z8dVdW Z9dXdY Z:dZd[ Z;d\d] Z<d^d_ Z=d`da Z>dbdc Z?ddde Z@dfdg ZAdhdi ZBdjdk ZCdldm ZDdndo ZEdpdq ZFe)j*j+ed}i eGe)j*jHeIJ drkdsdteejd0dud1dvdw ZKe)j*j+e)j*jHeIL dxkpVeIJ drkdydtdzd{ ZMd|S )~
TestJacobic                 C   sj   t  }d}d}d}d}t|||||}| | | | | | | | | | | | d S )Nr      r      )objectr   assertEqualorderassertIscurvexy)selfr   r    r!   zr   pj r%   U/home/air/goalskill_sales/back/venv/lib/python3.10/site-packages/ecdsa/test_jacobi.pytest___init__,   s   zTestJacobi.test___init__c                 C   sL   t t}t t}| t ||  W d    d S 1 sw   Y  d S N)r   from_affiner
   r   assertRaises
ValueErrorr"   p_ap_br%   r%   r&   test_add_with_different_curves9   s
   


"z)TestJacobi.test_add_with_different_curvesc                 C   s   |  tt d S r(   )assertNotEqualr
   r   )r"   r%   r%   r&   test_compare_different_curves@   s   z(TestJacobi.test_compare_different_curvesc                 C      t t}| |d d S )Nvaluer   r)   r
   r0   r"   r$   r%   r%   r&   test_equality_with_non_pointC      
z'TestJacobi.test_equality_with_non_pointc                 C   s"   t t}| }| t| d S r(   r   r)   r
   	to_affiner   r"   r$   pwr%   r%   r&   test_conversionH   s   
zTestJacobi.test_conversionc                 C   sF   t t}t }| }| | |  | | |  d S r(   )r   r)   r
   doubler   r    r!   r:   r%   r%   r&   test_single_doubleN   
   
zTestJacobi.test_single_doublec                 C   s&   t tddd}| }| |t d S Nr   r   )r   r   r=   r   r	   r5   r%   r%   r&   test_double_with_zero_pointW      z&TestJacobi.test_double_with_zero_pointc                 C   *   t tdt d}| }| |t d S r@   r   r   pr=   r   r	   r5   r%   r%   r&   &test_double_with_zero_equivalent_point^      z1TestJacobi.test_double_with_zero_equivalent_pointc                 C   rC   )Nr   r   rD   r5   r%   r%   r&   .test_double_with_zero_equivalent_point_non_1_ze   rG   z9TestJacobi.test_double_with_zero_equivalent_point_non_1_zc                 C   s.   t t}| }| || | || d S r(   r8   r"   r$   par%   r%   r&   test_compare_with_affine_pointl   s   
z)TestJacobi.test_compare_with_affine_pointc                 C   s&   t tddd}| }| |t d S r@   )r   r   r9   r   r	   rI   r%   r%   r&   test_to_affine_with_zero_points   rB   z)TestJacobi.test_to_affine_with_zero_pointc                 C   s.   t t}| }|| }| ||  d S r(   r   r)   r
   r9   r   r=   r"   r$   rJ   sr%   r%   r&   test_add_with_affine_pointz      
z%TestJacobi.test_add_with_affine_pointc                 C   s.   t t}| }|| }| ||  d S r(   rM   rN   r%   r%   r&   test_radd_with_affine_point   rQ   z&TestJacobi.test_radd_with_affine_pointc                 C   s"   t t}|t }| || d S r(   )r   r)   r
   r	   r   )r"   r$   rO   r%   r%   r&   test_add_with_infinity      
z!TestJacobi.test_add_with_infinityc                 C   s4   t t }t tddd}|| }| || d S r@   )r   r)   r
   r9   r   r   )r"   rJ   r$   rO   r%   r%   r&   test_add_zero_point_to_affine   s   z(TestJacobi.test_add_zero_point_to_affinec                 C   s"   t t}|d }| |t d S )Nr   )r   r)   r
   r   r	   r5   r%   r%   r&   test_multiply_by_zero   rT   z TestJacobi.test_multiply_by_zeroc                 C   s&   t tddd}|d }| |t d S r@   )r   r   r   r	   r5   r%   r%   r&   test_zero_point_multiply_by_one   rB   z*TestJacobi.test_zero_point_multiply_by_onec                 C   F   t t}td }|d }| | |  | | |  d S Nr   r   r)   r
   r   r    r!   r:   r%   r%   r&   test_multiply_by_one   r?   zTestJacobi.test_multiply_by_onec                 C   rX   Nr   rZ   r:   r%   r%   r&   test_multiply_by_two   r?   zTestJacobi.test_multiply_by_twoc                 C   s*   t t}td }d| }| || d S r\   r   r)   r
   r   r:   r%   r%   r&   test_rmul_by_two   s   
zTestJacobi.test_rmul_by_twoc                 C   s   t t}| |t d S r(   )r   r)   r
   r0   r	   r5   r%   r%   r&   #test_compare_non_zero_with_infinity   r7   z.TestJacobi.test_compare_non_zero_with_infinityc                 C   s   t tddd}| |t d S r@   )r   r   r   r	   r5   r%   r%   r&   %test_compare_zero_point_with_infinity   s   z0TestJacobi.test_compare_zero_point_with_infinityc                 C   s*   t t}| }|d }| || d S r\   )r   r)   r
   r=   r   )r"   r$   dblmlplr%   r%   r&   !test_compare_double_with_multiply   s   
z,TestJacobi.test_compare_double_with_multiplyr   r   )	min_value	max_valuec                 C   sR   t t}| | }|| }| | | f| | f | || d S r(   )r   r)   r   r9   r   r    r!   )r"   mulr$   r;   r%   r%   r&   test_multiplications   s
   
$zTestJacobi.test_multiplicationsc                 C   s:   t }| |j tt }|| }|| }| || d S r(   )r   
assertTrue_PointJacobi__precomputer   r)   r   )r"   rg   precompr$   abr%   r%   r&   test_precompute   s   	
zTestJacobi.test_precomputer   c                 C   sF   t t}t || }t || }|| }| ||||   d S r(   )r   r)   r   r   )r"   a_mulb_mulj_grl   rm   cr%   r%   r&   test_add_scaled_points   s
   
z!TestJacobi.test_add_scaled_pointsc           
      C   s   t t}t || }t || }t }tt|| || | }t t| | | | | | | |}|| }	| 	|	|||   d S r(   
r   r)   r   r   rE   r   r   r    r!   r   
r"   ro   rp   new_zrq   rl   rm   rE   new_zzrr   r%   r%   r&   test_add_one_scaled_point  s   
z$TestJacobi.test_add_one_scaled_pointr   c           
      C   s   t t}t || }t || }t }tt|| || | }t t| | | | | | | |}t t| | | | | | | |}|| }	| 	|	|||   d S r(   rt   ru   r%   r%   r&   test_add_same_scale_points&  s(   
z%TestJacobi.test_add_same_scale_pointsc                 C   s   t }t }|d }|  d}tt| |d  | | |d  | |}tt| |d  | | |d  | |}|| }| |||  d S )N      r   r   r   r   rE   scaler   r    r!   r   )r"   rq   rE   rl   z1r    r!   rr   r%   r%   r&   !test_add_same_scale_points_staticQ  s&   z,TestJacobi.test_add_same_scale_points_staticT)min_sizemax_sizeuniquec                 C   s   t t}t || }t || }t }tt|d | tt|d | |d |d  | }|d |d  | }	t t| | | | | |d  | |d }t t| |	 | | |	 |d  | |d }|| }
| 	|
|||   d S r@   rt   )r"   ro   rp   rv   rq   rl   rm   rE   new_zz0new_zz1rr   r%   r%   r&   test_add_different_scale_pointsh  s,   
z*TestJacobi.test_add_different_scale_pointsc           	      C   s   t }t }|d }|  d}tt| |d  | | |d  | |}d}tt| |d  | | |d  | |}|| }| |||  d S )Nrz   r{   r   r      r|   )	r"   rq   rE   rl   r~   r    z2r!   rr   r%   r%   r&   &test_add_different_scale_points_static  s(   z1TestJacobi.test_add_different_scale_points_staticc           	      C   s   t }t }|d }|  |d }d}tt| |d  | | |d  | |}tt| |d  | | |d  | |}|| }| |||  d S )Nrz      r{   r   r   r|   )	r"   rq   rE   rl   rm   r#   r    r!   rr   r%   r%   r&   +test_add_different_points_same_scale_static  s(   z6TestJacobi.test_add_different_points_same_scale_staticc                 C   s   t }t }d}|| }|  tt| |d  | | |d  | |}tt| | d}|| }| |||  d S )Nrz   r   r   r   )r   r   rE   r}   r   r    r!   r   )r"   rq   rE   r#   rl   r    r!   rr   r%   r%   r&   5test_add_same_point_different_scale_second_z_1_static  s&   z@TestJacobi.test_add_same_point_different_scale_second_z_1_staticc                 C   s^   t }d}|| }|  | }tt| | d}tt| | d}| t||  d S )Nrz   r   )r   r}   r   r   r    r!   r   r	   )r"   rq   r#   rl   rm   r    r!   r%   r%   r&   test_add_to_infinity_static  s$   z&TestJacobi.test_add_to_infinity_staticc                 C   s&   t t}| |d || |  d S )Nr   r^   r"   rq   r%   r%   r&   test_add_point_3_times  s   
z!TestJacobi.test_add_point_3_timesc                 C   s.   t tt t d}| |t  t d S rY   )r   r   r
   r    r!   r   r   r	   r   r%   r%   r&   test_mul_without_order  s   z!TestJacobi.test_mul_without_orderc                 C   s$   t t}| ||dtd d S rY   r   r)   r
   r   mul_addr	   r   r%   r%   r&   test_mul_add_inf  s   
zTestJacobi.test_mul_add_infc                 C   s(   t t}| |d |d|d d S )Nr   r   r   r)   r
   r   r   r   r%   r%   r&   test_mul_add_same  s   
zTestJacobi.test_mul_add_samec                 C   j   t td}t |d d}| |d ||  | |d |d |d   | |d |d|d d S )NT      i     r   r   r)   r   r   r   r"   rq   rm   r%   r%   r&   test_mul_add_precompute  s
   z"TestJacobi.test_mul_add_precomputec                 C   r   )NTr   r         r   r   r%   r%   r&   test_mul_add_precompute_large  s   z(TestJacobi.test_mul_add_precompute_largec                 C   s0   t t}|d }|d|d}| || d S )Nr   r   r   )r   r)   r
   r   r   )r"   rq   rl   rm   r%   r%   r&   test_mul_add_to_mul$  s   
zTestJacobi.test_mul_add_to_mulc                 C   s0   t t}|d }| |d|d|d  d S )Nr   r   r   r   )r"   rq   w_ar%   r%   r&   test_mul_add_differnt,  s   
z TestJacobi.test_mul_add_differntc                 C   s@   t t}|d }|d }| |d|d|d |d   d S )Nr   r   r   r   )r"   rq   r   w_br%   r%   r&   test_mul_add_slightly_different3  s   
&z*TestJacobi.test_mul_add_slightly_differentc                 C   sH   t t}td }td }|d }|d|d}| | ||  d S )Nr   i        )r   r)   r
   r   r   r9   )r"   rq   r   r   j_bretr%   r%   r&   test_mul_add;  s   
zTestJacobi.test_mul_addc                 C   sf   t t}t |d }| |d ||  | |d |d |d   | |d |d|d d S )Nr   r   r   r   r   r   r   r%   r%   r&   test_mul_add_largeF  s   
zTestJacobi.test_mul_add_largec                 C   sB   t t}t }t td }| ||d ||d t d S )Nr   )r   r)   r
   r   r   r   r	   )r"   rq   r   rm   r%   r%   r&   $test_mul_add_with_infinity_as_resultR  s   
"z/TestJacobi.test_mul_add_with_infinity_as_resultc                 C   sf   t tt t d}t }td }|  t t| | d}| ||d ||d t	 d S )Nr   "   )
r   r   r
   r    r!   r   r}   r   r   r	   )r"   rq   r   r   rm   r%   r%   r&   test_mul_add_without_order[  s   "z%TestJacobi.test_mul_add_without_orderc                 C   s2   t td }d|  }| |d|dt d S )N   r   r   r   )r"   rq   dbl_negr%   r%   r&   ,test_mul_add_with_doubled_negation_of_itselfg  s   
z7TestJacobi.test_mul_add_with_doubled_negation_of_itselfc                 C   sH   t tddddddddd}t tddddddddd}| || d S N   r   r   r   r   r    r!   r#   r   )r   r   r   )r"   pj1pj2r%   r%   r&   test_equalityn  s   zTestJacobi.test_equalityc                 C   r2   )Nr   r4   r   r%   r%   r&   !test_equality_with_invalid_objects  r7   z,TestJacobi.test_equality_with_invalid_objectc                 C   s$   t t}t t}| || d S r(   )r   r)   r
   r   r0   r,   r%   r%   r&   test_equality_with_wrong_curvesx  s   

z*TestJacobi.test_equality_with_wrong_curvesc              	   C   sN   t tddddddddd}|ddddddd\}}}| |||fd d S )	Nr   r   r   r   r   r   r   )r   r   r   )r   r   _addr   )r"   r   r    r!   r#   r%   r%   r&   test_add_with_point_at_infinity~  s   z*TestJacobi.test_add_with_point_at_infinityc                 C   s8   t tddddddddd}| tt|| d S r   )r   r   r   pickleloadsdumpsr5   r%   r%   r&   test_pickle  s   zTestJacobi.test_picklePyPyz!threading on PyPy breaks coverage)reasonr   c                 C   s   t d  t }t| | | d| d}| |jg  dd }g }t|D ]}|	t
j||fd q(|D ]}|  q8|| |D ]}|  qE| |jt j d S )Nr   r   Tc                 S   &   |   }tdD ]}| t|  qd S )Nr   r   ranger   	generatorr   _r%   r%   r&   runner     z.TestJacobi.test_multithreading.<locals>.runnertargetargs)r   r   r   r    r!   r   r   rj   r   append	threadingThreadstartjoin)r"   
thread_numgenr   threadsr   tr%   r%   r&   test_multithreading  s"   	"

zTestJacobi.test_multithreadingWindowszFthere are no signals on Windows, and threading breaks coverage on PyPyc                 C   sD  d}t d  t }t| | | d| d}| |jg  dd }dd }g }t|D ]}|	t
j||fd	 q.t
 }|  t
 }|  t
 }	|	  |	t
j||||	fd	 |D ]}
|
  qc| t |  |  || |	  W d    n1 sw   Y  |D ]}
|
  q| |jt j d S )
Nr   r   r   Tc                 S   r   )N2   r   r   r%   r%   r&   r     r   z>TestJacobi.test_multithreading_with_interrupts.<locals>.runnerc                 S   s.   |    |  tt tj |   d S r(   )releaseacquireoskillgetpidsignalSIGINT)barrier_startbarrier_end	lock_exitr%   r%   r&   interrupter  s   zCTestJacobi.test_multithreading_with_interrupts.<locals>.interrupterr   )r   r   r   r    r!   r   r   rj   r   r   r   r   Lockr   r   r*   KeyboardInterruptr   r   )r"   r   r   r   r   r   r   r   r   r   r   r%   r%   r&   #test_multithreading_with_interrupts  sH   "

	
z.TestJacobi.test_multithreading_with_interruptsNr%   )N__name__
__module____qualname__r'   r/   r1   r6   r<   r>   rA   rF   rH   rK   rL   rP   rR   rS   rU   rV   rW   r[   r]   r_   r`   ra   rd   r   SLOW_SETTINGSr   stintegersintr   r   rh   r   rn   rs   r   rE   rx   pytestmarkslowry   r   listsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   NO_OLD_SETTINGSskipifplatformpython_implementationr   systemr   r%   r%   r%   r&   r   +   s   				
		
	
	
 
r   )(r   sys	unittest2unittestImportErrorr   r   r   r   r   hypothesis.strategies
strategiesr   
hypothesisr   r   r   r   ellipticcurver   r   r	   ecdsar
   r   r   r   r   r   r   numbertheoryr   utilr   r   version_infor   argvTestCaser   r%   r%   r%   r&   <module>   s4    $	


