File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Signature/__pycache__/pss.cpython-310.pyc
Back
o ;jK5 � @ sz d dl mZmZmZ d dlZd dlmZmZmZ d dl m Z d dlmZ G dd� d�Zdd � Z d d� Zdd � Zdd� ZdS )� )�bchr�bord� iter_rangeN)�ceil_div� long_to_bytes� bytes_to_long)�strxor)�Randomc @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd S )� PSS_SigSchemezzA signature object for ``RSASSA-PSS``. Do not instantiate directly. Use :func:`Cryptodome.Signature.pss.new`. c C s || _ || _|| _|| _dS )at 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 : integer Length of the salt, in bytes. randfunc : callable A function that returns random bytes. N)�_key�_saltLen�_mgfunc� _randfunc)�self�keyZmgfuncZsaltLenZrandfunc� r �L/opt/saltstack/salt/lib/python3.10/site-packages/Cryptodome/Signature/pss.py�__init__/ s zPSS_SigScheme.__init__c C s | j �� S )z<Return ``True`` if this object can be used to sign messages.)r Zhas_private)r r r r �can_signF s zPSS_SigScheme.can_signc s� | j du r � j}n| j }| jdu r� fdd�}n| j}tjj�| jj�}t |d�}t � |d | j||�}t|�}| j� |�}|tt|�| jj| jj�krPtd��|S )a� Create the PKCS#1 PSS signature of a message. This function is also called ``RSASSA-PSS-SIGN`` and it is specified in `section 8.1.1 of RFC8017 <https://tools.ietf.org/html/rfc8017#section-8.1.1>`_. :parameter msg_hash: This is an object from the :mod:`Cryptodome.Hash` package. It has been used to digest the message to sign. :type msg_hash: hash object :return: the signature encoded as a *byte string*. :raise ValueError: if the RSA key is not long enough for the given hash algorithm. :raise TypeError: if the RSA key has no private half. Nc � t | |� �S �N��MGF1��x�y��msg_hashr r �<lambda>b � z$PSS_SigScheme.sign.<locals>.<lambda>� � z+Fault detected in RSA private key operation)r �digest_sizer � Cryptodome�Util�number�sizer �nr �_EMSA_PSS_ENCODEr r Z_decrypt_to_bytes�pow�e� ValueError) r r �sLen�mgf�modBits�k�em�em_int� signaturer r r �signJ s zPSS_SigScheme.signc s� | j du r � j}n| j }| jr| j}n� fdd�}tjj�| jj�}t |d�}t |�|kr1td��t|�}| j� |�}t |d d�} t|| �} t� | |d ||� dS )at Check if the PKCS#1 PSS signature over a message is valid. This function is also called ``RSASSA-PSS-VERIFY`` and it is specified in `section 8.1.2 of RFC8037 <https://tools.ietf.org/html/rfc8017#section-8.1.2>`_. :parameter msg_hash: The hash that was carried out over the message. This is an object belonging to the :mod:`Cryptodome.Hash` module. :type parameter: hash object :parameter signature: The signature that needs to be validated. :type signature: bytes :raise ValueError: if the signature is not valid. Nc r r r r r r r r � r z&PSS_SigScheme.verify.<locals>.<lambda>r �Incorrect signaturer! )r r"