o
    Mf                     @   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/humari/django-venv/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                   @   t   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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   (   t dd}|| j | || j d S Nr   r   setpointSr$   r   pointWr   r   r   test_setY      
zTestEccPoint_NIST_P192.test_setc                 C   F   | j  }| || j  || j | || j | | j | j d S Nr.   copyr$   r-   pointTassertNotEqualr/   r   r   r   	test_copy^   
   
z TestEccPoint_NIST_P192.test_copyc                 C   (   | j  }| j | }| || j   d S r4   r.   r$   point_at_infinityr   negSsumr   r   r   test_negatee      
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.   r7   r$   xyr=   r   pointRxpointRypointRpair   r   r   test_additionj      

z$TestEccPoint_NIST_P192.test_additionc                 C      d}d}| j  }|| j7 }| |j| | |j| | }| j  }||7 }| || j  | }|| j 7 }| || j  | }||7 }| || d S rD   r.   r6   r7   r$   rF   rG   r=   rH   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.   r6   doubler$   rF   rG   r=   rH   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$   rF   rG   r=   assertRaisesr   r	   r   r    rI   rJ   rK   rL   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 )NrY   l   rr6O^ho3&gaOqKl   [oge?/ or6uc;'{ l   D6vMc'~vLz6bHer.   r7   r$   rF   rG   r   r    r   rI   rJ   rK   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.   r7   r1   r9   rA   rM   rQ   rV   rd   ri   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*   r+   r,   r/   r   r   r   r1      r2   zTestEccPoint_NIST_P224.test_setc                 C   r3   r4   r5   r/   r   r   r   r9      r:   z TestEccPoint_NIST_P224.test_copyc                 C   r;   r4   r<   r>   r   r   r   rA      rB   z"TestEccPoint_NIST_P224.test_negatec                 C   rC   Nl   }Q+|y%w<{ Vu{adl   pZv8)_z-hK	G^6gyO9rE   rH   r   r   r   rM      rN   z$TestEccPoint_NIST_P224.test_additionc                 C   rO   rw   rP   rH   r   r   r   rQ     rR   z,TestEccPoint_NIST_P224.test_inplace_additionc                 C   rS   )Nl   _xxRh>7ZPJIw}-r*l   }]o`}MH^>A0Z]Sv>L1|+rT   rH   r   r   r   rV   &  rW   z$TestEccPoint_NIST_P224.test_doublingc                    rX   )N   ;WU'uoZw]o]em82~P)l   <N0VmoLBm_J+'"/F*iKl%l   mG[nWh8z{hbIU_OxQB)Jr   c                      rZ   r[   r]   r   r^   r   r   r_   J  r`   z=TestEccPoint_NIST_P224.test_scalar_multiply.<locals>.<lambda>ra   rc   r   r^   r   rd   ;  re   z+TestEccPoint_NIST_P224.test_scalar_multiplyc                 C   rf   )Nrx   l   6W]UDwyptq>3dd|?)5l   >HEK5\
5F2~?jTm{+E6l   1(^VKUC?++'*X:pCrg   rh   r   r   r   test_joing_scalar_multiplyU  rj   z1TestEccPoint_NIST_P224.test_joing_scalar_multiplyc                 C   rk   )N      rn   r^   r   r   r   rq   _  rr   z!TestEccPoint_NIST_P224.test_sizesNr   r   r   rs   r   r.   r7   r1   r9   rA   rM   rQ   rV   rd   ry   rq   r   r   r   r   ru      rt   ru   c                   @   sl   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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*   r+   r,   r/   r   r   r   r1   o  r2   zTestEccPoint_NIST_P256.test_setc                 C   r3   r4   r5   r/   r   r   r   r9   t  r:   z TestEccPoint_NIST_P256.test_copyc                 C   r;   r4   r<   r>   r   r   r   rA   {  rB   z"TestEccPoint_NIST_P256.test_negatec                 C   rC   Nl   ~(iM)E=kdHpit3&EpmRrl   dBhE@	hFTVL.E$udK].X rE   rH   r   r   r   rM     rN   z$TestEccPoint_NIST_P256.test_additionc                 C   rO   r~   rP   rH   r   r   r   rQ     rR   z,TestEccPoint_NIST_P256.test_inplace_additionc                 C   rS   )Nl   '6?0T.<63GwG:]Hsivl   P6e#` {yO8^g^ w{9lJ@z rT   rH   r   r   r   rV     rW   z$TestEccPoint_NIST_P256.test_doublingc                    rX   )N   _,)N$chKf-5lk<Xk#E l   ? nDf>1x066OPKFQl   ATU*-sX)>~|N\}T9%Dbu4ur   c                      rZ   r[   r]   r   r^   r   r   r_     r`   z=TestEccPoint_NIST_P256.test_scalar_multiply.<locals>.<lambda>ra   rc   r   r^   r   rd     re   z+TestEccPoint_NIST_P256.test_scalar_multiplyc                 C   rf   )Nr   l   T:XuMKt^5~{"/T3G1S l   vbaB>Y5OgEI# d3ZgX l   uR`/.5ES6p* Pr rg   rh   r   r   r   ry     rj   z1TestEccPoint_NIST_P256.test_joing_scalar_multiplyc                 C   rk   )N       rn   r^   r   r   r   rq     rr   z!TestEccPoint_NIST_P256.test_sizesNr|   r   r   r   r   r}   d  s&    
r}   c                   @   p   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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   s*   t ddd}|| j | || j d S )Nr   r   r,   r/   r   r   r   r1     s   zTestEccPoint_NIST_P384.test_setc                 C   r3   r4   r5   r/   r   r   r   r9      r:   z TestEccPoint_NIST_P384.test_copyc                 C   r;   r4   r<   r>   r   r   r   rA     rB   z"TestEccPoint_NIST_P384.test_negatec                 C   rC   )Nl   ^\mLH\%sz.	_QHp)wB'2h\|Sz9Y07s\\% l   $	rQ4 1ml w{g~OM wr6bLLU;8*$0xrs, rE   rH   r   r   r   rM     rN   z$TestEccPoint_NIST_P384.test_additionc                 C   rO   r~   rP   rH   r   r   r   _test_inplace_addition"  rR   z-TestEccPoint_NIST_P384._test_inplace_additionc                 C   rS   )Nl   LPeroBr0_nCYw~s7xI|Z:Ze*X!T l   ]e^A|\"Rn0WWCs(h}	c5JBNnN=.rT   rH   r   r   r   rV   <  rW   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                      rZ   r[   r]   r   r^   r   r   r_   `  r`   z=TestEccPoint_NIST_P384.test_scalar_multiply.<locals>.<lambda>r.   r$   rF   rG   r=   rb   r   rc   r   r^   r   rd   Q     


z+TestEccPoint_NIST_P384.test_scalar_multiplyc                 C   rf   )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 rg   rh   r   r   r   ry   b  rj   z1TestEccPoint_NIST_P384.test_joing_scalar_multiplyc                 C   rk   )Ni  0   rn   r^   r   r   r   rq   l  rr   z!TestEccPoint_NIST_P384.test_sizesN)r   r   r   rs   r   r.   r7   r1   r9   rA   rM   r   rV   rd   ry   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*   r+   r,   r/   r   r   r   r1   ~  r2   zTestEccPoint_NIST_P521.test_setc                 C   r3   r4   r5   r/   r   r   r   r9     r:   z TestEccPoint_NIST_P521.test_copyc                 C   r;   r4   r<   r>   r   r   r   rA     rB   z"TestEccPoint_NIST_P521.test_negatec                 C   rC   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rE   rH   r   r   r   rM     rN   z$TestEccPoint_NIST_P521.test_additionc                 C   rO   r   rP   rH   r   r   r   rQ     rR   z,TestEccPoint_NIST_P521.test_inplace_additionc                 C   rS   )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rT   rH   r   r   r   rV     rW   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                      rZ   r[   r]   r   r^   r   r   r_     r`   z=TestEccPoint_NIST_P521.test_scalar_multiply.<locals>.<lambda>r   rc   r   r^   r   rd     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? rg   rh   r   r   r   ry     s   
z1TestEccPoint_NIST_P521.test_joing_scalar_multiplyc                 C   rk   )Ni	  B   rn   r^   r   r   r   rq     rr   z!TestEccPoint_NIST_P521.test_sizesNr|   r   r   r   r   r   q  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   )	PublicKeyr   zpoint-at-infinity.org-P192.txtz&P-192 tests from point-at-infinity.orgc                 C      t | S r4   intkr   r   r   r_         r_   c                 C   
   t | dS N   r   rF   r   r   r   r_      r`   c                 C   r   r   r   rG   r   r   r   r_     r`   )r   rF   rG   c                 C   *   | j | }| |j| | |j| d S r4   r   r$   rF   rG   r   scalarrF   rG   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   r4   r   r   r   r   r   r_     r   c                 C   r   r   r   r   r   r   r   r_     r`   c                 C   r   r   r   r   r   r   r   r_     r`   c                 C   r   r4   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   r4   r   r   r   r   r   r_   )  r   c                 C   r   r   r   r   r   r   r   r_   *  r`   c                 C   r   r   r   r   r   r   r   r_   +  r`   c                 C   r   r4   r   r   r   r   r   r   -  r   c                   @   r   )TestEccPoint_PAI_P384r   r   Nr   r   r   r   r   r   4  r   r   zpoint-at-infinity.org-P384.txtz&P-384 tests from point-at-infinity.orgc                 C   r   r4   r   r   r   r   r   r_   >  r   c                 C   r   r   r   r   r   r   r   r_   ?  r`   c                 C   r   r   r   r   r   r   r   r_   @  r`   c                 C   r   r4   r   r   r   r   r   r   B  r   c                   @   r   )TestEccPoint_PAI_P521r   r   Nr   r   r   r   r   r   I  r   r   zpoint-at-infinity.org-P521.txtz&P-521 tests from point-at-infinity.orgc                 C   r   r4   r   r   r   r   r   r_   S  r   c                 C   r   r   r   r   r   r   r   r_   T  r`   c                 C   r   r   r   r   r   r   r   r_   U  r`   c                 C   r   r4   r   r   r   r   r   r   W  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   rF   r   r   rG   r   r   r   keyr   r   r   r   test_private_key`     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_keyr     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_derivedy     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   r_         z4TestEccKey_P192.test_invalid_curve.<locals>.<lambda>rb   r   r^   r   r   r   test_invalid_curve     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   r_     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   r_         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$   r8   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'z
NIST P-192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   ^      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   r_     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   r_     r   z0TestEccKey_P224.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   rv   r   r   r   r   r   r   r_     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'z
NIST P-224r   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   rF   r   r   rG   r   r   rb   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   r_   
  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   r_     r   z0TestEccKey_P256.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   r   r   r   r   r   r   r   r_     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'z
NIST P-256r   r   r   r   r   r   "  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   rF   r   rG   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   @  
   zTestEccKey_P384.test_public_keyc                 C   r   )Nr   r   r   r   r   r   r   r   r   H  r   z'TestEccKey_P384.test_public_key_derivedc                 C   r   )Nc                   S   r   )NzP-385r   r   r   r   r   r   r   r_   P  r   z4TestEccKey_P384.test_invalid_curve.<locals>.<lambda>r   r^   r   r   r   r   O  r   z"TestEccKey_P384.test_invalid_curvec                 C   r   )Nc                   S   r   )Nr   r   r   r   r   r   r   r   r_   S  r   z0TestEccKey_P384.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr   r   r   r   r   r   r   r   r_   T  r   r   r^   r   r   r   r   R  r   zTestEccKey_P384.test_invalid_dc                 C   r   )Nr   r   r   r   r   r   r   r   r   r   W  r   zTestEccKey_P384.test_equalityc                 C   r   )Nr   r   zcurve='NIST P-384'z
NIST P-384r   r   r   r   r   r   i  r   z%TestEccKey_P384.test_name_consistencyNr   r   r   r   r   r   )      r   c                   @   r   )TestEccKey_P521c                 C   r   )Nr   P-521r   r   r   	secp521r1
prime521v1r   )r   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   r_     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   r_     r   z0TestEccKey_P521.test_invalid_d.<locals>.<lambda>c                   S   r   )Nr  r   r   r   r   r   r   r   r_     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'z
NIST P-521r   r   r   r   r   r     r   z%TestEccKey_P521.test_name_consistencyNr   r   r   r   r   r  p  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   rb   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   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  #  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  8     z!TestEccModule_P384.test_constructc                 C   r  )	Nr  r   r  r   r   r   r  r   r  r  r   r   r   r  H  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  R  r&  z TestEccModule_P521.test_generatec                 C   r'  )Nr   r  r   r   r  r  r  r(  r%  r   r   r   r  ]  r)  z!TestEccModule_P521.test_constructc                 C   r  )	Nr  r   r  r   r   r  r  r   r  r  r   r   r   r  m  r  z*TestEccModule_P521.test_negative_constructNr  r   r   r   r   r+  P  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 r4   )r   r
   r(   ru   r}   r   r   r   r   r   r   r   r   r   r   r   r  r  r   r!  r"  r+  )configtestsr   r   r   	get_testsu  s.   r.  __main__c                   C   s   t t S r4   )unittest	TestSuiter.  r   r   r   r   r_     r   suite)defaultTest)1r0  binasciir   Crypto.SelfTest.st_commonr   Crypto.SelfTest.loaderr   Crypto.PublicKeyr   Crypto.PublicKey.ECCr   r   r   Crypto.Math.Numbersr	   TestCaser
   r(   ru   r}   r   r   r   tv_paitvr   rF   rG   r   setattrcountr   r   r   r   r   r   r   r   r  r  r   r!  r"  r+  r.  r   r2  mainr   r   r   r   <module>   s   !     CCEGG''&%%
