o
    in                     @   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   [/home/ubuntu/.local/lib/python3.10/site-packages/Crypto/SelfTest/PublicKey/test_ECC_NIST.pyOtherKeyType>   s    r   )r   generatepointQ
ValueErrorstrassertFalse
assertTrue)selfp1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   pointWr   r   r   test_set\      
zTestEccPoint_NIST_P192.test_setc                 C   F   | j  }| || j  || j | || j | | j | j d S Nr-   copyr$   r4   pointTassertNotEqualr5   r   r   r   	test_copya   
   
z TestEccPoint_NIST_P192.test_copyc                 C   (   | j  }| j | }| || j   d S r:   r-   r$   point_at_infinityr   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yrC   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 rJ   r-   r<   r=   r$   rL   rM   rC   rN   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$   rL   rM   rC   rN   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$   rL   rM   rC   assertRaisesr   r	   r   r    rO   rP   rQ   rR   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$   rL   rM   r   r    r   rO   rP   rQ   r   r   r   test_joint_scalar_multiply      z1TestEccPoint_NIST_P192.test_joint_scalar_multiplyc                 C   (   |  | j d |  | j d d S )N      r$   r-   size_in_bitssize_in_bytesr.   r   r   r   
test_sizes      z!TestEccPoint_NIST_P192.test_sizesN)r   r   r   __doc__r   r-   r=   r/   r7   r?   rG   rS   rW   r\   ri   rn   rv   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/      r0   z+TestEccPoint_NIST_P224.test_curve_attributec                 C   r1   r2   r3   r5   r   r   r   r7      r8   zTestEccPoint_NIST_P224.test_setc                 C   r9   r:   r;   r5   r   r   r   r?      r@   z TestEccPoint_NIST_P224.test_copyc                 C   rA   r:   rB   rD   r   r   r   rG      rH   z"TestEccPoint_NIST_P224.test_negatec                 C   rI   Nl   }Q+|y%w<{ Vu{adl   pZv8)_z-hK	G^6gyO9rK   rN   r   r   r   rS      rT   z$TestEccPoint_NIST_P224.test_additionc                 C   rU   r}   rV   rN   r   r   r   rW     rX   z,TestEccPoint_NIST_P224.test_inplace_additionc                 C   rY   )Nl   _xxRh>7ZPJIw}-r*l   }]o`}MH^>A0Z]Sv>L1|+rZ   rN   r   r   r   r\   ,  r]   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`   ra   rc   r   r.   r   r   rd   P  re   z=TestEccPoint_NIST_P224.test_scalar_multiply.<locals>.<lambda>rf   rh   r   r.   r   ri   A  rj   z+TestEccPoint_NIST_P224.test_scalar_multiplyc                 C   rk   )Nr~   l   6W]UDwyptq>3dd|?)5l   >HEK5\
5F2~?jTm{+E6l   1(^VKUC?++'*X:pCrl   rm   r   r   r   test_joing_scalar_multiply[  ro   z1TestEccPoint_NIST_P224.test_joing_scalar_multiplyc                 C   rp   )N      rs   r.   r   r   r   rv   e  rw   z!TestEccPoint_NIST_P224.test_sizesNr   r   r   rx   r   r-   r=   r/   r7   r?   rG   rS   rW   r\   ri   r   rv   r   r   r   r   rz      ry   rz   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  r0   z+TestEccPoint_NIST_P256.test_curve_attributec                 C   r1   r2   r3   r5   r   r   r   r7   x  r8   zTestEccPoint_NIST_P256.test_setc                 C   r9   r:   r;   r5   r   r   r   r?   }  r@   z TestEccPoint_NIST_P256.test_copyc                 C   rA   r:   rB   rD   r   r   r   rG     rH   z"TestEccPoint_NIST_P256.test_negatec                 C   rI   Nl   ~(iM)E=kdHpit3&EpmRrl   dBhE@	hFTVL.E$udK].X rK   rN   r   r   r   rS     rT   z$TestEccPoint_NIST_P256.test_additionc                 C   rU   r   rV   rN   r   r   r   rW     rX   z,TestEccPoint_NIST_P256.test_inplace_additionc                 C   rY   )Nl   '6?0T.<63GwG:]Hsivl   P6e#` {yO8^g^ w{9lJ@z rZ   rN   r   r   r   r\     r]   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`   ra   rc   r   r.   r   r   rd     re   z=TestEccPoint_NIST_P256.test_scalar_multiply.<locals>.<lambda>rf   rh   r   r.   r   ri     rj   z+TestEccPoint_NIST_P256.test_scalar_multiplyc                 C   rk   )Nr   l   T:XuMKt^5~{"/T3G1S l   vbaB>Y5OgEI# d3ZgX l   uR`/.5ES6p* Pr rl   rm   r   r   r   r     ro   z1TestEccPoint_NIST_P256.test_joing_scalar_multiplyc                 C   rp   )N       rs   r.   r   r   r   rv     rw   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/     r0   z+TestEccPoint_NIST_P384.test_curve_attributec                 C   s*   t ddd}|| j | || j d S )Nr   r   r3   r5   r   r   r   r7     s   zTestEccPoint_NIST_P384.test_setc                 C   r9   r:   r;   r5   r   r   r   r?     r@   z TestEccPoint_NIST_P384.test_copyc                 C   rA   r:   rB   rD   r   r   r   rG     rH   z"TestEccPoint_NIST_P384.test_negatec                 C   rI   )Nl   ^\mLH\%sz.	_QHp)wB'2h\|Sz9Y07s\\% l   $	rQ4 1ml w{g~OM wr6bLLU;8*$0xrs, rK   rN   r   r   r   rS     rT   z$TestEccPoint_NIST_P384.test_additionc                 C   rU   r   rV   rN   r   r   r   _test_inplace_addition.  rX   z-TestEccPoint_NIST_P384._test_inplace_additionc                 C   rY   )Nl   LPeroBr0_nCYw~s7xI|Z:Ze*X!T l   ]e^A|\"Rn0WWCs(h}	c5JBNnN=.rZ   rN   r   r   r   r\   H  r]   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`   ra   rc   r   r.   r   r   rd   l  re   z=TestEccPoint_NIST_P384.test_scalar_multiply.<locals>.<lambda>r-   r$   rL   rM   rC   rg   r   rh   r   r.   r   ri   ]     


z+TestEccPoint_NIST_P384.test_scalar_multiplyc                 C   rk   )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 rl   rm   r   r   r   r   n  ro   z1TestEccPoint_NIST_P384.test_joing_scalar_multiplyc                 C   rp   )Ni  0   rs   r.   r   r   r   rv   x  rw   z!TestEccPoint_NIST_P384.test_sizesN)r   r   r   rx   r   r-   r=   r/   r7   r?   rG   rS   r   r\   ri   r   rv   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/     r0   z+TestEccPoint_NIST_P521.test_curve_attributec                 C   r1   r2   r3   r5   r   r   r   r7     r8   zTestEccPoint_NIST_P521.test_setc                 C   r9   r:   r;   r5   r   r   r   r?     r@   z TestEccPoint_NIST_P521.test_copyc                 C   rA   r:   rB   rD   r   r   r   rG     rH   z"TestEccPoint_NIST_P521.test_negatec                 C   rI   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rK   rN   r   r   r   rS     rT   z$TestEccPoint_NIST_P521.test_additionc                 C   rU   r   rV   rN   r   r   r   rW     rX   z,TestEccPoint_NIST_P521.test_inplace_additionc                 C   rY   )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rZ   rN   r   r   r   r\     r]   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`   ra   rc   r   r.   r   r   rd     re   z=TestEccPoint_NIST_P521.test_scalar_multiply.<locals>.<lambda>r   rh   r   r.   r   ri     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? rl   rm   r   r   r   r     s   
z1TestEccPoint_NIST_P521.test_joing_scalar_multiplyc                 C   rp   )Ni	  B   rs   r.   r   r   r   rv     rw   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   rx   r   r   r   GxGypointGr   r   r   r   r         r   )	PublicKeyr   zpoint-at-infinity.org-P192.txtz&P-192 tests from point-at-infinity.orgc                 C      t | S r:   intkr   r   r   rd         rd   c                 C   
   t | dS N   r   rL   r   r   r   rd     re   c                 C   r   r   r   rM   r   r   r   rd     re   )r   rL   rM   c                 C   *   | j | }| |j| | |j| d S r:   r   r$   rL   rM   r   scalarrL   rM   resultr   r   r   new_test     
r   ztest_%dc                   @   r   )TestEccPoint_PAI_P224r   r{   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   r:   r   r   r   r   r   rd   #  r   c                 C   r   r   r   r   r   r   r   rd   $  re   c                 C   r   r   r   r   r   r   r   rd   %  re   c                 C   r   r:   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   r:   r   r   r   r   r   rd   8  r   c                 C   r   r   r   r   r   r   r   rd   9  re   c                 C   r   r   r   r   r   r   r   rd   :  re   c                 C   r   r:   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   r:   r   r   r   r   r   rd   M  r   c                 C   r   r   r   r   r   r   r   rd   N  re   c                 C   r   r   r   r   r   r   r   rd   O  re   c                 C   r   r:   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   r:   r   r   r   r   r   rd   b  r   c                 C   r   r   r   r   r   r   r   rd   c  re   c                 C   r   r   r   r   r   r   r   rd   d  re   c                 C   r   r:   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   rL   r   r   rM   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   priv_key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   rd         z4TestEccKey_P192.test_invalid_curve.<locals>.<lambda>rg   r   r.   r   r   r   test_invalid_curve  r0   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   rd     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   rd         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   private_keyprivate_key2private_key3r   public_key2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   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   r{   r   r   	secp224r1
prime224v1r   r   r   r   r   r     r   z TestEccKey_P224.test_private_keyc                 C   r   )Nr{   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   rd     r   z4TestEccKey_P224.test_invalid_curve.<locals>.<lambda>r   r.   r   r   r   r     r0   z"TestEccKey_P224.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr   r   r   r   r   r   r   r   rd     r   z0TestEccKey_P224.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   r{   r   r   r   r   r   r   rd     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   )Nr{   r   zcurve='NIST P-224'r|   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   rL   r   r   rM   r   r   rg   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   rd     r   z4TestEccKey_P256.test_invalid_curve.<locals>.<lambda>r   r.   r   r   r   r     r0   z"TestEccKey_P256.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr   r   r   r   r   r   r   r   rd     r   z0TestEccKey_P256.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   r   r   r   r   r   r   r   rd     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   rL   r   rM   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   rd   _  r   z4TestEccKey_P384.test_invalid_curve.<locals>.<lambda>r   r.   r   r   r   r   ^  r0   z"TestEccKey_P384.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr   r   r   r   r   r   r   r   rd   b  r   z0TestEccKey_P384.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   r   r   r   r   r   r   r   rd   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   rd     r   z4TestEccKey_P521.test_invalid_curve.<locals>.<lambda>r   r.   r   r   r   r     r0   z"TestEccKey_P521.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr  r   r   r   r   r   r   r   rd     r   z0TestEccKey_P521.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr  r   r   r   r   r   r   r   rd     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   rg   r   r   r#   r   coord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   r{   r   r   r  r   r   r   r   r    r  z TestEccModule_P224.test_generatec                 C   r  )Nr   r   r   r{   r  r   r   r  r   r   r   r   r    r  z!TestEccModule_P224.test_constructc                 C   r  )	Nr  r   r  r{   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  r0  r-  r   r   r   r  l  r1  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   r3  _  r2  r3  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 r:   )r   r
   r(   rz   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r(  r)  r*  r3  )configtestsr   r   r   	get_tests  s.   r6  __main__c                   C   s   t t S r:   )unittest	TestSuiter6  r   r   r   r   rd     r   suite)defaultTest)1r8  binasciir   Crypto.SelfTest.st_commonr   Crypto.SelfTest.loaderr   Crypto.PublicKeyr   Crypto.PublicKey.ECCr   r   r   Crypto.Math.Numbersr	   TestCaser
   r(   rz   r   r   r   r   tv_paitvr   rL   rM   r   setattrcountr   r   r   r   r   r   r   r  r  r  r(  r)  r*  r3  r6  r   r:  mainr   r   r   r   <module>   s   !     CCEGG''&%%
