
    ¿ig                     N    d dl mZ d dlmZmZmZmZ d Zd Zd Z	d Z
d Zd Zd	S )
    )long_to_bytes)EccKey	construct_import_curve25519_public_key_import_curve448_public_keyc                    |j         | j        z  }|                                rt          d          | j        dk    r*t          |j                            dd                    }n\| j        dk    r*t          |j                            dd                    }n't          |j        |	                                          }|S )NzInvalid ECDH point
Curve25519    little)	byteorderCurve4488   )
pointQdis_point_at_infinity
ValueErrorcurve	bytearrayxto_bytesr   size_in_bytes)key_privkey_pubpointPzs       R/var/www/html/afkarena/venv/lib/python3.11/site-packages/Cryptodome/Protocol/DH.py_compute_ecdhr      s    ^hj(F""$$ 0.//	/~%%fh''h'??@@	:	%	%fh''h'??@@ &(F$8$8$:$:;;H    c                 B    t          |           }t          d|          S )a  Create a new X25519 public key object,
    starting from the key encoded as raw ``bytes``,
    in the format described in RFC7748.

    Args:
      encoded (bytes):
        The x25519 public key to import.
        It must be 32 bytes.

    Returns:
      :class:`Cryptodome.PublicKey.EccKey` : a new ECC key object.

    Raises:
      ValueError: when the given key cannot be parsed.
    r	   r   point_x)r   r   encodedr   s     r   import_x25519_public_keyr$      s$    " 	&g..A<3333r   c                 $    t          | d          S )a  Create a new X25519 private key object,
    starting from the key encoded as raw ``bytes``,
    in the format described in RFC7748.

    Args:
      encoded (bytes):
        The X25519 private key to import.
        It must be 32 bytes.

    Returns:
      :class:`Cryptodome.PublicKey.EccKey` : a new ECC key object.

    Raises:
      ValueError: when the given key cannot be parsed.
    r	   seedr   r   r#   s    r   import_x25519_private_keyr*   ,   s    " '6666r   c                 B    t          |           }t          d|          S )a  Create a new X448 public key object,
    starting from the key encoded as raw ``bytes``,
    in the format described in RFC7748.

    Args:
      encoded (bytes):
        The x448 public key to import.
        It must be 56 bytes.

    Returns:
      :class:`Cryptodome.PublicKey.EccKey` : a new ECC key object.

    Raises:
      ValueError: when the given key cannot be parsed.
    r   r    )r   r   r"   s     r   import_x448_public_keyr,   @   s$    " 	$G,,A:q1111r   c                 $    t          | d          S )a  Create a new X448 private key object,
    starting from the key encoded as raw ``bytes``,
    in the format described in RFC7748.

    Args:
      encoded (bytes):
        The X448 private key to import.
        It must be 56 bytes.

    Returns:
      :class:`Cryptodome.PublicKey.EccKey` : a new ECC key object.

    Raises:
      ValueError: when the given key cannot be parsed.
    r   r&   r(   r)   s    r   import_x448_private_keyr.   U   s    " '4444r   c                  ,   |                      dd          }|                      dd          }|                      dd          }|                      dd          }|                      dd          }|t          d          d}d}d}d	 }	| |	||dd
          }|dz  }| |	||dd          }|dz  }| |	||dd
          }|dz  }| |	||dd          }|dz  }||z   dk     s|dk    s|dk    rt          d          d}
d}|r|rt          ||          }
|rB|r@t          |          t          |          k    rt          d          t          ||          }n)|r|rt          ||          }n|r|rt          ||          }||
z   } ||          S )a  Perform a Diffie-Hellman key agreement.

    Keywords:
      kdf (callable):
        A key derivation function that accepts ``bytes`` as input and returns
        ``bytes``.
      static_priv (EccKey):
        The local static private key. Optional.
      static_pub (EccKey):
        The static public key that belongs to the peer. Optional.
      eph_priv (EccKey):
        The local ephemeral private key, generated for this session. Optional.
      eph_pub (EccKey):
        The ephemeral public key, received from the peer for this session. Optional.

    At least two keys must be passed, of which one is a private key and one
    a public key.

    Returns (bytes):
      The derived secret key material.
    static_privN
static_pubeph_priveph_pubkdfz'kdf' is mandatoryr   c                     t          |t                    st          d|z            |r&|                                st          d|z            | |j        } n| |j        k    rt          d|z            | S )Nz'%s' must be an ECC keyz'%s' must be a private ECC keyz('%s' is defined on an incompatible curve)
isinstancer   	TypeErrorhas_privater   )r   keynameprivates       r   check_curvez"key_agreement.<locals>.check_curve   s    #v&& 	>5<=== 	E3??,, 	E<tCDDD=IEEciFMNNNr   T   F   z'Too few keys for the ECDH key agreementr   z"DH mode C(2e, 1s) is not supported)getr   r   bool)kwargsr0   r1   r2   r3   r4   
count_priv	count_pubr   r<   ZsZeZs                r   key_agreementrG   i   s   . **]D11KL$//Jzz*d++HjjD))G
**UD
!
!C
{-...JIE	 	 	 E;tDDa
E:|UCCQ	E8Z>>a
E7Iu==Q	Y!##zQ)q..BCCC	B	B 4z 4;
33 
1G 
1Z 0 000ABBB8W--	 1j 18Z00	 1[ 1;00
RA3q66Mr   N)Cryptodome.Util.numberr   Cryptodome.PublicKey.ECCr   r   r   r   r   r$   r*   r,   r.   rG    r   r   <module>rK      s    0 0 0 0 0 0? ? ? ? ? ? ? ? ? ? ? ?  4 4 4*7 7 7(2 2 2*5 5 5(W W W W Wr   