Submit
Path:
~
/
/
opt
/
alt
/
python37
/
lib64
/
python3.7
/
site-packages
/
Crypto
/
Signature
/
__pycache__
/
File Content:
PKCS1_PSS.cpython-37.pyc
B ��c�/ � @ s� d Z dZddgZddlT ejd dkr<ejd dkr<ddlT ddlZdd lm Z m Z mZ dd lm Z G dd� d�Zdd � Zdd� Zdd� Zddd�ZdS )a� RSA digital signature protocol with appendix according to PKCS#1 PSS. See RFC3447__ or the `original RSA Labs specification`__. This scheme is more properly called ``RSASSA-PSS``. For example, a sender may authenticate a message using SHA-1 and PSS like this: >>> from Crypto.Signature import PKCS1_PSS >>> from Crypto.Hash import SHA >>> from Crypto.PublicKey import RSA >>> from Crypto import Random >>> >>> message = 'To be signed' >>> key = RSA.importKey(open('privkey.der').read()) >>> h = SHA.new() >>> h.update(message) >>> signer = PKCS1_PSS.new(key) >>> signature = PKCS1_PSS.sign(key) At the receiver side, verification can be done like using the public part of the RSA key: >>> key = RSA.importKey(open('pubkey.der').read()) >>> h = SHA.new() >>> h.update(message) >>> verifier = PKCS1_PSS.new(key) >>> if verifier.verify(h, signature): >>> print "The signature is authentic." >>> else: >>> print "The signature is not authentic." :undocumented: __revision__, __package__ .. __: http://www.ietf.org/rfc/rfc3447.txt .. __: http://www.rsa.com/rsalabs/node.asp?id=2125 z$Id$�new� PSS_SigScheme� )�*� � N)� ceil_shift�ceil_div� long_to_bytes)�strxorc @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd S )r zKThis signature scheme can perform PKCS#1 PSS RSA signature or verification.c C s || _ || _|| _dS )a! Initialize this PKCS#1 PSS signature scheme object. :Parameters: key : an RSA key object If a private half is given, both signature and verification are possible. If a public half is given, only verification is possible. mgfunc : callable A mask generation function that accepts two parameters: a string to use as seed, and the lenth of the mask to generate, in bytes. saltLen : int Length of the salt, in bytes. N)�_key�_saltLen�_mgfunc)�self�key�mgfunc�saltLen� r �M/opt/alt/python37/lib64/python3.7/site-packages/Crypto/Signature/PKCS1_PSS.py�__init__O s zPSS_SigScheme.__init__c C s | j �� S )zCReturn True if this cipher object can be used for signing messages.)r Zhas_private)r r r r �can_sign` s zPSS_SigScheme.can_signc s� | j j}| jdkr� j}n| j}| jr.| j}n� fdd�}tjj�| j j �}t |d�}t� |d |||�}| j �|�}t d�|t|� | } | S )aB Produce the PKCS#1 PSS signature of a message. This function is named ``RSASSA-PSS-SIGN``, and is specified in section 8.1.1 of RFC3447. :Parameters: mhash : hash object The hash that was carried out over the message. This is an object belonging to the `Crypto.Hash` module. :Return: The PSS signature encoded as a string. :Raise ValueError: If the RSA key length is not sufficiently long to deal with the given hash algorithm. :Raise TypeError: If the RSA key has no private half. :attention: Modify the salt length and the mask generation function only if you know what you are doing. The receiver must use the same parameters too. Nc s t | |� �S )N)�MGF1)�x�y)�mhashr r �<lambda>� � z$PSS_SigScheme.sign.<locals>.<lambda>� r r )r Z _randfuncr �digest_sizer �Crypto�Util�number�size�nr �EMSA_PSS_ENCODEZdecrypt�bchr�len) r r Zrandfunc�sLen�mgf�modBits�k�em�m�Sr )r r �signd s zPSS_SigScheme.signc s� | j dkr� j}n| j }| jr&| j}n� fdd�}tjj�| jj�}t |d�}t |�|kr^dS | j�|d�d }t |d d�}td�|t |� | }yt � ||d ||�} W n tk r� dS X | S )a� Verify that a certain PKCS#1 PSS signature is authentic. This function checks if the party holding the private half of the given RSA key has really signed the message. This function is called ``RSASSA-PSS-VERIFY``, and is specified in section 8.1.2 of RFC3447. :Parameters: mhash : hash object The hash that was carried out over the message. This is an object belonging to the `Crypto.Hash` module. S : string The signature that needs to be validated. :Return: True if verification is correct. False otherwise. Nc s t | |� �S )N)r )r r )r r r r � r z&PSS_SigScheme.verify.<locals>.<lambda>r Fr r )r r r r r r r! r r"