
    ,hG@                         d dl Z d dlmZmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ  G d de      Z G d d	e      Z e       Z G d
 de      Z G d de      Zy)    N)bytes_to_longlong_to_bytes)VoidPointernull_pointerSmartPointerc_size_tc_uint8_ptrc_ulonglong)Integer)getrandbitsc                   0    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zy
)CurveID                        	   N)__name__
__module____qualname__P192P224P256P384P521ED25519ED448
CURVE25519CURVE448     Y/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/Crypto/PublicKey/_point.pyr   r      s/    DDDDDGEJHr%   r   c                       e Zd Zi Z ej
                         Zg dZg dZg dZ	g dZ
g dZddgZdd	gZg d
Zg dZeez   e	z   e
z   ez   ez   ez   ez   ez   Zd Zd Zd Zd Zd Zy)_Curves)p192z
NIST P-192zP-192
prime192v1	secp192r1nistp192)p224z
NIST P-224zP-224
prime224v1	secp224r1nistp224)p256z
NIST P-256zP-256
prime256v1	secp256r1nistp256)p384z
NIST P-384zP-384
prime384v1	secp384r1nistp384)p521z
NIST P-521zP-521
prime521v1	secp521r1nistp521ed25519Ed25519ed448Ed448)
curve25519
Curve25519X25519)curve448Curve448X448c                     || j                   v S N	all_names)selfitems     r&   __contains__z_Curves.__contains__1   s    t~~%%r%   c                     | j                   S rH   rI   rK   s    r&   __dir__z_Curves.__dir__4   s    ~~r%   c                 ^   || j                   v rfddlm} |j                         }t        j
                  |_        | j                  j                  t        j                  | j                   |             n|| j                  v rfddlm} |j                         }t        j                  |_        | j                  j                  t        j                  | j                  |             n7|| j                  v rfddlm} |j                         }t        j                   |_        | j                  j                  t        j                  | j                  |             n|| j"                  v rfddlm} |j%                         }t        j&                  |_        | j                  j                  t        j                  | j"                  |             nO|| j(                  v rfddlm} |j+                         }t        j,                  |_        | j                  j                  t        j                  | j(                  |             n|| j.                  v rfddlm} |j3                         }	t        j4                  |	_        | j                  j                  t        j                  | j.                  |	             ng|| j6                  v reddlm} |j9                         }
t        j:                  |
_        | j                  j                  t        j                  | j6                  |
             n|| j<                  v reddlm} |jA                         }t        jB                  |_        | j                  j                  t        j                  | j<                  |             n|| jD                  v reddlm} |jG                         }t        jH                  |_        | j                  j                  t        j                  | jD                  |             ntK        d|z        | j                  |   S )Nr   )	_nist_ecc)_edwards)_montgomeryzUnsupported curve '%s')&
p192_names rR   
p192_curver   r   idcurvesupdatedictfromkeys
p224_names
p224_curver   
p256_names
p256_curver   
p384_names
p384_curver   
p521_names
p521_curver   ed25519_namesrS   ed25519_curver    ed448_namesed448_curver!   curve25519_namesrT   curve25519_curver"   curve448_namescurve448_curver#   
ValueError)rK   namerR   r)   r-   r1   r5   r9   rS   r=   r?   rT   rA   rD   s                 r&   loadz_Curves.load7   s   4??"#'')DllDGKKt}}T__dCDT__$#'')DllDGKKt}}T__dCDT__$#'')DllDGKKt}}T__dCDT__$#'')DllDGKKt}}T__dCDT__$#'')DllDGKKt}}T__dCDT'''",,.G GJKKt}}T-?-?IJT%%%"((*E}}EHKKt}}T-=-=uEFT***%$557J#..JMKKt}}T-B-BJOPT(((%"113H!**HKKKt}}T-@-@(KL5<=={{4  r%   c                 f   | j                   5  | j                  j                  |      }|| j                  |      }|| j                  v s|| j
                  v rt        |j                  |      |_        n&t        |j                  |j                  |      |_        |j                  t        j                  t        j                  fv |_        |j                  t        j                   t        j"                  fv |_        |j                  xs |j$                   |_        d d d        |S # 1 sw Y   S xY wrH   )curves_lockrY   getro   ri   rk   	EccXPointGxGEccPointGyrX   r   r    r!   
is_edwardsr"   r#   is_montgomeryis_weierstrass)rK   rn   curves      r&   __getitem__z_Curves.__getitem__i   s     	AKKOOD)E}		$4000DD<O<O4O'$7EG&uxx4@EG#(88/O#O &+hh73E3E3:3C3C3E 'E#,1,<,< -@,1,?,?(A$	A 	A s   DD&&D0c                 b    | j                   D ]  }| |   }	 | j                  j                         S rH   )rJ   rY   items)rK   rn   _s      r&   r~   z_Curves.itemsy   s1    NN 	DT
A	{{  ""r%   N)r   r   r   rY   	threadingRLockrq   rU   r]   r_   ra   rc   re   rg   ri   rk   rJ   rM   rP   ro   r|   r~   r$   r%   r&   r(   r(      s    F!)//#KJJJJJ	*MG$K=5NZ'*4zAJN#$&679GHI&0!d #r%   r(   c                       e Zd ZdZddZd Zd Zd Zd Zd Z	d Z
d	 Zed
        Zed        Zed        Zd Zd Zd Zd Zd Zd Zd Zd Zy)rv   a  A class to model a point on an Elliptic Curve.

    The class supports operators for:

    * Adding two points: ``R = S + T``
    * In-place addition: ``S += T``
    * Negating a point: ``R = -T``
    * Comparing two points: ``if S == T: ...`` or ``if S != T: ...``
    * Multiplying a point by a scalar: ``R = S*k``
    * In-place multiplication by a scalar: ``T *= k``

    :ivar curve: The **canonical** name of the curve as defined in the `ECC table`_.
    :vartype curve: string

    :ivar x: The affine X-coordinate of the ECC point
    :vartype x: integer

    :ivar y: The affine Y-coordinate of the ECC point
    :vartype y: integer

    :ivar xy: The tuple with affine X- and Y- coordinates
    c                    	 t         |   | _        | j                  j
                  | _        | j                  j                  t        j                  k(  rt        d      | j                         }t        ||      }t        ||      }t        |      |k7  st        |      |k7  rt        d      | j                  j                  j                  }| j                  j                  j                  }t!               | _        	 | j                  j$                  j'                         }	 || j"                  j-                         t/        |      t/        |      t1        |      |	      }
|
r|
dk(  rt        d      t        d|
z        t3        | j"                  j'                         |      | _        y # t        $ r t        dt	        |      z        w xY w# t(        $ r	 t*        }	Y w xY w)NUnknown curve name %sz)EccPoint cannot be created for Curve25519Incorrect coordinate length   )The EC point does not belong to the curve(Error %d while instantiating an EC point)_curves_curveKeyErrorrm   str	canonicalr{   rX   r   r"   size_in_bytesr   lenrawlib	new_point
free_pointr   _pointcontextrr   AttributeErrorr   
address_ofr	   r   r   )rK   xyr{   modulus_bytesxbybr   	free_funcr   results              r&   __init__zEccPoint.__init__   s   	C!%.DK [[**
;;>>W///HII**,1m,1m,r7m#s2w-'?:;;KK&&00	KK&&11	!m	#kk))--/G 4;;113&r?&r?#M2"	$ | !LMMG&PQQ #4;;??#4i@G  	C4s5zABB	C(  	#"G	#s   F) <$G )!G
GGc                    | j                   j                  j                  }| j                   j                  j                  }t	               | _         || j
                  j                         |j
                  j                               }|rt        d|z        t        | j
                  j                         |      | _        | S Nz"Error %d while cloning an EC point
r   r   cloner   r   r   r   rr   rm   r   rK   pointr   r   r   s        r&   setzEccPoint.set   s    ""((KK&&11	!mt{{--/||'')+ AFJKK"4;;??#4i@r%   c                     t        |t              sy| j                  j                  j                  }d || j
                  j                         |j
                  j                               k(  S NFr   )
isinstancerv   r   r   cmpr   rr   )rK   r   cmp_funcs      r&   __eq__zEccPoint.__eq__   sN    %*;;%%))HT[[__.0@0@0BCCCr%   c                     | |k(   S rH   r$   )rK   r   s     r&   __ne__zEccPoint.__ne__   s    5=  r%   c                     | j                   j                  j                  }| j                         } ||j                  j                               }|rt        d|z        |S )Nz$Error %d while inverting an EC point)r   r   negcopyr   rr   rm   )rK   neg_funcnpr   s       r&   __neg__zEccPoint.__neg__   sO    ;;%%))YY["))--/*CfLMM	r%   c                 R    | j                   \  }}t        ||| j                        }|S zReturn a copy of this point.)xyrv   r{   )rK   r   r   r   s       r&   r   zEccPoint.copy   s&    ww1aDJJ'	r%   c                 j    | j                   j                  r| j                  dk(  S | j                  dk(  S ),``True`` if this is the *point-at-infinity*.r   )r   r   )r   rx   r   r   rO   s    r&   is_point_at_infinityzEccPoint.is_point_at_infinity   s.     ;;!!66Q;77f$$r%   c                     | j                   j                  rt        dd| j                        S t        dd| j                        S )-Return the *point-at-infinity* for the curve.r   r   )r   rx   rv   r{   rO   s    r&   point_at_infinityzEccPoint.point_at_infinity   s7     ;;!!Aq$**--Aq$**--r%   c                      | j                   d   S )Nr   r   rO   s    r&   r   z
EccPoint.x       wwqzr%   c                      | j                   d   S )Nr   r   rO   s    r&   r   z
EccPoint.y   r   r%   c                 z   | j                         }t        |      }t        |      }| j                  j                  j                  } |t        |      t        |      t        |      | j                  j                               }|rt        d|z        t        t        |            t        t        |            fS )Nz#Error %d while encoding an EC point)r   	bytearrayr   r   get_xyr	   r   r   rr   rm   r   r   )rK   r   r   r   r   r   s         r&   r   zEccPoint.xy  s    **,}%}%##**B#B /)+ BVKLLb)*GM"4E,FGGr%   c                 .    | j                         dz   dz  S z"Size of each coordinate, in bytes.r   r   size_in_bitsrO   s    r&   r   zEccPoint.size_in_bytes      !!#a'A--r%   c                 .    | j                   j                  S z!Size of each coordinate, in bits.r   modulus_bitsrO   s    r&   r   zEccPoint.size_in_bits      {{'''r%   c                     | j                   j                  j                  } || j                  j	                               }|rt        d|z        | S )zuDouble this point (in-place operation).

        Returns:
            This same object (to enable chaining).
        z#Error %d while doubling an EC point)r   r   doubler   rr   rm   )rK   double_funcr   s      r&   r   zEccPoint.double  sG     kk((//T[[__./BVKLLr%   c                     | j                   j                  j                  } || j                  j	                         |j                  j	                               }|r|dk(  rt        d      t        d|z        | S )zAdd a second point to this one   z#EC points are not on the same curvez#Error %d while adding two EC points)r   r   addr   rr   rm   )rK   r   add_funcr   s       r&   __iadd__zEccPoint.__iadd__'  si     ;;%%))$++//+U\\-=-=-?@| !FGGBVKLLr%   c                 0    | j                         }||z  }|S )z8Return a new point, the addition of this one and anotherr   )rK   r   r   s      r&   __add__zEccPoint.__add__2  s     YY[
e	r%   c           
      <   | j                   j                  j                  }|dk  rt        d      t	        |      } || j
                  j                         t        |      t        t        |            t        t        d                  }|rt        d|z        | S zMultiply this point by a scalarr   z?Scalar multiplication is only defined for non-negative integers@   z%Error %d during scalar multiplicationr   r   scalarrm   r   r   rr   r	   r   r   r
   r   rK   r   scalar_funcsbr   s        r&   __imul__zEccPoint.__imul__9       kk((//A:^__6"T[[__.(_%c"g.(R9; DvMNNr%   c                 0    | j                         }||z  }|S z2Return a new point, the scalar product of this oner   rK   r   r   s      r&   __mul__zEccPoint.__mul__H       YY[
f	r%   c                 $    | j                  |      S rH   r   rK   	left_hands     r&   __rmul__zEccPoint.__rmul__O      ||I&&r%   N)r1   )r   r   r   __doc__r   r   r   r   r   r   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r$   r%   r&   rv   rv      s    .'ARD!%.     H H.(	'r%   rv   c                   b    e Zd ZdZd Zd Zd Zd Zd Zd Z	e
d        Zd	 Zd
 Zd Zd Zd Zy)rs   a  A class to model a point on an Elliptic Curve,
    where only the X-coordinate is exposed.

    The class supports operators for:

    * Multiplying a point by a scalar: ``R = S*k``
    * In-place multiplication by a scalar: ``T *= k``

    :ivar curve: The **canonical** name of the curve as defined in the `ECC table`_.
    :vartype curve: string

    :ivar x: The affine X-coordinate of the ECC point
    :vartype x: integer
    c                    	 t         |   | _        | j                  j
                  | _        | j                  j                  t        j                  t        j                  fvrt        d      | j                  j                  j                  }| j                  j                  j                  }t               | _        	 | j                  j                   j#                         }| j)                         }|t&        }n.t+        t-        ||            }t/        |      |k7  rt        d      t               | _         || j                  j1                         |t3        |      |      }|dk(  rt        d      |rt        d|z        t5        | j                  j#                         |      | _        y # t        $ r t        dt	        |      z        w xY w# t$        $ r
 t&        }Y w xY w)Nr   z5EccXPoint can only be created for Curve25519/Curve448r   r   r   r   )r   r   r   rm   r   r   r{   rX   r   r"   r#   r   r   r   r   r   r   rr   r   r   r   r	   r   r   r   r   r   )	rK   r   r{   r   r   r   r   r   r   s	            r&   r   zEccXPoint.__init__c  s   
	C!%.DK [[**
;;>>'"4"4g6F6F!GGTUUKK&&00	KK&&11	!m	#kk))--/G **,9B]1m<=B2w-' !>??!m4;;113#M2"$
 R<HIIG&PQQ #4;;??#4i@M  	C4s5zABB	C  	#"G	#s   F, <$G ,!GG#"G#c                    | j                   j                  j                  }| j                   j                  j                  }t	               | _         || j
                  j                         |j
                  j                               }|rt        d|z        t        | j
                  j                         |      | _        | S r   r   r   s        r&   r   zEccXPoint.set  s    ""((KK&&11	!mt{{--/||'')+AFJKK"4;;??#4i@r%   c                     t        |t              sy| j                  j                  j                  }| j
                  j                         }|j
                  j                         } |||      }d|k(  S r   )r   rs   r   r   r   r   rr   )rK   r   r   p1p2ress         r&   r   zEccXPoint.__eq__  s[    %+;;%%))[[__\\r2Cxr%   c                     	 | j                   }t        || j                        S # t        $ r | j                         cY S w xY wr   )r   rm   r   rs   r{   )rK   r   s     r&   r   zEccXPoint.copy  sC    	,A DJJ''  	,))++	,s   $ A A c                 <    	 | j                   }y# t        $ r Y yw xY w)r   TF)r   rm   )rK   r   s     r&   r   zEccXPoint.is_point_at_infinity  s)    	A   		s    	c                 .    t        d| j                        S )r   N)rs   r{   rO   s    r&   r   zEccXPoint.point_at_infinity  s     tzz**r%   c                 H   | j                         }t        |      }| j                  j                  j                  } |t        |      t        |      | j                  j                               }|dk(  rt        d      |rt        d|z        t        t        |            S )N   z)No X coordinate for the point at infinityz'Error %d while getting X of an EC point)r   r   r   r   get_xr	   r   r   rr   rm   r   r   )rK   r   r   r   r   s        r&   r   zEccXPoint.x  s    **,}%""(({2.{{(* R<HIIFOPP}R())r%   c                 .    | j                         dz   dz  S r   r   rO   s    r&   r   zEccXPoint.size_in_bytes  r   r%   c                 .    | j                   j                  S r   r   rO   s    r&   r   zEccXPoint.size_in_bits  r   r%   c           
      <   | j                   j                  j                  }|dk  rt        d      t	        |      } || j
                  j                         t        |      t        t        |            t        t        d                  }|rt        d|z        | S r   r   r   s        r&   r   zEccXPoint.__imul__  r   r%   c                 0    | j                         }||z  }|S r   r   r   s      r&   r   zEccXPoint.__mul__  r   r%   c                 $    | j                  |      S rH   r   r   s     r&   r   zEccXPoint.__rmul__  r   r%   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r$   r%   r&   rs   rs   S  sT    -A^(+
 * *.('r%   rs   )r   Crypto.Util.numberr   r   Crypto.Util._raw_apir   r   r   r   r	   r
   Crypto.Math.Numbersr   Crypto.Random.randomr   objectr   r(   r   rv   rs   r$   r%   r&   <module>r     s`     ;/ / ( ,	f 	c#f c#L )M'v M'`Z' Z'r%   