
    he                     (    d dl mZ d dlmZ d Zd Zy)    )long_to_bytes)EccKeyc                     |j                   | j                  z  }|j                         rt        d      t	        |j
                  |j                               }|S )NzInvalid ECDH point)pointQdis_point_at_infinity
ValueErrorr   xsize_in_bytes)key_privkey_pubpointPzs       ]/var/www/html/retail-simulation-api/retail/lib/python3.12/site-packages/Crypto/Protocol/DH.py_compute_ecdhr      sJ    ^^hjj(F""$-..fhh 4 4 67AH    c                     | j                  dd      }| j                  dd      }| j                  dd      }| j                  dd      }| j                  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        ||      }
|r1|r/t        |      t        |      k7  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|j                         st        d|z        | |j                  } | S | |j                  k7  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_privatecurve)r   keynameprivates       r   check_curvez"key_agreement.<locals>.check_curve2   ss    #v&5<==3??,<tCDD=IIE  ciiFM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)kwargsr   r   r   r   r   
count_priv	count_pubr   r!   ZsZeZs                r   key_agreementr,      s   . **]D1KL$/Jzz*d+HjjD)G
**UD
!C
{-..JIE	 E;tDa
E:|UCQ	E8Z>a
E7Iu=Q	Y!#zQ)q.BCC	B	Bz;
3GZ 00ABB8W-	j8Z0	[;0
RAq6Mr   N)Crypto.Util.numberr   Crypto.PublicKey.ECCr   r   r,    r   r   <module>r0      s    , 'Wr   