HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/nacl/bindings/__pycache__/crypto_box.cpython-38.pyc
U

�֫[�%�@s�ddlmZmZmZddlmZddlmZm	Z	ddl
mZddgZe	�
�Ze	��Ze	��Ze	��Ze	��Ze	��Ze	��Ze	��Zdd�Zdd	�Zd
d�Zdd�Z d
d�Z!dd�Z"dd�Z#dd�Z$dd�Z%dS)�)�absolute_import�division�print_function)�
exceptions)�ffi�lib)�ensure�crypto_box_keypair�
crypto_boxcCs`t�dt�}t�dt�}t�||�}t|dkdtjd�t�	|t�dd�t�	|t�dd�fS)zq
    Returns a randomly generated public and secret key.

    :rtype: (bytes(public_key), bytes(secret_key))
    �unsigned char[]r�Unexpected library error�ZraisingN)
r�new�crypto_box_PUBLICKEYBYTES�crypto_box_SECRETKEYBYTESrr	r�exc�RuntimeError�buffer)�pk�sk�rc�r�:/usr/lib/python3/dist-packages/nacl/bindings/crypto_box.pyr	#s��cCs�tt|t�dtd�t|�tkr*t�d��t�	dt
�}t�	dt�}t�
|||�}t|dkdtjd�t�|t
�dd�t�|t�dd�fS)a
    Returns a (public, secret) keypair deterministically generated
    from an input ``seed``.

    .. warning:: The seed **must** be high-entropy; therefore,
        its generator **must** be a cryptographic quality
        random function like, for example, :func:`~nacl.utils.random`.

    .. warning:: The seed **must** be protected and remain secret.
        Anyone who knows the seed is really in possession of
        the corresponding PrivateKey.


    :param seed: bytes
    :rtype: (bytes(public_key), bytes(secret_key))
    zseed must be bytesr
zInvalid seedrrrN)r�
isinstance�bytes�	TypeError�len�crypto_box_SEEDBYTESr�
ValueErrorrrrrr�crypto_box_seed_keypairrr)Zseedrrrrrrr7s 
�
��rcCs�t|�tkrt�d��t|�tkr,t�d��t|�tkrBt�d��dt|}t�dt|��}t	�
||t|�|||�}t|dkdtjd�t�
|t|��td	�S)
z�
    Encrypts and returns a message ``message`` using the secret key ``sk``,
    public key ``pk``, and the nonce ``nonce``.

    :param message: bytes
    :param nonce: bytes
    :param pk: bytes
    :param sk: bytes
    :rtype: bytes
    �Invalid nonce size�Invalid public key�Invalid secret key�rrrr
N)r�crypto_box_NONCEBYTESrrrr�crypto_box_ZEROBYTESrrrr
rrr�crypto_box_BOXZEROBYTES)�message�noncerr�padded�
ciphertextrrrrr
]s


�cCs�t|�tkrt�d��t|�tkr,t�d��t|�tkrBt�d��dt|}t�dt|��}t	�
||t|�|||�}t|dkdtjd�t�
|t|��td	�S)
a
    Decrypts and returns an encrypted message ``ciphertext``, using the secret
    key ``sk``, public key ``pk``, and the nonce ``nonce``.

    :param ciphertext: bytes
    :param nonce: bytes
    :param pk: bytes
    :param sk: bytes
    :rtype: bytes
    r r!r"r#rr�/An error occurred trying to decrypt the messager
N)rr$rrrrr&rrr�crypto_box_openr�CryptoErrorrr%)r*r(rrr)�	plaintext�resrrrr,|s



�r,cCsnt|�tkrt�d��t|�tkr,t�d��t�dt�}t�	|||�}t
|dkdtjd�t�|t�dd�S)a
    Computes and returns the shared key for the public key ``pk`` and the
    secret key ``sk``. This can be used to speed up operations where the same
    set of keys is going to be used multiple times.

    :param pk: bytes
    :param sk: bytes
    :rtype: bytes
    r!r"rrrr
N)
rrrrrrr�crypto_box_BEFORENMBYTESr�crypto_box_beforenmrrr)rr�krrrrr1�s


�r1cCs�t|�tkrt�d��t|�tkr,t�d��dt|}t�dt|��}t�	||t|�||�}t
|dkdtjd�t�|t|��t
d�S)	z�
    Encrypts and returns the message ``message`` using the shared key ``k`` and
    the nonce ``nonce``.

    :param message: bytes
    :param nonce: bytes
    :param k: bytes
    :rtype: bytes
    �
Invalid nonce�Invalid shared keyr#rrrr
N)rr$rrr0r%rrr�crypto_box_afternmrrrr&)r'r(r2r)r*rrrrr5�s


�r5cCs�t|�tkrt�d��t|�tkr,t�d��dt|}t�dt|��}t�	||t|�||�}t
|dkdtjd�t�|t|��t
d�S)	z�
    Decrypts and returns the encrypted message ``ciphertext``, using the shared
    key ``k`` and the nonce ``nonce``.

    :param ciphertext: bytes
    :param nonce: bytes
    :param k: bytes
    :rtype: bytes
    r3r4r#rrr+r
N)rr$rrr0r&rrr�crypto_box_open_afternmrr-rr%)r*r(r2r)r.r/rrrr6�s"


�
�r6cCs�tt|t�dtd�tt|t�dtd�t|�tkr>t�d��t|�}t|}t	�
d|�}t�||||�}t|dkdtj
d�t	�||�dd�S)	a�
    Encrypts and returns a message ``message`` using an ephemeral secret key
    and the public key ``pk``.
    The ephemeral public key, which is embedded in the sealed box, is also
    used, in combination with ``pk``, to derive the nonce needed for the
    underlying box construct.

    :param message: bytes
    :param pk: bytes
    :rtype: bytes

    .. versionadded:: 1.2
    zinput message must be bytesr
�public key must be bytesr!rrrN)rrrrrrrr�crypto_box_SEALBYTESrrr�crypto_box_sealrr)r'r�_mlen�_clenr*rrrrr9�s&
�
�
�r9cCs�tt|t�dtd�tt|t�dtd�tt|t�dtd�t|�tkrRt�d��t|�tkrht�d��t|�}|t	}t
�d|�}t�
|||||�}t|dkd	tjd�t
�||�d
d
�S)a�
    Decrypts and returns an encrypted message ``ciphertext``, using the
    recipent's secret key ``sk`` and the sender's ephemeral public key
    embedded in the sealed box. The box contruct nonce is derived from
    the recipient's public key ``pk`` and the sender's public key.

    :param ciphertext: bytes
    :param pk: bytes
    :param sk: bytes
    :rtype: bytes

    .. versionadded:: 1.2
    zinput ciphertext must be bytesr
r7zsecret key must be bytesr!r"rrr+N)rrrrrrrrrr8rrr�crypto_box_seal_openr-r)r*rrr;r:r.r/rrrr<s0
�
�
�


�r<N)&Z
__future__rrrZnaclrrZnacl._sodiumrrZnacl.exceptionsr�__all__Zcrypto_box_secretkeybytesrZcrypto_box_publickeybytesrZcrypto_box_seedbytesrZcrypto_box_noncebytesr$Zcrypto_box_zerobytesr%Zcrypto_box_boxzerobytesr&Zcrypto_box_beforenmbytesr0Zcrypto_box_sealbytesr8r	rr
r,r1r5r6r9r<rrrr�<module>s*&&