
    Tfg>                        d dl mZ d dlmZ ddlmZmZmZmZ ddl	m
Z
mZmZ ddlmZmZ g dZdZd	Z G d
 de          Z G d d          Z edej        ej        dd          Z edej        ej        dd          Z edej        ej        dd          Z edej        ej         dd          Z! edej"        ej#        dd          Z$ edej%        ej&        dd          Z' ed ej(        ej)        d!d"          Z* ed#ej+        ej,        d$d%          Z- ed&ej.        ej/        d'd(          Z0 ed)ej1        ej2        d*d+          Z3 ed,ej4        ej5        d-d.          Z6 ed/ej7        ej8        d0d1          Z9 ed2ej:        ej;        d3d4          Z< ed5ej=        ej>        d6d7          Z? ed8ej@        ejA        d9d:          ZB ed;ejC        ejD        d<d=          ZE ed>ejF        ejG        d?d@          ZH edAejI        ejJ        dBdC          ZK edDejL        ejM        dEdF          ZN edGejO        ejP        dHdI          ZQ edJejR        ejS        dKdL          ZT edMejU        ejV        dNdO          ZW edPejX        ejY        dQdR          ZZ edSej[        ej\        dTdU          Z] edVej^        ej_        dW          Z` edXeja        ejb        dY          Zce$e'e*e-e0e3e6e<eBeHeNeTeZeeee!e`ece9e?eEeKeQeWe]gZddZ Zed[ Zfd\S )]    )division)PY2   )derecdsaellipticcurveeddsa)orderlennumber_to_stringstring_to_number)normalise_bytes
bit_length)"UnknownCurveErrorr
   Curve	SECP112r1	SECP112r2	SECP128r1	SECP160r1NIST192pNIST224pNIST256pNIST384pNIST521pcurves
find_curvecurve_by_name	SECP256k1BRAINPOOLP160r1BRAINPOOLP160t1BRAINPOOLP192r1BRAINPOOLP192t1BRAINPOOLP224r1BRAINPOOLP224t1BRAINPOOLP256r1BRAINPOOLP256t1BRAINPOOLP320r1BRAINPOOLP320t1BRAINPOOLP384r1BRAINPOOLP384t1BRAINPOOLP512r1BRAINPOOLP512t1PRIME_FIELD_OIDCHARACTERISTIC_TWO_FIELD_OIDEd25519Ed448)r      H  ='  r   r   )r   r0   r1   r2   r   r0   c                       e Zd ZdS )r   N)__name__
__module____qualname__     >/var/www/html/env/lib/python3.11/site-packages/ecdsa/curves.pyr   r   5   s        Dr8   r   c                   h    e Zd ZddZd Zd Zd ZddZddZe	dd	            Z
edd
            ZdS )r   Nc                    || _         || _        || _        || _        |                                | _        t          |t          j                  r<t          |	                                          dz   dz   dz  | _
        | j
        | _        nBt          | j                  | _
        dt          |	                                          z  | _        d| j
        z  | _        || _        |rt          j        | | _        d S d S )Nr         r0   )nameopenssl_namecurve	generatororder
isinstancer   	CurveEdTwr   pbaselenverifying_key_lengthr
   signature_lengthoidr   
encode_oidencoded_oid)selfr>   r@   rA   rI   r?   s         r9   __init__zCurve.__init__:   s    	(
"__&&
e]455 		@
 'uwwyy11A59a?DL(,D%%#DJ//DL()HUWWYY,?,?(?D% !DL 0 	4"~s3D	4 	4r8   c                 z    t          |t                    r | j        |j        k    o| j        |j        k    S t          S N)rC   r   r@   rA   NotImplementedrL   others     r9   __eq__zCurve.__eq__O   s;    eU## 	
ek)Odn.O r8   c                     | |k     S rO   r7   rQ   s     r9   __ne__zCurve.__ne__V   s    5=  r8   c                     | j         S rO   r>   )rL   s    r9   __repr__zCurve.__repr__Y   s
    yr8   uncompressedc           	      t   || j         rd}nd}|dvrt          d          |dk    r)| j         st          d          t          j        | j          S t          | j        t          j                  r|dk    sJ t          d          | j        	                                }t          j
        d          }t          j        t          j        t           t          j
        |                    }t          j        t          j        t          | j                                        |z  |                    t          j        t          | j                                        |z  |                              }t          j        | j                            |                    }t          j
        | j                                                  }|||||g}	| j                                        r@t          j
        | j                                                  }
|	                    |
           t          j        |	 S )	a  Serialise the curve parameters to binary string.

        :param str encoding: the format to save the curve parameters in.
            Default is ``named_curve``, with fallback being the ``explicit``
            if the OID is not set for the curve.
        :param str point_encoding: the point encoding of the generator when
            explicit curve encoding is used. Ignored for ``named_curve``
            format.

        :return: DER encoded ECParameters structure
        :rtype: bytes
        Nnamed_curveexplicitr[   r\   z5Only 'named_curve' and 'explicit' encodings supportedzJCan't encode curve using named_curve encoding without associated curve OIDz6Twisted Edwards curves don't support explicit encodingr   )rI   
ValueErrorr   r   rJ   rC   r@   r   rD   rE   encode_integerencode_sequencer,   encode_octet_stringr   abrA   to_bytesrB   cofactorappend)rL   encodingpoint_encodingcurve_pversionfield_idr@   baserB   seq_elementsre   s              r9   to_derzCurve.to_der\   s    x &(%666G   }$$8 '+   >48,,
M$;<< 	z))))#H  
 *,,..$Q''&NO,c.@.I.I
 
 ## '!97CC  # '!97CC 	
 
 &t~'>'>~'N'NOO"4>#7#7#9#9::5$>:   	*)$**=*=*?*?@@H)))"L11r8   c                 T    t          j        |                     ||          d          S )a  
        Serialise the curve parameters to the :term:`PEM` format.

        :param str encoding: the format to save the curve parameters in.
            Default is ``named_curve``, with fallback being the ``explicit``
            if the OID is not set for the curve.
        :param str point_encoding: the point encoding of the generator when
            explicit curve encoding is used. Ignored for ``named_curve``
            format.

        :return: PEM encoded ECParameters structure
        :rtype: str
        zEC PARAMETERS)r   topemrn   )rL   rg   rh   s      r9   to_pemzCurve.to_pem   s+     yKK.11?
 
 	
r8   c                    |st          d          }t          d |D                       st          d          t          |           } t	          j        |           sTd|vrt	          j        d          t	          j        |           \  }}|rt	          j        d          t          |          S d|vrt	          j        d          t	          j	        |           \  }}|rt	          j        d	          t	          j
        |          \  }}|d
k    rt	          j        d          t	          j	        |          \  }}t	          j	        |          \  }}t	          j        |          \  }	}t	          j
        |          \  }
}d}|rt	          j
        |          \  }}t	          j        |          \  }}|t          k    rt          d          |t          k    r"t          d                    |                    t	          j
        |          \  }}|rt	          j        d          t	          j        |          \  }}t	          j        |          \  }}t!          |          }t!          |          }t#          j        ||||          }t"          j                            ||	d|
d          }t+          d||d          }t,          D ]}||k    r|c S |S )a  Decode the curve parameters from DER file.

        :param data: the binary string to decode the parameters from
        :type data: :term:`bytes-like object`
        :param valid_encodings: set of names of allowed encodings, by default
            all (set by passing ``None``), supported ones are ``named_curve``
            and ``explicit``
        :type valid_encodings: :term:`set-like object`
        r]   c              3      K   | ]}|d v V  	dS )r]   Nr7   ).0is     r9   	<genexpr>z!Curve.from_der.<locals>.<genexpr>   s(      MM133MMMMMMr8   z1Only named_curve and explicit encodings supportedr[   z(named_curve curve parameters not allowedzUnexpected data after OIDr\   z%explicit curve parameters not allowedz,Unexpected data after ECParameters structurer   z!Unknown parameter encoding formatNz#Characteristic 2 curves unsupportedzUnknown field type: {0}z:Unexpected data after ECParameters.fieldID.Prime-p element)rY   
compressedhybridT)valid_encodingsrB   rA   unknown)setallr^   r   r   is_sequenceUnexpectedDERremove_objectr   remove_sequenceremove_integerremove_octet_stringr-   r   r,   formatr   r   CurveFpPointJacobi
from_bytesr   r   )datary   rI   emptyseqrj   restrk   r@   
base_bytesrB   re   _
field_typeprimecurve_a_bytescurve_b_bytescurve_acurve_bcurve_fprl   	tmp_curveru   s                          r9   from_derzCurve.from_der   s*     	?!"=>>OMM_MMMMM 	C   t$$t$$ 	#O33'>   *400JC E'(CDDDc??"_,,#$KLLL(..
U 	#>   *3//a<<#$GHHH,T22$)$//t2488
D(..t 	3 ,T22KHa ,X66
D555#$IJJJ((#)00<<   )$//u 	#L  
 "5e<<t!5d;;t #=11"=11 ((KK (33D 4 
 
 )XtT::	  	 	AA~~ r8   c                     t           s)t          |t                    r|                                }|                    d          }|dk    rt          j        d          |                     t          j        ||d                   |          S )am  Decode the curve parameters from PEM file.

        :param str string: the text string to decode the parameters from
        :param valid_encodings: set of names of allowed encodings, by default
            all (set by passing ``None``), supported ones are ``named_curve``
            and ``explicit``
        :type valid_encodings: :term:`set-like object`
        s   -----BEGIN EC PARAMETERS-----z"EC PARAMETERS PEM header not foundN)	r   rC   strencodefindr   r~   r   unpem)clsstringry   ec_param_indexs       r9   from_pemzCurve.from_pem  s      	%z&#.. 	%]]__F%EFFR#$HIII||If^__-..
 
 	
r8   rO   )NrY   )r4   r5   r6   rM   rS   rU   rX   rn   rq   staticmethodr   classmethodr   r7   r8   r9   r   r   9   s        4 4 4 4*  ! ! !  :2 :2 :2 :2x
 
 
 
$ Y Y Y \Yv 
 
 
 [
 
 
r8   r   r   )r         r      	secp112r1r   )r   r   r   r   r<   	secp112r2r   )r   r   r   r      	secp128r1r   )r   r   r   r   r=   	secp160r1r   )r   r0   r1   r2   r   r   r   
prime192v1r   )r   r   r   r   !   	secp224r1r   )r   r0   r1   r2   r   r   r<   
prime256v1r   )r   r   r   r   "   	secp384r1r   )r   r   r   r   #   	secp521r1r   )r   r   r   r   
   	secp256k1r   )
r   r   $   r   r   r0   r=   r   r   r   brainpoolP160r1r   )
r   r   r   r   r   r0   r=   r   r   r0   brainpoolP160t1r    )
r   r   r   r   r   r0   r=   r   r   r   brainpoolP192r1r!   )
r   r   r   r   r   r0   r=   r   r      brainpoolP192t1r"   )
r   r   r   r   r   r0   r=   r   r      brainpoolP224r1r#   )
r   r   r   r   r   r0   r=   r   r   r   brainpoolP224t1r$   )
r   r   r   r   r   r0   r=   r   r   r<   brainpoolP256r1r%   )
r   r   r   r   r   r0   r=   r   r   r=   brainpoolP256t1r&   )
r   r   r   r   r   r0   r=   r   r   	   brainpoolP320r1r'   )
r   r   r   r   r   r0   r=   r   r   r   brainpoolP320t1r(   )
r   r   r   r   r   r0   r=   r   r      brainpoolP384r1r)   )
r   r   r   r   r   r0   r=   r   r      brainpoolP384t1r*   )
r   r   r   r   r   r0   r=   r   r      brainpoolP512r1r+   )
r   r   r   r   r   r0   r=   r   r      brainpoolP512t1r.   )r   r   e   p   r/   )r   r   r   q   c                 |    t           D ]}|j        | k    r|c S t          d| dd t           D                       )a9  Select a curve based on its OID

    :param tuple[int,...] oid_curve: ASN.1 Object Identifier of the
        curve to return, like ``(1, 2, 840, 10045, 3, 1, 7)`` for ``NIST256p``.

    :raises UnknownCurveError: When the oid doesn't match any of the supported
        curves

    :rtype: ~ecdsa.curves.Curve
    z&I don't know about the curve with oid z.I only know about these: c                     g | ]	}|j         
S r7   rW   rt   cs     r9   
<listcomp>zfind_curve.<locals>.<listcomp>5  s    4L4L4LQV4L4L4Lr8   )r   rI   r   )	oid_curver   s     r9   r   r   %  sd       5IHHH 

)24L4LV4L4L4L4L	N  r8   c                     t           D ]#}| |j        k    s|j        r| |j        k    r|c S $t          d                    | d t           D                                 )a{  Select a curve based on its name.

    Returns a :py:class:`~ecdsa.curves.Curve` object with a ``name`` name.
    Note that ``name`` is case-sensitve.

    :param str name: Name of the curve to return, like ``NIST256p`` or
        ``prime256v1``

    :raises UnknownCurveError: When the name doesn't match any of the supported
        curves

    :rtype: ~ecdsa.curves.Curve
    z9Curve with name {0!r} unknown, only curves supported: {1}c                     g | ]	}|j         
S r7   rW   r   s     r9   r   z!curve_by_name.<locals>.<listcomp>L  s    ***a16***r8   )r   r>   r?   r   r   )r>   r   s     r9   r   r   9  ss       16>>an>1G1GHHH
CJJ**6***	
 	
  r8   N)g
__future__r   sixr    r   r   r   r	   utilr
   r   r   _compatr   r   __all__r,   r-   	Exceptionr   r   curve_112r1generator_112r1r   curve_112r2generator_112r2r   curve_128r1generator_128r1r   curve_160r1generator_160r1r   	curve_192generator_192r   	curve_224generator_224r   	curve_256generator_256r   	curve_384generator_384r   	curve_521generator_521r   curve_secp256k1generator_secp256k1r   curve_brainpoolp160r1generator_brainpoolp160r1r   curve_brainpoolp160t1generator_brainpoolp160t1r   curve_brainpoolp192r1generator_brainpoolp192r1r    curve_brainpoolp192t1generator_brainpoolp192t1r!   curve_brainpoolp224r1generator_brainpoolp224r1r"   curve_brainpoolp224t1generator_brainpoolp224t1r#   curve_brainpoolp256r1generator_brainpoolp256r1r$   curve_brainpoolp256t1generator_brainpoolp256t1r%   curve_brainpoolp320r1generator_brainpoolp320r1r&   curve_brainpoolp320t1generator_brainpoolp320t1r'   curve_brainpoolp384r1generator_brainpoolp384r1r(   curve_brainpoolp384t1generator_brainpoolp384t1r)   curve_brainpoolp512r1generator_brainpoolp512r1r*   curve_brainpoolp512t1generator_brainpoolp512t1r+   curve_ed25519generator_ed25519r.   curve_ed448generator_ed448r/   r   r   r   r7   r8   r9   <module>r     s               . . . . . . . . . . . . > > > > > > > > > > 0 0 0 0 0 0 0 0
# # #L +7 	 	 	 	 		 	 	 	`
 `
 `
 `
 `
 `
 `
 `
H E		 	 E		 	 E		 	 E		 	 5	O	  5	O	  5	O	  5	O	  5	O	  E		 	 %		##  %		##  %		##  %		##  %		##  %		##  %		##  %		##  %		##  %		#$  %		#$  %		#$  %		#$  %		#$  %			  					 	 	5
<  (    r8   