
    +hG                     "   d dl Z 	 d dlZn# e$ r d dlZY nw xY wd dlZ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 ddlmZ ddlm Z  i Z!ej"        dk    rd	e!d
<    G 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)inverse_mod)	randrange)      i  deadlinec                   d
   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z ed           e ej        d e ej                                                   d                         Z! ed           e ej        d e ej                                                    e"d           e" e ej                                         d                                                 Z# ed           e ej        d e ej                                          ej        d e ej                                                    e"dd          d                                      Z$ ed           e ej        d e ej                                          ej        d e ej                                          ej        d e e%j&                    dz
                                d!                         Z' ed           e ej        d e ej                                          ej        d e ej                                          ej        d e e%j&                    dz
                                 e"ddd           e"ddd           e"d" e ej                     d"z
            d           e"d" e ej                     d"z
            d          d#                                                                         Z(d$ Z) ed%           e ej        d e ej                                          ej        d e ej                                          ej*         ej        d e e%j&                    dz
                      d"d"d&'                     e"d"d"d"dg           e"d"d"d"dg           e"d" e ej                     d"z
            d"dg           e"d" e ej                     d"z
            d"dg          d(                                                                         Z+d) Z,d* Z-d+ Z.d, Z/d- Z0d. Z1d/ Z2d0 Z3d1 Z4d2 Z5d3 Z6d4 Z7d5 Z8d6 Z9d7 Z:d8 Z;d9 Z<d: Z=d; Z> edBi e? e ej        dd                    d<                         Z@eAjB        C                     eDjE                    d=k    d>?          d@             ZFdAS )C
TestJacobic                    t                      }d}d}d}d}t          |||||          }|                     |                                |           |                     |                                |           |                     |                                |           |                     |                                |           d S )Nr      r      )objectr	   assertEqualorderassertIscurvexy)selfr   r    r!   zr   pjs          U/var/www/html/e360mart/e360mart_env/lib/python3.11/site-packages/ecdsa/test_jacobi.pytest___init__zTestJacobi.test___init__$   s    1a//U+++bhhjj%(((########    c                     t          j        t                    }t          j        t                    }|                     t
                    5  ||z    d d d            d S # 1 swxY w Y   d S N)r	   from_affiner   r   assertRaises
ValueErrorr"   p_ap_bs      r%   test_add_with_different_curvesz)TestJacobi.test_add_with_different_curves1   s    %m44%m44z** 	 	#II	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A  A$'A$c                 F    |                      t          t                     d S r)   )assertNotEqualr   r   )r"   s    r%   test_compare_different_curvesz(TestJacobi.test_compare_different_curves8   s    M=99999r'   c                 d    t          j        t                    }|                     |d           d S )Nvaluer	   r*   r   r2   r"   r$   s     r%   test_equality_with_non_pointz'TestJacobi.test_equality_with_non_point;   s.    $]33B(((((r'   c                     t          j        t                    }|                                }|                     t          |           d S r)   r	   r*   r   	to_affiner   r"   r$   pws      r%   test_conversionzTestJacobi.test_conversion@   s;    $]33\\^^+++++r'   c                 n   t          j        t                    }t          j                    }|                                }|                     |                                |                                           |                     |                                |                                           d S r)   )r	   r*   r   doubler   r    r!   r<   s      r%   test_single_doublezTestJacobi.test_single_doubleF   s    $]33!##YY[[((((((((r'   c                     t          t          ddd          }|                                }|                     |t                     d S Nr   r   )r	   r   r@   r   r
   r7   s     r%   test_double_with_zero_pointz&TestJacobi.test_double_with_zero_pointO   s<    Aq!,,YY[[b(#####r'   c                     t          t          dt          j                    d          }|                                }|                     |t
                     d S rC   r	   r   pr@   r   r
   r7   s     r%   &test_double_with_zero_equivalent_pointz1TestJacobi.test_double_with_zero_equivalent_pointV   B    Ay{}}a88YY[[b(#####r'   c                     t          t          dt          j                    d          }|                                }|                     |t
                     d S )Nr   r   rF   r7   s     r%   .test_double_with_zero_equivalent_point_non_1_zz9TestJacobi.test_double_with_zero_equivalent_point_non_1_z]   rI   r'   c                     t          j        t                    }|                                }|                     ||           |                     ||           d S r)   r:   r"   r$   pas      r%   test_compare_with_affine_pointz)TestJacobi.test_compare_with_affine_pointd   sQ    $]33\\^^R   R     r'   c                     t          t          ddd          }|                                }|                     |t                     d S rC   )r	   r   r;   r   r
   rM   s      r%   test_to_affine_with_zero_pointz)TestJacobi.test_to_affine_with_zero_pointk   s<    Aq!,,\\^^b(#####r'   c                     t          j        t                    }|                                }||z   }|                     ||                                           d S r)   r	   r*   r   r;   r   r@   r"   r$   rN   ss       r%   test_add_with_affine_pointz%TestJacobi.test_add_with_affine_pointr   L    $]33\\^^GBIIKK(((((r'   c                     t          j        t                    }|                                }||z   }|                     ||                                           d S r)   rS   rT   s       r%   test_radd_with_affine_pointz&TestJacobi.test_radd_with_affine_pointz   rW   r'   c                 x    t          j        t                    }|t          z   }|                     ||           d S r)   )r	   r*   r   r
   r   )r"   r$   rU   s      r%   test_add_with_infinityz!TestJacobi.test_add_with_infinity   s7    $]33MBr'   c                     t          j        t                                                    }t          t          ddd          }||z   }|                     ||           d S rC   )r	   r*   r   r;   r   r   )r"   rN   r$   rU   s       r%   test_add_zero_point_to_affinez(TestJacobi.test_add_zero_point_to_affine   sT    $]33==??Aq!,,Gar'   c                 x    t          j        t                    }|dz  }|                     |t                     d S )Nr   )r	   r*   r   r   r
   r7   s     r%   test_multiply_by_zeroz TestJacobi.test_multiply_by_zero   s5    $]33!Vb(#####r'   c                 t    t          t          ddd          }|dz  }|                     |t                     d S rC   )r	   r   r   r
   r7   s     r%   test_zero_point_multiply_by_onez*TestJacobi.test_zero_point_multiply_by_one   s8    Aq!,,!Vb(#####r'   c                 >   t          j        t                    }t          dz  }|dz  }|                     |                                |                                           |                     |                                |                                           d S Nr   r	   r*   r   r   r    r!   r<   s      r%   test_multiply_by_onezTestJacobi.test_multiply_by_one   w    $]33Q!V((((((((r'   c                 >   t          j        t                    }t          dz  }|dz  }|                     |                                |                                           |                     |                                |                                           d S Nr   rd   r<   s      r%   test_multiply_by_twozTestJacobi.test_multiply_by_two   rf   r'   c                     t          j        t                    }t          dz  }d|z  }|                     ||           d S rh   r	   r*   r   r   r<   s      r%   test_rmul_by_twozTestJacobi.test_rmul_by_two   sA    $]33QVR     r'   c                 n    t          j        t                    }|                     |t                     d S r)   )r	   r*   r   r2   r
   r7   s     r%   #test_compare_non_zero_with_infinityz.TestJacobi.test_compare_non_zero_with_infinity   s.    $]33B)))))r'   c                 j    t          t          ddd          }|                     |t                     d S rC   )r	   r   r   r
   r7   s     r%   %test_compare_zero_point_with_infinityz0TestJacobi.test_compare_zero_point_with_infinity   s1    Aq!,,X&&&&&r'   c                     t          j        t                    }|                                }|dz  }|                     ||           d S rh   )r	   r*   r   r@   r   )r"   r$   dblmlpls       r%   !test_compare_double_with_multiplyz,TestJacobi.test_compare_double_with_multiply   sD    $]33iikkAvd#####r'   
   )max_examplesr   )	min_value	max_valuec                 `   t          j        t                    }|                                |z  }||z  }|                     |                                |                                f|                                |                                f           |                     ||           d S r)   )r	   r*   r   r;   r   r    r!   )r"   mulr$   r=   s       r%   test_multiplicationszTestJacobi.test_multiplications   s     $%>??\\^^c!#X"$$&&"$$&&)BDDFFBDDFF+;<<<R     r'   c                     t           }|                     |j                   t          j        t                     }||z  }||z  }|                     ||           d S r)   )r   
assertTrue_PointJacobi__precomputer	   r*   r   )r"   rz   precompr$   abs         r%   test_precomputezTestJacobi.test_precompute   s]     ,8999$%>??cMHAr'   r   r   c                     t          j        t                    }t          j        ||z            }t          j        ||z            }||z   }|                     ||||z   z             d S r)   )r	   r*   r   r   )r"   a_mulb_mulj_gr   r   cs          r%   test_add_scaled_pointsz!TestJacobi.test_add_scaled_points   sk     %&?@@#C%K00#C%K00EC55=122222r'   c                    t          j        t                    }t          j        ||z            }t          j        ||z            }t          j                    }t          t          ||                     ||z  |z  }t          t          |                                |z  |z  |                                |z  |z  |z  |          }||z   }	| 	                    |	|||z   z             d S r)   
r	   r*   r   r   rG   r   r   r    r!   r   
r"   r   r   new_zr   r   r   rG   new_zzr   s
             r%   test_add_one_scaled_pointz$TestJacobi.test_add_one_scaled_point   s     %&?@@#C%K00#C%K00!#%%{5!$$%%%"!CCEEFNQCCEEFNU"Q&	
 
 EC55=122222r'   r   c                 n   t          j        t                    }t          j        ||z            }t          j        ||z            }t          j                    }t          t          ||                     ||z  |z  }t          t          |                                |z  |z  |                                |z  |z  |z  |          }t          t          |                                |z  |z  |                                |z  |z  |z  |          }||z   }	| 	                    |	|||z   z             d S r)   r   r   s
             r%   test_add_same_scale_pointsz%TestJacobi.test_add_same_scale_points  s'    %&?@@#C%K00#C%K00!#%%{5!$$%%%"!CCEEFNQCCEEFNU"Q&	
 
 !CCEEFNQCCEEFNU"Q&	
 
 EC55=122222r'   c                    t           }t          j                    }|dz  }|                                 d}t	          t          |                                |dz  z  |z  |                                |dz  z  |z  |          }t	          t          |                                |dz  z  |z  |                                |dz  z  |z  |          }||z   }|                     |||z              d S )N      r   r   r   r   rG   scaler	   r    r!   r   )r"   r   rG   r   z1r    r!   r   s           r%   !test_add_same_scale_points_staticz,TestJacobi.test_add_same_scale_points_staticH  s    '!#%%"H				!CCEEBEMACCEEBEMA	
 
 !CCEEBEMACCEEBEMA	
 
 EAE"""""r'      T)min_sizemax_sizeuniquec                 0   t          j        t                    }t          j        ||z            }t          j        ||z            }t          j                    }t          t          |d         |                     t          t          |d         |                     |d         |d         z  |z  }|d         |d         z  |z  }	t          t          |                                |z  |z  |                                |z  |d         z  |z  |d                   }t          t          |                                |	z  |z  |                                |	z  |d         z  |z  |d                   }||z   }
| 	                    |
|||z   z             d S rC   r   )r"   r   r   r   r   r   r   rG   new_zz0new_zz1r   s              r%   test_add_different_scale_pointsz*TestJacobi.test_add_different_scale_points_  sw   , %&?@@#C%K00#C%K00!#%%{58Q''((({58Q''((((U1X%)(U1X%)!CCEEGOaCCEEGOeAh&*!H	
 
 !CCEEGOaCCEEGOeAh&*!H	
 
 EC55=122222r'   c                    t           }t          j                    }|dz  }|                                 d}t	          t          |                                |dz  z  |z  |                                |dz  z  |z  |          }d}t	          t          |                                |dz  z  |z  |                                |dz  z  |z  |          }||z   }|                     |||z              d S )Nr   r   r   r      r   )	r"   r   rG   r   r   r    z2r!   r   s	            r%   &test_add_different_scale_points_staticz1TestJacobi.test_add_different_scale_points_static  s    '!#%%"H				!CCEEBEMACCEEBEMA	
 
 !CCEEBEMACCEEBEMA	
 
 EAE"""""r'   c                 v    t          j        t                    }|                     |dz  ||z   |z              d S )Nr   rk   r"   r   s     r%   test_add_point_3_timesz!TestJacobi.test_add_point_3_times  s:    %m44q#)c/22222r'   c                     t          t          t          j                    t          j                    d          }|                     |t          j                    z  t                     d S rc   )r	   r   r   r    r!   r   r   r
   r   s     r%   test_mul_without_orderz!TestJacobi.test_mul_without_order  sO    )]_%6%68I8I1MM}2444h?????r'   c                     t          j        t                    }|                     ||                    dt
          d                     d S rc   r	   r*   r   r   mul_addr
   r   s     r%   test_mul_add_infzTestJacobi.test_mul_add_inf  s>    %m44ckk!Xq99:::::r'   c                     t          j        t                    }|                     |dz  |                    d|d                     d S )Nr   r   r	   r*   r   r   r   r   s     r%   test_mul_add_samezTestJacobi.test_mul_add_same  sB    %m44q#++aa"8"899999r'   c                 B   t          j        t          d          }t          j        |dz  d          }|                     |dz  ||z              |                     |dz  |dz  |dz  z              |                     |dz  |                    d|d                     d S )NT      i     r   r	   r*   r   r   r   r"   r   r   s      r%   test_mul_add_precomputez"TestJacobi.test_mul_add_precompute  s    %&?FF#C#It44sC!G,,,,cAgAo>>>,ckk!Q.B.BCCCCCr'   c                 B   t          j        t          d          }t          j        |dz  d          }|                     |dz  ||z              |                     |dz  |dz  |dz  z              |                     |dz  |                    d|d                     d S )NTr   r         r   r   s      r%   test_mul_add_precompute_largez(TestJacobi.test_mul_add_precompute_large  s    %&?FF#C#It44sC!G,,,()3<!f*+D	
 	
 	
 	()3;;vq&+I+I	
 	
 	
 	
 	
r'   c                     t          j        t                    }|dz  }|                    d|d          }|                     ||           d S )Nr   r   r   )r	   r*   r   r   r   )r"   r   r   r   s       r%   test_mul_add_to_mulzTestJacobi.test_mul_add_to_mul  sL    %m44!GKK3""Ar'   c                     t          j        t                    }|dz  }|                     |                    d|d          |dz             d S )Nr   r   r   r   )r"   r   w_as      r%   test_mul_add_differntz TestJacobi.test_mul_add_differnt  sK    %m44AgQQ//q99999r'   c                     t          j        t                    }|dz  }|dz  }|                     |                    d|d          |dz  |dz  z              d S )Nr   r   r   r   )r"   r   r   w_bs       r%   test_mul_add_slightly_differentz*TestJacobi.test_mul_add_slightly_different  s]    %m44AgAgQQ//q371BCCCCCr'   c                     t          j        t                    }t          dz  }t          dz  }|dz  }|                    d|d          }|                     |                                ||z              d S )Nr   i        )r	   r*   r   r   r   r;   )r"   r   r   r   j_brets         r%   test_mul_addzTestJacobi.test_mul_add  sl    %m44c!{+Djkk#sD))#)44444r'   c                 >   t          j        t                    }t          j        |dz            }|                     |dz  ||z              |                     |dz  |dz  |dz  z              |                     |dz  |                    d|d                     d S )Nr   r   r   r   r   r   r   s      r%   test_mul_add_largezTestJacobi.test_mul_add_large  s    %m44#C#I..sC!G,,,()3<!f*+D	
 	
 	
 	()3;;vq&+I+I	
 	
 	
 	
 	
r'   c                    t          j        t                    }t          j                    }t          j        t          dz            }|                     |                    |dz  ||dz            t                     d S )Nr   )r	   r*   r   r   r   r   r
   )r"   r   r   r   s       r%   $test_mul_add_with_infinity_as_resultz/TestJacobi.test_mul_add_with_infinity_as_result   si    %m44#%%#MC$788US[!Uc\BBHMMMMMr'   c                    t          t          t          j                    t          j                    d          }t          j                    }t          dz  }|                                 t          t          |                                |                                d          }|                     |                    |dz  ||dz            t                     d S )Nr   "   )
r	   r   r   r    r!   r   r   r   r   r
   )r"   r   r   r   r   s        r%   test_mul_add_without_orderz%TestJacobi.test_mul_add_without_order	  s    )]_%6%68I8I1MM#%%b 			35577CEEGGQ77URZERK@@(KKKKKr'   c                     t          j        t          dz            }d| z  }|                     |                    d|d          t
                     d S )N   r   r   r   )r"   r   dbl_negs      r%   ,test_mul_add_with_doubled_negation_of_itselfz7TestJacobi.test_mul_add_with_doubled_negation_of_itself  sN    %mb&899t*Q33X>>>>>r'   c                     t          t          dddd          dddd          }t          t          dddd          dddd          }|                     ||           d S N   r   r   r   )r   r    r!   r#   r   )r	   r   r   )r"   pj1pj2s      r%   test_equalityzTestJacobi.test_equality  sj    Aq! 4 4Q!1MMMAq! 4 4Q!1MMMc"""""r'   c                 d    t          j        t                    }|                     |d           d S )N   r6   r   s     r%   !test_equality_with_invalid_objectz,TestJacobi.test_equality_with_invalid_object!  s.    %m44C$$$$$r'   c                     t          j        t                    }t          j        t                    }|                     ||           d S r)   )r	   r*   r   r   r2   r-   s      r%   test_equality_with_wrong_curvesz*TestJacobi.test_equality_with_wrong_curves&  s>    %m44%m44C%%%%%r'   c                     t          t          dddd          dddd          }|                     t          j        t          j        |                    |           d S r   )r	   r   r   pickleloadsdumpsr7   s     r%   test_picklezTestJacobi.test_pickle,  sX    wr1a33qA!LLLfl2&6&677<<<<<r'   c                 \   t           dz   t           }t          |                                |                                |                                d|                                d          }|                     |j        g            d }g }t          |          D ],}|	                    t          j        ||f                     -|D ]}|                                  ||           |D ]}|                                 |                     |j        t           j                   d S )Nr   r   Tc                 v    |                                  }t          d          D ]}| t          |          z   d S )Nru   r   ranger   	generatorr   _s      r%   runnerz.TestJacobi.test_multithreading.<locals>.runner<  F    OO%%E2YY - -Ie,,,,,- -r'   targetargs)r   r	   r   r    r!   r   r   r~   r   append	threadingThreadstartjoin)r"   
thread_numgenr   threadsr   ts          r%   test_multithreadingzTestJacobi.test_multithreading0  s3    	! #))++suuwwCIIKKNN5r:::	- 	- 	-
 z"" 	I 	IANN9+6GGGHHHH 	 	AGGIIIIs 	 	AFFHHHH(4	
 	
 	
 	
 	
r'   Windowszthere are no signals on Windows)reasonc                    d}t           dz   t           }t          |                                |                                |                                d|                                d          }|                     |j        g            d }d }g }t          |          D ],}|	                    t          j        ||f                     -t          j                    }|                                 t          j                    }|                                 t          j                    }	|	                                 |	                    t          j        ||||	f                     |D ]}
|
                                 |                     t                     5  |                                 |                                  ||           |	                                 d d d            n# 1 swxY w Y   |D ]}
|
                                 |                     |j        t           j                   d S )Nru   r   r   Tc                 v    |                                  }t          d          D ]}| t          |          z   d S )N2   r   r   s      r%   r   z>TestJacobi.test_multithreading_with_interrupts.<locals>.runnera  r   r'   c                     |                                   |                                 t          j        t          j                    t
          j                   |                                  d S r)   )releaseacquireoskillgetpidsignalSIGINT)barrier_startbarrier_end	lock_exits      r%   interrupterzCTestJacobi.test_multithreading_with_interrupts.<locals>.interrupterf  sX    !!###!!!GBIKK///r'   r   )r   r	   r   r    r!   r   r   r~   r   r   r   r   Lockr  r   r+   KeyboardInterruptr  r   )r"   r   r   r   r  r   r   r  r	  r
  r   s              r%   #test_multithreading_with_interruptsz.TestJacobi.test_multithreading_with_interruptsR  s   
 
! #))++suuwwCIIKKNN5r:::	- 	- 	-
	  	  	  z"" 	I 	IANN9+6GGGHHHH!((n&&N$$	"#[)<  	
 	
 	
  	 	AGGIIII011 	  	 !!###!!!F3KKK 	  	  	  	  	  	  	  	  	  	  	  	  	  	  	   	 	AFFHHHH(4	
 	
 	
 	
 	
s   #AG77G;>G;N )G__name__
__module____qualname__r&   r0   r3   r8   r>   rA   rD   rH   rK   rO   rQ   rV   rY   r[   r]   r_   ra   re   ri   rl   rn   rp   rt   r   r   stintegersintr   r   r{   r   r   r   r   rG   r   r   r   listsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   NO_OLD_SETTINGSr   pytestmarkskipifplatformsystemr  r  r'   r%   r   r   #   s/	       $ $ $  : : :) ) )
, , ,) ) )$ $ $$ $ $$ $ $! ! !$ $ $) ) )) ) )       $ $ $$ $ $) ) )) ) )! ! !* * *
' ' '
$ $ $ X2
U33'F'@'F'H'H#I#I	
 	
 	
 
! !  ! X2
U33'F'@'F'H'H#I#I	
 	
 	
 
 WQZZWSS0*0223344  54 Z   X2
U33'F'@'F'H'H#I#I	
 	
 	
 	33'F'@'F'H'H#I#I	
 	
 	
	  WQ]]3 3 ]  3 X2
U33'F'@'F'H'H#I#I	
 	
 	
 	33'F'@'F'H'H#I#I	
 	
 	
 	a33/F/D/F/H/H1/L+M+MNNN 3 3  3, X2
U33'F'@'F'H'H#I#I	
 	
 	
 	33'F'@'F'H'H#I#I	
 	
 	
 	a33/F/D/F/H/H1/L+M+MNNN  WQ1WQ1WQ3-3559::A>>WQ3-3559::A>>3 3 ?> ?>    38# # #. X2
U33'F'@'F'H'H#I#I	
 	
 	
 	33'F'@'F'H'H#I#I	
 	
 	
 	BKss+B+@+B+D+Dq+H'I'I   	
 	
 	
   WQAq6WQAq6WQ3-3559::QFCCWQ3-3559::QFCC3 3 DC DC  !  *3<# # #03 3 3
@ @ @
; ; ;
: : :
D D D

 

 

  : : :D D D	5 	5 	5

 

 

N N N
L 
L 
L? ? ?# # #
% % %
& & &= = = X    
U;2;b11122
 
 32 ! 
@ [Y&0   ;
 ;
	 ;
 ;
 ;
r'   r   )%r   	unittest2unittestImportErrorr  sysr  r  r   r  hypothesis.strategies
strategiesr  
hypothesisr   r   r   r   ellipticcurver   r	   r
   ecdsar   r   r   r   r   r   numbertheoryr   utilr   r  version_infoTestCaser   r  r'   r%   <module>r*     s           OOOOO 
			 



        " " " " " " 7 7 7 7 7 7 7 7 7 7 7 7 9 9 9 9 9 9 9 9 9 9                & % % % % %       f"&OJn	
 n	
 n	
 n	
 n	
" n	
 n	
 n	
 n	
 n	
s    	