Your IP : 18.188.137.209


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

3

y�_5/�@sddlmZmZmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
ddlmZmZddlmZmZmZdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zeje�Gdd�de��Zeje�Gdd�de��Zejej�Gdd�de��Z ejej!�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�
serialization)�AsymmetricSignatureContext�AsymmetricVerificationContext�eccCst|tj�stdtj��dS)Nz/Unsupported elliptic curve signature algorithm.)�
isinstancerZECDSArrZ UNSUPPORTED_PUBLIC_KEY_ALGORITHM)�signature_algorithm�r�/usr/lib64/python3.6/ec.py�_check_signature_algorithmsrcCs�|jj|�}|j||jjk�|jj|�}||jjkr>td��|jjr^|jj	|�dkr^td��|jj
|�}|j||jjk�|jj|�jd�}|S)Nz;ECDSA keys with unnamed curves are unsupported at this timer�ascii)
�_lib�EC_KEY_get0_group�openssl_assert�_ffi�NULL�EC_GROUP_get_curve_nameZ	NID_undef�NotImplementedErrorZ$CRYPTOGRAPHY_OPENSSL_102U_OR_GREATERZEC_GROUP_get_asn1_flagZ
OBJ_nid2sn�string�decode)�backendZec_key�groupZnidZ
curve_name�snrrr�_ec_key_curve_sn"sr#cCs|jj||jj�dS)z�
    Set the named curve flag on the EC_KEY. This causes OpenSSL to
    serialize EC keys along with their curve OID which makes
    deserialization easier.
    N)rZEC_KEY_set_asn1_flagZOPENSSL_EC_NAMED_CURVE)r Zec_cdatarrr�_mark_asn1_named_ec_curve@sr$cCs8ytj|�Stk
r2tdj|�tj��YnXdS)Nz${} is not a supported elliptic curve)rZ_CURVE_TYPES�KeyErrorr�formatrZUNSUPPORTED_ELLIPTIC_CURVE)r r"rrr�_sn_to_elliptic_curveLsr'cCsz|jj|j�}|j|dk�|jjd|�}|jjdd�}|jjd|t|�|||j�}|j|dk�|jj|�d|d�S)Nrzunsigned char[]zunsigned int[]�)	rZ
ECDSA_size�_ec_keyrr�newZ
ECDSA_sign�len�buffer)r �private_key�dataZmax_sizeZsigbufZ
siglen_ptr�resrrr�_ecdsa_sig_signVsr0cCs8|jjd|t|�|t|�|j�}|dkr4|j�t�dS)Nrr()rZECDSA_verifyr+r)Z_consume_errorsr)r �
public_key�	signaturer.r/rrr�_ecdsa_sig_verifycs
r3c@s$eZdZdd�Zdd�Zdd�ZdS)�_ECDSASignatureContextcCs||_||_tj||�|_dS)N)�_backend�_private_keyr�Hash�_digest)�selfr r-�	algorithmrrr�__init__nsz_ECDSASignatureContext.__init__cCs|jj|�dS)N)r8�update)r9r.rrrr<ssz_ECDSASignatureContext.updatecCs|jj�}t|j|j|�S)N)r8�finalizer0r5r6)r9�digestrrrr=vs
z_ECDSASignatureContext.finalizeN)�__name__�
__module__�__qualname__r;r<r=rrrrr4lsr4c@s$eZdZdd�Zdd�Zdd�ZdS)�_ECDSAVerificationContextcCs$||_||_||_tj||�|_dS)N)r5�_public_key�
_signaturerr7r8)r9r r1r2r:rrrr;~sz"_ECDSAVerificationContext.__init__cCs|jj|�dS)N)r8r<)r9r.rrrr<�sz _ECDSAVerificationContext.updatecCs"|jj�}t|j|j|j|�dS)N)r8r=r3r5rCrD)r9r>rrr�verify�s
z _ECDSAVerificationContext.verifyN)r?r@rAr;r<rErrrrrB|srBc@sZeZdZdd�Zejd�Zedd��Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dd�ZdS)�_EllipticCurvePrivateKeycCs6||_||_||_t||�}t||�|_t||�dS)N)r5r)�	_evp_pkeyr#r'�_curver$)r9r �ec_key_cdata�evp_pkeyr"rrrr;�s
z!_EllipticCurvePrivateKey.__init__rHcCs|jjS)N)�curve�key_size)r9rrrrL�sz!_EllipticCurvePrivateKey.key_sizecCs(t�t|�t|j�t|j||j�S)N)rrr
r:r4r5)r9rrrr�signer�s

z_EllipticCurvePrivateKey.signercCs�|jj||j�stdtj��|jj|jjkr4td��|jjj	|j
�}|jjj|�dd}|jj|dk�|jj
jd|�}|jjj|j
�}|jjj||||j
|jj
j�}|jj|dk�|jj
j|�d|�S)Nz1This backend does not support the ECDH algorithm.z2peer_public_key and self are not on the same curve��rz	uint8_t[])r5Z+elliptic_curve_exchange_algorithm_supportedrKrrZUNSUPPORTED_EXCHANGE_ALGORITHM�name�
ValueErrorrrr)ZEC_GROUP_get_degreerrr*�EC_KEY_get0_public_keyZECDH_compute_keyrr,)r9r:Zpeer_public_keyr!Zz_lenZz_bufZpeer_key�rrrr�exchange�s$
z!_EllipticCurvePrivateKey.exchangecCs�|jjj|j�}|jj||jjjk�|jjj|�}|jj|�}|jjj	|j�}|jj||jjjk�|jjj
||�}|jj|dk�|jj|�}t|j||�S)Nr()
r5rrr)rrrrZ_ec_key_new_by_curve_nidrRZEC_KEY_set_public_keyZ_ec_cdata_to_evp_pkey�_EllipticCurvePublicKey)r9r!Z	curve_nidZ
public_ec_key�pointr/rJrrrr1�sz#_EllipticCurvePrivateKey.public_keycCs2|jjj|j�}|jj|�}tj||j�j�d�S)N)�
private_value�public_numbers)	r5rZEC_KEY_get0_private_keyr)�
_bn_to_intrZEllipticCurvePrivateNumbersr1rX)r9ZbnrWrrr�private_numbers�s
z(_EllipticCurvePrivateKey.private_numberscCs|jj|||||j|j�S)N)r5Z_private_key_bytesrGr))r9�encodingr&Zencryption_algorithmrrr�
private_bytes�sz&_EllipticCurvePrivateKey.private_bytescCs*t|�t|j||j�\}}t|j||�S)N)rr	r5�
_algorithmr0)r9r.rr:rrr�sign�sz_EllipticCurvePrivateKey.signN)r?r@rAr;r�read_only_propertyrK�propertyrLrMrTr1rZr\r^rrrrrF�s	

rFc@sReZdZdd�Zejd�Zedd��Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
dS)rUcCs6||_||_||_t||�}t||�|_t||�dS)N)r5r)rGr#r'rHr$)r9r rIrJr"rrrr;�s
z _EllipticCurvePublicKey.__init__rHcCs|jjS)N)rKrL)r9rrrrL�sz _EllipticCurvePublicKey.key_sizecCs6t�tjd|�t|�t|j�t|j|||j�S)Nr2)rr�_check_bytesrr
r:rBr5)r9r2rrrr�verifiers
z _EllipticCurvePublicKey.verifierc

Cs�|jj|j�\}}|jjj|j�}|jj||jjjk�|jj��Z}|jjj	|�}|jjj	|�}||||||�}|jj|dk�|jj
|�}|jj
|�}	WdQRXtj||	|j
d�S)Nr()�x�yrK)r5Z _ec_key_determine_group_get_funcr)rrRrrr�_tmp_bn_ctxZ
BN_CTX_getrYrZEllipticCurvePublicNumbersrH)
r9Zget_funcr!rV�bn_ctxZbn_xZbn_yr/rcrdrrrrXsz&_EllipticCurvePublicKey.public_numbersc	Cs|tjjkr|jjj}n|tjjks(t�|jjj}|jjj	|j
�}|jj||jjj
k�|jjj|j
�}|jj||jjj
k�|jj��l}|jjj||||jjj
d|�}|jj|dk�|jjjd|�}|jjj||||||�}|jj||k�WdQRX|jjj|�dd�S)Nrzchar[])r
�PublicFormat�CompressedPointr5rZPOINT_CONVERSION_COMPRESSED�UncompressedPoint�AssertionErrorZPOINT_CONVERSION_UNCOMPRESSEDrr)rrrrRreZEC_POINT_point2octr*r,)	r9r&Z
conversionr!rVrfZbuflenZbufr/rrr�
_encode_points"
z%_EllipticCurvePublicKey._encode_pointcCsp|tjjks$|tjjks$|tjjkrV|tjjk	sD|tjjtjjfkrLtd��|j|�S|jj	||||j
d�SdS)NzKX962 encoding must be used with CompressedPoint or UncompressedPoint format)r
ZEncodingZX962rgrhrirQrkr5Z_public_key_bytesrG)r9r[r&rrr�public_bytes6s
z$_EllipticCurvePublicKey.public_bytescCs0t|�t|j||j�\}}t|j|||�dS)N)rr	r5r]r3)r9r2r.rr:rrrrELsz_EllipticCurvePublicKey.verifyN)r?r@rAr;rr_rKr`rLrbrXrkrlrErrrrrU�s	

rUN)#Z
__future__rrrZcryptographyrZcryptography.exceptionsrrrZ*cryptography.hazmat.backends.openssl.utilsr	r
rZcryptography.hazmat.primitivesrr
Z)cryptography.hazmat.primitives.asymmetricrrrrr#r$r'r0r3Zregister_interface�objectr4rBZ(EllipticCurvePrivateKeyWithSerializationrFZ'EllipticCurvePublicKeyWithSerializationrUrrrr�<module>s&

	a

?>