U
    Øcc4   ã                   @   sÚ   U d dl mZ d dlmZmZ d dlmZ eej	ƒZ
e ¡ Zeed< e ¡ Zeed< d Zd Ze
rpe ¡ Ze ¡ Zeedœdd„Zeeed	œd
d„Zeedœdd„Zeedœdd„Zeeed	œdd„Zeeed	œdd„ZdS )é    )Ú
exceptions)ÚffiÚlib)ÚensureÚcrypto_scalarmult_BYTESÚcrypto_scalarmult_SCALARBYTES)ÚnÚreturnc                 C   s@   t  dt¡}t || ¡}t|dkdtjd t  |t	¡dd… S )zŽ
    Computes and returns the scalar product of a standard group element and an
    integer ``n``.

    :param n: bytes
    :rtype: bytes
    úunsigned char[]r   úUnexpected library error©ZraisingN)
r   Únewr   r   Úcrypto_scalarmult_baser   ÚexcÚRuntimeErrorÚbufferr   ©r   ÚqÚrc© r   úC/tmp/pip-unpacked-wheel-e6sdgn5m/nacl/bindings/crypto_scalarmult.pyr   $   s    r   )r   Úpr	   c                 C   sB   t  dt¡}t || |¡}t|dkdtjd t  |t	¡dd… S )z¡
    Computes and returns the scalar product of the given group element and an
    integer ``n``.

    :param p: bytes
    :param n: bytes
    :rtype: bytes
    r
   r   r   r   N)
r   r   r   r   Úcrypto_scalarmultr   r   r   r   r   ©r   r   r   r   r   r   r   r   4   s    	r   c                 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 )	a  
    Computes and returns the scalar product of a standard group element and an
    integer ``n`` on the edwards25519 curve.

    :param n: a :py:data:`.crypto_scalarmult_ed25519_SCALARBYTES` long bytes
              sequence representing a scalar
    :type n: bytes
    :return: a point on the edwards25519 curve, represented as a
             :py:data:`.crypto_scalarmult_ed25519_BYTES` long bytes sequence
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.
    úNot available in minimal buildr   ú&Input must be a {} long bytes sequenceÚ%crypto_scalarmult_ed25519_SCALARBYTESr
   r   r   N)r   Úhas_crypto_scalarmult_ed25519r   ÚUnavailableErrorÚ
isinstanceÚbytesÚlenr   ÚformatÚ	TypeErrorr   r   Úcrypto_scalarmult_ed25519_BYTESr   Úcrypto_scalarmult_ed25519_baser   r   r   r   r   r   r%   E   s"    ý

ÿú	r%   c                 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 )	a:  
    Computes and returns the scalar product of a standard group element and an
    integer ``n`` on the edwards25519 curve. The integer ``n`` is not clamped.

    :param n: a :py:data:`.crypto_scalarmult_ed25519_SCALARBYTES` long bytes
              sequence representing a scalar
    :type n: bytes
    :return: a point on the edwards25519 curve, represented as a
             :py:data:`.crypto_scalarmult_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$   r   Ú&crypto_scalarmult_ed25519_base_noclampr   r   r   r   r   r   r&   j   s"    ý

ÿú	r&   c                 C   s¢   t tdtjd t t| tƒo&t| ƒtkd d¡tj	d t t|tƒoNt|ƒt
kd d¡tj	d t dt
¡}t || |¡}t |dkdtjd t |t
¡d	d	… S )
aq  
    Computes and returns the scalar product of a *clamped* integer ``n``
    and the given group element on the edwards25519 curve.
    The scalar is clamped, as done in the public key generation case,
    by setting to zero the bits in position [0, 1, 2, 255] and setting
    to one the bit in position 254.

    :param n: a :py:data:`.crypto_scalarmult_ed25519_SCALARBYTES` long bytes
              sequence representing a scalar
    :type n: bytes
    :param p: a :py:data:`.crypto_scalarmult_ed25519_BYTES` long bytes sequence
              representing a point on the edwards25519 curve
    :type p: bytes
    :return: a point on the edwards25519 curve, represented as a
             :py:data:`.crypto_scalarmult_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   r   N)r   r   r   r   r   r    r!   r   r"   r#   r$   r   r   r   Úcrypto_scalarmult_ed25519r   r   r   r   r   r   r'      s0    ý

ÿú	ÿûr'   c                 C   s¢   t tdtjd t t| tƒo&t| ƒtkd d¡tj	d t t|tƒoNt|ƒt
kd d¡tj	d t dt
¡}t || |¡}t |dkdtjd t |t
¡d	d	… S )
aÝ  
    Computes and returns the scalar product of an integer ``n``
    and the given group element on the edwards25519 curve. The integer
    ``n`` is not clamped.

    :param n: a :py:data:`.crypto_scalarmult_ed25519_SCALARBYTES` long bytes
              sequence representing a scalar
    :type n: bytes
    :param p: a :py:data:`.crypto_scalarmult_ed25519_BYTES` long bytes sequence
              representing a point on the edwards25519 curve
    :type p: bytes
    :return: a point on the edwards25519 curve, represented as a
             :py:data:`.crypto_scalarmult_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   r   N)r   r   r   r   r   r    r!   r   r"   r#   r$   r   r   r   Ú!crypto_scalarmult_ed25519_noclampr   r   r   r   r   r   r(   Â   s0    ý

ÿú	ÿûr(   N)Znaclr   r   Znacl._sodiumr   r   Znacl.exceptionsr   ÚboolZ$PYNACL_HAS_CRYPTO_SCALARMULT_ED25519r   Zcrypto_scalarmult_bytesr   ÚintÚ__annotations__Zcrypto_scalarmult_scalarbytesr   r$   r   Zcrypto_scalarmult_ed25519_bytesZ%crypto_scalarmult_ed25519_scalarbytesr    r   r   r%   r&   r'   r(   r   r   r   r   Ú<module>   s$    
ÿ%%3