Your IP : 18.216.208.243


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__/dh.cpython-36.pyc

3

l�_�'�@s�ddlmZmZmZddlmZddlmZmZddl	m
Z
ddlmZdd�Z
dd	�Zejej�Gd
d�de��Zdd
�Zejej�Gdd�de��Zejej�Gdd�de��ZdS)�)�absolute_import�division�print_function)�utils)�UnsupportedAlgorithm�_Reasons)�
serialization)�dhcCs�|j}|j}|j|�}|j||jk�|j||j�}|jr�|jd�}|j	||j||j�|j
|d�}|j||j||j�}|j|dk�|S)Nz	BIGNUM **r�)�_lib�_ffiZDHparams_dup�openssl_assert�NULL�gcZDH_freeZCRYPTOGRAPHY_IS_LIBRESSL�new�DH_get0_pqg�BN_dupZDH_set0_pqg)�dh_cdata�backend�libZffi�param_cdata�qZq_dup�res�r�/usr/lib64/python3.6/dh.py�_dh_params_dup
s

rcCst||�}t||�S)N)r�
_DHParameters)rrrrrr�_dh_cdata_to_parameterss
rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
rcCs||_||_dS)N)�_backend�	_dh_cdata)�selfrrrrr�__init__&sz_DHParameters.__init__cCs�|jjjd�}|jjjd�}|jjjd�}|jjj|j|||�|jj|d|jjjk�|jj|d|jjjk�|d|jjjkr�d}n|jj|d�}t	j
|jj|d�|jj|d�|d�S)Nz	BIGNUM **r)�p�gr)rrrrrrr
r�
_bn_to_intr	�DHParameterNumbers)r r"r#r�q_valrrr�parameter_numbers*sz_DHParameters.parameter_numberscCs|jj|�S)N)rZgenerate_dh_private_key)r rrr�generate_private_key;sz"_DHParameters.generate_private_keycCs~|tjjk	rtd��|jjjsl|jjjd�}|jjj	|j
|jjj||jjj�|d|jjjkrltdt
j��|jj|||j
�S)Nz%Only PKCS3 serialization is supportedz	BIGNUM **rz'DH X9.42 serialization is not supported)rZParameterFormatZPKCS3�
ValueErrorrr�Cryptography_HAS_EVP_PKEY_DHXrrrrrrr�UNSUPPORTED_SERIALIZATIONZ_parameter_bytes)r �encoding�formatrrrr�parameter_bytes>s
z_DHParameters.parameter_bytesN)�__name__�
__module__�__qualname__r!r'r(r.rrrrr$srcCsL|jjd�}|jj|||jj|jj�|j|d|jjk�|jj|d�S)Nz	BIGNUM **r)rrrrrr
ZBN_num_bits)rrr"rrr�_get_dh_num_bitsRsr2c@sHeZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dS)�
_DHPrivateKeycCs&||_||_||_|jjj|�|_dS)N)rr�	_evp_pkeyrZDH_size�_key_size_bytes)r rr�evp_pkeyrrrr![sz_DHPrivateKey.__init__cCst|j|j�S)N)r2rr)r rrr�key_sizeasz_DHPrivateKey.key_sizecCsT|jjjd�}|jjjd�}|jjjd�}|jjj|j|||�|jj|d|jjjk�|jj|d|jjjk�|d|jjjkr�d}n|jj|d�}|jjjd�}|jjjd�}|jjj	|j||�|jj|d|jjjk�|jj|d|jjjk�t
jt
jt
j
|jj|d�|jj|d�|d�|jj|d�d�|jj|d�d�S)Nz	BIGNUM **r)r"r#r)r'�y)�public_numbers�x)rrrrrrr
rr$�DH_get0_keyr	ZDHPrivateNumbers�DHPublicNumbersr%)r r"r#rr&�pub_keyZpriv_keyrrr�private_numberses,z_DHPrivateKey.private_numberscCs�|jjjd|j�}|jjjd�}|jjj|j||jjj�|jj|d|jjjk�|jjj	||d|j�}|dkr�|jj
�}td|��nL|jj|dk�|jjj|�d|�}|jt
|�}|dkr�d||}|SdS)Nzunsigned char[]z	BIGNUM **rr
zKError computing shared key. Public key is likely invalid for this exchange.����)rrrr5rr;rrr
ZDH_compute_keyZ_consume_errors_with_textr)�buffer�len)r Zpeer_public_keyZbufr=rZerrors_with_text�keyZpadrrr�exchange�s$
z_DHPrivateKey.exchangecCs�t|j|j�}|jjjd�}|jjj|j||jjj�|jj|d|jjjk�|jjj	|d�}|jj||jjjk�|jjj
|||jjj�}|jj|dk�|jj|�}t|j||�S)Nz	BIGNUM **rr
)
rrrrrrr;rr
rZDH_set0_keyZ_dh_cdata_to_evp_pkey�_DHPublicKey)r rr=Zpub_key_duprr6rrr�
public_key�sz_DHPrivateKey.public_keycCst|j|j�S)N)rrr)r rrr�
parameters�sz_DHPrivateKey.parameterscCs�|tjjk	rtd��|jjjsl|jjjd�}|jjj	|j
|jjj||jjj�|d|jjjkrltdt
j��|jj|||||j|j
�S)Nz0DH private keys support only PKCS8 serializationz	BIGNUM **rz'DH X9.42 serialization is not supported)rZ
PrivateFormatZPKCS8r)rrr*rrrrrrrr+Z_private_key_bytesr4)r r,r-Zencryption_algorithmrrrr�
private_bytes�s*
z_DHPrivateKey.private_bytesN)r/r0r1r!�propertyr7r>rDrFrGrHrrrrr3Ysr3c@s8eZdZdd�Zedd��Zdd�Zdd�Zd	d
�ZdS)rEcCs&||_||_||_t|j|j�|_dS)N)rrr4r2�_key_size_bits)r rrr6rrrr!�sz_DHPublicKey.__init__cCs|jS)N)rJ)r rrrr7�sz_DHPublicKey.key_sizecCs|jjjd�}|jjjd�}|jjjd�}|jjj|j|||�|jj|d|jjjk�|jj|d|jjjk�|d|jjjkr�d}n|jj|d�}|jjjd�}|jjj	|j||jjj�|jj|d|jjjk�t
jt
j|jj|d�|jj|d�|d�|jj|d�d�S)Nz	BIGNUM **r)r"r#r)r'r8)
rrrrrrr
rr$r;r	r<r%)r r"r#rr&r=rrrr9�s&z_DHPublicKey.public_numberscCst|j|j�S)N)rrr)r rrrrG�sz_DHPublicKey.parameterscCs�|tjjk	rtd��|jjjsl|jjjd�}|jjj	|j
|jjj||jjj�|d|jjjkrltdt
j��|jj||||jd�S)Nz>DH public keys support only SubjectPublicKeyInfo serializationz	BIGNUM **rz'DH X9.42 serialization is not supported)rZPublicFormatZSubjectPublicKeyInfor)rrr*rrrrrrrr+Z_public_key_bytesr4)r r,r-rrrr�public_bytes�s 
z_DHPublicKey.public_bytesN)	r/r0r1r!rIr7r9rGrKrrrrrE�s
rEN)Z
__future__rrrZcryptographyrZcryptography.exceptionsrrZcryptography.hazmat.primitivesrZ)cryptography.hazmat.primitives.asymmetricr	rrZregister_interfaceZDHParametersWithSerialization�objectrr2ZDHPrivateKeyWithSerializationr3ZDHPublicKeyWithSerializationrErrrr�<module>s-v

?>