
    i5                     l   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j                    Z ej                    Z ej                    ZdedefdZdededefdZdededefd	Zd
edefdZd
edefdZd
edefdZdededefdZdededefdZdededefdZd
edefdZdS )    )
exceptions)ffilib)ensurepreturnc                    t          t          dt          j                   t          t	          | t
                    ot          |           t          k    dt          j                   t          j
        |           }|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   rcs     Z/usr/local/lib/hermes-agent/venv/lib/python3.11/site-packages/nacl/bindings/crypto_core.pyr   r   #   s     ($    1eDQ+D!DG    
	/	2	2B7N    qc                 6   t          t          dt          j                   t          t	          | t
                    oDt	          |t
                    o/t          |           t          k    ot          |          t          k    d                    d          t          j	                   t          j        dt                    }t          j        || |          }t          |dk    dt          j                   t          j        |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   s       r   r!   r!   @        ($    1e 	0q%  	0FF//	0 FF//5<<'	
 	
 	 	 	 	 	!#<==A		$Q1	-	-B
27.8HIIII:a233AAA66r   c                 6   t          t          dt          j                   t          t	          | t
                    oDt	          |t
                    o/t          |           t          k    ot          |          t          k    d                    d          t          j	                   t          j        dt                    }t          j        || |          }t          |dk    dt          j                   t          j        |t                    dd         S )	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$   s       r   r(   r(   i   r&   r   sc                    t          t          dt          j                   t          t	          | t
                    ot          |           t          k    d                    d          t          j	                   t          j        dt                    }t          j        ||           }t          |dk    dt          j                   t          j        |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   s      r   r-   r-      s    " ($    1eJQ+J!J4;;-	
 	
     	!#BCCA		.q!	4	4B
27.8HIIII:a899!!!<<r   c                    t          t          dt          j                   t          t	          | t
                    ot          |           t          k    d                    d          t          j	                   t          j        dt                    }t          j        ||            t          j        |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%   s     r   r/   r/      s     ($    1eJQ+J!J4;;-	
 	
     	!#BCCA)!Q///:a899!!!<<r   c                    t          t          dt          j                   t          t	          | t
                    ot          |           t          k    d                    d          t          j	                   t          j        dt                    }t          j        ||            t          j        |t                    dd         S )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#   r0   s     r   r2   r2      s     ($    1eJQ+J!J4;;-	
 	
     	!#BCCA-a333:a899!!!<<r   c                    t          t          dt          j                   t          t	          | t
                    oDt	          |t
                    o/t          |           t          k    ot          |          t          k    d                    d          t          j	                   t          j        dt                    }t          j        || |           t          j        |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%   s      r   r5   r5          " ($    1e 	6q%  	6FF55	6 FF557>>-	
 	
 	 	 	 	 	!#BCCA&q!Q///:a899!!!<<r   c                    t          t          dt          j                   t          t	          | t
                    oDt	          |t
                    o/t          |           t          k    ot          |          t          k    d                    d          t          j	                   t          j        dt                    }t          j        || |           t          j        |t                    dd         S )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   r4   r,   r   N)r   r   r   r   r   r   r   r,   r   r   r   r    r   crypto_core_ed25519_scalar_subr#   r6   s      r   r9   r9   )  r7   r   c                    t          t          dt          j                   t          t	          | t
                    oDt	          |t
                    o/t          |           t          k    ot          |          t          k    d                    d          t          j	                   t          j        dt                    }t          j        || |           t          j        |t                    dd         S )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   r4   r,   r   N)r   r   r   r   r   r   r   r,   r   r   r   r    r   crypto_core_ed25519_scalar_mulr#   r6   s      r   r;   r;   R  r7   r   c                    t          t          dt          j                   t          t	          | t
                    ot          |           t          k    d                    d          t          j	                   t          j        dt                    }t          j        ||            t          j        |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   r=   r   r   r   r    r,   r   !crypto_core_ed25519_scalar_reducer#   r0   s     r   r>   r>   {  s     ($    1e 	@FF??4;;7	
 	
     	!#BCCA)!Q///:a899!!!<<r   N)naclr   r   nacl._sodiumr   r   nacl.exceptionsr   boolPYNACL_HAS_CRYPTO_CORE_ED25519r   r   r,   r=   crypto_core_ed25519_bytescrypto_core_ed25519_scalarbytes)crypto_core_ed25519_nonreducedscalarbytesr   r   r!   r(   r-   r/   r2   r5   r9   r;   r>    r   r   <module>rH      s0    # " " " " " ! ! ! ! ! ! ! ! " " " " " " $sABB  "# ,- )  = = ? ?&Ic&I&K&K#5577 .
% D    :&7u &7 &75 &7 &7 &7 &7R&7u &7 &75 &7 &7 &7 &7R$= $=5 $= $= $= $=N =  =5  =  =  =  =F!=U !=u != != != !=H&=e &= &=% &= &= &= &=R&=e &= &=% &= &= &= &=R&=e &= &=% &= &= &= &=R!= !=5 != != != != != !=r   