o
    g5                     @   s&  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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   S/var/www/html/api-tag/env/lib/python3.10/site-packages/nacl/bindings/crypto_core.pyr   #   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   unsigned char[]r   Unexpected library errorN)r   r   r   r   r   r   r   r   formatr   r   newr   crypto_core_ed25519_addRuntimeErrorbufferr   r   rr   r   r   r   r   @   *   


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%   i   r$   r%   sc                 C   sx   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 )	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   r0      (   


r0   c                 C   r.   )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	   r/   r(   r   N)r   r   r   r   r   r   r   r(   r   r   r   r   r   crypto_core_ed25519_scalar_subr!   r1   r   r   r   r3   )  r2   r3   c                 C   r.   )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	   r/   r(   r   N)r   r   r   r   r   r   r   r(   r   r   r   r   r   crypto_core_ed25519_scalar_mulr!   r1   r   r   r   r4   R  r2   r4   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   r5   r   r   r   r   r(   r   !crypto_core_ed25519_scalar_reducer!   r,   r   r   r   r6   {  s    

	r6   N)naclr   r   nacl._sodiumr   r   nacl.exceptionsr   boolPYNACL_HAS_CRYPTO_CORE_ED25519r   r   r(   r5   crypto_core_ed25519_bytescrypto_core_ed25519_scalarbytes)crypto_core_ed25519_nonreducedscalarbytesr   r   r   r%   r)   r+   r-   r0   r3   r4   r6   r   r   r   r   <module>   s,   
))'#$)))