o
    FDi:                     @   s8  d dl mZ d dlmZmZ d dlmZ eej	Z
d Zd Zd Ze
r-e Ze Ze ZdedefddZdedefd	d
ZdededefddZdededefddZdedefddZdedefddZdedefddZdededefddZdededefddZdededefddZdedefddZdS )     )
exceptions)ffilib)ensurepreturnc                 C   sD   t tdtjd t t| tot| tkdtjd t	
| }|dkS )a  
    Check if ``p`` represents a point on the edwards25519 curve, in canonical
    form, on the main subgroup, and that the point doesn't have a small order.

    :param p: a :py:data:`.crypto_core_ed25519_BYTES` long bytes sequence
              representing a point on the edwards25519 curve
    :type p: bytes
    :return: point validity
    :rtype: bool
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    Not available in minimal buildraisingz=Point must be a crypto_core_ed25519_BYTES long bytes sequence   )r   has_crypto_core_ed25519excUnavailableError
isinstancebyteslencrypto_core_ed25519_BYTES	TypeErrorr   "crypto_core_ed25519_is_valid_point)r   rc r   R/var/www/Datamplify/venv/lib/python3.10/site-packages/nacl/bindings/crypto_core.pyr   #   s   
r   rc                 C   x   t tdtjd t t| tot| tkddtj	d t
dt}t|| }t |dkdtjd t
|tdd S )	a  
    Maps a 32 bytes vector ``r`` to a point. The point is guaranteed to be on the main subgroup.
    This function directly exposes the Elligator 2 map, uses the high bit to set
    the sign of the X coordinate, and the resulting point is multiplied by the cofactor.

    :param r: a :py:data:`.crypto_core_ed25519_BYTES` long bytes
              sequence representing arbitrary data
    :type r: bytes
    :return: a point on the edwards25519 curve main order subgroup, represented as a
             :py:data:`.crypto_core_ed25519_BYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   z*Integer r must be a {} long bytes sequencer   unsigned char[]r   Unexpected library errorN)r   r   r   r   r   r   r   r   formatr   r   newr    crypto_core_ed25519_from_uniformRuntimeErrorbuffer)r   r   r   r   r   r   r   @   s    r   qc                 C      t tdtjd t t| tot|tot| tkot|tkddtj	d t
dt}t|| |}t |dkdtjd t
|tdd S )	aj  
    Add two points on the edwards25519 curve.

    :param p: a :py:data:`.crypto_core_ed25519_BYTES` long bytes sequence
              representing a point on the edwards25519 curve
    :type p: bytes
    :param q: a :py:data:`.crypto_core_ed25519_BYTES` long bytes sequence
              representing a point on the edwards25519 curve
    :type q: bytes
    :return: a point on the edwards25519 curve represented as
             a :py:data:`.crypto_core_ed25519_BYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   +Each point must be a {} long bytes sequencer   r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   crypto_core_ed25519_addr   r    r   r!   r   r   r   r   r   r$   e   *   


r$   c                 C   r"   )	ay  
    Subtract a point from another on the edwards25519 curve.

    :param p: a :py:data:`.crypto_core_ed25519_BYTES` long bytes sequence
              representing a point on the edwards25519 curve
    :type p: bytes
    :param q: a :py:data:`.crypto_core_ed25519_BYTES` long bytes sequence
              representing a point on the edwards25519 curve
    :type q: bytes
    :return: a point on the edwards25519 curve represented as
             a :py:data:`.crypto_core_ed25519_BYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   r#   r   r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   crypto_core_ed25519_subr   r    r%   r   r   r   r'      r&   r'   sc                 C   r   )	at  
    Return the multiplicative inverse of integer ``s`` modulo ``L``,
    i.e an integer ``i`` such that ``s * i = 1 (mod L)``, where ``L``
    is the order of the main subgroup.

    Raises a ``exc.RuntimeError`` if ``s`` is the integer zero.

    :param s: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type s: bytes
    :return: an integer represented as a
              :py:data:`.crypto_core_ed25519_SCALARBYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   *Integer s must be a {} long bytes sequencecrypto_core_ed25519_SCALARBYTESr   r   r   N)r   r   r   r   r   r   r   r*   r   r   r   r   r   !crypto_core_ed25519_scalar_invertr   r    )r(   r   r   r   r   r   r+      s    r+   c                 C   d   t tdtjd t t| tot| tkddtj	d t
dt}t||  t
|tdd S )a  
    Return the integer ``n`` such that ``s + n = 0 (mod L)``, where ``L``
    is the order of the main subgroup.

    :param s: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type s: bytes
    :return: an integer represented as a
              :py:data:`.crypto_core_ed25519_SCALARBYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   r)   r*   r   N)r   r   r   r   r   r   r   r*   r   r   r   r   r   !crypto_core_ed25519_scalar_negater    r(   r   r   r   r   r-      s   r-   c                 C   r,   )a(  
    Return the complement of integer ``s`` modulo ``L``, i.e. an integer
    ``c`` such that ``s + c = 1 (mod L)``, where ``L`` is the order of
    the main subgroup.

    :param s: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type s: bytes
    :return: an integer represented as a
              :py:data:`.crypto_core_ed25519_SCALARBYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   r)   r*   r   N)r   r   r   r   r   r   r   r*   r   r   r   r   r   %crypto_core_ed25519_scalar_complementr    r.   r   r   r   r/     s   r/   c                 C   |   t tdtjd t t| tot|tot| tkot|tkddtj	d t
dt}t|| | t
|tdd S )al  
    Add integers ``p`` and ``q`` modulo ``L``, where ``L`` is the order of
    the main subgroup.

    :param p: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type p: bytes
    :param q: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type q: bytes
    :return: an integer represented as a
              :py:data:`.crypto_core_ed25519_SCALARBYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   -Each integer must be a {} long bytes sequencer*   r   N)r   r   r   r   r   r   r   r*   r   r   r   r   r   crypto_core_ed25519_scalar_addr    r   r!   r   r   r   r   r2   %  (   


r2   c                 C   r0   )aq  
    Subtract integers ``p`` and ``q`` modulo ``L``, where ``L`` is the
    order of the main subgroup.

    :param p: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type p: bytes
    :param q: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type q: bytes
    :return: an integer represented as a
              :py:data:`.crypto_core_ed25519_SCALARBYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   r1   r*   r   N)r   r   r   r   r   r   r   r*   r   r   r   r   r   crypto_core_ed25519_scalar_subr    r3   r   r   r   r5   N  r4   r5   c                 C   r0   )aq  
    Multiply integers ``p`` and ``q`` modulo ``L``, where ``L`` is the
    order of the main subgroup.

    :param p: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type p: bytes
    :param q: a :py:data:`.crypto_core_ed25519_SCALARBYTES`
              long bytes sequence representing an integer
    :type q: bytes
    :return: an integer represented as a
              :py:data:`.crypto_core_ed25519_SCALARBYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   r1   r*   r   N)r   r   r   r   r   r   r   r*   r   r   r   r   r   crypto_core_ed25519_scalar_mulr    r3   r   r   r   r6   w  r4   r6   c                 C   sd   t tdtjd t t| tot| tkddtj	d t
dt}t||  t
|tdd S )a  
    Reduce integer ``s`` to ``s`` modulo ``L``, where ``L`` is the order
    of the main subgroup.

    :param s: a :py:data:`.crypto_core_ed25519_NONREDUCEDSCALARBYTES`
              long bytes sequence representing an integer
    :type s: bytes
    :return: an integer represented as a
              :py:data:`.crypto_core_ed25519_SCALARBYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    r   r	   r)   )crypto_core_ed25519_NONREDUCEDSCALARBYTESr   N)r   r   r   r   r   r   r   r7   r   r   r   r   r*   r   !crypto_core_ed25519_scalar_reducer    r.   r   r   r   r8     s    

	r8   N)naclr   r   nacl._sodiumr   r   nacl.exceptionsr   boolPYNACL_HAS_CRYPTO_CORE_ED25519r   r   r*   r7   crypto_core_ed25519_bytescrypto_core_ed25519_scalarbytes)crypto_core_ed25519_nonreducedscalarbytesr   r   r   r$   r'   r+   r-   r/   r2   r5   r6   r8   r   r   r   r   <module>   s.   
%))'#$)))