OwlCyberSecurity - MANAGER
Edit File: crypto_sign.cpython-38.pyc
U �֫[�% � @ s� d dl mZmZmZ d dlmZ d dlmZm Z d dl mZ e �� Z e �� d Ze �� Ze �� Ze �� Ze �� Zdd� Zdd � Zd d� Zdd � Zdd� Zdd� ZG dd� de�Zdd� Zdd� Z dd� Z!dS )� )�absolute_import�division�print_function)� exceptions)�ffi�lib)�ensure� c C s` 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 ��r c C sx t | �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)) zInvalid seedr r r r N) �len�crypto_sign_SEEDBYTESr � ValueErrorr r r r r �crypto_sign_seed_keypairr r r )Zseedr r r r r r r 5 s ��r c C s` 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 *r r r N) r r r �crypto_sign_BYTESr �crypto_signr r r r )�messager �signedZ signed_lenr r r r r M s �r c C sV t �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 r r �Signature was forged or corruptN)r r r r �crypto_sign_openr �BadSignatureErrorr )r! r r Zmessage_lenr r r r# a s �� r# c C sZ t | �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 r r r N)r r r r �crypto_sign_curve25519_BYTESr r r �$crypto_sign_ed25519_pk_to_curve25519r r r )Zpublic_key_bytesZcurve_public_key_lenZcurve_public_keyr r r r r'