
    9ih!                         S SK Jr  S SKrS SKJr  S SKrS SKJrJrJ	r	  S SK
Jr  S SKJr  SSKJr   " S	 S
5      rSS jrg)    )MGF1N)_copy_bytes)ceil_divbytes_to_longlong_to_bytes)strxor)Random   )oaep_decodec                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
PKCS1OAEP_Cipher"   zTCipher object for PKCS#1 v1.5 OAEP.
Do not create directly: use :func:`new` instead.c                    ^  UT l         U(       a  UT l        O[        R                  R                  T l        U(       a  UT l        OU 4S jT l        [        SSU5      T l        UT l        g)a]  Initialize this PKCS#1 OAEP cipher object.

:Parameters:
 key : an RSA key object
        If a private half is given, both encryption and decryption are possible.
        If a public half is given, only encryption is possible.
 hashAlgo : hash object
        The hash function to use. This can be a module under `Crypto.Hash`
        or an existing hash object created from any of such modules. If not specified,
        `Crypto.Hash.SHA1` is used.
 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.
        If not specified, the standard MGF1 consistent with ``hashAlgo`` is used (a safe choice).
 label : bytes/bytearray/memoryview
        A label to apply to this particular encryption. If not specified,
        an empty string is used. Specifying a label does not improve
        security.
 randfunc : callable
        A function that returns random bytes.

:attention: Modify the mask generation function only if you know what you are doing.
            Sender and receiver must use the same one.
c                 0   > [        XTR                  5      $ )N)r   _hashObj)xyselfs     X/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/Crypto/Cipher/PKCS1_OAEP.py<lambda>+PKCS1OAEP_Cipher.__init__.<locals>.<lambda>I   s    T!%>    N)	_keyr   CryptoHashSHA1_mgfr   _label	_randfunc)r   keyhashAlgomgfunclabelrandfuncs   `     r   __init__PKCS1OAEP_Cipher.__init__&   sO    2 	$DM"KK,,DMDI>DI!$e4!r   c                 6    U R                   R                  5       $ )zNLegacy function to check if you can call :meth:`encrypt`.

.. deprecated:: 3.0)r   can_encryptr   s    r   r(   PKCS1OAEP_Cipher.can_encryptN        yy$$&&r   c                 6    U R                   R                  5       $ )zNLegacy function to check if you can call :meth:`decrypt`.

.. deprecated:: 3.0)r   can_decryptr)   s    r   r-   PKCS1OAEP_Cipher.can_decryptT   r+   r   c                    [         R                  R                  R                  U R                  R
                  5      n[        US5      nU R                  R                  n[        U5      nX5-
  SU-  -
  S-
  nUS:  a  [        S5      eU R                  R                  U R                  5      R                  5       nSU-  nXx-   S-   [        SSU5      -   n	U R                  U5      n
U R!                  XU-
  S-
  5      n[#        X5      nU R!                  X5      n[#        X5      nSU-   U-   n[%        U5      nU R                  R'                  U5      n[)        UU5      nU$ )	a  Encrypt a message with PKCS#1 OAEP.

:param message:
    The message to encrypt, also known as plaintext. It can be of
    variable length, but not longer than the RSA modulus (in bytes)
    minus 2, minus twice the hash output size.
    For instance, if you use RSA 2048 and SHA-256, the longest message
    you can encrypt is 190 byte long.
:type message: bytes/bytearray/memoryview

:returns: The ciphertext, as large as the RSA modulus.
:rtype: bytes

:raises ValueError:
    if the message is too long.
      r   zPlaintext is too long.       Nr
   )r   Utilnumbersizer   nr   r   digest_sizelen
ValueErrornewr   digestr   r   r   r   r   _encryptr   )r   messagemodBitskhLenmLenps_lenlHashpsdbrosdbMaskmaskedDBseedMask
maskedSeedemem_intm_intcs                      r   encryptPKCS1OAEP_Cipher.encryptZ   s=   & ++$$))$))++6Wa }}((7| AH$q(A:566!!$++.557vZ'!KdG$DDnnT"3$q)"%99X,C*
z!H,r"		""6*%#r   c                    [         R                  R                  R                  U R                  R
                  5      n[        US5      nU R                  R                  n[        U5      U:w  d  X4S-   :  a  [        S5      e[        U5      nU R                  R                  U5      nU R                  R                  U R                  5      R                  5       nUSUS-    nXdS-   S n	U R!                  X5      n
[#        X5      nU R!                  XU-
  S-
  5      n[#        X5      n[%        XgU5      nUS::  a  [        S5      eXS $ )a  Decrypt a message with PKCS#1 OAEP.

:param ciphertext: The encrypted message.
:type ciphertext: bytes/bytearray/memoryview

:returns: The original message (plaintext).
:rtype: bytes

:raises ValueError:
    if the ciphertext has the wrong length, or if decryption
    fails the integrity check (in which case, the decryption
    key is probably wrong).
:raises TypeError:
    if the RSA key has no private half (i.e. you are trying
    to decrypt using a public key).
r0   r1   z!Ciphertext with incorrect length.r
   Nr   zIncorrect decryption.)r   r4   r5   r6   r   r7   r   r   r8   r9   r:   r   _decrypt_to_bytesr;   r   r<   r   r   r   )r   
ciphertextr?   r@   rA   ct_intrL   rD   rK   rI   rJ   seedrH   rF   ress                  r   decryptPKCS1OAEP_Cipher.decrypt   s    & ++$$))$))++6Wa }}(( z?a1Av:@AAz*YY((0!!$++.557 $q&\
1fg;99X,j+44*H%"R(!8455$xr   )r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r%   r(   r-   rP   rX   __static_attributes__ r   r   r   r   "   s"    8&"P''4l1r   r   c                 B    Uc  [         R                  n[        XX#U5      $ )a>  Return a cipher object :class:`PKCS1OAEP_Cipher`
   that can be used to perform PKCS#1 OAEP encryption or decryption.

:param key:
  The key object to use to encrypt or decrypt the message.
  Decryption is only possible with a private RSA key.
:type key: RSA key object

:param hashAlgo:
  The hash function to use. This can be a module under `Crypto.Hash`
  or an existing hash object created from any of such modules.
  If not specified, `Crypto.Hash.SHA1` is used.
:type hashAlgo: hash object

:param mgfunc:
  A mask generation function that accepts two parameters: a string to
  use as seed, and the lenth of the mask to generate, in bytes.
  If not specified, the standard MGF1 consistent with ``hashAlgo`` is used (a safe choice).
:type mgfunc: callable

:param label:
  A label to apply to this particular encryption. If not specified,
  an empty string is used. Specifying a label does not improve
  security.
:type label: bytes/bytearray/memoryview

:param randfunc:
  A function that returns random bytes.
  The default is `Random.get_random_bytes`.
:type randfunc: callable
)r	   get_random_bytesr   )r    r!   r"   r#   r$   s        r   r;   r;      s%    B **C6(CCr   )NNr   N)Crypto.Signature.pssr   Crypto.Hash.SHA1r   Crypto.Util.py3compatr   Crypto.Util.numberr   r   r   Crypto.Util.strxorr   r	   _pkcs1_oaep_decoder   r   r;   r`   r   r   <module>ri      s5   . &  -  E E %  +_ _D#Dr   