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_sign.cpython-38.pyc
U

�֫[�%�@s�ddlmZmZmZddlmZddlmZm	Z	ddl
mZe	��Z
e	��dZe	��Ze	��Ze	��Ze	��Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�ZGdd�de�Zdd�Zdd�Z dd�Z!dS)�)�absolute_import�division�print_function)�
exceptions)�ffi�lib)�ensure�cCs`t�dt�}t�dt�}t�||�}t|dkdtjd�t�	|t�dd�t�	|t�dd�fS)zu
    Returns a randomly generated public key and secret key.

    :rtype: (bytes(public_key), bytes(secret_key))
    �unsigned char[]r�Unexpected library error�ZraisingN)
r�new�crypto_sign_PUBLICKEYBYTES�crypto_sign_SECRETKEYBYTESr�crypto_sign_keypairr�exc�RuntimeError�buffer)�pk�sk�rc�r�;/usr/lib/python3/dist-packages/nacl/bindings/crypto_sign.pyr!s��rcCsxt|�tkrt�d��t�dt�}t�dt�}t�	|||�}t
|dkdtjd�t�|t�dd�t�|t�dd�fS)z�
    Computes and returns the public key and secret key using the seed ``seed``.

    :param seed: bytes
    :rtype: (bytes(public_key), bytes(secret_key))
    zInvalid seedr
rrrN)
�len�crypto_sign_SEEDBYTESr�
ValueErrorrr
rrr�crypto_sign_seed_keypairrrr)Zseedrrrrrrr5s
��rcCs`t�dt|�t�}t�d�}t�|||t|�|�}t|dkdtjd�t�	||d�dd�S)z�
    Signs the message ``message`` using the secret key ``sk`` and returns the
    signed message.

    :param message: bytes
    :param sk: bytes
    :rtype: bytes
    r
�unsigned long long *rrrN)
rr
r�crypto_sign_BYTESr�crypto_signrrrr)�messager�signedZ
signed_lenrrrrrMs	
�rcCsVt�dt|��}t�d�}t�|||t|�|�dkr>t�d��t�||d�dd�S)z�
    Verifies the signature of the signed message ``signed`` using the public
    key ``pk`` and returns the unsigned message.

    :param signed: bytes
    :param pk: bytes
    :rtype: bytes
    r
rr�Signature was forged or corruptN)rr
rr�crypto_sign_openr�BadSignatureErrorr)r!rr Zmessage_lenrrrr#as	
��
r#cCsZt|�tkrt�d��t}t�d|�}t�||�}t	|dkdtj
d�t�||�dd�S)a
    Converts a public Ed25519 key (encoded as bytes ``public_key_bytes``) to
    a public Curve25519 key as bytes.

    Raises a ValueError if ``public_key_bytes`` is not of length
    ``crypto_sign_PUBLICKEYBYTES``

    :param public_key_bytes: bytes
    :rtype: bytes
    �Invalid curve public keyr
rrrN)rrrr�crypto_sign_curve25519_BYTESrr
r�$crypto_sign_ed25519_pk_to_curve25519rrr)Zpublic_key_bytesZcurve_public_key_lenZcurve_public_keyrrrrr'ts
��r'cCsZt|�tkrt�d��t}t�d|�}t�||�}t	|dkdtj
d�t�||�dd�S)a
    Converts a secret Ed25519 key (encoded as bytes ``secret_key_bytes``) to
    a secret Curve25519 key as bytes.

    Raises a ValueError if ``secret_key_bytes``is not of length
    ``crypto_sign_SECRETKEYBYTES``

    :param public_key_bytes: bytes
    :rtype: bytes
    r%r
rrrN)rrrrr&rr
r�$crypto_sign_ed25519_sk_to_curve25519rrr)Zsecret_key_bytesZcurve_secret_key_lenZcurve_secret_keyrrrrr(�s
��r(c@seZdZdZdgZdd�ZdS)�crypto_sign_ed25519ph_statezO
    State object wrapping the sha-512 state used in ed25519ph computation
    �statecCs2t�dt�|_t�|j�}t|dkdtjd�dS)Nr
rrr)	rr
� crypto_sign_ed25519ph_STATEBYTESr*rZcrypto_sign_ed25519ph_initrrr)�selfrrrr�__init__�s��z$crypto_sign_ed25519ph_state.__init__N)�__name__�
__module__�__qualname__�__doc__�	__slots__r-rrrrr)�sr)cCsXtt|t�dtjd�tt|t�dtjd�t�|j|t	|��}t|dkdtj
d�dS)z�
    Update the hash state wrapped in edph

    :param edph: the ed25519ph state being updated
    :type edph: crypto_sign_ed25519ph_state
    :param pmsg: the partial message
    :type pmsg: bytes
    :rtype: None
    �/edph parameter must be a ed25519ph_state objectrz%pmsg parameter must be a bytes objectrrN)r�
isinstancer)r�	TypeError�bytesr�crypto_sign_ed25519ph_updater*rr)�edphZpmsgrrrrr7�s 

�
���r7cCs�tt|t�dtjd�tt|t�dtjd�tt|�tkd�t�tjd�t	�
dt�}t�
|j|t	j|�}t|dkdtjd�t	�|t�dd�S)	aR
    Create a signature for the data hashed in edph
    using the secret key sk

    :param edph: the ed25519ph state for the data
                 being signed
    :type edph: crypto_sign_ed25519ph_state
    :param sk: the ed25519 secret part of the signing key
    :type sk: bytes
    :return: ed25519ph signature
    :rtype: bytes
    r3rz+secret key parameter must be a bytes objectz!secret key must be {0} bytes longr
rrN)rr4r)rr5r6rr�formatrr
rr�"crypto_sign_ed25519ph_final_creater*ZNULLrr)r8r�	signaturerrrrr:�s2
�
�����r:cCs�tt|t�dtjd�tt|t�dtjd�tt|�tkd�t�tjd�tt|t�dtjd�tt|�t	kd�t	�tjd�t
�|j||�}|dkr�t�
d��d	S)
a�
    Verify a prehashed signature using the public key pk

    :param edph: the ed25519ph state for the data
                 being verified
    :type edph: crypto_sign_ed25519ph_state
    :param signature: the signature being verified
    :type signature: bytes
    :param pk: the ed25519 public part of the signing key
    :type pk: bytes
    :return: True if the signature is valid
    :rtype: boolean
    :raises exc.BadSignatureError: if the signature is not valid
    r3rz*signature parameter must be a bytes objectz signature must be {0} bytes longz+public key parameter must be a bytes objectz!public key must be {0} bytes longrr"T)rr4r)rr5r6rrr9rr�"crypto_sign_ed25519ph_final_verifyr*r$)r8r;rrrrrr<�s>
�
���
����
r<N)"Z
__future__rrrZnaclrrZnacl._sodiumrrZnacl.exceptionsrZcrypto_sign_bytesrZcrypto_sign_secretkeybytesrZcrypto_sign_publickeybytesrrZcrypto_box_secretkeybytesr&Z crypto_sign_ed25519ph_statebytesr+rrrr#r'r(�objectr)r7r:r<rrrr�<module>s&$