HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/oscrypto/__pycache__/_ecdsa.cpython-39.pyc
a

�,�h"Y�@s�ddlmZmZmZmZddlZddlZddlZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZddlmZddlmZmZddlmZdd	lmZejd
kr�eZ e!Z"ndd�Z e	�Z#e#d
kr�e$d��gd�Z%dddd�Z&dddd�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dd �Z-Gd!d"�d"�Z.Gd#d$�d$�Z/e/ddd�Z0e.d%d&d'�Z1e/e1d(d)d*�Z2e.d+d&d,�Z3e/e3d-d.d/�Z4e.d0d&d1�Z5e/e5d2d3d4�Z6e.d5d&d6�Z7e/e7d7d8d9�Z8e.d:d&d;�Z9e/e9d<d=d>�Z:dS)?�)�unicode_literals�division�absolute_import�print_functionN�)�backend)
�Certificate�DSASignature�ECDomainParameters�ECPointBitString�ECPrivateKey�int_from_bytes�PrivateKeyAlgorithm�PrivateKeyInfo�PublicKeyAlgorithm�
PublicKeyInfo)�pretty_message)�	type_name�byte_cls)�
rand_bytes)�SignatureError)�cCs
t|g�S)N)�bytes)�num�r�@/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/oscrypto/_ecdsa.py�chr_clssrZ	winlegacyz2Pure-python ECDSA code is only for Windows XP/2003)�ec_generate_pair�ec_compute_public_key_point�ec_public_key_info�
ecdsa_sign�ecdsa_verify� �0�B�Z	secp256r1Z	secp384r1Z	secp521r1�cCs�|tgd��vr"ttdt|����t|}tttd�|}t|�}t	|dd�}|dkr:||j
kr:qdq:tdtdt
d|d�d	��td
|d��d��}t|�}|��|d
jd<t||�|fS)a�
    Generates a EC public/private key pair

    :param curve:
        A unicode string. Valid values include "secp256r1", "secp384r1" and
        "secp521r1".

    :raises:
        ValueError - when any of the parameters contain an invalid value
        TypeError - when any of the parameters are of the wrong type

    :return:
        A 2-element tuple of (asn1crypto.keys.PublicKeyInfo,
        asn1crypto.keys.PrivateKeyInfo)
    r%�\
            curve must be one of "secp256r1", "secp384r1", "secp521r1", not %s
            F��signedr�ec�named��name�value��	algorithm�
parametersZ
ecPrivkeyVer1)�version�private_key)r2Zprivate_key_algorithmr3r3�
public_key)�set�
ValueErrorr�repr�CURVE_BYTES�SECP256R1_BASE_POINT�SECP384R1_BASE_POINT�SECP521R1_BASE_POINTrr
�orderrrr
rr�copy�parsedr)�curve�curve_num_bytes�curve_base_point�private_key_bytes�private_key_intZprivate_key_infoZec_pointrrrrCsB�������rcCs�t|t�sttdt|����|j\}}|dkr:ttd���|dkrPttd���n:|dkr�|tgd��vrzttdt|����t	t
td�|}||d	jd	j
}t�|j|j�S)
a
    Constructs the PublicKeyInfo for a PrivateKeyInfo

    :param private_key:
        An asn1crypto.keys.PrivateKeyInfo object

    :raises:
        ValueError - when any of the parameters contain an invalid value

    :return:
        An asn1crypto.keys.ECPointBitString object
    zy
            private_key must be an instance of the
            asn1crypto.keys.PrivateKeyInfo class, not %s
            Zimplicit_cazj
            Unable to compute public key for EC key using Implicit CA
            parameters
            Z	specifiedzX
            Unable to compute public key for EC key over a specified field
            r+r%zj
                Named curve must be one of "secp256r1", "secp384r1", "secp521r1", not %s
                r3)�
isinstancer�	TypeErrorrrr?r6r5r7r9r:r;r>�nativerZfrom_coords�x�y)r3Z
curve_type�detailsZ
base_pointZpublic_pointrrrrs8
�
�����rcCsB|tgd��vr"ttdt|����ttdtd|d�d��|d��S)a�
    Constructs the PublicKeyInfo for an ECPointBitString

    :param private_key:
        An asn1crypto.keys.ECPointBitString object

    :param curve:
        A unicode string of the curve name - one of secp256r1, secp384r1 or secp521r1

    :raises:
        ValueError - when any of the parameters contain an invalid value

    :return:
        An asn1crypto.keys.PublicKeyInfo object
    r%r'r*r+r,r/)r0r4)r5r6rr7rrr
)�public_key_pointr?rrrr�s����rcCs*t|d�rt|jt�s(ttdt|����|j}|tgd��vrJt	td���t|t
�sfttdt|����|tgd��vr�t	tdt|����tt
|�}|jdj}|dj}|dj}t|}tttd�|}	|	j}
||���}t|�}t|d	d
�|
}
d|}d|}t�||d|||���}t�|||���}t�||d|||���}t�|||���}d
}d
}d}t|�|k�r�t�|||���}||7}�qpt|d
|�d	d
�}|d
k�sl||
k�rȐql|	|j|
}|d
k�r�qlt||
�|
|||
|
}|d
k�r�ql�q�qlt||d����S)aN
    Generates an ECDSA signature in pure Python (thus slow)

    :param private_key:
        The PrivateKey to generate the signature with

    :param data:
        A byte string of the data the signature is for

    :param hash_algorithm:
        A unicode string of "sha1", "sha256", "sha384" or "sha512"

    :raises:
        ValueError - when any of the parameters contain an invalid value
        TypeError - when any of the parameters are of the wrong type
        OSError - when an error is returned by the OS crypto library

    :return:
        A byte string of the signature
    �asn1zy
            private_key must be an instance of the
            oscrypto.asymmetric.PrivateKey class, not %s
            r%zx
            private_key does not use one of the named curves secp256r1,
            secp384r1 or secp521r1
            �<
            data must be a byte string, not %s
            ��sha1�sha224�sha256�sha384�sha512�z
            hash_algorithm must be one of "sha1", "sha224", "sha256", "sha384",
            "sha512", not %s
            r3Fr(��r�)�r�s)�hasattrrDrKrrErrr?r5r6rr7�getattr�hashlibr>�contentsrFr8r9r:r;r<�digest�lenr
�hmac�newrG�inverse_modr	�dump)r3�data�hash_algorithm�
curve_name�	hash_funcZec_private_keyrBrCr@rA�nr]Zhash_length�h�V�KrWrX�T�krrrr �st��
��


��

r cCs�t|d�}|rt|jttf�s0ttdt|����|j}|t	gd��vrRt
td���t|t�snttdt|����t|t�s�ttdt|����|t	gd��vr�t
tdt|����|j}t|t�r�|j
}tttd�|}|d	��\}}	|j}
t|j||	|
�}z"t�|�}|d
j}|dj}
Wnt
�y6td��Yn0d
}||dkO}|||
kO}||
dkO}||
|
kO}|�rztd��tt|�}||���}t|dd�|
}t|
|
�}|||
}|||
}||||}||j|
k�r�td��dS)a�
    Verifies an ECDSA signature in pure Python (thus slow)

    :param certificate_or_public_key:
        A Certificate or PublicKey instance to verify the signature with

    :param signature:
        A byte string of the signature to verify

    :param data:
        A byte string of the data the signature is for

    :param hash_algorithm:
        A unicode string of "md5", "sha1", "sha256", "sha384" or "sha512"

    :raises:
        oscrypto.errors.SignatureError - when the signature is determined to be invalid
        ValueError - when any of the parameters contain an invalid value
        TypeError - when any of the parameters are of the wrong type
        OSError - when an error is returned by the OS crypto library
    rKz�
            certificate_or_public_key must be an instance of the
            oscrypto.asymmetric.PublicKey or oscrypto.asymmetric.Certificate
            classes, not %s
            r%z�
            certificate_or_public_key does not use one of the named curves
            secp256r1, secp384r1 or secp521r1
            zA
            signature must be a byte string, not %s
            rLrMrSr4rWrXzSignature is invalidrrFr(N)rYrDrKrrrErrr?r5r6rr7r4r9r:r;Z	to_coordsr<�
PrimePointr	�loadrFrrZr[r]r
rarG)Zcertificate_or_public_key�	signaturercrdZhas_asn1rerKrArGrHrgrJrWrX�invalidrfr]�z�w�u1�u2Z
hash_pointrrrr!`sx
�	�
�
��
��



r!c	Cs�|dks||kr||}||}}d\}}}}|dkrrt||�|f\}}}||||||||f\}}}}q.|dks~J�|dkr�|S||SdS)z�
    Compute the modular inverse of a (mod p)

    :param a:
        An integer

    :param p:
        An integer

    :return:
        An integer
    r)rrrrrN)�divmod)	�a�p�c�dZuc�vcZudZvd�qrrrras
&rac@s eZdZdZdd�Zdd�ZdS)�
PrimeCurvezc
    Elliptic curve over a prime field. Characteristic two field curves are not
    supported.
    cCs||_||_||_dS)a
        The curve of points satisfying y^2 = x^3 + a*x + b (mod p)

        :param p:
            The prime number as an integer

        :param a:
            The component a as an integer

        :param b:
            The component b as an integer
        N)rwrv�b)�selfrwrvr}rrr�__init__-szPrimeCurve.__init__cCsB|j|j}|j|j|j}|||j|j|j|jdkS)z~
        :param point:
            A Point object

        :return:
            Boolean if the point is on this curve
        r)rHrGrvr}rw)r~Zpoint�y2�x3rrr�contains?s	zPrimeCurve.containsN)�__name__�
__module__�__qualname__�__doc__rr�rrrrr|'sr|c@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)rmz1
    A point on a prime-field elliptic curve
    NcCsR||_||_||_||_|jr2|j�|�s2td��|jrN||jtkrNtd��dS)a)
        :param curve:
            A PrimeCurve object

        :param x:
            The x coordinate of the point as an integer

        :param y:
            The y coordinate of the point as an integer

        :param order:
            The order of the point, as an integer - optional
        zInvalid EC pointN)r?rGrHr<r�r6�INFINITY)r~r?rGrHr<rrrrRszPrimePoint.__init__cCs0|j|jkr(|j|jkr(|j|jkr(dSdSdS)zy
        :param other:
            A PrimePoint object

        :return:
            0 if identical, 1 otherwise
        rrN)r?rGrH�r~�otherrrr�__cmp__os$zPrimePoint.__cmp__cCs�|tkr|S|tkr|S|j|jks(J�|j|jkrX|j|j|jjdkrPtS|��S|jj}|j|jt|j|j|�|}|||j|j|}||j||j|}t|j||�S)zq
        :param other:
            A PrimePoint object

        :return:
            A PrimePoint object
        r)r�r?rGrHrw�doublerarm)r~r�rw�l_r��y3rrr�__add__|s"zPrimePoint.__add__cCs�dd�}|}|jr||j}|dkr(tS|tkr4tS|dks@J�d|}t|j|j|j|j�}||�d}|}|dkr�|��}||@dkr�||@dkr�||}||@dkr�||@dkr�||}|d}qp|S)��
        :param other:
            An integer to multiple the Point by

        :return:
            A PrimePoint object
        cSs*|dksJ�d}||kr"d|}q|dS)Nrr�r)rG�resultrrr�leftmost_bit�s

z(PrimePoint.__mul__.<locals>.leftmost_bitrrr�r)r<r�rmr?rGrHr�)r~r�r��eZe3Z
negative_self�ir�rrr�__mul__�s*	

zPrimePoint.__mul__cCs||S)r�rr�rrr�__rmul__�s	zPrimePoint.__rmul__cCst|jj}|jj}d|j|j|td|j|�|}||d|j|}||j||j|}t|j||�S)zS
        :return:
            A PrimePoint object that is twice this point
        rr�)r?rwrvrGrarHrm)r~rwrvr�r�r�rrrr��s(zPrimePoint.double)N)
r�r�r�r�rr�r�r�r�r�rrrrrmMs

+rml
����������������l
�9��{�u��D�j�Sg9�g(Bl
��+�'1t�:�_|v!a�:@m�l
H�<�^�W]�dZ{cx��W\Iql
1(�i�&^#a�;�������l���������?l��FeY8��w�-X"PVd�/�%�PP!-l!�"X�!#BX�t�J9!'�|�%�V�A�-l4~
f�&Dv�@h�!�f�E0m9_qlM/l=*�8%���(��������?l������?@��lK`�O�pq^cv
3,�e<
1�U�]>{|R�*��Zl�B11e	%:f=K`�wr�H�7g�HK8�hkl�Q~o��]�l+f�Ug+<�)Z?�8�O�?q!�OlQ%�x+�Oh�bi+}s�����@��l�����~�����������������l�*�'�#.T��Ebc+�Z'@=D 1 "(�?7N2Z�_+��|��S/1fl�
�d�x�R��joyU8T(	:�ss�"�n�Z�L�8k�&�"_�Ul_�!�uR��/�sX0
@qa�N�Q�N�B&J��xS8KJ�E�Y�
�	K%�lls)��e`g�w�l
X_[n�lv|�������������l#�����������������������������������l#?�VQ(zO�%b�95~c�te1oR{�V��;�LHw>�l�-rZE]�"Sr�&Ga9}*Fl#f=��x�K�)H-apY$3^Q�	n�%k�{;/K!u{4-{�?$�O��d8�V1�l�3s:�l#Pf�?�Q�E$XN�!85aZ��U��WL9�YL��h�z
�f�$Du13otc!�%�pMxjRr`l#	dp"z\}[�z�3"n�Z;PK�#
`�7�r�o�C�Q������������������);�
__future__rrrrr[r_�sys�rZ_asn1rr	r
rrr
rrrr�_errorsr�_typesrr�utilr�errorsr�version_info�chrr�xrange�rangeZ_backend�SystemError�__all__r8ZCURVE_EXTRA_BITSrrrr r!rar|rmr�ZSECP192R1_CURVEZSECP192R1_BASE_POINTZSECP224R1_CURVEZSECP224R1_BASE_POINTZSECP256R1_CURVEr9ZSECP384R1_CURVEr:ZSECP521R1_CURVEr;rrrr�<module>s�0

��<;%%#&��	��	��	��	��