§
    8·tc."  ã                   ób   — d dl Zd dl mZmZmZ d dlmZmZmZm	Z	  G d„ d¦  «        Z
d	d„Zd„ ZdS )
é    N)Úceil_divÚbytes_to_longÚlong_to_bytes)ÚDerSequenceÚDerNullÚDerOctetStringÚDerObjectIdc                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚPKCS115_SigSchemez†A signature object for ``RSASSA-PKCS1-v1_5``.
    Do not instantiate directly.
    Use :func:`Cryptodome.Signature.pkcs1_15.new`.
    c                 ó   — || _         dS )a  Initialize this PKCS#1 v1.5 signature scheme object.

        :Parameters:
          rsa_key : an RSA key object
            Creation of signatures is only possible if this is a *private*
            RSA key. Verification of signatures is always possible.
        N)Ú_key)ÚselfÚrsa_keys     ú?/usr/lib/python3/dist-packages/Cryptodome/Signature/pkcs1_15.pyÚ__init__zPKCS115_SigScheme.__init__)   s   € ð ˆŒ	ˆ	ˆ	ó    c                 ó4   — | j                              ¦   «         S )z<Return ``True`` if this object can be used to sign messages.)r   Úhas_private)r   s    r   Úcan_signzPKCS115_SigScheme.can_sign3   s   € àŒy×$Ò$Ñ&Ô&Ð&r   c                 ó  — t           j        j                             | j        j        ¦  «        }t          |d¦  «        }t          ||¦  «        }t          |¦  «        }| j         	                    |¦  «        }t          ||¦  «        }|S )a„  Create the PKCS#1 v1.5 signature of a message.

        This function is also called ``RSASSA-PKCS1-V1_5-SIGN`` and
        it is specified in
        `section 8.2.1 of RFC8017 <https://tools.ietf.org/html/rfc8017#page-36>`_.

        :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.
        é   )Ú
CryptodomeÚUtilÚnumberÚsizer   Únr   Ú_EMSA_PKCS1_V1_5_ENCODEr   Ú_decryptr   )r   Úmsg_hashÚmodBitsÚkÚemÚem_intÚm_intÚ	signatures           r   ÚsignzPKCS115_SigScheme.sign7   sw   € õ$ ”/Ô(×-Ò-¨d¬i¬kÑ:Ô:ˆÝ�W˜QÑÔˆõ % X¨qÑ1Ô1ˆå˜rÑ"Ô"ˆà”	×"Ò" 6Ñ*Ô*ˆå! %¨Ñ+Ô+ˆ	ØÐr   c                 óh  — t           j        j                             | j        j        ¦  «        }t          |d¦  «        }t          |¦  «        |k    rt          d¦  «        ‚t          |¦  «        }| j         
                    |¦  «        }t          ||¦  «        }	 t          ||d¦  «        g}	 |j                             d¦  «        }	n# t          $ r d}	Y nw xY w|	s$|                     t          ||d¦  «        ¦  «         n# t          $ r t          d¦  «        ‚w xY w||vrt          d¦  «        ‚dS )a|  Check if the  PKCS#1 v1.5 signature over a message is valid.

        This function is also called ``RSASSA-PKCS1-V1_5-VERIFY`` and
        it is specified in
        `section 8.2.2 of RFC8037 <https://tools.ietf.org/html/rfc8017#page-37>`_.

        :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: byte string

        :raise ValueError: if the signature is not valid.
        r   zInvalid signatureTz1.2.840.113549.2.FN)r   r   r   r   r   r   r   ÚlenÚ
ValueErrorr   Ú_encryptr   r   ÚoidÚ
startswithÚAttributeErrorÚappend)
r   r   r%   r    r!   Úsignature_intr#   Úem1Úpossible_em1Úalgorithm_is_mds
             r   ÚverifyzPKCS115_SigScheme.verifyV   sR  € õ( ”/Ô(×-Ò-¨d¬i¬kÑ:Ô:ˆÝ�W˜aÑ Ô ˆõ ˆy‰>Œ>˜QÒÐÝÐ0Ñ1Ô1Ð1å% iÑ0Ô0ˆà”×#Ò# MÑ2Ô2ˆå˜F AÑ&Ô&ˆð	2Ý4°X¸qÀ$ÑGÔGÐIˆLð(Ø"*¤,×"9Ò"9Ð:MÑ"NÔ"N��øÝ!ð (ð (ð (Ø"'���ð(øøøà"ð QØ×#Ò#Õ$;¸HÀaÈÑ$OÔ$OÑPÔPÐPøøÝð 	2ð 	2ð 	2ÝÐ0Ñ1Ô1Ð1ð	2øøøð �lÐ"Ð"ÝÐ0Ñ1Ô1Ð1Øˆs0   ÂD Â.C	 ÃD Ã	CÃD ÃCÃ)D ÄDN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r&   r3   © r   r   r   r   #   sZ   € € € € € ðð ð
ð ð ð'ð 'ð 'ðð ð ð>4ð 4ð 4ð 4ð 4r   r   Tc                 óT  — t          t          | j        ¦  «                             ¦   «         g¦  «        }|r3|                     t          ¦   «                              ¦   «         ¦  «         t          |                      ¦   «         ¦  «        }t          |                     ¦   «         |                     ¦   «         g¦  «                             ¦   «         }|t          |¦  «        dz   k     rt          dt          |¦  «        z  ¦  «        ‚d|t          |¦  «        z
  dz
  z  }d|z   dz   |z   S )aè  
    Implement the ``EMSA-PKCS1-V1_5-ENCODE`` function, as defined
    in PKCS#1 v2.1 (RFC3447, 9.2).

    ``_EMSA-PKCS1-V1_5-ENCODE`` actually accepts the message ``M`` as input,
    and hash it internally. Here, we expect that the message has already
    been hashed instead.

    :Parameters:
     msg_hash : hash object
            The hash object that holds the digest of the message being signed.
     emLen : int
            The length the final encoding must have, in bytes.
     with_hash_parameters : bool
            If True (default), include NULL parameters for the hash
            algorithm in the ``digestAlgorithm`` SEQUENCE.

    :attention: the early standard (RFC2313) stated that ``DigestInfo``
        had to be BER-encoded. This means that old signatures
        might have length tags in indefinite form, which
        is not supported in DER. Such encoding cannot be
        reproduced by this function.

    :Return: An ``emLen`` byte long string that encodes the hash.
    é   z9Selected hash algorithm has a too long digest (%d bytes).ó   ÿé   s    ó    )
r   r	   r+   Úencoder.   r   r   Údigestr(   Ú	TypeError)r   ÚemLenÚwith_hash_parametersÚ
digestAlgor?   Ú
digestInfoÚPSs          r   r   r   �   s  € õd �{¨8¬<Ñ8Ô8×?Ò?ÑAÔAÐCÑDÔD€Jàð .Ø×Ò�'™)œ)×*Ò*Ñ,Ô,Ñ-Ô-Ð-å  §¢Ñ!2Ô!2Ñ3Ô3€FÝØ×%Ò%Ñ'Ô'Ø—M’M‘O”Oðñ ô ÷ ’v‘x”xð ð �S�‰_Œ_˜RÑÒÐÝÐSÕVYÐZ`ÑVaÔVaÑaÑbÔbÐbØ	�E�C 
™OœOÑ+¨aÑ/Ñ	0€BØ˜Ñ˜gÑ%¨
Ñ2Ð2r   c                 ó    — t          | ¦  «        S )aŠ  Create a signature object for creating
    or verifying PKCS#1 v1.5 signatures.

    :parameter rsa_key:
      The RSA key to use for signing or verifying the message.
      This is a :class:`Cryptodome.PublicKey.RSA` object.
      Signing is only possible when ``rsa_key`` is a **private** RSA key.
    :type rsa_key: RSA object

    :return: a :class:`PKCS115_SigScheme` signature object
    )r   )r   s    r   ÚnewrG   Ñ   s   € õ ˜WÑ%Ô%Ð%r   )T)ÚCryptodome.Util.numberr   r   r   r   ÚCryptodome.Util.asn1r   r   r   r	   r   r   rG   r8   r   r   ú<module>rJ      s¸   ðð> Ð Ð Ð Ø IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IÐ IØ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ RÐ Rðgð gð gð gð gñ gô gð gðTB3ð B3ð B3ð B3ðH&ð &ð &ð &ð &r   