a
    !f                     @   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pg ZeD ].ZejejejfddZeed ej e q G d!d" d"e jZedd#d$d%d d&d d'd dphg ZeD ].Zejejejfd(dZeed ej e qnG 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pDg ZeD ].Zejejejfd8dZee!d ej e qJG d9d: 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 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 )[    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||  ds.J W n4 tyd } zdt|v sPJ W Y d }~n
d }~0 0 z||7 }dsxJ W n4 ty } zdt|v sJ W Y d }~n
d }~0 0 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   l/var/www/html/python-backend/venv/lib/python3.9/site-packages/Cryptodome/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                   @   st   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   s(   t dd}|| j | || j d S Nr   r   setpointSr$   r   ZpointWr   r   r   test_setY   s    
zTestEccPoint_NIST_P192.test_setc                 C   sF   | j  }| || j  || j | || j | | j | j d S Nr,   copyr$   r+   pointTassertNotEqualr-   r   r   r   	test_copy^   s
    
z TestEccPoint_NIST_P192.test_copyc                 C   s(   | j  }| j | }| || j   d S r/   r,   r$   point_at_infinityr   ZnegSsumr   r   r   test_negatee   s    
z"TestEccPoint_NIST_P192.test_negatec                 C   s   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,   r2   r$   xyr6   r   pointRxpointRypointRpair   r   r   test_additionj   s    

z$TestEccPoint_NIST_P192.test_additionc                 C   s   d}d}| j  }|| j7 }| |j| | |j| | }| j  }||7 }| || j  | }|| j 7 }| || j  | }||7 }| || d S r:   r,   r1   r2   r$   r<   r=   r6   r>   r   r   r   test_inplace_addition   s     



z,TestEccPoint_NIST_P192.test_inplace_additionc                 C   s   d}d}| j  }|  | |j| | |j| | j  }| }|  | || | j  }||7 }| |j| | |j| d S )Nl   bi~hIR wYTSD{1.-l   	%Y^-<6!N	qp r,   r1   doubler$   r<   r=   r6   r>   r   r   r   test_doubling   s    


z$TestEccPoint_NIST_P192.test_doublingc                    s   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                      s
    j d S Nr,   r   r   r   r   <lambda>       z=TestEccPoint_NIST_P192.test_scalar_multiply.<locals>.<lambda>r,   r$   r<   r=   r6   assertRaisesr   r	   r   r    r?   r@   rA   rB   r   rM   r   test_scalar_multiply   s     



z+TestEccPoint_NIST_P192.test_scalar_multiplyc                 C   sD   d}d}d}d}| j | | j|  }| |j| | |j| d S )NrI   l   rr6O^ho3&gaOqKl   [oge?/ or6uc;'{ l   D6vMc'~vLz6bHer,   r2   r$   r<   r=   r   r    r   r?   r@   rA   r   r   r   test_joint_scalar_multiply   s    z1TestEccPoint_NIST_P192.test_joint_scalar_multiplyc                 C   s(   |  | j d |  | j d d S )N      r$   r,   Zsize_in_bitsZsize_in_bytesrM   r   r   r   
test_sizes   s    z!TestEccPoint_NIST_P192.test_sizesN)r   r   r   __doc__r   r,   r2   r.   r4   r9   rC   rE   rH   rS   rV   rZ   r   r   r   r   r'   L   s(   
r'   c                   @   st   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_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   s(   t dd}|| j | || j d S r)   r*   r-   r   r   r   r.      s    
zTestEccPoint_NIST_P224.test_setc                 C   sF   | j  }| || j  || j | || j | | j | j d S r/   r0   r-   r   r   r   r4      s
    
z TestEccPoint_NIST_P224.test_copyc                 C   s(   | j  }| j | }| || j   d S r/   r5   r7   r   r   r   r9      s    
z"TestEccPoint_NIST_P224.test_negatec                 C   s   d}d}| j | j }| |j| | |j| | }| j | }| || j  || j  }| || j  || }| || d S Nl   }Q+|y%w<{ Vu{adl   pZv8)_z-hK	G^6gyO9r;   r>   r   r   r   rC      s    

z$TestEccPoint_NIST_P224.test_additionc                 C   s   d}d}| j  }|| j7 }| |j| | |j| | }| j  }||7 }| || j  | }|| j 7 }| || j  | }||7 }| || d S r^   rD   r>   r   r   r   rE     s     



z,TestEccPoint_NIST_P224.test_inplace_additionc                 C   s   d}d}| j  }|  | |j| | |j| | j  }| }|  | || | j  }||7 }| |j| | |j| d S )Nl   _xxRh>7ZPJIw}-r*l   }]o`}MH^>A0Z]Sv>L1|+rF   r>   r   r   r   rH   &  s    


z$TestEccPoint_NIST_P224.test_doublingc                    s   d}d}d} j | } |j|  |j|  j  } j d } ||  t fdd | j  } |j|  |j| t| j  } |j|  |j| d S )N   ;WU'uoZw]o]em82~P)l   <N0VmoLBm_J+'"/F*iKl%l   mG[nWh8z{hbIU_OxQB)Jr   c                      s
    j d S rJ   rL   r   rM   r   r   rN   J  rO   z=TestEccPoint_NIST_P224.test_scalar_multiply.<locals>.<lambda>rP   rR   r   rM   r   rS   ;  s     



z+TestEccPoint_NIST_P224.test_scalar_multiplyc                 C   sD   d}d}d}d}| j | | j|  }| |j| | |j| d S )Nr_   l   6W]UDwyptq>3dd|?)5l   >HEK5\
5F2~?jTm{+E6l   1(^VKUC?++'*X:pCrT   rU   r   r   r   test_joing_scalar_multiplyU  s    z1TestEccPoint_NIST_P224.test_joing_scalar_multiplyc                 C   s(   |  | j d |  | j d d S )N      rY   rM   r   r   r   rZ   _  s    z!TestEccPoint_NIST_P224.test_sizesNr   r   r   r[   r   r,   r2   r.   r4   r9   rC   rE   rH   rS   r`   rZ   r   r   r   r   r\      s(   
r\   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   s(   t dd}|| j | || j d S r)   r*   r-   r   r   r   r.   o  s    
zTestEccPoint_NIST_P256.test_setc                 C   sF   | j  }| || j  || j | || j | | j | j d S r/   r0   r-   r   r   r   r4   t  s
    
z TestEccPoint_NIST_P256.test_copyc                 C   s(   | j  }| j | }| || j   d S r/   r5   r7   r   r   r   r9   {  s    
z"TestEccPoint_NIST_P256.test_negatec                 C   s   d}d}| j | j }| |j| | |j| | }| j | }| || j  || j  }| || j  || }| || d S Nl   ~(iM)E=kdHpit3&EpmRrl   dBhE@	hFTVL.E$udK].X r;   r>   r   r   r   rC     s    

z$TestEccPoint_NIST_P256.test_additionc                 C   s   d}d}| j  }|| j7 }| |j| | |j| | }| j  }||7 }| || j  | }|| j 7 }| || j  | }||7 }| || d S re   rD   r>   r   r   r   rE     s     



z,TestEccPoint_NIST_P256.test_inplace_additionc                 C   s   d}d}| j  }|  | |j| | |j| | j  }| }|  | || | j  }||7 }| |j| | |j| d S )Nl   '6?0T.<63GwG:]Hsivl   P6e#` {yO8^g^ w{9lJ@z rF   r>   r   r   r   rH     s    


z$TestEccPoint_NIST_P256.test_doublingc                    s   d}d}d} j | } |j|  |j|  j  } j d } ||  t fdd | j  } |j|  |j| t| j  } |j|  |j| d S )N   _,)N$chKf-5lk<Xk#E l   ? nDf>1x066OPKFQl   ATU*-sX)>~|N\}T9%Dbu4ur   c                      s
    j d S rJ   rL   r   rM   r   r   rN     rO   z=TestEccPoint_NIST_P256.test_scalar_multiply.<locals>.<lambda>rP   rR   r   rM   r   rS     s     



z+TestEccPoint_NIST_P256.test_scalar_multiplyc                 C   sD   d}d}d}d}| j | | j|  }| |j| | |j| d S )Nrf   l   T:XuMKt^5~{"/T3G1S l   vbaB>Y5OgEI# d3ZgX l   uR`/.5ES6p* Pr rT   rU   r   r   r   r`     s    z1TestEccPoint_NIST_P256.test_joing_scalar_multiplyc                 C   s(   |  | j d |  | j d d S )N       rY   rM   r   r   r   rZ     s    z!TestEccPoint_NIST_P256.test_sizesNrc   r   r   r   r   rd   d  s$   
rd   c                   @   sp   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   rj   r*   r-   r   r   r   r.     s    zTestEccPoint_NIST_P384.test_setc                 C   sF   | j  }| || j  || j | || j | | j | j d S r/   r0   r-   r   r   r   r4      s
    
z TestEccPoint_NIST_P384.test_copyc                 C   s(   | j  }| j | }| || j   d S r/   r5   r7   r   r   r   r9     s    
z"TestEccPoint_NIST_P384.test_negatec                 C   s   d}d}| j | j }| |j| | |j| | }| j | }| || j  || j  }| || j  || }| || d S )Nl   ^\mLH\%sz.	_QHp)wB'2h\|Sz9Y07s\\% l   $	rQ4 1ml w{g~OM wr6bLLU;8*$0xrs, r;   r>   r   r   r   rC     s    

z$TestEccPoint_NIST_P384.test_additionc                 C   s   d}d}| j  }|| j7 }| |j| | |j| | }| j  }||7 }| || j  | }|| j 7 }| || j  | }||7 }| || d S re   rD   r>   r   r   r   _test_inplace_addition"  s     



z-TestEccPoint_NIST_P384._test_inplace_additionc                 C   s   d}d}| j  }|  | |j| | |j| | j  }| }|  | || | j  }||7 }| |j| | |j| d S )Nl   LPeroBr0_nCYw~s7xI|Z:Ze*X!T l   ]e^A|\"Rn0WWCs(h}	c5JBNnN=.rF   r>   r   r   r   rH   <  s    


z$TestEccPoint_NIST_P384.test_doublingc                    sj   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                      s
    j d S rJ   rL   r   rM   r   r   rN   `  rO   z=TestEccPoint_NIST_P384.test_scalar_multiply.<locals>.<lambda>r,   r$   r<   r=   r6   rQ   r   rR   r   rM   r   rS   Q  s    


z+TestEccPoint_NIST_P384.test_scalar_multiplyc                 C   sD   d}d}d}d}| j | | j|  }| |j| | |j| d S )Nrl   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 rT   rU   r   r   r   r`   b  s    z1TestEccPoint_NIST_P384.test_joing_scalar_multiplyc                 C   s(   |  | j d |  | j d d S )Ni  0   rY   rM   r   r   r   rZ   l  s    z!TestEccPoint_NIST_P384.test_sizesN)r   r   r   r[   r   r,   r2   r.   r4   r9   rC   rk   rH   rS   r`   rZ   r   r   r   r   ri     s(   
ri   c                   @   sp   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_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   s(   t dd}|| j | || j d S r)   r*   r-   r   r   r   r.   ~  s    
zTestEccPoint_NIST_P521.test_setc                 C   sF   | j  }| || j  || j | || j | | j | j d S r/   r0   r-   r   r   r   r4     s
    
z TestEccPoint_NIST_P521.test_copyc                 C   s(   | j  }| j | }| || j   d S r/   r5   r7   r   r   r   r9     s    
z"TestEccPoint_NIST_P521.test_negatec                 C   s   d}d}| j | j }| |j| | |j| | }| j | }| || j  || j  }| || j  || }| || d S 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r;   r>   r   r   r   rC     s    

z$TestEccPoint_NIST_P521.test_additionc                 C   s   d}d}| j  }|| j7 }| |j| | |j| | }| j  }||7 }| || j  | }|| j 7 }| || j  | }||7 }| || d S rq   rD   r>   r   r   r   rE     s     



z,TestEccPoint_NIST_P521.test_inplace_additionc                 C   s   d}d}| j  }|  | |j| | |j| | j  }| }|  | || | j  }||7 }| |j| | |j| d S )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rF   r>   r   r   r   rH     s    


z$TestEccPoint_NIST_P521.test_doublingc                    sj   d}d}d} j | } |j|  |j|  j  } j d } ||  t fdd d S )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                      s
    j d S rJ   rL   r   rM   r   r   rN     rO   z=TestEccPoint_NIST_P521.test_scalar_multiply.<locals>.<lambda>rm   rR   r   rM   r   rS     s    


z+TestEccPoint_NIST_P521.test_scalar_multiplyc                 C   sH   d}d}d}d}| j | }|| j| 7 }| |j| | |j| d S )Nrr   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? rT   rU   r   r   r   r`     s    
z1TestEccPoint_NIST_P521.test_joing_scalar_multiplyc                 C   s(   |  | j d |  | j d d S )Ni	  B   rY   rM   r   r   r   rZ     s    z!TestEccPoint_NIST_P521.test_sizesNrc   r   r   r   r   ro   q  s(   ro   c                   @   s(   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   r[   r   r   r   GxGypointGr   r   r   r   rt     s   rt   )Z	PublicKeyr   zpoint-at-infinity.org-P192.txtz&P-192 tests from point-at-infinity.orgc                 C   s   t | S r/   intkr   r   r   rN     rO   rN   c                 C   s
   t | dS N   rz   r<   r   r   r   rN      rO   c                 C   s
   t | dS r~   rz   r=   r   r   r   rN     rO   )r}   r<   r=   c                 C   s*   | j | }| |j| | |j| d S r/   ry   r$   r<   r=   r   Zscalarr<   r=   resultr   r   r   new_test  s    
r   ztest_%dc                   @   s(   e Zd ZdZed ZeejejdZ	dS )TestEccPoint_PAI_P224ru   r]   Nrv   r   r   r   r   r   
  s   r   zpoint-at-infinity.org-P224.txtz&P-224 tests from point-at-infinity.orgc                 C   s   t | S r/   rz   r|   r   r   r   rN     rO   c                 C   s
   t | dS r~   rz   r   r   r   r   rN     rO   c                 C   s
   t | dS r~   rz   r   r   r   r   rN     rO   c                 C   s*   | j | }| |j| | |j| d S r/   r   r   r   r   r   r     s    
c                   @   s(   e Zd ZdZed ZeejejdZ	dS )TestEccPoint_PAI_P256ru   p256Nrv   r   r   r   r   r     s   r   zpoint-at-infinity.org-P256.txtz&P-256 tests from point-at-infinity.orgc                 C   s   t | S r/   rz   r|   r   r   r   rN   )  rO   c                 C   s
   t | dS r~   rz   r   r   r   r   rN   *  rO   c                 C   s
   t | dS r~   rz   r   r   r   r   rN   +  rO   c                 C   s*   | j | }| |j| | |j| d S r/   r   r   r   r   r   r   -  s    
c                   @   s(   e Zd ZdZed ZeejejdZ	dS )TestEccPoint_PAI_P384ru   rj   Nrv   r   r   r   r   r   4  s   r   zpoint-at-infinity.org-P384.txtz&P-384 tests from point-at-infinity.orgc                 C   s   t | S r/   rz   r|   r   r   r   rN   >  rO   c                 C   s
   t | dS r~   rz   r   r   r   r   rN   ?  rO   c                 C   s
   t | dS r~   rz   r   r   r   r   rN   @  rO   c                 C   s*   | j | }| |j| | |j| d S r/   r   r   r   r   r   r   B  s    
c                   @   s(   e Zd ZdZed ZeejejdZ	dS )TestEccPoint_PAI_P521ru   rp   Nrv   r   r   r   r   r   I  s   r   zpoint-at-infinity.org-P521.txtz&P-521 tests from point-at-infinity.orgc                 C   s   t | S r/   rz   r|   r   r   r   rN   S  rO   c                 C   s
   t | dS r~   rz   r   r   r   r   rN   T  rO   c                 C   s
   t | dS r~   rz   r   r   r   r   rN   U  rO   c                 C   s*   | j | }| |j| | |j| d S r/   r   r   r   r   r   r   W  s    
c                   @   sD   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   s   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   r<   r   rw   r=   rx   r   r   keyr   r   r   r   test_private_key`  s    z TestEccKey_P192.test_private_keyc                 C   sF   t td jtd jdd}td|d}| |  | |j| d S )Nr(   r   r   r   r   	r   r   rw   rx   r   r   r   r$   r   r   r   r   r   r   r   test_public_keyr  s    zTestEccKey_P192.test_public_keyc                 C   s6   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_derivedy  s    z'TestEccKey_P192.test_public_key_derivedc                 C   s   |  tdd  d S )Nc                   S   s   t dddS )NzP-193r   r   r   r   r   r   r   rN     rO   z4TestEccKey_P192.test_invalid_curve.<locals>.<lambda>rQ   r   rM   r   r   r   test_invalid_curve  s    z"TestEccKey_P192.test_invalid_curvec                 C   s$   |  tdd  |  tdd  d S )Nc                   S   s   t dddS )Nr   r   r   r   r   r   r   r   rN     rO   z0TestEccKey_P192.test_invalid_d.<locals>.<lambda>c                   S   s   t dtd jdS )Nr   r(   r   r   r   orderr   r   r   r   rN     s   r   rM   r   r   r   test_invalid_d  s    zTestEccKey_P192.test_invalid_dc                 C   s   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$   r3   r   Zprivate_keyZprivate_key2Zprivate_key3r   Zpublic_key2Zpublic_key3r   r   r   test_equality  s    zTestEccKey_P192.test_equalityc                 C   s@   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   ZassertInr%   r$   r   r   r   r   r   r   r   test_name_consistency  s    z%TestEccKey_P192.test_name_consistencyN
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ^  s   r   c                   @   sD   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_P224c                 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
dd}t dd|d}| |jd | |  | |j| t ddd}t ddd}d S )	NP-224r   r   r]   r   r   	secp224r1
prime224v1r   r   r   r   r   r     s    z TestEccKey_P224.test_private_keyc                 C   sF   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     s    zTestEccKey_P224.test_public_keyc                 C   s6   t ddd}| }| |  | |j|j d S )Nr   r   r   r   r   r   r   r   r     s    z'TestEccKey_P224.test_public_key_derivedc                 C   s   |  tdd  d S )Nc                   S   s   t dddS )NzP-225r   r   r   r   r   r   r   rN     rO   z4TestEccKey_P224.test_invalid_curve.<locals>.<lambda>r   rM   r   r   r   r     s    z"TestEccKey_P224.test_invalid_curvec                 C   s$   |  tdd  |  tdd  d S )Nc                   S   s   t dddS )Nr   r   r   r   r   r   r   r   rN     rO   z0TestEccKey_P224.test_invalid_d.<locals>.<lambda>c                   S   s   t dtd jdS )Nr   r]   r   r   r   r   r   r   rN     s   r   rM   r   r   r   r     s    zTestEccKey_P224.test_invalid_dc                 C   s   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     s    zTestEccKey_P224.test_equalityc                 C   s@   t jdd}| dt| | |jd | | jd d S )Nr]   r   zcurve='NIST P-224'z
NIST P-224r   r   r   r   r   r     s    z%TestEccKey_P224.test_name_consistencyNr   r   r   r   r   r     s   r   c                   @   sD   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_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   r<   r   rw   r=   rx   r   rQ   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   s6   t ddd}| }| |  | |j|j d S )Nr   r   r   r   r   r   r   r   r     s    z'TestEccKey_P256.test_public_key_derivedc                 C   s   |  tdd  d S )Nc                   S   s   t dddS )NzP-257r   r   r   r   r   r   r   rN   
  rO   z4TestEccKey_P256.test_invalid_curve.<locals>.<lambda>r   rM   r   r   r   r   	  s    z"TestEccKey_P256.test_invalid_curvec                 C   s$   |  tdd  |  tdd  d S )Nc                   S   s   t dddS )Nr   r   r   r   r   r   r   r   rN     rO   z0TestEccKey_P256.test_invalid_d.<locals>.<lambda>c                   S   s   t dtd jdS )Nr   r   r   r   r   r   r   r   rN     rO   r   rM   r   r   r   r     s    zTestEccKey_P256.test_invalid_dc                 C   s   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     s    zTestEccKey_P256.test_equalityc                 C   s@   t jdd}| dt| | |jd | | jd d S )Nr   r   zcurve='NIST P-256'z
NIST P-256r   r   r   r   r   r   "  s    z%TestEccKey_P256.test_name_consistencyNr   r   r   r   r   r     s   r   c                   @   sD   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_P384c                 C   s   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 )Nrj   r   r   r   r   	secp384r1
prime384v1r   r   r$   r    r   r   r   r<   rw   r=   rx   r   )r   rj   r   r   r   r   r   r   +  s    z TestEccKey_P384.test_private_keyc                 C   sD   t d }t|j|jd}td|d}| |  | |j| d S )Nrj   r   r   	r   r   rw   rx   r   r   r   r$   r   )r   rj   r   r   r   r   r   r   @  s
    zTestEccKey_P384.test_public_keyc                 C   s6   t ddd}| }| |  | |j|j d S )Nr   r   r   r   r   r   r   r   r   H  s    z'TestEccKey_P384.test_public_key_derivedc                 C   s   |  tdd  d S )Nc                   S   s   t dddS )NzP-385r   r   r   r   r   r   r   rN   P  rO   z4TestEccKey_P384.test_invalid_curve.<locals>.<lambda>r   rM   r   r   r   r   O  s    z"TestEccKey_P384.test_invalid_curvec                 C   s$   |  tdd  |  tdd  d S )Nc                   S   s   t dddS )Nr   r   r   r   r   r   r   r   rN   S  rO   z0TestEccKey_P384.test_invalid_d.<locals>.<lambda>c                   S   s   t dtd jdS )Nr   rj   r   r   r   r   r   r   rN   T  s   r   rM   r   r   r   r   R  s    zTestEccKey_P384.test_invalid_dc                 C   s   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   W  s    zTestEccKey_P384.test_equalityc                 C   s@   t jdd}| dt| | |jd | | jd d S )Nrj   r   zcurve='NIST P-384'z
NIST P-384r   r   r   r   r   r   i  s    z%TestEccKey_P384.test_name_consistencyNr   r   r   r   r   r   )  s   r   c                   @   sD   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_P521c                 C   s   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 )Nrp   P-521r   r   r   	secp521r1
prime521v1r   )r   rp   r   r   r   r   r   r   r  s    z TestEccKey_P521.test_private_keyc                 C   sD   t d }t|j|jd}td|d}| |  | |j| d S )Nrp   r   r   r   )r   rp   r   r   r   r   r   r     s
    zTestEccKey_P521.test_public_keyc                 C   s6   t ddd}| }| |  | |j|j d S )Nr   r   r   r   r   r   r   r   r     s    z'TestEccKey_P521.test_public_key_derivedc                 C   s   |  tdd  d S )Nc                   S   s   t dddS )NzP-522r   r   r   r   r   r   r   rN     rO   z4TestEccKey_P521.test_invalid_curve.<locals>.<lambda>r   rM   r   r   r   r     s    z"TestEccKey_P521.test_invalid_curvec                 C   s$   |  tdd  |  tdd  d S )Nc                   S   s   t dddS )Nr   r   r   r   r   r   r   r   rN     rO   z0TestEccKey_P521.test_invalid_d.<locals>.<lambda>c                   S   s   t dtd jdS )Nr   rp   r   r   r   r   r   r   rN     s   r   rM   r   r   r   r     s    zTestEccKey_P521.test_invalid_dc                 C   s   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     s    zTestEccKey_P521.test_equalityc                 C   s@   t jdd}| dt| | |jd | | jd d S )Nrp   r   zcurve='NIST P-521'z
NIST P-521r   r   r   r   r   r     s    z%TestEccKey_P521.test_name_consistencyNr   r   r   r   r   r   p  s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestEccModule_P192c                 C   s`   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   rw   rx   r    r   r   r   r   test_generate  s    z TestEccModule_P192.test_generatec                 C   s   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   Grw   rx   r   r   r   r   r   test_construct  s    z!TestEccModule_P192.test_constructc                 C   s^   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   rw   rx   rQ   r   r   r#   r   ZcoordZcoordGr   r   r   test_negative_construct  s    z*TestEccModule_P192.test_negative_constructNr   r   r   r   r   r   r   r   r   r   r     s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestEccModule_P224c                 C   s`   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     s    z TestEccModule_P224.test_generatec                 C   s   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     s    z!TestEccModule_P224.test_constructc                 C   s^   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 )	Nr   r   r   r]   r   r   r   r   r   r   r   r   r   r     s    z*TestEccModule_P224.test_negative_constructNr   r   r   r   r   r     s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )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   s   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     s    z!TestEccModule_P256.test_constructc                 C   s^   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 )	Nr   r   r   r   r   r   r   r   r   r   r   r   r   r   #  s    z*TestEccModule_P256.test_negative_constructNr   r   r   r   r   r     s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestEccModule_P384c                 C   s^   t d }tjdd}| |  | |jt|j|j	d|j
  tjdd tjdd d S )Nrj   r   r   r   r   r   r   r   r   r   r$   r   r   rw   rx   r    r   r   r   r   r   r   r   -  s     z TestEccModule_P384.test_generatec                 C   s   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 )Nrj   r   r   r   r   r   r   r   r   r#   r   r   r$   r   r   rw   rx   r   r   r   r   r   r   8  s    z!TestEccModule_P384.test_constructc                 C   s^   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 )	Nr   r   r   rj   r   r   r   r   r   r   r   r   r   r   H  s    z*TestEccModule_P384.test_negative_constructNr   r   r   r   r   r   +  s   r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestEccModule_P521c                 C   s^   t d }tjdd}| |  | |jt|j|j	d|j
  tjdd tjdd d S )Nrp   r   r   r   r   r   r   r   r   r   r   R  s     z TestEccModule_P521.test_generatec                 C   s   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 )Nrp   r   r   r   r   r   r   r   r   r   r   r   r   ]  s    z!TestEccModule_P521.test_constructc                 C   s^   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 )	Nr   r   r   rp   r   r   r   r   r   r   r   r   r   r   m  s    z*TestEccModule_P521.test_negative_constructNr   r   r   r   r   r   P  s   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 r/   )r   r
   r'   r\   rd   ri   ro   rt   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 r/   )unittestZ	TestSuiter   r   r   r   r   rN     rO   suite)ZdefaultTest)1r   binasciir   ZCryptodome.SelfTest.st_commonr   ZCryptodome.SelfTest.loaderr   ZCryptodome.PublicKeyr   ZCryptodome.PublicKey.ECCr   r   r   ZCryptodome.Math.Numbersr	   ZTestCaser
   r'   r\   rd   ri   ro   rt   Ztv_paitvr}   r<   r=   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''&%%
