
    9i"                     \    S SK rS SK JrJrJr  S SKJrJrJrJ	r	   " S S5      r
SS jrS rg)	    N)ceil_divbytes_to_longlong_to_bytes)DerSequenceDerNullDerOctetStringDerObjectIdc                   0    \ rS rSrSrS rS rS rS rSr	g)	PKCS115_SigScheme#   zvA signature object for ``RSASSA-PKCS1-v1_5``.
Do not instantiate directly.
Use :func:`Crypto.Signature.pkcs1_15.new`.
c                     Xl         g)zInitialize 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     Y/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/Crypto/Signature/pkcs1_15.py__init__PKCS115_SigScheme.__init__)   s	     	    c                 6    U R                   R                  5       $ )z<Return ``True`` if this object can be used to sign messages.)r   has_private)r   s    r   can_signPKCS115_SigScheme.can_sign3   s    yy$$&&r   c                    [         R                  R                  R                  U R                  R
                  5      n[        US5      n[        X5      n[        U5      nU R                  R                  U5      nU[        [        U5      U R                  R                  U R                  R
                  5      :w  a  [        S5      eU$ )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:`Crypto.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.
   z+Fault detected in RSA private key operation)CryptoUtilnumbersizer   nr   _EMSA_PKCS1_V1_5_ENCODEr   _decrypt_to_bytespowe
ValueError)r   msg_hashmodBitskemem_int	signatures          r   signPKCS115_SigScheme.sign7   s    $ ++$$))$))++6WQ %X1r"II//7	Sy1499;;		LLJKKr   c                 :   [         R                  R                  R                  U R                  R
                  5      n[        US5      n[        U5      U:w  a  [        S5      e[        U5      nU R                  R                  U5      n[        Xd5      n [        XS5      /n UR                  R                  S5      n	U	(       d  UR!                  [        XS5      5        Xx;  a  [        S5      eg! [         a    Sn	 NAf = f! [         a    [        S5      ef = f)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:`Crypto.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   lenr%   r   _encryptr   r!   oid
startswithAttributeErrorappend)
r   r&   r+   r'   r(   signature_intr*   em1possible_em1algorithm_is_mds
             r   verifyPKCS115_SigScheme.verifyW   s   ( ++$$))$))++6Wa  y>Q011%i0##M2F&	24X$GIL("*,,"9"9:M"N ###$;H$OP "011 " ("'(  	2011	2s0   D $C2 ?"D 2D>D  DD Dr   N)
__name__
__module____qualname____firstlineno____doc__r   r   r,   r9   __static_attributes__ r   r   r   r   #   s    
'@4r   r   c                    [        [        U R                  5      R                  5       /5      nU(       a'  UR	                  [        5       R                  5       5        [        U R                  5       5      n[        UR                  5       UR                  5       /5      R                  5       nU[        U5      S-   :  a  [        S[        U5      -  5      eSU[        U5      -
  S-
  -  nSU-   S-   U-   $ )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.
   z3DigestInfo is too long for this RSA key (%d bytes).      s        )
r   r	   r1   encoder4   r   r   digestr/   	TypeError)r&   emLenwith_hash_parameters
digestAlgorH   
digestInfoPSs          r   r!   r!      s    d {8<<8??ACDJ')**,- !23F%%'MMO  vx  S_RMPST^P__``	EC
O+a/	0Bg%
22r   c                     [        U 5      $ )af  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:`Crypto.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   newrP      s     W%%r   )T)Crypto.Util.numberr   r   r   r   Crypto.Util.asn1r   r   r   r	   r   r!   rP   rA   r   r   <module>rS      s/   >  E E N Nh hVB3H&r   