o
     jn                     @   s  d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZ d dlmZ G dd	 d	e jZG d
d de jZG dd de jZG dd de jZG dd de jZG dd de jZG dd de jZeddddd dd dd dp}g ZeD ]ZejejejfddZeed ej e qG d!d" d"e jZedd#d$d%d d&d d'd dpg ZeD ]Zejejejfd(dZeed ej e qG d)d* d*e jZ edd+d,d-d d.d d/d dpg ZeD ]Zejejejfd0dZee d ej e qG d1d2 d2e jZ!edd3d4d5d d6d d7d dpg ZeD ]Zejejejfd8dZee!d ej e q G d9d: d:e jZ"edd;d<d=d d>d d?d dpTg ZeD ]Zejejejfd@dZee"d ej e qWG dAdB dBe jZ#G dCdD dDe jZ$G dEdF dFe jZ%G dGdH dHe jZ&G dIdJ dJe jZ'G dKdL dLe jZ(G dMdN dNe jZ)G dOdP dPe jZ*G dQdR dRe jZ+G dSdT dTe jZ,i fdUdVZ-e.dWkrdXd Z/e j0dYdZ dS dS )[    N)	unhexlify)list_test_cases)load_test_vectors)ECC)EccPoint_curvesEccKey)Integerc                   @   s   e Zd Zdd Zdd ZdS )TestEccPointc              
   C   s   t jddj}t jddj}z||  J  ty. } zdt|v s$J W Y d }~nd }~ww z||7 }J  tyO } zdt|v sEJ W Y d }~nd }~ww G dd d}| || k | || k d S )NP-256curveP-384Fznot on the same curvec                   @   s   e Zd ZdS )z+TestEccPoint.test_mix.<locals>.OtherKeyTypeN)__name__
__module____qualname__ r   r   h/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/Crypto/SelfTest/PublicKey/test_ECC_NIST.pyOtherKeyType>   s    r   )r   generatepointQ
ValueErrorstrassertFalse
assertTrue)selfp1Zp2er   r   r   r   test_mix-   s&   zTestEccPoint.test_mixc                 C   s&   t jddddd}| t|d d S )Nr   l   }	&_n i9]}!5$7P%^-& l   -
k%j&*/n;[jH**7 
i/v{-l   ]W][@iMmlQ;i?XU,p )r   dpoint_xpoint_ya  EccKey(curve='NIST P-256', point_x=20573031766139722500939782666697015100983491952082159880539639074939225934381, point_y=108863130203210779921520632367477406025152638284581252625277850513266505911389, d=75467964919405407085864614198393977741148485328036093939970922195112333446269))r   	constructassertEqualrepr)r   r   r   r   r   	test_reprD   s   zTestEccPoint.test_reprN)r   r   r   r   r%   r   r   r   r   r
   +   s    r
   c                   @   |   e Zd ZdZeddddZedd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 )TestEccPoint_NIST_P192ztTests defined in section 4.1 of https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.204.9073&rep=rep1&type=pdfl   ,/}H 5iH\D>GEl   ;_!3o3nk3>
6@I%p192r   l   S.7lpPa7ng>=}Tb"l   y5R]2vNA>RmKwYfe% !dc                 C      |  | jjd d S )N
NIST P-192r#   pointSr   r   r   r   r   test_curve_attributeY      z+TestEccPoint_NIST_P192.test_curve_attributec                 C   (   t dd}|| j | || j d S Nr   r   setr,   r#   r   ZpointWr   r   r   test_set\      
zTestEccPoint_NIST_P192.test_setc                 C   F   | j  }| || j  || j | || j | | j | j d S Nr,   copyr#   r3   pointTassertNotEqualr4   r   r   r   	test_copya   
   
z TestEccPoint_NIST_P192.test_copyc                 C   (   | j  }| j | }| || j   d S r8   r,   r#   point_at_infinityr   ZnegSsumr   r   r   test_negateh      
z"TestEccPoint_NIST_P192.test_negatec                 C      d}d}| j | j }| |j| | |j| | }| j | }| || j  || j  }| || j  || }| || d S Nl   <Sb!tX?w|xh\7% l   K*m/_JSl(U[yq;}r,   r;   r#   xyrA   r   pointRxpointRypointRpair   r   r   test_additionm      

z$TestEccPoint_NIST_P192.test_additionc                 C      d}d}| j  }|| j7 }| |j| | |j| | }| j  }||7 }| || j  | }|| j 7 }| || j  | }||7 }| || d S rG   r,   r:   r;   r#   rI   rJ   rA   rK   r   r   r   test_inplace_addition       



z,TestEccPoint_NIST_P192.test_inplace_additionc                 C      d}d}| j  }|  | |j| | |j| | j  }| }|  | || | j  }||7 }| |j| | |j| d S )Nl   bi~hIR wYTSD{1.-l   	%Y^-<6!N	qp r,   r:   doubler#   rI   rJ   rA   rK   r   r   r   test_doubling      


z$TestEccPoint_NIST_P192.test_doublingc                       d}d}d} j | } |j|  |j|  j  } j d } ||  t fdd | j  } |j|  |j| t| j  } |j|  |j| d S )N   tlkdcH(Lj]u5Qx
l   1m~KT4IwxIG-i!wl   {5syq-BKBior   c                      
    j d S Nr,   r   r-   r   r   <lambda>      
 z=TestEccPoint_NIST_P192.test_scalar_multiply.<locals>.<lambda>r,   r#   rI   rJ   rA   assertRaisesr   r	   r   r   rL   rM   rN   rO   r   r-   r   test_scalar_multiply       



z+TestEccPoint_NIST_P192.test_scalar_multiplyc                 C   D   d}d}d}d}| j | | j|  }| |j| | |j| d S )Nr\   l   rr6O^ho3&gaOqKl   [oge?/ or6uc;'{ l   D6vMc'~vLz6bHer,   r;   r#   rI   rJ   r   r   r   rL   rM   rN   r   r   r   test_joint_scalar_multiply      z1TestEccPoint_NIST_P192.test_joint_scalar_multiplyc                 C   (   |  | j d |  | j d d S )N      r#   r,   Zsize_in_bitsZsize_in_bytesr-   r   r   r   
test_sizes      z!TestEccPoint_NIST_P192.test_sizesN)r   r   r   __doc__r   r,   r;   r.   r5   r=   rD   rP   rT   rY   rf   rk   rq   r   r   r   r   r'   L   ,    
r'   c                   @   r&   )TestEccPoint_NIST_P224ztTests defined in section 4.2 of https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.204.9073&rep=rep1&type=pdfl   [;!4E7<_1*vK6N9!TY:)Pl   "?Iq.pGA26', X-p/i;p224r   l   m=Mp@2i#M#Y B/#nX\jd-l   4i"nQ)N}:{	hk-xBISIQ
1c                 C   r)   )N
NIST P-224r+   r-   r   r   r   r.      r/   z+TestEccPoint_NIST_P224.test_curve_attributec                 C   r0   r1   r2   r4   r   r   r   r5      r6   zTestEccPoint_NIST_P224.test_setc                 C   r7   r8   r9   r4   r   r   r   r=      r>   z TestEccPoint_NIST_P224.test_copyc                 C   r?   r8   r@   rB   r   r   r   rD      rE   z"TestEccPoint_NIST_P224.test_negatec                 C   rF   Nl   }Q+|y%w<{ Vu{adl   pZv8)_z-hK	G^6gyO9rH   rK   r   r   r   rP      rQ   z$TestEccPoint_NIST_P224.test_additionc                 C   rR   rx   rS   rK   r   r   r   rT     rU   z,TestEccPoint_NIST_P224.test_inplace_additionc                 C   rV   )Nl   _xxRh>7ZPJIw}-r*l   }]o`}MH^>A0Z]Sv>L1|+rW   rK   r   r   r   rY   ,  rZ   z$TestEccPoint_NIST_P224.test_doublingc                    r[   )N   ;WU'uoZw]o]em82~P)l   <N0VmoLBm_J+'"/F*iKl%l   mG[nWh8z{hbIU_OxQB)Jr   c                      r]   r^   r`   r   r-   r   r   ra   P  rb   z=TestEccPoint_NIST_P224.test_scalar_multiply.<locals>.<lambda>rc   re   r   r-   r   rf   A  rg   z+TestEccPoint_NIST_P224.test_scalar_multiplyc                 C   rh   )Nry   l   6W]UDwyptq>3dd|?)5l   >HEK5\
5F2~?jTm{+E6l   1(^VKUC?++'*X:pCri   rj   r   r   r   test_joing_scalar_multiply[  rl   z1TestEccPoint_NIST_P224.test_joing_scalar_multiplyc                 C   rm   )N      rp   r-   r   r   r   rq   e  rr   z!TestEccPoint_NIST_P224.test_sizesNr   r   r   rs   r   r,   r;   r.   r5   r=   rD   rP   rT   rY   rf   rz   rq   r   r   r   r   ru      rt   ru   c                   @   st   e Zd ZdZed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S )TestEccPoint_NIST_P256ztTests defined in section 4.3 of https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.204.9073&rep=rep1&type=pdfl   ,;zQCl:a*N<xn.h&#/_"$^ l   V"`,1kWypYLG+-pJ|?W@ l   kkdg\[W9r*9.B,LI5/f:hcXUl   Cdc'2gs1E+.-'a!Tc                 C   r)   )N
NIST P-256r+   r-   r   r   r   r.   u  r/   z+TestEccPoint_NIST_P256.test_curve_attributec                 C   r0   r1   r2   r4   r   r   r   r5   x  r6   zTestEccPoint_NIST_P256.test_setc                 C   r7   r8   r9   r4   r   r   r   r=   }  r>   z TestEccPoint_NIST_P256.test_copyc                 C   r?   r8   r@   rB   r   r   r   rD     rE   z"TestEccPoint_NIST_P256.test_negatec                 C   rF   Nl   ~(iM)E=kdHpit3&EpmRrl   dBhE@	hFTVL.E$udK].X rH   rK   r   r   r   rP     rQ   z$TestEccPoint_NIST_P256.test_additionc                 C   rR   r   rS   rK   r   r   r   rT     rU   z,TestEccPoint_NIST_P256.test_inplace_additionc                 C   rV   )Nl   '6?0T.<63GwG:]Hsivl   P6e#` {yO8^g^ w{9lJ@z rW   rK   r   r   r   rY     rZ   z$TestEccPoint_NIST_P256.test_doublingc                    r[   )N   _,)N$chKf-5lk<Xk#E l   ? nDf>1x066OPKFQl   ATU*-sX)>~|N\}T9%Dbu4ur   c                      r]   r^   r`   r   r-   r   r   ra     rb   z=TestEccPoint_NIST_P256.test_scalar_multiply.<locals>.<lambda>rc   re   r   r-   r   rf     rg   z+TestEccPoint_NIST_P256.test_scalar_multiplyc                 C   rh   )Nr   l   T:XuMKt^5~{"/T3G1S l   vbaB>Y5OgEI# d3ZgX l   uR`/.5ES6p* Pr ri   rj   r   r   r   rz     rl   z1TestEccPoint_NIST_P256.test_joing_scalar_multiplyc                 C   rm   )N       rp   r-   r   r   r   rq     rr   z!TestEccPoint_NIST_P256.test_sizesNr}   r   r   r   r   r~   j  s(    
r~   c                   @   x   e Zd ZdZedddZed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 )TestEccPoint_NIST_P384ztTests defined in section 4.4 of https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.204.9073&rep=rep1&type=pdfl   K<L3YUH[Am]8$_-'DM./8;V~Ho\"l   E^PjWvM0M7bKL84\mn&J

"[!66p#y|@z~W~ p384l   Q'"f4OcE-XJ9ija>:}@sMLUl   P}&zIy$GY9Q%?pa(Fv|EO{ c                 C   r)   )N
NIST P-384r+   r-   r   r   r   r.     r/   z+TestEccPoint_NIST_P384.test_curve_attributec                 C   s*   t ddd}|| j | || j d S )Nr   r   r2   r4   r   r   r   r5     s   zTestEccPoint_NIST_P384.test_setc                 C   r7   r8   r9   r4   r   r   r   r=     r>   z TestEccPoint_NIST_P384.test_copyc                 C   r?   r8   r@   rB   r   r   r   rD     rE   z"TestEccPoint_NIST_P384.test_negatec                 C   rF   )Nl   ^\mLH\%sz.	_QHp)wB'2h\|Sz9Y07s\\% l   $	rQ4 1ml w{g~OM wr6bLLU;8*$0xrs, rH   rK   r   r   r   rP     rQ   z$TestEccPoint_NIST_P384.test_additionc                 C   rR   r   rS   rK   r   r   r   _test_inplace_addition.  rU   z-TestEccPoint_NIST_P384._test_inplace_additionc                 C   rV   )Nl   LPeroBr0_nCYw~s7xI|Z:Ze*X!T l   ]e^A|\"Rn0WWCs(h}	c5JBNnN=.rW   rK   r   r   r   rY   H  rZ   z$TestEccPoint_NIST_P384.test_doublingc                    j   d}d}d} j | } |j|  |j|  j  } j d } ||  t fdd d S )N   4.v0Z:z;ODK#Gv)Z5mXCDs:frkIl   R@dV]9"O/'5r}]~AYwHoY4-?~wl   f9;Y?5.BieXcXtqMDb7K6X}1 }Xr   c                      r]   r^   r`   r   r-   r   r   ra   l  rb   z=TestEccPoint_NIST_P384.test_scalar_multiply.<locals>.<lambda>r,   r#   rI   rJ   rA   rd   r   re   r   r-   r   rf   ]     


z+TestEccPoint_NIST_P384.test_scalar_multiplyc                 C   rh   )Nr   l   ]8|$W!&%TxFgqeYTKeM80,YO_l   tdvO*;q/$L]0	}pn<x&"FFe5hYE~"l   q!jB%~^Y7yK\+5{SWxFJR1DwJA6g)4 ri   rj   r   r   r   rz   n  rl   z1TestEccPoint_NIST_P384.test_joing_scalar_multiplyc                 C   rm   )Ni  0   rp   r-   r   r   r   rq   x  rr   z!TestEccPoint_NIST_P384.test_sizesN)r   r   r   rs   r   r,   r;   r.   r5   r=   rD   rP   r   rY   rf   rz   rq   r   r   r   r   r     s,    
r   c                   @   r   )TestEccPoint_NIST_P521ztTests defined in section 4.5 of https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.204.9073&rep=rep1&type=pdfl#   A5;LK5N}W,*n<UP%hA=Cb?iOtiL1!@vlv'Wl#   #5kS7?I]*[nnkYi[7.	 d9MT3X=TP5_Icc	np521l#   GJo7 $=?>D^`bXkNo	tG`xw-dg!;I7>S{) wh\.,#l#   cae.tDffI*"a%A&4h#Ww5%D2>n<!}6@fNvF$>8vpc                 C   r)   )N
NIST P-521r+   r-   r   r   r   r.     r/   z+TestEccPoint_NIST_P521.test_curve_attributec                 C   r0   r1   r2   r4   r   r   r   r5     r6   zTestEccPoint_NIST_P521.test_setc                 C   r7   r8   r9   r4   r   r   r   r=     r>   z TestEccPoint_NIST_P521.test_copyc                 C   r?   r8   r@   rB   r   r   r   rD     rE   z"TestEccPoint_NIST_P521.test_negatec                 C   rF   Nl#   Y[V=xCmuOFl*sg	Np)giD>u{9gh0!cK-Op-^Nl#   U,R&9/@a}#>;cd{cl@E'98kh~a7?!-(O+SrH   rK   r   r   r   rP     rQ   z$TestEccPoint_NIST_P521.test_additionc                 C   rR   r   rS   rK   r   r   r   rT     rU   z,TestEccPoint_NIST_P521.test_inplace_additionc                 C   rV   )Nl#   k'<J cmtW9T@%T$SD!kdlPgciSW_%3byF`($/rl#   C5APS?( w8OoXx
e\**L3tX@7N&xrZ7}r.8QIarW   rK   r   r   r   rY     rZ   z$TestEccPoint_NIST_P521.test_doublingc                    r   )N#   \??7gf@YKjrR)P6_r	[<lSfPL3ZM
TUU3TM|K\xl#   QUx2?z=[nWq0 6&7mnktztX;Ia^Rm<9-Te	bFl#   [}5]v3nLIYjzQ`:Gk`O<Y[w `5Q**e7U5qr   c                      r]   r^   r`   r   r-   r   r   ra     rb   z=TestEccPoint_NIST_P521.test_scalar_multiply.<locals>.<lambda>r   re   r   r-   r   rf     r   z+TestEccPoint_NIST_P521.test_scalar_multiplyc                 C   sH   d}d}d}d}| j | }|| j| 7 }| |j| | |j| d S )Nr   l#   |TB)I%_
#wUV6C9c  1z7bnl<#qI"fu#0	Xajpx8=nMl#   =etEK9JBadZYx
./jVa@3hMhA]_`s}J+dptl#   XM`Wi&GgwH"!e+oeG$,oQ Tk9P>@5{U':c0'=NDH? ri   rj   r   r   r   rz     s   
z1TestEccPoint_NIST_P521.test_joing_scalar_multiplyc                 C   rm   )Ni	  B   rp   r-   r   r   r   rq     rr   z!TestEccPoint_NIST_P521.test_sizesNr}   r   r   r   r   r   }  s,    r   c                   @   (   e Zd ZdZed ZeejejdZ	dS )TestEccPoint_PAI_P1929Test vectors from http://point-at-infinity.org/ecc/nisttvr(   N
r   r   r   rs   r   r   r   GxGypointGr   r   r   r   r         r   )Z	PublicKeyr   zpoint-at-infinity.org-P192.txtz&P-192 tests from point-at-infinity.orgc                 C      t | S r8   intkr   r   r   ra         ra   c                 C   
   t | dS N   r   rI   r   r   r   ra     rb   c                 C   r   r   r   rJ   r   r   r   ra     rb   )r   rI   rJ   c                 C   *   | j | }| |j| | |j| d S r8   r   r#   rI   rJ   r   ZscalarrI   rJ   resultr   r   r   new_test     
r   ztest_%dc                   @   r   )TestEccPoint_PAI_P224r   rv   Nr   r   r   r   r   r     r   r   zpoint-at-infinity.org-P224.txtz&P-224 tests from point-at-infinity.orgc                 C   r   r8   r   r   r   r   r   ra   #  r   c                 C   r   r   r   r   r   r   r   ra   $  rb   c                 C   r   r   r   r   r   r   r   ra   %  rb   c                 C   r   r8   r   r   r   r   r   r   '  r   c                   @   r   )TestEccPoint_PAI_P256r   p256Nr   r   r   r   r   r   .  r   r   zpoint-at-infinity.org-P256.txtz&P-256 tests from point-at-infinity.orgc                 C   r   r8   r   r   r   r   r   ra   8  r   c                 C   r   r   r   r   r   r   r   ra   9  rb   c                 C   r   r   r   r   r   r   r   ra   :  rb   c                 C   r   r8   r   r   r   r   r   r   <  r   c                   @   r   )TestEccPoint_PAI_P384r   r   Nr   r   r   r   r   r   C  r   r   zpoint-at-infinity.org-P384.txtz&P-384 tests from point-at-infinity.orgc                 C   r   r8   r   r   r   r   r   ra   M  r   c                 C   r   r   r   r   r   r   r   ra   N  rb   c                 C   r   r   r   r   r   r   r   ra   O  rb   c                 C   r   r8   r   r   r   r   r   r   Q  r   c                   @   r   )TestEccPoint_PAI_P521r   r   Nr   r   r   r   r   r   X  r   r   zpoint-at-infinity.org-P521.txtz&P-521 tests from point-at-infinity.orgc                 C   r   r8   r   r   r   r   r   ra   b  r   c                 C   r   r   r   r   r   r   r   ra   c  rb   c                 C   r   r   r   r   r   r   r   ra   d  rb   c                 C   r   r8   r   r   r   r   r   r   f  r   c                   @   D   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S )TestEccKey_P192c                 C      t ddd}| |jd | |  | |jjtd j | |jj	td j
 ttd jtd j
dd}t dd|d}| |jd | |  | |j| t ddd}t ddd}d S )	NP-192   r   r   r(   r   r   r   point	secp192r1
prime192v1r   r#   r   r   has_privater   rI   r   r   rJ   r   r   r   keyr   r   r   r   test_private_keyo     z TestEccKey_P192.test_private_keyc                 C   F   t td jtd jdd}td|d}| |  | |j| d S )Nr(   r   r   r   r   	r   r   r   r   r   r   r   r#   r   r   r   r   r   r   r   test_public_key     zTestEccKey_P192.test_public_keyc                 C   6   t ddd}| }| |  | |j|j d S )Nr      r   r   
public_keyr   r   r#   r   r   Zpriv_keyZpub_keyr   r   r   test_public_key_derived     z'TestEccKey_P192.test_public_key_derivedc                 C      |  tdd  d S )Nc                   S      t dddS )NzP-193r   r   r   r   r   r   r   ra         z4TestEccKey_P192.test_invalid_curve.<locals>.<lambda>rd   r   r-   r   r   r   test_invalid_curve  r/   z"TestEccKey_P192.test_invalid_curvec                 C   $   |  tdd  |  tdd  d S )Nc                   S   r   )Nr   r   r   r   r   r   r   r   ra     r   z0TestEccKey_P192.test_invalid_d.<locals>.<lambda>c                   S      t dtd jdS )Nr   r(   r   r   r   orderr   r   r   r   ra         r   r-   r   r   r   test_invalid_d     zTestEccKey_P192.test_invalid_dc                 C      t jddd}t jddd}t jddd}| }| }| }| || | || | || | || | || d S )Nr   r   r   r      r   r"   r   r#   r<   r   Zprivate_keyZprivate_key2Zprivate_key3r   Zpublic_key2Zpublic_key3r   r   r   test_equality     zTestEccKey_P192.test_equalityc                 C   @   t jdd}| dt| | |jd | | jd d S )Nr(   r   zcurve='NIST P-192'r*   r   r   ZassertInr$   r#   r   r   r   r   r   r   r   test_name_consistency     z%TestEccKey_P192.test_name_consistencyN
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   m      r   c                   @   r   )TestEccKey_P224c                 C   r   )	NP-224r   r   rv   r   r   	secp224r1
prime224v1r   r   r   r   r   r     r   z TestEccKey_P224.test_private_keyc                 C   r   )Nrv   r   r   r   r   r   r   r   r   r     r   zTestEccKey_P224.test_public_keyc                 C   r   )Nr   r   r   r   r   r   r   r   r     r   z'TestEccKey_P224.test_public_key_derivedc                 C   r   )Nc                   S   r   )NzP-225r   r   r   r   r   r   r   ra     r   z4TestEccKey_P224.test_invalid_curve.<locals>.<lambda>r   r-   r   r   r   r     r/   z"TestEccKey_P224.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr   r   r   r   r   r   r   r   ra     r   z0TestEccKey_P224.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   rv   r   r   r   r   r   r   ra     r   r   r-   r   r   r   r     r   zTestEccKey_P224.test_invalid_dc                 C   r   )Nr   r   r   r   r   r   r   r   r   r     r   zTestEccKey_P224.test_equalityc                 C   r   )Nrv   r   zcurve='NIST P-224'rw   r   r   r   r   r   r     r   z%TestEccKey_P224.test_name_consistencyNr   r   r   r   r   r     r   r   c                   @   r   )TestEccKey_P256c                 C   s   t ddd}| |jd | |  | |jjtd j | |jj	td j
 ttd jtd j
}t dd|d}| |jd | |  | |j| t ddd}t ddd}| jtt ddd	 d S )
Nr   r   r   r   r   	secp256r1
prime256v1s    HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH)r   seed)r   r#   r   r   r   r   rI   r   r   rJ   r   r   rd   r   r   r   r   r   r     s   z TestEccKey_P256.test_private_keyc                 C   sB   t td jtd j}td|d}| |  | |j| d S )Nr   r   r   r   r   r   r   r   r   
  s   zTestEccKey_P256.test_public_keyc                 C   r   )Nr   r   r   r   r   r   r   r   r     r   z'TestEccKey_P256.test_public_key_derivedc                 C   r   )Nc                   S   r   )NzP-257r   r   r   r   r   r   r   ra     r   z4TestEccKey_P256.test_invalid_curve.<locals>.<lambda>r   r-   r   r   r   r     r/   z"TestEccKey_P256.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr   r   r   r   r   r   r   r   ra     r   z0TestEccKey_P256.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   r   r   r   r   r   r   r   ra     s    r   r-   r   r   r   r     r   zTestEccKey_P256.test_invalid_dc                 C   r   )Nr   r   r   r   r   r   r   r   r   r     r   zTestEccKey_P256.test_equalityc                 C   r   )Nr   r   zcurve='NIST P-256'r   r   r   r   r   r   r   1  r   z%TestEccKey_P256.test_name_consistencyNr   r   r   r   r   r     s    r   c                   @   r   )TestEccKey_P384c                 C      t d }tddd}| |jd | |  | |jj|j | |jj	|j
 t|j|j
d}tdd|d}| |jd | |  | |j| tddd}tddd}tddd}d S )Nr   r   r   r   r   	secp384r1
prime384v1r   r   r#   r   r   r   r   rI   r   rJ   r   r   )r   r   r   r   r   r   r   r   :     z TestEccKey_P384.test_private_keyc                 C   D   t d }t|j|jd}td|d}| |  | |j| d S )Nr   r   r   	r   r   r   r   r   r   r   r#   r   )r   r   r   r   r   r   r   r   O  
   zTestEccKey_P384.test_public_keyc                 C   r   )Nr   r   r   r   r   r   r   r   r   W  r   z'TestEccKey_P384.test_public_key_derivedc                 C   r   )Nc                   S   r   )NzP-385r   r   r   r   r   r   r   ra   _  r   z4TestEccKey_P384.test_invalid_curve.<locals>.<lambda>r   r-   r   r   r   r   ^  r/   z"TestEccKey_P384.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr   r   r   r   r   r   r   r   ra   b  r   z0TestEccKey_P384.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   r   r   r   r   r   r   r   ra   c  r   r   r-   r   r   r   r   a  r   zTestEccKey_P384.test_invalid_dc                 C   r   )Nr   r   r   r   r   r   r   r   r   r   f  r   zTestEccKey_P384.test_equalityc                 C   r   )Nr   r   zcurve='NIST P-384'r   r   r   r   r   r   r   x  r   z%TestEccKey_P384.test_name_consistencyNr   r   r   r   r   r   8      r   c                   @   r   )TestEccKey_P521c                 C   r   )Nr   P-521r   r   r   	secp521r1
prime521v1r   )r   r   r   r   r   r   r   r     r   z TestEccKey_P521.test_private_keyc                 C   r   )Nr   r   r   r   )r   r   r   r   r   r   r   r     r   zTestEccKey_P521.test_public_keyc                 C   r   )Nr   r   r   r   r   r   r   r   r     r   z'TestEccKey_P521.test_public_key_derivedc                 C   r   )Nc                   S   r   )NzP-522r   r   r   r   r   r   r   ra     r   z4TestEccKey_P521.test_invalid_curve.<locals>.<lambda>r   r-   r   r   r   r     r/   z"TestEccKey_P521.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr   r   r   r   r   r   r   r   ra     r   z0TestEccKey_P521.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   r   r   r   r   r   r   r   ra     r   r   r-   r   r   r   r     r   zTestEccKey_P521.test_invalid_dc                 C   r   )Nr   r   r   r   r   r   r   r   r   r     r   zTestEccKey_P521.test_equalityc                 C   r   )Nr   r   zcurve='NIST P-521'r   r   r   r   r   r   r     r   z%TestEccKey_P521.test_name_consistencyNr   r   r   r   r   r     r   r   c                   @   $   e Zd Zdd Zdd Zdd ZdS )TestEccModule_P192c                 C   `   t jdd}| |  | |jttd jtd j	d|j
 d t jdd t jdd d S )Nr   r   r(   r   r   r   r   r   r   r#   r   r   r   r   r   r   r   r   r   r   test_generate     z TestEccModule_P192.test_generatec                 C      t jddd}| |  | |jtd j t jdtd jtd j	d}| 
|  | |jtd j t jddd t jddd t jddd d S )Nr   r   r   r(   r   r    r!   r   r   r   r"   r   r   r#   r   r   Gr   r   r   r   r   r   r   test_construct     z!TestEccModule_P192.test_constructc                 C   ^   t ddd}t td jtd jd}| jttjfddi| | jttjfddd| d S )	N
   r   r    r!   r(   r   r      r   dictr   r   r   rd   r   r   r"   r   ZcoordZcoordGr   r   r   test_negative_construct      z*TestEccModule_P192.test_negative_constructNr   r   r   r  r
  r  r   r   r   r   r        r  c                   @   r   )TestEccModule_P224c                 C   r  )Nr   r   rv   r   r   r  r   r   r   r   r    r  z TestEccModule_P224.test_generatec                 C   r  )Nr   r   r   rv   r  r   r   r  r   r   r   r   r
    r  z!TestEccModule_P224.test_constructc                 C   r  )	Nr  r   r  rv   r   r   r  r   r  r  r   r   r   r    r  z*TestEccModule_P224.test_negative_constructNr  r   r   r   r   r    r  r  c                   @   r   )TestEccModule_P256c                 C   s^   t jdd}| |  | |jttd jtd j	|j
 d t jdd t jdd d S )Nr   r   r   r   r   r  r   r   r   r   r    s   z TestEccModule_P256.test_generatec                 C   r  )Nr   r   r   r   r  r   r   r  r   r   r   r   r
  "  r  z!TestEccModule_P256.test_constructc                 C   r  )	Nr  r   r  r   r   r   r  r   r  r  r   r   r   r  2  r  z*TestEccModule_P256.test_negative_constructNr  r   r   r   r   r    s    r  c                   @   r   )TestEccModule_P384c                 C   ^   t d }tjdd}| |  | |jt|j|j	d|j
  tjdd tjdd d S )Nr   r   r   r   r   r   r   r   r   r   r#   r   r   r   r   r   r   r   r   r   r   r   r  <      z TestEccModule_P384.test_generatec                 C      t d }tjddd}| |  | |jt d j tjd|j|j	d}| 
|  | |j|j tjddd tjddd tjddd d S )Nr   r   r   r   r  r   r   r   r   r"   r   r   r#   r   r	  r   r   r   r  r   r   r   r
  G     z!TestEccModule_P384.test_constructc                 C   r  )	Nr  r   r  r   r   r   r  r   r  r  r   r   r   r  W  r  z*TestEccModule_P384.test_negative_constructNr  r   r   r   r   r  :      r  c                   @   r   )TestEccModule_P521c                 C   r  )Nr   r   r   r   r   r  r  r   r   r   r  a  r  z TestEccModule_P521.test_generatec                 C   r  )Nr   r   r   r   r  r   r   r  r  r   r   r   r
  l  r   z!TestEccModule_P521.test_constructc                 C   r  )	Nr  r   r  r   r   r   r  r   r  r  r   r   r   r  |  r  z*TestEccModule_P521.test_negative_constructNr  r   r   r   r   r"  _  r!  r"  c                 C   s  g }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t	7 }|t t
7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|t t7 }|S r8   )r   r
   r'   ru   r~   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r"  )configZtestsr   r   r   	get_tests  s.   r$  __main__c                   C   s   t t S r8   )unittestZ	TestSuiter$  r   r   r   r   ra     r   suite)ZdefaultTest)1r&  binasciir   ZCrypto.SelfTest.st_commonr   ZCrypto.SelfTest.loaderr   ZCrypto.PublicKeyr   ZCrypto.PublicKey.ECCr   r   r   ZCrypto.Math.Numbersr	   ZTestCaser
   r'   ru   r~   r   r   r   Ztv_paitvr   rI   rJ   r   setattrcountr   r   r   r   r   r   r   r   r   r  r  r  r  r"  r$  r   r'  mainr   r   r   r   <module>   s   !     CCEGG''&%%
