%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/
Upload File :
Create Path :
Current File : //opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyc

�
�ac@ sddlmZyddlmZeZWnEek
rqyddlmZeZWnek
rmeZnXnXddl	m
Z
ddlmZddl
mZe
defd��Y�Zd	efd
��YZdefd��YZeeee�Zd
S(i����(tdivision(tmpz(tpython_2_unicode_compatiblei(tnumbertheory(tRWLocktCurveFpcB sweZdZer!dd�Zndd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
RS(s9Elliptic Curve over the field of integers modulo a prime.cC s:t|�|_t|�|_t|�|_||_dS(su
        The curve of points satisfying y^2 = x^3 + a*x + b (mod p).

        h is an integer that is the cofactor of the elliptic curve domain
        parameters; it is the number of points satisfying the elliptic curve
        equation divided by the order of the base point. It is used for selection
        of efficient algorithm for public point verification.
        N(Rt_CurveFp__pt_CurveFp__at_CurveFp__bt_CurveFp__h(tselftptatbth((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__init__;s	cC s(||_||_||_||_dS(su
        The curve of points satisfying y^2 = x^3 + a*x + b (mod p).

        h is an integer that is the cofactor of the elliptic curve domain
        parameters; it is the number of points satisfying the elliptic curve
        equation divided by the order of the base point. It is used for selection
        of efficient algorithm for public point verification.
        N(RRRR	(R
RRR
R((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyRKs				cC sGt|t�rC|j|jkoB|j|jkoB|j|jkStS(N(t
isinstanceRRRRtNotImplemented(R
tother((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__eq__Ys
cC st|j|j|jf�S(N(thashRRR(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__hash__ascC s|jS(N(R(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyRdscC s|jS(N(R(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyRgscC s|jS(N(R(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR
jscC s|jS(N(R	(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pytcofactormscC s/|||||j||j|jdkS(s!Is the point (x,y) on this curve?i(RRR(R
txty((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pytcontains_pointpscC s d|j|j|j|jfS(NsCurveFp(p=%d, a=%d, b=%d, h=%d)(RRRR	(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__str__tsN(t__name__t
__module__t__doc__tGMPYtNoneRRRRRR
RRR(((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR6s							tPointJacobicB seZdZded�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd�Ze
ed	��Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Ze
d��Zd�Ze
d��Zd�Zd�ZRS(s�
  Point on an elliptic curve. Uses Jacobi coordinates.

  In Jacobian coordinates, there are three parameters, X, Y and Z.
  They correspond to affine parameters 'x' and 'y' like so:

  x = X / Z²
  y = Y / Z³
  c	C sK||_t�|_tr`t|�|_t|�|_t|�|_|oWt|�|_n$||_||_||_||_g|_	|rG|s�t
�d}|d9}t|||||�}|d9}|j	j|j
�|j�f�xQ||krC|d9}|j�j�}|j	j|j
�|j�f�q�WndS(s
      Initialise a point that uses Jacobi representation internally.

      :param CurveFp curve: curve on which the point resides
      :param int x: the X parameter of Jacobi representation (equal to x when
        converting from affine coordinates
      :param int y: the Y parameter of Jacobi representation (equal to y when
        converting from affine coordinates
      :param int z: the Z parameter of Jacobi representation (equal to 1 when
        converting from affine coordinates
      :param int order: the point order, must be non zero when using
        generator=True
      :param bool generator: the point provided is a curve generator, as
        such, it will be commonly used with scalar multiplication. This will
        cause to precompute multiplication table for it
      iiN(t_PointJacobi__curveRt_scale_lockRRt_PointJacobi__xt_PointJacobi__yt_PointJacobi__zt_PointJacobi__ordert_PointJacobi__precomputetAssertionErrorR tappendRRtdoubletscale(	R
tcurveRRtztordert	generatortitdoubler((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR�s.						

"
cC sfzL|jj�|tkr.|jp-|jS|j|j|j}}}Wd|jj�Xt|t�r�|j	�|j
�d}}}nUt|t�r�z.|jj�|j|j|j}}}Wd|jj�XntS|j
|j�kr�tS|j
j�}|||}	|||}
||
||	|dkoe||
|||	||dkS(s#Compare two points with each-other.Nii(R"treader_acquiretINFINITYR$R%R#treader_releaseRtPointRRR RR!R,tFalseR(R
Rtx1ty1tz1tx2ty2tz2Rtzz1tzz2((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR�s*
!#
!cC s|jS(sEReturn the order of the point.

      None if it is undefined.
      (R&(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR.�scC s|jS(s-Return curve over which the point is defined.(R!(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR,�scC s{z9|jj�|jdkr&|jS|j}|j}Wd|jj�X|jj�}tj||�}||d|S(s7
      Return affine x coordinate.

      This method should be used only when the 'y' coordinate is not needed.
      It's computationally more efficient to use `to_affine()` and then
      call x() and y() on the returned instance. Or call `scale()`
      and then x() and y() on the returned instance.
      iNi(	R"R2R%R#R4R!RRtinverse_mod(R
RR-R((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR�s	
	
cC s{z9|jj�|jdkr&|jS|j}|j}Wd|jj�X|jj�}tj||�}||d|S(s7
      Return affine y coordinate.

      This method should be used only when the 'x' coordinate is not needed.
      It's computationally more efficient to use `to_affine()` and then
      call x() and y() on the returned instance. Or call `scale()`
      and then x() and y() on the returned instance.
      iNi(	R"R2R%R$R4R!RRR?(R
RR-R((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR�s	
	
cC s�z$|jj�|jdkr#|SWd|jj�Xzx|jj�|jj�}tj|j|�}|||}|j	|||_	|j
||||_
d|_Wd|jj�X|S(s_
      Return point scaled so that z == 1.

      Modifies point in place, returns self.
      iN(R"R2R%R4twriter_acquireR!RRR?R#R$twriter_release(R
Rtz_invtzz_inv((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR+s


cC sA|js|jrtS|j�t|j|j|j|j�S(sReturn point in affine form.(R$R%R3R+R5R!R#R&(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt	to_affine"s

cC s1t|j�|j�|j�d|j�|�S(sCreate from an affine point.

      :param bool generator: set to True to make the point to precalculate
        multiplication table - useful for public point when verifying many
        signatures (around 100 or so) or for generator points of a curve.
      i(R R,RRR.(tpointR/((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pytfrom_affine+s!c
C s�||||||}}|s'dS|||}d||d|||}d||}	|	|	d||}
|	||
d||}d||}|
||fS(s"Add a point to itself with z == 1.iiiii(iii((
R
tX1tY1RRtXXtYYtYYYYtStMtTtY3tZ3((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt_double_with_z_1@scC s�|dkr"|j||||�S|s,dS||||||}}|sSdS|||}|||}	d||d|||}
d|||	|	|}||d|
|}||
|d||}
||d||	|}||
|fS(s#Add a point to itself, arbitrary z.iiiii(iii(iii(RQ(R
RGRHtZ1RRRIRJRKtZZRLRMRNRORP((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt_doublePsc	C s�|js
tS|jj�|jj�}}z.|jj�|j|j|j}}}Wd|jj	�X|j
|||||�\}}}|s�|r�tSt|j||||j�S(sAdd a point to itself.N(
R$R3R!RRR"R2R#R%R4RTR R&(	R
RRRGRHRRtX3RORP((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR*fs	
!$cC s�||}||}d||}||}	d||}
|rg|
rg|j||||jj��S||}|
d|	d||}|
||d||	|}
d||}||
|fS(s&add points when both Z1 and Z2 equal 1ii(RQR!R(R
RGRHtX2tY2RtHtHHtItJtrtVRURORP((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt
_add_with_z_1ys



cC s�||d|}|||}||}	||d|}
|rl|
rl|j|||||jj��S|
||	|}||||||	||}||||}
|||
fS(sadd points when Z1 == Z2i(RTR!R(R
RGRHRRRVRWRtAtBtCtDRURORP((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt_add_with_z_eq�s
""cC s|||}|||||||}}	|||}
|
|
|}d||}|
|}
d|	||}|r�|
r�|j||||jj��S||}|||
d||}|||d||
|}||
d|||}|||fS(sadd points when Z2 == 1ii(RQR!R(R
RGRHRRRVRWRtZ1Z1tU2tS2RXRYRZR[R\R]RURORP((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt_add_with_z2_1�s!

cC s5|||}|||}	||	|}
|||}|||	|}||||}
||
}d|||}|||}d|
||}|r�|r�|j|||||jj��S|
|}|||d||}|||d|||}||d||	||}|||fS(sadd points with arbitrary zii(RTR!R(R
RGRHRRRVRWtZ2RRdtZ2Z2tU1RetS1RfRXRZR[R\R]RURORP((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt_add_with_z_ne�s"
"
cC s||S(sAdd other to self.((R
R((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__radd__�scC s�|s|r|||fS|s)|r6|||fS||kr�|dkrg|j|||||�S|j||||||�S|dkr�|j||||||�S|dkr�|j||||||�S|j|||||||�S(s&add two points, select fastest method.i(R^RcRgRl(R
RGRHRRRVRWRhR((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt_add�s

cC sG|tkr|S|tkr |St|t�rAtj|�}n|j|jkrbtd��n|jj�}z.|jj	�|j
|j|j}}}Wd|jj
�Xz.|jj	�|j
|j|j}}}Wd|jj
�X|j|||||||�\}	}
}|
s'|r+tSt|j|	|
||j�S(s!Add two points on elliptic curve.s%The other point is on different curveN(R3RR5R RFR!t
ValueErrorRR"R2R#R$R%R4RnR&(R
RRRGRHRRRVRWRhRURORP((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__add__�s*
!
!*cC s||S(sMultiply point by an integer.((R
R((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__rmul__�sc		C s
ddd|jj�f\}}}}|j}x�|jD]�\}}|dr�|ddkr�|dd}||||||d|�\}}}q�|dd}||||||d|�\}}}q:|d}q:W|s�|r�tSt|j||||j�S(s4Multiply point by integer with precomputation table.iiii(R!RRnR'R3R R&(	R
RRURORPRRnRVRW((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt_mul_precompute�s'	
+*cC sug}xh|rp|drV|d}|dkr<|d}n||g7}||8}n
|dg7}|d}q	W|S(s&Calculate non-adjacent form of number.iii((tmulttrettnd((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt_naf
s	





c	C s�|js|rtS|dkr%|S|jrB||jd}n|jrX|j|�S|j�}|j|j}}d\}}}|jj�|jj	�}}|j
}	|j}
x�t|j
|��D]�}|	|||||�\}}}|dkr+|
|||||d|�\}}}q�|dkr�|
|||||d|�\}}}q�q�W|ss|rwtSt|j||||j�S(sMultiply point by an integer.iii(iii(R$R3R&R'RrR+R#R!RRRTRntreversedRvR (R
RRVRWRURORPRRRTRnR0((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__mul__s.		
		!+.cC s=|dkst�d}x||kr4d|}qW|dS(sCReturn integer with the same magnitude as x but hamming weight of 1iii(R((Rtresult((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt
_leftmost_bit;s
cC sl|tks|dkr ||S|dkr4||St|t�sUtj|�}n|jrw|jrw||||S|jr�||j}||j}n|jt||��d}d\}}}|jj	�|jj
�}}	|j�}|j|j
}
}|j�}|j|j
}}
||j�}|j|j
}}|j}|j}x�|dkr=||||||	�\}}}|d}||@r�||@r�||||||d|�\}}}q]||@r|||||
|d|�\}}}q]||@r]||||||
d|�\}}}q]q]W|sL|rPtSt|j||||j�S(su
      Do two multiplications at the same time, add results.

      calculates self*self_mul + other*other_mul
      iii(iii(R3RR RFR'R&RztmaxR!RRR+R#R$RTRn(R
tself_mulRt	other_mulR0RURORPRRRGRHRVRWtbothtX4tY4RTRn((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pytmul_addDsD	
		!
*
*
.cC sLz7|jj�t|j|j|j|j|j�SWd|jj�XdS(sReturn negated point.N(	R"R2R R!R#R$R%R&R4(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt__neg__us

N( RRRRR6RRR.R,RRR+RDtstaticmethodRFRQRTR*R^RcRgRlRmRnRpRqRrRvRxRzR�R�(((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR ys8	-																					!		1R5cB s}eZdZd
d�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�ZRS(ssA point on an elliptic curve. Altering x and y is forbidding,
     but they can be read by the x() and y() methods.cC s�||_trQ|ot|�|_|o3t|�|_|oHt|�|_n||_||_||_|jr�|jj||�s�t�n|r�|j�dkr�|r�||t	ks�t�ndS(s@curve, x, y, order; order (optional) is the order of this point.iN(
t
_Point__curveRRt	_Point__xt	_Point__yt
_Point__orderRR(RR3(R
R,RRR.((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR�s					cC sGt|t�rC|j|jkoB|j|jkoB|j|jkStS(s9Return True if the points are identical, False otherwise.(RR5R�R�R�R(R
R((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR�s
cC s&t|j|j|jj�|j�S(N(R5R�R�RR�(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR��scC st|t�stS|tkr#|S|tkr3|S|j|jksKt�|j|jkr�|j|j|jj�dkr�tS|j	�Sn|jj�}|j|jt
j|j|j|�|}|||j|j|}||j||j|}t|j||�S(sAdd one point to another point.i(RR5RR3R�R(R�R�RR*RR?(R
RRtltx3ty3((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyRp�s"#

!cC s*d�}|}|dks7|jr;||jdkr;tS|tkrKtS|dkra||Sd|}t|j|j|j|j�}||�d}|}x�|dkr%|j�}||@dkr�||@dkr�||}n||@dkr||@dkr||}n|d}q�W|S(sMultiply a point by an integer.cS s=|dkst�d}x||kr4d|}qW|dS(Niii(R((RRy((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pytleftmost_bit�s
iiii(R�R3R5R�R�R�R*(R
RR�tete3t
negative_selfR0Ry((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyRx�s(	(

" 
 
cC s||S(sMultiply a point by an integer.((R
R((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyRq�scC s$|tkrdSd|j|jfS(Ntinfinitys(%d,%d)(R3R�R�(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR�scC s�|tkrtS|jj�}|jj�}d|j|j|tjd|j|�|}||d|j|}||j||j|}t|j||�S(s)Return a new point that is twice the old.ii(	R3R�RRR�RR?R�R5(R
RRR�R�R�((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR*�scC s|jS(N(R�(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR�scC s|jS(N(R�(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyRscC s|jS(N(R�(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR,scC s|jS(N(R�(R
((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR.sN(RRRRRRR�RpRxRqRR*RRR,R.(((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyR5s				$						N(t
__future__Rtgmpy2RtTrueRtImportErrortgmpyR6tsixRtRt_rwlockRtobjectRR R5RR3(((sH/opt/plesk/python/2.7/lib/python2.7/site-packages/ecdsa/ellipticcurve.pyt<module>$s&



B���

Zerion Mini Shell 1.0