
    dfG                     *   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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jD                  dkD  rd	e!d
<    G d dejF                        Z$y# e$ r d dlZY w xY w)    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                   R	   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%jL                         dz
                    d!               Z' ed       e ej:                  d e ej@                                      ej:                  d e ej@                                      ej:                  d e e%jL                         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jT                   ej:                  d e e%jL                         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@eAj                  j                   eDj                         d=k(  d>?      d@        ZFyA)C
TestJacobic                 F   t               }d}d}d}d}t        |||||      }| j                  |j                         |       | j	                  |j                         |       | j                  |j                         |       | j                  |j                         |       y )Nr      r      )objectr	   assertEqualorderassertIscurvexy)selfr   r    r!   zr   pjs          J/home/api-vastappli/venv/lib/python3.12/site-packages/ecdsa/test_jacobi.pytest___init__zTestJacobi.test___init__$   s    1a/U+bhhj%(##    c                     t        j                  t              }t        j                  t              }| j	                  t
              5  ||z    d d d        y # 1 sw Y   y xY wN)r	   from_affiner   r   assertRaises
ValueErrorr"   p_ap_bs      r%   test_add_with_different_curvesz)TestJacobi.test_add_with_different_curves1   sL    %%m4%%m4z* 	#I	 	 	s   AA c                 8    | j                  t        t               y r)   )assertNotEqualr   r   )r"   s    r%   test_compare_different_curvesz(TestJacobi.test_compare_different_curves8   s    M=9r'   c                 Z    t        j                  t              }| j                  |d       y )Nvaluer	   r*   r   r2   r"   r$   s     r%   test_equality_with_non_pointz'TestJacobi.test_equality_with_non_point;   s"    $$]3B(r'   c                     t        j                  t              }|j                         }| j	                  t        |       y r)   r	   r*   r   	to_affiner   r"   r$   pws      r%   test_conversionzTestJacobi.test_conversion@   s-    $$]3\\^+r'   c                 6   t        j                  t              }t        j                         }|j                         }| j	                  |j                         |j                                | j	                  |j                         |j                                y r)   )r	   r*   r   doubler   r    r!   r<   s      r%   test_single_doublezTestJacobi.test_single_doubleF   sc    $$]3!!#YY[((r'   c                 t    t        t        ddd      }|j                         }| j                  |t               y 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      }|j                         }| j	                  |t
               y rC   r	   r   pr@   r   r
   r7   s     r%   &test_double_with_zero_equivalent_pointz1TestJacobi.test_double_with_zero_equivalent_pointV   1    Ay{{}a8YY[b(#r'   c                     t        t        dt        j                         d      }|j                         }| j	                  |t
               y )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              }|j                         }| j	                  ||       | j	                  ||       y r)   r:   r"   r$   pas      r%   test_compare_with_affine_pointz)TestJacobi.test_compare_with_affine_pointd   s=    $$]3\\^R R r'   c                 t    t        t        ddd      }|j                         }| j                  |t               y 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              }|j                         }||z   }| j	                  ||j                                y r)   r	   r*   r   r;   r   r@   r"   r$   rN   ss       r%   test_add_with_affine_pointz%TestJacobi.test_add_with_affine_pointr   <    $$]3\\^GBIIK(r'   c                     t        j                  t              }|j                         }||z   }| j	                  ||j                                y r)   rS   rT   s       r%   test_radd_with_affine_pointz&TestJacobi.test_radd_with_affine_pointz   rW   r'   c                 l    t        j                  t              }|t        z   }| j	                  ||       y r)   )r	   r*   r   r
   r   )r"   r$   rU   s      r%   test_add_with_infinityz!TestJacobi.test_add_with_infinity   s+    $$]3MBr'   c                     t        j                  t              j                         }t        t        ddd      }||z   }| j                  ||       y 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   sB    $$]3==?Aq!,Gar'   c                 l    t        j                  t              }|dz  }| j                  |t               y )Nr   )r	   r*   r   r   r
   r7   s     r%   test_multiply_by_zeroz TestJacobi.test_multiply_by_zero   s)    $$]3!Vb(#r'   c                 ^    t        t        ddd      }|dz  }| j                  |t               y rC   )r	   r   r   r
   r7   s     r%   test_zero_point_multiply_by_onez*TestJacobi.test_zero_point_multiply_by_one   s)    Aq!,!Vb(#r'   c                 
   t        j                  t              }t        dz  }|dz  }| j                  |j	                         |j	                                | j                  |j                         |j                                y Nr   r	   r*   r   r   r    r!   r<   s      r%   test_multiply_by_onezTestJacobi.test_multiply_by_one   ]    $$]3Q!V((r'   c                 
   t        j                  t              }t        dz  }|dz  }| j                  |j	                         |j	                                | j                  |j                         |j                                y Nr   rd   r<   s      r%   test_multiply_by_twozTestJacobi.test_multiply_by_two   rf   r'   c                 v    t        j                  t              }t        dz  }d|z  }| j                  ||       y rh   r	   r*   r   r   r<   s      r%   test_rmul_by_twozTestJacobi.test_rmul_by_two   s5    $$]3QVR r'   c                 b    t        j                  t              }| j                  |t               y r)   )r	   r*   r   r2   r
   r7   s     r%   #test_compare_non_zero_with_infinityz.TestJacobi.test_compare_non_zero_with_infinity   s"    $$]3B)r'   c                 T    t        t        ddd      }| j                  |t               y rC   )r	   r   r   r
   r7   s     r%   %test_compare_zero_point_with_infinityz0TestJacobi.test_compare_zero_point_with_infinity   s"    Aq!,X&r'   c                     t        j                  t              }|j                         }|dz  }| j	                  ||       y rh   )r	   r*   r   r@   r   )r"   r$   dblmlpls       r%   !test_compare_double_with_multiplyz,TestJacobi.test_compare_double_with_multiply   s6    $$]3iikAvd#r'   
   )max_examplesr   )	min_value	max_valuec                 &   t        j                  t              }|j                         |z  }||z  }| j	                  |j                         |j                         f|j                         |j                         f       | j	                  ||       y r)   )r	   r*   r   r;   r   r    r!   )r"   mulr$   r=   s       r%   test_multiplicationszTestJacobi.test_multiplications   sp     $$%>?\\^c!#X"$$&"$$&)BDDFBDDF+;<R r'   c                     t         }| j                  |j                         t        j                  t               }||z  }||z  }| j                  ||       y r)   )r   
assertTrue_PointJacobi__precomputer	   r*   r   )r"   rz   precompr$   abs         r%   test_precomputezTestJacobi.test_precompute   sN     ,889$$%>?cMHAr'   r   r   c                     t        j                  t              }t        j                  ||z        }t        j                  ||z        }||z   }| j                  ||||z   z         y r)   )r	   r*   r   r   )r"   a_mulb_mulj_gr   r   cs          r%   test_add_scaled_pointsz!TestJacobi.test_add_scaled_points   s_     %%&?@##C%K0##C%K0EC55=12r'   c                    t        j                  t              }t        j                  ||z        }t        j                  ||z        }t        j                         }t        t        ||             ||z  |z  }t        t        |j                         |z  |z  |j                         |z  |z  |z  |      }||z   }	| j                  |	|||z   z         y 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##C%K0!##%{5!$%"!CCEFNQCCEFNU"Q&	
 EC55=12r'   r   c                 &   t        j                  t              }t        j                  ||z        }t        j                  ||z        }t        j                         }t        t        ||             ||z  |z  }t        t        |j                         |z  |z  |j                         |z  |z  |z  |      }t        t        |j                         |z  |z  |j                         |z  |z  |z  |      }||z   }	| j                  |	|||z   z         y r)   r   r   s
             r%   test_add_same_scale_pointsz%TestJacobi.test_add_same_scale_points  s     %%&?@##C%K0##C%K0!##%{5!$%"!CCEFNQCCEFNU"Q&	
 !CCEFNQCCEFNU"Q&	
 EC55=12r'   c                    t         }t        j                         }|dz  }|j                          d}t	        t        |j                         |dz  z  |z  |j                         |dz  z  |z  |      }t	        t        |j                         |dz  z  |z  |j                         |dz  z  |z  |      }||z   }| j                  |||z          y )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		!CCEBEMACCEBEMA	
 !CCEBEMACCEBEMA	
 EAE"r'      T)min_sizemax_sizeuniquec                    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        |j                         |z  |z  |j                         |z  |d   z  |z  |d         }t        t        |j                         |	z  |z  |j                         |	z  |d   z  |z  |d         }||z   }
| j                  |
|||z   z         y 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_  sG   , %%&?@##C%K0##C%K0!##%{58Q'({58Q'((U1X%)(U1X%)!CCEGOaCCEGOeAh&*!H	
 !CCEGOaCCEGOeAh&*!H	
 EC55=12r'   c                    t         }t        j                         }|dz  }|j                          d}t	        t        |j                         |dz  z  |z  |j                         |dz  z  |z  |      }d}t	        t        |j                         |dz  z  |z  |j                         |dz  z  |z  |      }||z   }| j                  |||z          y )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		!CCEBEMACCEBEMA	
 !CCEBEMACCEBEMA	
 EAE"r'   c                 l    t        j                  t              }| j                  |dz  ||z   |z          y )Nr   rk   r"   r   s     r%   test_add_point_3_timesz!TestJacobi.test_add_point_3_times  s.    %%m4q#)c/2r'   c                     t        t        t        j                         t        j                         d      }| j                  |t        j                         z  t               y rc   )r	   r   r   r    r!   r   r   r
   r   s     r%   test_mul_without_orderz!TestJacobi.test_mul_without_order  s>    )]__%68I1M}2244h?r'   c                     t        j                  t              }| j                  ||j	                  dt
        d             y rc   r	   r*   r   r   mul_addr
   r   s     r%   test_mul_add_infzTestJacobi.test_mul_add_inf  s/    %%m4ckk!Xq9:r'   c                     t        j                  t              }| j                  |dz  |j	                  d|d             y )Nr   r   r	   r*   r   r   r   r   s     r%   test_mul_add_samezTestJacobi.test_mul_add_same  s3    %%m4q#++aa"89r'   c                 "   t        j                  t        d      }t        j                  |dz  d      }| j                  |dz  ||z          | j                  |dz  |dz  |dz  z          | j                  |dz  |j	                  d|d             y )NT      i     r   r	   r*   r   r   r   r"   r   r   s      r%   test_mul_add_precomputez"TestJacobi.test_mul_add_precompute  s    %%&?F##C#It4sC!G,,cAgAo>,ckk!Q.BCr'   c                 "   t        j                  t        d      }t        j                  |dz  d      }| j                  |dz  ||z          | j                  |dz  |dz  |dz  z          | j                  |dz  |j	                  d|d             y )NTr   r         r   r   s      r%   test_mul_add_precompute_largez(TestJacobi.test_mul_add_precompute_large  s    %%&?F##C#It4sC!G,()3<!f*+D	
 	()3;;vq&+I	
r'   c                     t        j                  t              }|dz  }|j                  d|d      }| j	                  ||       y )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  s=    %%m4!GKK3"Ar'   c                     t        j                  t              }|dz  }| j                  |j	                  d|d      |dz         y )Nr   r   r   r   )r"   r   w_as      r%   test_mul_add_differntz TestJacobi.test_mul_add_differnt  s<    %%m4AgQQ/q9r'   c                     t        j                  t              }|dz  }|dz  }| j                  |j	                  d|d      |dz  |dz  z          y )Nr   r   r   r   )r"   r   r   w_bs       r%   test_mul_add_slightly_differentz*TestJacobi.test_mul_add_slightly_different  sN    %%m4AgAgQQ/q371BCr'   c                     t        j                  t              }t        dz  }t        dz  }|dz  }|j                  d|d      }| j	                  |j                         ||z          y )Nr   i        )r	   r*   r   r   r   r;   )r"   r   r   r   j_brets         r%   test_mul_addzTestJacobi.test_mul_add  s[    %%m4c!{+Djkk#sD)#)4r'   c                    t        j                  t              }t        j                  |dz        }| j                  |dz  ||z          | j                  |dz  |dz  |dz  z          | j                  |dz  |j	                  d|d             y )Nr   r   r   r   r   r   r   s      r%   test_mul_add_largezTestJacobi.test_mul_add_large  s    %%m4##C#I.sC!G,()3<!f*+D	
 	()3;;vq&+I	
r'   c                     t        j                  t              }t        j                         }t        j                  t        dz        }| j	                  |j                  |dz  ||dz        t               y )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   sZ    %%m4##%##MC$78US[!Uc\BHMr'   c                    t        t        t        j                         t        j                         d      }t        j
                         }t        dz  }|j                          t        t        |j                         |j	                         d      }| j                  |j                  |dz  ||dz        t               y )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8I1M##%b 			3557CEEGQ7URZERK@(Kr'   c                     t        j                  t        dz        }d| z  }| j                  |j	                  d|d      t
               y )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  s?    %%mb&89t*Q3X>r'   c                     t        t        dddd      dddd      }t        t        dddd      dddd      }| j                  ||       y N   r   r   r   )r   r    r!   r#   r   )r	   r   r   )r"   pj1pj2s      r%   test_equalityzTestJacobi.test_equality  sL    Aq! 4Q!1MAq! 4Q!1Mc"r'   c                 Z    t        j                  t              }| j                  |d       y )N   r6   r   s     r%   !test_equality_with_invalid_objectz,TestJacobi.test_equality_with_invalid_object!  s"    %%m4C$r'   c                     t        j                  t              }t        j                  t              }| j	                  ||       y r)   )r	   r*   r   r   r2   r-   s      r%   test_equality_with_wrong_curvesz*TestJacobi.test_equality_with_wrong_curves&  s2    %%m4%%m4C%r'   c                     t        t        dddd      dddd      }| j                  t        j                  t        j
                  |            |       y r   )r	   r   r   pickleloadsdumpsr7   s     r%   test_picklezTestJacobi.test_pickle,  sA    wr1a3qA!Lfll2&67<r'   c                 "   t         dz   t         }t        |j                         |j                         |j	                         d|j                         d      }| j                  |j                  g        d }g }t        |      D ])  }|j                  t        j                  ||f             + |D ]  }|j                            ||       |D ]  }|j                           | j                  |j                  t         j                         y )Nr   r   Tc                 `    | j                         }t        d      D ]  }| t        |      z    y )Nru   r   ranger   	generatorr   _s      r%   runnerz.TestJacobi.test_multithreading.<locals>.runner<  .    OO%E2Y -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  s     	! #))+suuwCIIKN55r:	-
 z" 	IANN9++6GH	I  	AGGI	 	s 	AFFH	 	((44	
r'   Windowszthere are no signals on Windows)reasonc                 
   d}t         dz   t         }t        |j                         |j                         |j	                         d|j                         d      }| j                  |j                  g        d }d }g }t        |      D ])  }|j                  t        j                  ||f             + t        j                         }|j                          t        j                         }|j                          t        j                         }	|	j                          |j                  t        j                  ||||	f             |D ]  }
|
j                           | j                  t               5  |j                          |j#                           ||       |	j                          d d d        |D ]  }
|
j%                           | j                  |j                  t         j                         y # 1 sw Y   KxY w)Nru   r   r   Tc                 `    | j                         }t        d      D ]  }| t        |      z    y )N2   r   r   s      r%   r   z>TestJacobi.test_multithreading_with_interrupts.<locals>.runnera  r   r'   c                     | j                          |j                          t        j                  t        j                         t
        j                         |j                          y r)   )releaseacquireoskillgetpidsignalSIGINT)barrier_startbarrier_end	lock_exits      r%   interrupterzCTestJacobi.test_multithreading_with_interrupts.<locals>.interrupterf  s>    !!#!GGBIIK/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   
 
! #))+suuwCIIKN55r:	-
	  z" 	IANN9++6GH	I "(nn&NN$	"#[)<	
  	AGGI	 01 	 !!#!3K 	   	AFFH	 	((44	
	  	 s   69G99H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}   $:)
,)$$$!$)) $$))!*
'
$ 2
3'F'@'F'F'H#I	

! ! 2
3'F'@'F'F'H#I	

 QZS0*00234 5   2
3'F'@'F'F'H#I	
 	3'F'@'F'F'H#I	
	 Q]3  3 2
3'F'@'F'F'H#I	
 	3'F'@'F'F'H#I	
 	a3/F/D/F/F/H1/L+MN3 3, 2
3'F'@'F'F'H#I	
 	3'F'@'F'F'H#I	
 	a3/F/D/F/F/H1/L+MN Q1Q1Q3-3359:A>Q3-3359:A>3 ? ?   38#. 2
3'F'@'F'F'H#I	
 	3'F'@'F'F'H#I	
 	BKKs+B+@+B+B+Dq+H'I 	
  QAq6QAq6Q3-3359:QFCQ3-3359:QFC3 D D  ! *3<#03
@
;
:
D

:D	5

N
L?#
%
&=   
;2;;b12
 3 !
@ [[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      
 
     " 7 7 9 9  &  f"&OJn	
"" n	
=  s   B 	BB