Your IP : 18.218.231.116


Current Path : /lib64/python3.6/site-packages/cryptography/hazmat/backends/openssl/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/cryptography/hazmat/backends/openssl/__pycache__/rsa.cpython-36.pyc

3

l�_�C�@s<ddlmZmZmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
ddlmZddlmZmZmZddlmZmZmZmZmZmZddlmZmZd	d
�Zdd�Zd
d�Z dd�Z!dd�Z"dd�Z#dd�Z$ej%e�Gdd�de&��Z'ej%e�Gdd�de&��Z(ej%e�Gdd�de&��Z)ej%e�Gdd�de&��Z*dS) �)�absolute_import�division�print_function)�utils)�InvalidSignature�UnsupportedAlgorithm�_Reasons)�_calculate_digest_and_algorithm�_check_not_prehashed�_warn_sign_verify_deprecated)�hashes)�AsymmetricSignatureContext�AsymmetricVerificationContext�rsa)�AsymmetricPadding�MGF1�OAEP�PKCS1v15�PSS�calculate_max_pss_salt_length)�RSAPrivateKeyWithSerialization�RSAPublicKeyWithSerializationcCs,|j}|tjks|tjkr$t||�S|SdS)N)Z_salt_lengthrZ
MAX_LENGTHrr)Zpss�keyZhash_algorithmZsalt�r�/usr/lib64/python3.6/rsa.py�_get_rsa_pss_salt_length&s
rcCs�t|t�std��t|t�r&|jj}nVt|t�rh|jj}t|jt	�sPt
dtj��|j
|�s|t
dtj��nt
dj|j�tj��t|||||�S)Nz1Padding must be an instance of AsymmetricPadding.z'Only MGF1 is supported by this backend.zPThis combination of padding and hash algorithm is not supported by this backend.z${} is not supported by this backend.)�
isinstancer�	TypeErrorr�_lib�RSA_PKCS1_PADDINGrZRSA_PKCS1_OAEP_PADDING�_mgfrrr�UNSUPPORTED_MGFZrsa_padding_supported�UNSUPPORTED_PADDING�format�name�_enc_dec_rsa_pkey_ctx)�backendr�data�padding�padding_enumrrr�_enc_dec_rsa/s$






r*cCst|t�r|jj}|jj}n|jj}|jj}|jj|j|j	j
�}|j||j	j
k�|j	j||jj
�}||�}|j|dk�|jj||�}|j|dk�|jj|j�}	|j|	dk�t|t�o�|jj�r|j|jj�}
|jj||
�}|j|dk�|j|j�}|jj||�}|j|dk�t|t��r�|jdk	�r�t|j�dk�r�|jjt|j��}|j||j	j
k�|j	j||jt|j��|jj||t|j��}|j|dk�|j	jd|	�}
|j	jd|	�}||||
|t|��}|j	j|�d|
d�}|jj�|dk�rtd��|S)N�rzsize_t *zunsigned char[]zEncryption/decryption failed.) r�
_RSAPublicKeyrZEVP_PKEY_encrypt_initZEVP_PKEY_encryptZEVP_PKEY_decrypt_initZEVP_PKEY_decrypt�EVP_PKEY_CTX_new�	_evp_pkey�_ffi�NULL�openssl_assert�gc�EVP_PKEY_CTX_free�EVP_PKEY_CTX_set_rsa_padding�
EVP_PKEY_sizerZCryptography_HAS_RSA_OAEP_MD�_evp_md_non_null_from_algorithmr �
_algorithm�EVP_PKEY_CTX_set_rsa_mgf1_mdZEVP_PKEY_CTX_set_rsa_oaep_mdZ_label�lenZOPENSSL_mallocZmemmoveZ EVP_PKEY_CTX_set0_rsa_oaep_label�new�bufferZERR_clear_error�
ValueError)r&rr'r)r(ZinitZcrypt�pkey_ctx�resZbuf_size�mgf1_mdZoaep_mdZlabelptrZoutlen�bufZresbufrrrr%NsN




r%cCs�t|t�std��|jj|j�}|j|dk�t|t�rB|jj}nZt|t	�r�t|j
t�sdtdt
j��||jddkr~td��|jj}ntdj|j�t
j��|S)Nz'Expected provider of AsymmetricPadding.rz'Only MGF1 is supported by this backend.�zDDigest too large for key size. Use a larger key or different digest.z${} is not supported by this backend.)rrrrr5r.r1rrrr rrrr!Zdigest_sizer<ZRSA_PKCS1_PSS_PADDINGr#r$r")r&rr(�	algorithmZ	pkey_sizer)rrr�_rsa_sig_determine_padding�s&





rCcCst||||�}|j|�}|jj|j|jj�}|j||jjk�|jj||jj	�}||�}	|j|	dk�|jj
||�}	|	dkr�|j�tdj
|j�tj��|jj||�}	|j|	dk�t|t��r|jj|t|||��}	|j|	dk�|j|jj�}
|jj||
�}	|j|	dk�|S)Nr+rz4{} is not supported by this backend for RSA signing.)rCr6rr-r.r/r0r1r2r3ZEVP_PKEY_CTX_set_signature_md�_consume_errorsrr#r$rZUNSUPPORTED_HASHr4rrZ EVP_PKEY_CTX_set_rsa_pss_saltlenrr r7r8)r&r(rBrr'Z	init_funcr)Zevp_mdr=r>r?rrr�_rsa_sig_setup�s2

rEc
Cs�t||||||jj�}|jjd�}|jj||jj||t|��}|j|dk�|jjd|d�}|jj||||t|��}|dkr�|j	�}	t
d|	��|jj|�dd�S)Nzsize_t *r+zunsigned char[]rzuDigest or salt length too long for key size. Use a larger key or shorter salt length if you are specifying a PSS salt)rErZEVP_PKEY_sign_initr/r:Z
EVP_PKEY_signr0r9r1�_consume_errors_with_textr<r;)
r&r(rB�private_keyr'r=Zbuflenr>r@�errorsrrr�
_rsa_sig_sign�s&
rIcCsXt||||||jj�}|jj||t|�|t|��}|j|dk�|dkrT|j�t�dS)Nr)rErZEVP_PKEY_verify_initZEVP_PKEY_verifyr9r1rDr)r&r(rB�
public_key�	signaturer'r=r>rrr�_rsa_sig_verify�s
rLc@s$eZdZdd�Zdd�Zdd�ZdS)�_RSASignatureContextcCs<||_||_t||||�||_||_tj|j|j�|_dS)N)�_backend�_private_keyrC�_paddingr7r�Hash�	_hash_ctx)�selfr&rGr(rBrrr�__init__�sz_RSASignatureContext.__init__cCs|jj|�dS)N)rR�update)rSr'rrrrUsz_RSASignatureContext.updatecCst|j|j|j|j|jj��S)N)rIrNrPr7rOrR�finalize)rSrrrrVsz_RSASignatureContext.finalizeN)�__name__�
__module__�__qualname__rTrUrVrrrrrM�srMc@s$eZdZdd�Zdd�Zdd�ZdS)�_RSAVerificationContextcCsF||_||_||_||_t||||�|}||_tj|j|j�|_dS)N)	rN�_public_key�
_signaturerPrCr7rrQrR)rSr&rJrKr(rBrrrrTsz _RSAVerificationContext.__init__cCs|jj|�dS)N)rRrU)rSr'rrrrU(sz_RSAVerificationContext.updatecCs"t|j|j|j|j|j|jj��S)N)rLrNrPr7r[r\rRrV)rSrrr�verify+sz_RSAVerificationContext.verifyN)rWrXrYrTrUr]rrrrrZsrZc@sNeZdZdd�Zejd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)�_RSAPrivateKeycCs�|jj|�}|dkr&|j�}td|��|jj||jj�}|j|dk�||_||_	||_
|jjjd�}|jjj|j	||jjj|jjj�|jj|d|jjjk�|jjj
|d�|_dS)Nr+zInvalid private keyz	BIGNUM **r)rZ
RSA_check_keyrFr<ZRSA_blinding_onr/r0r1rN�
_rsa_cdatar.r:�RSA_get0_key�BN_num_bits�	_key_size)rSr&�	rsa_cdata�evp_pkeyr>rH�nrrrrT8s"
z_RSAPrivateKey.__init__rbcCst�t|�t|j|||�S)N)rr
rMrN)rSr(rBrrr�signerSsz_RSAPrivateKey.signercCs2|jdd}|t|�kr"td��t|j|||�S)N��z,Ciphertext length must be equal to key size.)�key_sizer9r<r*rN)rSZ
ciphertextr(Zkey_size_bytesrrr�decryptXsz_RSAPrivateKey.decryptcCsV|jjj|j�}|jj||jjjk�|jjj||jjj�}|jj	|�}t
|j||�S)N)rNrZRSAPublicKey_dupr_r1r/r0r2ZRSA_freeZ_rsa_cdata_to_evp_pkeyr,)rSZctxrdrrrrJ_s
z_RSAPrivateKey.public_keyc	Cs|jjjd�}|jjjd�}|jjjd�}|jjjd�}|jjjd�}|jjjd�}|jjjd�}|jjjd�}|jjj|j|||�|jj|d|jjjk�|jj|d|jjjk�|jj|d|jjjk�|jjj|j||�|jj|d|jjjk�|jj|d|jjjk�|jjj	|j|||�|jj|d|jjjk�|jj|d|jjjk�|jj|d|jjjk�t
j|jj|d�|jj|d�|jj|d�|jj|d�|jj|d�|jj|d�t
j
|jj|d�|jj|d�d�d�S)Nz	BIGNUM **r)�ere)�p�q�d�dmp1�dmq1�iqmp�public_numbers)rNr/r:rr`r_r1r0ZRSA_get0_factorsZRSA_get0_crt_paramsrZRSAPrivateNumbers�
_bn_to_int�RSAPublicNumbers)	rSrerkrnrlrmrorprqrrr�private_numbersfs<z_RSAPrivateKey.private_numberscCs|jj|||||j|j�S)N)rNZ_private_key_bytesr.r_)rS�encodingr#Zencryption_algorithmrrr�
private_bytes�sz_RSAPrivateKey.private_bytescCs$t|j||�\}}t|j||||�S)N)r	rNrI)rSr'r(rBrrr�sign�sz_RSAPrivateKey.signN)
rWrXrYrTr�read_only_propertyrirfrjrJrurwrxrrrrr^6s
#
r^c@sFeZdZdd�Zejd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�ZdS)r,cCst||_||_||_|jjjd�}|jjj|j||jjj|jjj�|jj|d|jjjk�|jjj	|d�|_
dS)Nz	BIGNUM **r)rNr_r.r/r:rr`r0r1rarb)rSr&rcrdrerrrrT�sz_RSAPublicKey.__init__rbcCs,t�tjd|�t|�t|j||||�S)NrK)rr�_check_bytesr
rZrN)rSrKr(rBrrr�verifier�s
z_RSAPublicKey.verifiercCst|j|||�S)N)r*rN)rSZ	plaintextr(rrr�encrypt�sz_RSAPublicKey.encryptcCs�|jjjd�}|jjjd�}|jjj|j|||jjj�|jj|d|jjjk�|jj|d|jjjk�tj	|jj
|d�|jj
|d�d�S)Nz	BIGNUM **r)rkre)rNr/r:rr`r_r0r1rrtrs)rSrerkrrrrr�sz_RSAPublicKey.public_numberscCs|jj||||j|j�S)N)rNZ_public_key_bytesr.r_)rSrvr#rrr�public_bytes�sz_RSAPublicKey.public_bytescCs&t|j||�\}}t|j|||||�S)N)r	rNrL)rSrKr'r(rBrrrr]�sz_RSAPublicKey.verifyN)rWrXrYrTrryrir{r|rrr}r]rrrrr,�s
	
r,N)+Z
__future__rrrZcryptographyrZcryptography.exceptionsrrrZ*cryptography.hazmat.backends.openssl.utilsr	r
rZcryptography.hazmat.primitivesrZ)cryptography.hazmat.primitives.asymmetricr
rrZ1cryptography.hazmat.primitives.asymmetric.paddingrrrrrrZ-cryptography.hazmat.primitives.asymmetric.rsarrrr*r%rCrErIrLZregister_interface�objectrMrZr^r,rrrr�<module>s, 	;""c

?>