403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/Cryptodome/PublicKey/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/Cryptodome/PublicKey/__pycache__/ECC.cpython-311.pyc
�

8�tc�����ddlmZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZmZddl
mZmZddlmZddlmZmZmZmZddlmZmZmZdd	lmZmZmZmZm Z m!Z!dd
l"m#Z#ddl$m%Z%edd
��Z&edd��Z'iZ(gd�a)d�Z*e*��[*gd�a+d�Z,e,��[,gd�a-d�Z.e.��[.Gd�de/��Z0Gd�de1��Z2e2e(dj3e(dj4d��Z5e(d�6e5���Z7e(�8e9�:tRe7����[5[7b)e2e(dj3e(dj4d��Z;e(d�6e;���Z<e(�8e9�:tVe<����[;[<b+e2e(dj3e(dj4d��Z=e(d�6e=���Z>e(�8e9�:tZe>����[=[>b-Gd�de1��Z?d �Z@d!�ZAd"�ZBd#�ZCd2d$�ZDd%�ZEd&�ZFd'�ZGd(�ZHd)�ZId2d*�ZJeKd+kr�ddlLZLd,ZMe(djN�O��ZPd-ZQeLjL��ZReSeQ��D]ZTePeMzZU�eVd.eLjL��eRz
eQzd/zd0��eLjL��ZReSeQ��D]ZTeUeMzZU�eVd1eLjL��eRz
eQzd/zd0��dSdS)3�)�print_functionN)�
namedtuple)�bord�tobytes�tostr�bchr�	is_string)�
bytes_to_long�
long_to_bytes)�Integer)�DerObjectId�DerOctetString�DerSequence�DerBitString)�_expand_subject_public_key_info�_create_subject_public_key_info� _extract_subject_public_key_info)�load_pycryptodome_raw_lib�VoidPointer�SmartPointer�c_size_t�c_uint8_ptr�c_ulonglong)�get_random_bytes)�getrandbitszCryptodome.PublicKey._ec_wsav
typedef void EcContext;
typedef void EcPoint;
int ec_ws_new_context(EcContext **pec_ctx,
                      const uint8_t *modulus,
                      const uint8_t *b,
                      const uint8_t *order,
                      size_t len,
                      uint64_t seed);
void ec_free_context(EcContext *ec_ctx);
int ec_ws_new_point(EcPoint **pecp,
                    const uint8_t *x,
                    const uint8_t *y,
                    size_t len,
                    const EcContext *ec_ctx);
void ec_free_point(EcPoint *ecp);
int ec_ws_get_xy(uint8_t *x,
                 uint8_t *y,
                 size_t len,
                 const EcPoint *ecp);
int ec_ws_double(EcPoint *p);
int ec_ws_add(EcPoint *ecpa, EcPoint *ecpb);
int ec_ws_scalar(EcPoint *ecp,
                 const uint8_t *k,
                 size_t len,
                 uint64_t seed);
int ec_ws_clone(EcPoint **pecp2, const EcPoint *ecp);
int ec_ws_copy(EcPoint *ecp1, const EcPoint *ecp2);
int ec_ws_cmp(const EcPoint *ecp1, const EcPoint *ecp2);
int ec_ws_neg(EcPoint *p);
int ec_ws_normalize(EcPoint *ecp);
int ec_ws_is_pai(EcPoint *ecp);
�_Curvez7p b order Gx Gy G modulus_bits oid context desc openssh)�p256�
NIST P-256zP-256�
prime256v1�	secp256r1�nistp256c
�R�d}d}d}d}d}t|d��}t|d��}t|d��}t��}t�|���t|��t|��t|��t
t|����ttd������}	|	rtd|	z���t|���tj
��}
tt|��t|��t|��t|��t|��dd	d
|
dd��}t �t$�t(|����dS)
Nl������?@��lK`�O�pq^cv
3,�e<
1�U�]>{|R�*��ZlQ%�x+�Oh�bi+}s�����@��l�B11e	%:f=K`�wr�H�7g�HK8�hkl�Q~o��]�l+f�Ug+<�)Z?�8�O�?q!�O� �@z#Error %d initializing P-256 context�z1.2.840.10045.3.1.7rzecdsa-sha2-nistp256)rr�_ec_lib�ec_ws_new_context�
address_ofrr�lenrr�ImportErrorr�get�ec_free_contextrr�_curves�update�dict�fromkeys�
p256_names)�p�b�order�Gx�Gy�p256_modulus�p256_b�
p256_order�ec_p256_context�result�contextrs            �:/usr/lib/python3/dist-packages/Cryptodome/PublicKey/ECC.py�	init_p256r>csk��J�A�J�A�N�E�	K�B�	K�B� ��B�'�'�L�
�1�b�
!�
!�F��u�b�)�)�J�!�m�m�O�
�
&�
&��'A�'A�'C�'C�'2�<�'@�'@�'2�6�':�':�'2�:�'>�'>�'/��L�0A�0A�'B�'B�'2�;�r�?�?�'C�'C�)�)�F��J��?�&�H�I�I�I��?�.�.�0�0�'�2I�J�J�G��'�!�*�*��!�*�*��%�.�.��"�+�+��"�+�+���'���'�
)�
)�D��N�N�4�=�=��T�2�2�3�3�3�3�3�)�p384�
NIST P-384zP-384�
prime384v1�	secp384r1�nistp384c
�R�d}d}d}d}d}t|d��}t|d��}t|d��}t��}t�|���t|��t|��t|��t
t|����ttd������}	|	rtd|	z���t|���tj
��}
tt|��t|��t|��t|��t|��dd	d
|
dd��}t �t$�t(|����dS)
Nl�����~�����������������l�*�'�#.T��Ebc+�Z'@=D 1 "(�?7N2Z�_+��|��S/1fls)��e`g�w�l
X_[n�lv|�������������l�
�d�x�R��joyU8T(	:�ss�"�n�Z�L�8k�&�"_�Ul_�!�uR��/�sX0
@qa�N�Q�N�B&J��xS8KJ�E�Y�
�	K%�l�0r$z#Error %d initializing P-384 contexti�z1.3.132.0.34rAzecdsa-sha2-nistp384)rrr&r'r(rrr)rrr*rr+r,rrr-r.r/r0�
p384_names)r2r3r4r5r6�p384_modulus�p384_b�
p384_order�ec_p384_contextr;r<r@s            r=�	init_p384rL�sk��j�A�j�A�n�E�	k�B�	k�B� ��B�'�'�L�
�1�b�
!�
!�F��u�b�)�)�J�!�m�m�O�
�
&�
&��'A�'A�'C�'C�'2�<�'@�'@�'2�6�':�':�'2�:�'>�'>�'/��L�0A�0A�'B�'B�'2�;�r�?�?�'C�'C�)�)�F��J��?�&�H�I�I�I��?�.�.�0�0�'�2I�J�J�G��'�!�*�*��!�*�*��%�.�.��"�+�+��"�+�+��� ���'�
)�
)�D��N�N�4�=�=��T�2�2�3�3�3�3�3r?)�p521�
NIST P-521zP-521�
prime521v1�	secp521r1�nistp521c
�R�d}d}d}d}d}t|d��}t|d��}t|d��}t��}t�|���t|��t|��t|��t
t|����ttd������}	|	rtd|	z���t|���tj
��}
tt|��t|��t|��t|��t|��dd	d
|
dd��}t �t$�t(|����dS)
Nl#�����������������������������������l#?�VQ(zO�%b�95~c�te1oR{�V��;�LHw>�l�-rZE]�"Sr�&Ga9}*Fl#	dp"z\}[�z�3"n�Z;PK�#
`�7�r�o�C�Q������������������l#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`�Br$z#Error %d initializing P-521 contexti	z1.3.132.0.35rNzecdsa-sha2-nistp521)rrr&r'r(rrr)rrr*rr+r,rrr-r.r/r0�
p521_names)r2r3r4r5r6�p521_modulus�p521_b�
p521_order�ec_p521_contextr;r<rMs            r=�	init_p521rY�sz��	S�A�	S�A�
W�E�
T�B�
T�B� ��B�'�'�L�
�1�b�
!�
!�F��u�b�)�)�J�!�m�m�O�
�
&�
&��'A�'A�'C�'C�'2�<�'@�'@�'2�6�':�':�'2�:�'>�'>�'/��L�0A�0A�'B�'B�'2�;�r�?�?�'C�'C�)�)�F��J��?�&�H�I�I�I��?�.�.�0�0�'�2I�J�J�G��'�!�*�*��!�*�*��%�.�.��"�+�+��"�+�+��� ���'�
)�
)�D��N�N�4�=�=��T�2�2�3�3�3�3�3r?c��eZdZdS)�UnsupportedEccFeatureN)�__name__�
__module__�__qualname__�r?r=r[r[�s�������Dr?r[c��eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
ed
���Zed���Z
ed���Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�EccPointa=A class to abstract a point over an Elliptic Curve.

    The class support special methods for:

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

    :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 X- and Y- coordinates
    rc�@�	t||_n-#t$r tdt	|��z���wxYw||_|���}|jj}t||��}t||��}t|��|kst|��|krtd���t��|_t�
|j���t|��t|��t!|��|�����}|r'|dkrtd���td|z���t%|j���tj��|_dS)NzUnknown curve name %szIncorrect coordinate length�z)The EC point does not belong to the curvez(Error %d while instantiating an EC point)r-�_curve�KeyError�
ValueError�str�_curve_name�
size_in_bytesr<rr)r�_pointr&�ec_ws_new_pointr(rrr+r�
ec_free_point)	�self�x�y�curve�
modulus_bytesr<�xb�ybr;s	         r=�__init__zEccPoint.__init__sy��	C�!�%�.�D�K�K���	C�	C�	C��4�s�5�z�z�A�B�B�B�	C���� ����*�*�,�,�
��+�%��
�1�m�
,�
,��
�1�m�
,�
,���r�7�7�m�#�#�s�2�w�w�-�'?�'?��:�;�;�;�!�m�m����(�(���)?�)?�)A�)A�)4�R���)4�R���)1�-�)@�)@�)0�����	8�8��
�	R���|�|� �!L�M�M�M��G�&�P�Q�Q�Q�#�4�;�?�?�#4�#4�#*�#8�:�:����s��*?c�R�t��|_t�|j���|j�����}|rt
d|z���t|j���tj��|_|S)Nz"Error %d while cloning an EC point)	rrjr&�ec_ws_cloner(r+rfrrl�rm�pointr;s   r=�setzEccPoint.set"s���!�m�m����$�$�T�[�%;�%;�%=�%=�%*�\�%5�%5�%7�%7�9�9���	L��A�F�J�K�K�K�"�4�;�?�?�#4�#4�#*�#8�:�:����r?c��dt�|j���|j�����kS�Nr)r&�	ec_ws_cmprjr+)rmrxs  r=�__eq__zEccPoint.__eq__-s7���G�%�%�d�k�o�o�&7�&7���9I�9I�9K�9K�L�L�L�Lr?c��|���}t�|j�����}|rtd|z���|S)Nz$Error %d while inverting an EC point)�copyr&�	ec_ws_negrjr+rf)rm�npr;s   r=�__neg__zEccPoint.__neg__0sN��
�Y�Y�[�[���"�"�2�9�=�=�?�?�3�3���	N��C�f�L�M�M�M��	r?c�F�|j\}}t|||j��}|S)zReturn a copy of this point.)�xyrarh)rmrnror�s    r=rz
EccPoint.copy7s&���w���1�
�a��D�,�
-�
-���	r?c��|jdkS)z*``True`` if this is the point-at-infinity.)rr�r��rms r=�is_point_at_infinityzEccPoint.is_point_at_infinity=s���w�&� � r?c�.�tdd|j��S)z<Return the point-at-infinity for the curve this point is on.r)rarhr�s r=�point_at_infinityzEccPoint.point_at_infinityAs����1�d�.�/�/�/r?c��|jdSr{r�r�s r=rnz
EccPoint.xE����w�q�z�r?c��|jdS)N�r�r�s r=roz
EccPoint.yIr�r?c��|���}t|��}t|��}t�t	|��t	|��t|��|j�����}|rtd|z���tt|����tt|����fS)Nz#Error %d while encoding an EC point)ri�	bytearrayr&�ec_ws_get_xyrrrjr+rfrr
)rmrqrrrsr;s     r=r�zEccPoint.xyMs����*�*�,�,�
�
�}�
%�
%��
�}�
%�
%���%�%�k�"�o�o�&1�"�o�o�&.�}�&=�&=�&*�k�o�o�&7�&7�9�9���	M��B�V�K�L�L�L��
�b�)�)�*�*�G�M�"�4E�4E�,F�,F�G�Gr?c�6�|���dzdzS)z"Size of each coordinate, in bytes.��)�size_in_bitsr�s r=rizEccPoint.size_in_bytes[s���!�!�#�#�a�'�A�-�-r?c��|jjS)z!Size of each coordinate, in bits.)rd�modulus_bitsr�s r=r�zEccPoint.size_in_bits_s
���{�'�'r?c��t�|j�����}|rt	d|z���|S)z�Double this point (in-place operation).

        :Return:
            :class:`EccPoint` : this same object (to enable chaining)
        z#Error %d while doubling an EC point)r&�ec_ws_doublerjr+rf)rmr;s  r=�doublezEccPoint.doublecsE���%�%�d�k�o�o�&7�&7�8�8���	M��B�V�K�L�L�L��r?c���t�|j���|j�����}|r'|dkrt	d���t	d|z���|S)zAdd a second point to this one�z#EC points are not on the same curvez#Error %d while adding two EC points)r&�	ec_ws_addrjr+rfrws   r=�__iadd__zEccPoint.__iadd__osm���"�"�4�;�?�?�#4�#4�e�l�6F�6F�6H�6H�I�I���	M���|�|� �!F�G�G�G��B�V�K�L�L�L��r?c�8�|���}||z
}|S)z8Return a new point, the addition of this one and another�r)rmrxr�s   r=�__add__zEccPoint.__add__ys���Y�Y�[�[��
�e����	r?c
�`�|dkrtd���t|��}t�|j���t
|��tt|����ttd������}|rtd|z���|S)zMultiply this point by a scalarrz?Scalar multiplication is only defined for non-negative integersr$z%Error %d during scalar multiplication)rfrr&�ec_ws_scalarrjr+rrr)rr)rm�scalar�sbr;s    r=�__imul__zEccPoint.__imul__�s����A�:�:��^�_�_�_�
�6�
"�
"���%�%�d�k�o�o�&7�&7�&1�"�o�o�&.�s�2�w�w�&7�&7�&1�+�b�/�/�&B�&B�D�D���	O��D�v�M�N�N�N��r?c�8�|���}||z}|S)z2Return a new point, the scalar product of this oner�)rmr�r�s   r=�__mul__zEccPoint.__mul__�s���Y�Y�[�[��
�f����	r?c�,�|�|��S�N)r�)rm�	left_hands  r=�__rmul__zEccPoint.__rmul__�s���|�|�I�&�&�&r?N)r)r\r]r^�__doc__rtryr}r�rr�r��propertyrnror�rir�r�r�r�r�r�r�r_r?r=rara�s\��������(:�:�:�:�@	�	�	�M�M�M�������!�!�!�0�0�0�����X������X���H�H��X�H�.�.�.�(�(�(�
�
�
�������������'�'�'�'�'r?rar)�Gr@rMc��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	e
d���Ze
d	���Zd
�Z
d�Zdd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�EccKeya�Class defining an ECC key.
    Do not instantiate directly.
    Use :func:`generate`, :func:`construct` or :func:`import_key` instead.

    :ivar curve: The name of the ECC as defined in :numref:`curve_names`.
    :vartype curve: string

    :ivar pointQ: an ECC point representating the public component
    :vartype pointQ: :class:`EccPoint`

    :ivar d: A scalar representating the private component
    :vartype d: integer
    c�>�t|��}|�dd��}|�dd��|_|�dd��|_|rt	dt|��z���|tvrtd|���t||_|j�|j�td���nFt|j��|_d|jcxkr|jj
ksntd	���|jj|_dS)
a�Create a new ECC key

        Keywords:
          curve : string
            It must be *"p256"*, *"P-256"*, *"prime256v1"* or *"secp256r1"*.
          d : integer
            Only for a private key. It must be in the range ``[1..order-1]``.
          point : EccPoint
            Mandatory for a public key. If provided for a private key,
            the implementation will NOT check whether it matches ``d``.
        rpN�drx�Unknown parameters: zUnsupported curve (%s)zBEither private or public ECC component must be specified, not bothr�zInvalid ECC private component)
r/�pop�_drj�	TypeErrorrgr-rfrdrr4�descrp)rm�kwargs�kwargs_�
curve_names    r=rtzEccKey.__init__�s���v�,�,���[�[��$�/�/�
��+�+�c�4�(�(����k�k�'�4�0�0����	C��2�S��\�\�A�B�B�B��W�$�$��5�z�B�B�B��j�)����7�?��{�"� �!e�f�f�f�#��d�g�&�&�D�G����3�3�3�3�$�+�"3�3�3�3�3� �!@�A�A�A��[�%��
�
�
r?c�z�|���|���krdS|j|jkS)NF)�has_private�pointQ)rm�others  r=r}z
EccKey.__eq__�s9�������$�"2�"2�"4�"4�4�4��5��|�t�{�*�*r?c��|���rdt|j��z}nd}|jj\}}d|jj|||fzS)Nz, d=%d�z,EccKey(curve='%s', point_x=%d, point_y=%d%s))r��intr�r�r�rdr�)rm�extrarnros    r=�__repr__zEccKey.__repr__�sX�������	��s�4�7�|�|�+�E�E��E��{�~���1�=���AQ�ST�VW�Y^�@_�_�_r?c��|jduS)zJ``True`` if this key can be used for making signatures or decrypting data.N)r�r�s r=r�zEccKey.has_private�s���w�d�"�"r?c��d|cxkr|jjksnJ�|jj}tjd|���}|j|z}||z�|��}|jj|zj|z}|||z||zzz|z}||fS)Nrr�)�
min_inclusive�
max_exclusive)rdr4r�random_ranger��inverser�rn)	rm�z�kr4�blind�blind_d�inv_blind_k�r�ss	         r=�_signzEccKey._sign�s����1�(�(�(�(�t�{�(�(�(�(�(�(�(���!���$�1�38�:�:�:���'�E�/���q�y�)�)�%�0�0��
�[�]�Q�
�!�E�)���5�1�9�w��{�2�3�e�;���1�v�
r?c���|jj}|d�|��}|jj||z|zz}|j||dz|zz}||zj|dkS)Nr�r)rdr4r�r�r�rn)rmr��rsr4�sinv�point1�point2s       r=�_verifyzEccKey._verify�sg����!���!�u�}�}�U�#�#�����4�!�8�u�"4�5������1���� 6�7�����"�b��e�+�+r?c�V�|���std���|jS)NzThis is not a private ECC key)r�rfr�r�s r=r�zEccKey.ds,�����!�!�	>��<�=�=�=��w�r?c�P�|j�|jj|jz|_|jSr�)rjrdr�r�r�s r=r�z
EccKey.pointQ	s$���;���+�-�$�'�1�D�K��{�r?c�B�t|jj|j���S)z^A matching ECC public key.

        Returns:
            a new :class:`EccKey` object
        )rprx)r�rdr�r�r�s r=�
public_keyzEccKey.public_keys���D�K�,�D�K�@�@�@�@r?c��|j���}|rQd|jj���z}t	|��|jj�|��z}nBd|jj�|��z|jj�|��z}d}t||t|j	j
����S)N���1.2.840.10045.2.1)r�riro�is_oddrrn�to_bytesrr
rd�oid)rm�compressrq�
first_byter��unrestricted_oids      r=�_export_subjectPublicKeyInfoz#EccKey._export_subjectPublicKeyInfos�����1�1�3�3�
��	A��T�[�]�1�1�3�3�3�J��z�*�*��+�-�0�0��?�?�@�J�J�"��+�-�0�0��?�?�@��+�-�0�0��?�?�@�J�/��.�/?�/9�/:�4�;�?�/K�/K�M�M�	Mr?Tc���|���sJ�|j���}d|jj�|��z|jj�|��z}dt
|j�|����t|j	j
d���t|d���g}|s|d=t|���
��S)Nr�r�r��explicitr�)r�r�rirnr�rorr�r
rdr�rr�encode)rm�include_ec_paramsrqr��seqs     r=�_export_private_derzEccKey._export_private_der2s������!�!�!�!�!���1�1�3�3�
���k�m�,�,�]�;�;�<��k�m�,�,�]�;�;�<�
���d�f�o�o�m�<�<�=�=��4�;�?�Q�7�7�7��J��3�3�3�5��
!�	��A���3���&�&�(�(�(r?c���ddlm}|�dd���d|vrtd���d}|�d���}|j||fd	t
|jj��i|��}|S)
Nr��PKCS8�
passphrase�
protection�5At least the 'protection' parameter should be presentr�F)r��
key_params)	�
Cryptodome.IOr�r+rfr��wrapr
rdr�)rmr�r�r��private_keyr;s      r=�
_export_pkcs8zEccKey._export_pkcs8Ms���'�'�'�'�'�'��:�:�l�D�)�)�5�,�f�:T�:T��T�U�U�U�.���.�.��.�G�G�����K�,�&�&�'2�4�;�?�'C�'C�&�%�&�&���
r?c�d�ddlm}|�|��}|�|d��S)Nr��PEMz
PUBLIC KEY)r�r�r�r�)rmr�r��encoded_ders    r=�_export_public_pemzEccKey._export_public_pem[s;��%�%�%�%�%�%��7�7��A�A���z�z�+�|�4�4�4r?c�V�ddlm}|���}|j|d|fi|��S)Nrr�zEC PRIVATE KEY)r�r�r�r��rmr�r�r�r�s     r=�_export_private_pemzEccKey._export_private_pemasD��%�%�%�%�%�%��.�.�0�0���s�z�+�'7��N�N�v�N�N�Nr?c�b�ddlm}|���}|�|d��S)Nrr�zPRIVATE KEY)r�r�r�r�)rmr�r�s   r=�(_export_private_clear_pkcs8_in_clear_pemz/EccKey._export_private_clear_pkcs8_in_clear_pemgs9��%�%�%�%�%�%��(�(�*�*���z�z�+�}�5�5�5r?c��ddlm}|sJ�d|vrtd���|jdd|i|��}|�|d��S)Nrr�r�r�r�zENCRYPTED PRIVATE KEYr_)r�r�rfr�r�rs     r=�,_export_private_encrypted_pkcs8_in_clear_pemz3EccKey._export_private_encrypted_pkcs8_in_clear_pemmsl��%�%�%�%�%�%������v�%�%��T�U�U�U�(�d�(�I�I�J�I�&�I�I���z�z�+�'>�?�?�?r?c��|���rtd���|jj}|j���}|rQd|jj���z}t|��|jj	�
|��z}nBd|jj	�
|��z|jj�
|��z}|�d��d}t|��t|��|f}d�
d�|D����}|dzttj|����zS)Nz"Cannot export OpenSSH private keysr�r��-r?c�X�g|]'}tjdt|����|z��(S)�>I)�struct�packr))�.0rns  r=�
<listcomp>z*EccKey._export_openssh.<locals>.<listcomp>�s/��F�F�F�1���T�3�q�6�6�2�2�Q�6�F�F�Fr?� )r�rfrd�opensshr�riror�rrnr��splitr�joinr�binascii�
b2a_base64)	rmr�r�rqr�r��middle�comps�blobs	         r=�_export_opensshzEccKey._export_opensshvs=�������	C��A�B�B�B��{�"����1�1�3�3�
��	A��T�[�]�1�1�3�3�3�J��z�*�*��+�-�0�0��?�?�@�J�J�"��+�-�0�0��?�?�@��+�-�0�0��?�?�@�J����C����#�����������<���x�x�F�F��F�F�F�G�G���c�z�E�(�"5�d�";�";�<�<�<�<r?c�V�|���}|�d��}|dvrtd|z���|�dd��}|���r�|�dd��}t	|��r t|��}|std���|�d	d
��}|dkr4|r$|r|j|fi|��S|���S|j|fi|��S|dkr8|r|std
���|r|j	dd|i|��S|�
��Std���|rtd|z���|dkr|�|��S|dkr|�|��S|�
|��S)a�	Export this ECC key.

        Args:
          format (string):
            The format to use for encoding the key:

            - ``'DER'``. The key will be encoded in ASN.1 DER format (binary).
              For a public key, the ASN.1 ``subjectPublicKeyInfo`` structure
              defined in `RFC5480`_ will be used.
              For a private key, the ASN.1 ``ECPrivateKey`` structure defined
              in `RFC5915`_ is used instead (possibly within a PKCS#8 envelope,
              see the ``use_pkcs8`` flag below).
            - ``'PEM'``. The key will be encoded in a PEM_ envelope (ASCII).
            - ``'OpenSSH'``. The key will be encoded in the OpenSSH_ format
              (ASCII, public keys only).

          passphrase (byte string or string):
            The passphrase to use for protecting the private key.

          use_pkcs8 (boolean):
            Only relevant for private keys.

            If ``True`` (default and recommended), the `PKCS#8`_ representation
            will be used.

            If ``False``, the much weaker `PEM encryption`_ mechanism will be used.

          protection (string):
            When a private key is exported with password-protection
            and PKCS#8 (both ``DER`` and ``PEM`` formats), this parameter MUST be
            present and be a valid algorithm supported by :mod:`Cryptodome.IO.PKCS8`.
            It is recommended to use ``PBKDF2WithHMAC-SHA1AndAES128-CBC``.

          compress (boolean):
            If ``True``, a more compact representation of the public key
            with the X-coordinate only is used.

            If ``False`` (default), the full public key will be exported.

        .. warning::
            If you don't provide a passphrase, the private key will be
            exported in the clear!

        .. note::
            When exporting a private key with password-protection and `PKCS#8`_
            (both ``DER`` and ``PEM`` formats), any extra parameters
            to ``export_key()`` will be passed to :mod:`Cryptodome.IO.PKCS8`.

        .. _PEM:        http://www.ietf.org/rfc/rfc1421.txt
        .. _`PEM encryption`: http://www.ietf.org/rfc/rfc1423.txt
        .. _`PKCS#8`:   http://www.ietf.org/rfc/rfc5208.txt
        .. _OpenSSH:    http://www.openssh.com/txt/rfc5656.txt
        .. _RFC5480:    https://tools.ietf.org/html/rfc5480
        .. _RFC5915:    http://www.ietf.org/rfc/rfc5915.txt

        Returns:
            A multi-line string (for PEM and OpenSSH) or bytes (for DER) with the encoded key.
        �format)r��DER�OpenSSHzUnknown format '%s'r�Fr�NzEmpty passphrase�	use_pkcs8Tr�rz8Private keys can only be encrpyted with DER using PKCS#8z1Private keys cannot be exported in OpenSSH formatzUnexpected parameters: '%s'r_)rr�rfr�r	rrrrr�r�r�r�r)rmr��args�
ext_formatr�r�rs       r=�
export_keyzEccKey.export_key�s��x�{�{�}�}���X�X�h�'�'�
��6�6�6��2�Z�?�@�@�@��8�8�J��.�.�������!	6����,��5�5�J���$�$�
9�$�Z�0�0�
�!�9�$�%7�8�8�8�����d�3�3�I��U�"�"��H�!�O�P�t�P�Q[�d�d�_c�d�d�d�#�L�L�N�N�N�3�4�3�J�G�G�$�G�G�G��u�$�$��a�i�a�$�%_�`�`�`��6�-�4�-�L�L��L�t�L�L�L��3�3�5�5�5� �!T�U�U�U��
G� �!>��!E�F�F�F��U�"�"��.�.�x�8�8�8��u�$�$��8�8��B�B�B��+�+�H�5�5�5r?N)T)r\r]r^r�rtr}r�r�r�r�r�r�r�r�r�r�r�r�rrrrrr_r?r=r�r��s^�������� &� &� &�D+�+�+�`�`�`�#�#�#�
���,�,�,�����X��
����X��
A�A�A�M�M�M�4)�)�)�)�6���5�5�5�O�O�O�6�6�6�@�@�@�=�=�=�*d6�d6�d6�d6�d6r?r�c��|�d��}t|}|�dt��}|rtdt	|��z���tjd|j|���}t||���S)a:Generate a new private key on the given curve.

    Args:

      curve (string):
        Mandatory. It must be a curve name defined in :numref:`curve_names`.

      randfunc (callable):
        Optional. The RNG to read randomness from.
        If ``None``, :func:`Cryptodome.Random.get_random_bytes` is used.
    rp�randfuncr�r�)r�r�r!)rpr�)	r�r-rr�rgrr�r4r�)r�r�rpr!r�s     r=�generater"�s������G�$�$�J��J��E��z�z�*�&6�7�7�H�
�>��.��V���<�=�=�=���1�+0�;�&.�	0�	0�	0�A��
�a�(�(�(�(r?c�z�|d}t|}|�dd��}|�dd��}d|vrtd���d||fvrt|||��|d<|�dd��}|�*d|vr&|j|z}|j||fkrtd���td	i|��S)
a(Build a new ECC key (private or public) starting
    from some base components.

    Args:

      curve (string):
        Mandatory. It must be a curve name defined in :numref:`curve_names`.

      d (integer):
        Only for a private key. It must be in the range ``[1..order-1]``.

      point_x (integer):
        Mandatory for a public key. X coordinate (affine) of the ECC point.

      point_y (integer):
        Mandatory for a public key. Y coordinate (affine) of the ECC point.

    Returns:
      :class:`EccKey` : a new ECC key object
    rp�point_xN�point_yrxzUnknown keyword: pointr�z(Private and public ECC keys do not matchr_)	r-r�r�rar+r�r�rfr�)r�r�rpr$r%r��pub_keys       r=�	constructr's���,���J��J��E��j�j��D�)�)�G��j�j��D�)�)�G��&����0�1�1�1��G�W�%�%�%�"�7�G�Z�@�@��w��	�
�
�3����A��}��F�*�*��'�A�+���:�'�7�+�+�+��G�H�H�H����F���r?c�h�t���D]\}}|j|krn�td|z���|j���}t
|d��}|dkrgt|��dd|zzkrtd���tj
|d|dz���}tj
||dzd���}n�|dvr�t|��d|zkrtd���tj
|dd���}|d	z|d	zz
|jz�|j��}|dkr|�
��r
|j|z
}|d	kr|���r
|j|z
}ntd
���t|||���S)z�Convert an encoded EC point into an EccKey object

    curve_name: string with the OID of the curve
    ec_point: byte string with the EC point (not DER encoded)

    �Unsupported ECC curve (OID: %s)r�r�r�zIncorrect EC point lengthN)r��r+zIncorrect EC point encoding)rpr$r%)r-�itemsr�r[r2rirr)rfr�
from_bytesr3�sqrtr��is_evenr')�	curve_oid�ec_pointr�rprq�
point_typernros        r=�_import_public_derr38s���%�]�]�_�_�S�S��
�E��9�	�!�!��E�"�$�$E�	�$Q�R�R�R��G�)�)�+�+�M��h�q�k�"�"�J��T����x�=�=�Q��]�!2�2�3�3��8�9�9�9���x��-��/�(9�:�;�;����x�
�a��(8�(8�9�:�:���	�{�	"�	"��x�=�=�Q��.�/�/��8�9�9�9���x����|�,�,��
��T�A�a�C�Z�%�'�
!�'�'���0�0������!�(�(�*�*����!��A�����!�)�)�+�+����!��A���6�7�7�7��:�q�!�<�<�<�<r?c���t|��\}}}d}d}d}||||fvrtd|z���|std���t���|��j}t
||��S)z4Convert a subjectPublicKeyInfo into an EccKey objectr��1.3.132.1.12�1.3.132.1.13�!Unsupported ECC purpose (OID: %s)zMissing ECC parameters)rr[rfr
�decode�valuer3)	�encodedr�r�r1�paramsr��ecdh_oid�	ecmqv_oidr0s	         r=�_import_subjectPublicKeyInfor>gs���<�G�D�D��C��6�+���H��I�
�#�X�y�9�9�9�#�$G�#�$M�N�N�N��3��1�2�2�2��
�
�$�$�V�,�,�2�I��i��2�2�2r?c���t���|d���}|ddkrtd���	td����|d��j}|�||krtd���|}n#t$rYnwxYw|�td	���t
���D]\}}|j|krn�td
|z���t���|d��j
}|j���}t|��|krtd���tj|��}	t|��dkrWt!d����|d
��j}
t#||
��}|jj}|jj}
ndx}}
t+||	||
���S)N)r+r*)�nr_elementsrr�z!Incorrect ECC private key versionr�r�zCurve mismatchzNo curve foundr)zPrivate key is too smallr*r+)rpr�r$r%)rr8rfr
r9r-r,r�r[r�payloadr2rir)rr-rr3r�rnror')r:r�r0r��
parametersr�rp�scalar_bytesrqr��public_key_encr�r$r%s              r=�_import_private_derrE�s����-�-�&�&�w�F�&�C�C�K��1�~�����<�=�=�=�
� �!�,�,�,�3�3�K��N�C�C�I�
�� �Z�9�%<�%<��-�.�.�.��	�	���
�
�
���
�������)�*�*�*�$�]�]�_�_�S�S��
�E��9�	�!�!��E�"�$�$E�	�$Q�R�R�R�!�#�#�*�*�;�q�>�:�:�B�L��G�)�)�+�+�M�
�<���M�)�)��3�4�4�4���<�(�(�A��;���1���%�q�1�1�1�8�8��Q��H�H�N��'�	�>�B�B�
��#�%���#�%��� � ��'��:��G�W�M�M�M�Ms�AB�
B�Bc���ddlm}|�||��\}}}d}d}d}||||fvrtd|z���t	���|��j}	t|||	��S)Nrr�r�r5r6r7)r�r��unwrapr[r
r8r9rE)
r:r�r��algo_oidr�r;r�r<r=r0s
          r=�
_import_pkcs8rI�s���#�#�#�#�#�#�%*�L�L��*�$E�$E�!�H�k�6�+���H��I��(�(�I�>�>�>�#�$G�(�$R�S�S�S��
�
�$�$�V�,�,�2�I��{�J�	�B�B�Br?c�>�t|��}t|��Sr�)rr>)r:r��sp_infos   r=�_import_x509_certrL�s��.�w�7�7�G�'��0�0�0r?c��	t||��S#t$r}|�d}~wtttf$rYnwxYw	t||��S#t$r}|�d}~wtttf$rYnwxYw	t
||��S#t$r}|�d}~wtttf$rYnwxYw	t||��S#t$r}|�d}~wtttf$rYnwxYwtd���)NzNot an ECC DER key)r>r[rfr��
IndexErrorrLrErI)r:r��errs   r=�_import_derrP�so��
�+�G�Z�@�@�@�� �����	������	�:�.�
�
�
���
����
� ��*�5�5�5�� �����	������	�:�.�
�
�
���
����
�"�7�J�7�7�7�� �����	������	�:�.�
�
�
���
����
��W�j�1�1�1�� �����	������	�:�.�
�
�
���
�����)�
*�
*�*sm��
;��;�;�A�
A8�A�A8�7A8�<B�
B5�B�B5�4B5�9C	�	
C2�C�C2�1C2c�T�tj|�d��d��}g}t|��dkrct	jd|dd���d}|�|dd|z���|d|zd�}t|��dk�ct���D]@\}}t|j
�d��d��}|d|krn�Atd���t|j
|d��S)	N� r�r*r	rrr�zUnsupported ECC curve)r�
a2b_base64rr)r
�unpack�appendr-r,rrrfr3r�)r:�	keystring�keyparts�lkr�rprs       r=�_import_openssh_publicrYs���#�G�M�M�$�$7�$7��$:�;�;�I��H�

�i�.�.�1�
�
�
�]�4��2�A�2��
/�
/��
2�����	�!�A��F�(�+�,�,�,��a�"�f�g�g�&�	��i�.�.�1�
�
�
%�]�]�_�_�2�2��
�E����,�,�S�1�1�!�4�5�5���A�;�&� � ��E�!��0�1�1�1��e�i��!��5�5�5r?c��ddlm}m}m}m}|||��\}}||��\}}|t
vrt
d|z���t
|}	|	jdzdz}
||��\}}t|d��dkrtd���t|��d	|
zdzkrtd
���tj|dd|
z���}tj|d|
zd���}
t||
|���}||��\}}tj|��}||��\}}||��t|||���S)
Nr�)�import_openssh_private_generic�
read_bytes�read_string�
check_paddingzUnsupported ECC curve %sr�r�rr*z/Only uncompressed OpenSSH EC keys are supportedr�zIncorrect public key length)rp)rpr�rx)�_opensshr[r\r]r^r-r[r�rrfr)rr-rar�)�data�passwordr[r\r]r^�ssh_name�	decrypted�namerprqr�r$r%rxr�r��_�paddeds                   r=�_import_openssh_private_eccrgs���C�C�C�C�C�C�C�C�C�C�C�C�9�8��x�H�H��H�i�!�k�)�,�,�O�D�)��7���#�$>��$E�F�F�F��D�M�E��'�!�+��1�M�&�J�y�1�1��J�	��J�q�M���a����J�K�K�K�
�:���!�m�+�a�/�/�/��6�7�7�7�� ��A�a�
�o�,=�!>�?�?�G�� ��A�m�O�,<�,<�!=�>�>�G��W�g�T�2�2�2�E�'�Z�	�2�2��K����;�'�'�A���I�&�&�I�A�v��M�&��������/�/�/�/r?c�(�ddlm}t|��}|�t|��}|�d��r;t	|��}|�||��\}}}t
||��}|S|�d��r�t	|��}d}d}	tj|dz|	zd	|tj	�
��}|�||��\}
}}|rd}	t|
|��}n,#t$r}|�d}~wt$rtd���wxYw|S|�d��rt|��St|��dkr)t|d��d
krt||��Std���)a�Import an ECC key (public or private).

    Args:
      encoded (bytes or multi-line string):
        The ECC key to import.

        An ECC **public** key can be:

        - An X.509 certificate, binary (DER) or ASCII (PEM)
        - An X.509 ``subjectPublicKeyInfo``, binary (DER) or ASCII (PEM)
        - An OpenSSH line (e.g. the content of ``~/.ssh/id_ecdsa``, ASCII)

        An ECC **private** key can be:

        - In binary format (DER, see section 3 of `RFC5915`_ or `PKCS#8`_)
        - In ASCII format (PEM or `OpenSSH 6.5+`_)

        Private keys can be in the clear or password-protected.

        For details about the PEM encoding, see `RFC1421`_/`RFC1423`_.

      passphrase (byte string):
        The passphrase to use for decrypting a private key.
        Encryption may be applied protected at the PEM level or at the PKCS#8 level.
        This parameter is ignored if the key in input is not encrypted.

    Returns:
      :class:`EccKey` : a new ECC key object

    Raises:
      ValueError: when the given key cannot be parsed (possibly because
        the pass phrase is wrong).

    .. _RFC1421: http://www.ietf.org/rfc/rfc1421.txt
    .. _RFC1423: http://www.ietf.org/rfc/rfc1423.txt
    .. _RFC5915: http://www.ietf.org/rfc/rfc5915.txt
    .. _`PKCS#8`: http://www.ietf.org/rfc/rfc5208.txt
    .. _`OpenSSH 6.5+`: https://flak.tedunangst.com/post/new-openssh-key-format-and-bcrypt-pbkdf
    rr�Ns-----BEGIN OPENSSH PRIVATE KEYs-----z-----BEGIN EC PARAMETERS-----z-----END EC PARAMETERS-----z.*?r�)�flagsz(Invalid DER encoding inside the PEM filesecdsa-sha2-rFzECC key format is not supported)r�r�r�
startswithrr8rg�re�sub�DOTALLrPr[rfrYr)r)r:r�r��text_encoded�openssh_encoded�marker�enc_flagr;�ecparams_start�ecparams_end�der_encoded�uefs            r=�
import_keyrv5s���R"�!�!�!�!�!��g���G����Z�(�(�
����;�<�<���W�~�~��,/�J�J�|�Z�,P�,P�)����,�_�j�I�I���
�	�	�	�H�	%�	%���W�~�~��9��4���v�n�u�4�|�C�R� ,�&(�i�1�1�1��),�
�
�<��(L�(L�%��V�X��	��J�	I� ��j�9�9�F�F��$�	�	�	��I������	I�	I�	I��G�H�H�H�	I�����
����.�)�)�/�%�g�.�.�.��7�|�|�a���D����,�,��4�4��7�J�/�/�/�
�6�
7�
7�7s�&C7�7
D �D�D �__main__l��_,)�N�$�c�
hKf-5lk<X�k�#Ei�z	(P-256 G)i��msz(P-256 arbitrary point)r�)W�
__future__rrkr
r�collectionsr�Cryptodome.Util.py3compatrrrrr	�Cryptodome.Util.numberr
r�Cryptodome.Math.Numbersr�Cryptodome.Util.asn1r
rrr�Cryptodome.PublicKeyrrr�Cryptodome.Util._raw_apirrrrrr�Cryptodome.Randomr�Cryptodome.Random.randomrr&rr-r1r>rGrLrTrYrfr[�objectrar5r6�p256_G�_replacerr.r/r0�p384_Gr@�p521_GrMr�r"r'r3r>rErIrLrPrYrgrvr\�timer�r�rrx�count�start�rangern�pointX�printr_r?r=�<module>r�s���>&�%�%�%�%�%�	�	�	�	�
�
�
�
�����"�"�"�"�"�"�K�K�K�K�K�K�K�K�K�K�K�K�K�K�?�?�?�?�?�?�?�?�+�+�+�+�+�+�,�,�,�,�,�,�,�,�,�,�,�,�@�@�@�@�@�@�@�@�@�@�/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�/�.�.�.�.�.�0�0�0�0�0�0�$�
#�$A� D� � ��D
��H�W�	X�	X��
�����
�#4�#4�#4�L
�	����
����
�#4�#4�#4�L
�	����
����
�#4�#4�#4�L
�	����
�	�	�	�	�	�J�	�	�	�i'�i'�i'�i'�i'�v�i'�i'�i'�Z
��'�&�/�$�g�f�o�&8�&�	A�	A���v����&��)�)�����t�}�}�Z��.�.�/�/�/�
�D�*�	��'�&�/�$�g�f�o�&8�&�	A�	A���v����&��)�)�����t�}�}�Z��.�.�/�/�/�
�D�*�	��'�&�/�$�g�f�o�&8�&�	A�	A���v����&��)�)�����t�}�}�Z��.�.�/�/�/�
�D�*�E6�E6�E6�E6�E6�V�E6�E6�E6�P
)�)�)�4)�)�)�X,=�,=�,=�^$3�$3�$3�N/N�/N�/N�/N�dC�C�C�41�1�1�+�+�+�B6�6�6�&0�0�0�BU8�U8�U8�U8�p�z����K�K�K�J�A��F�O��"�"�$�$�E��E��D�I�K�K�E�
�U�5�\�\���������	�E�+�	��	���e�+�u�4�t�;�T�B�B�B��D�I�K�K�E�
�U�5�\�\�����!����	�E�
#�i�d�i�k�k�E�&9�U�%B�T�%I�4�P�P�P�P�P�#�r?

Youez - 2016 - github.com/yon3zu
LinuXploit