ó Û_e[c@`sddlmZmZmZddlmZddlmZmZddl m Z ddl m Z d„Z d„Zeje jƒdefd „ƒYƒZd „Zd „Zeje jƒd efd „ƒYƒZeje jƒdefd„ƒYƒZdS(i(tabsolute_importtdivisiontprint_function(tutils(tUnsupportedAlgorithmt_Reasons(t serialization(tdhcC`sË|j}|j}|j|ƒ}|j||jkƒ|j||jƒ}|jrÇ|jdƒ}|j ||j||jƒ|j |dƒ}|j ||j||jƒ}|j|dkƒn|S(Ns BIGNUM **ii( t_libt_ffit DHparams_duptopenssl_asserttNULLtgctDH_freet"CRYPTOGRAPHY_OPENSSL_LESS_THAN_102tnewt DH_get0_pqgtBN_dupt DH_set0_pqg(tdh_cdatatbackendtlibtffit param_cdatatqtq_duptres((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt_dh_params_dup s   cC`st||ƒ}t||ƒS(N(Rt _DHParameters(RRR((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt_dh_cdata_to_parameterssRcB`s,eZd„Zd„Zd„Zd„ZRS(cC`s||_||_dS(N(t_backendt _dh_cdata(tselfRR((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt__init__&s cC`s|jjjdƒ}|jjjdƒ}|jjjdƒ}|jjj|j|||ƒ|jj|d|jjjkƒ|jj|d|jjjkƒ|d|jjjkrÆd}n|jj |dƒ}t j d|jj |dƒd|jj |dƒd|ƒS(Ns BIGNUM **itptgR( RR RRRR R R tNonet _bn_to_intRtDHParameterNumbers(R!R#R$Rtq_val((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pytparameter_numbers*s##  cC`s|jj|ƒS(N(Rtgenerate_dh_private_key(R!((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pytgenerate_private_key;scC`sÀ|tjjk r!tdƒ‚n|jjjs§|jjjdƒ}|jjj |j |jjj ||jjj ƒ|d|jjj kr§t dt jƒ‚q§n|jj|||j ƒS(Ns%Only PKCS3 serialization is supporteds BIGNUM **is'DH X9.42 serialization is not supported(RtParameterFormattPKCS3t ValueErrorRRtCryptography_HAS_EVP_PKEY_DHXR RRR R RRtUNSUPPORTED_SERIALIZATIONt_parameter_bytes(R!tencodingtformatR((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pytparameter_bytes>s"   (t__name__t __module__R"R)R+R4(((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyR$s   cC`s<|j}|j|dj|j|jƒƒtdƒ‚dS(Nis.Public key value is invalid for this exchange.(RR t_lib_reason_matcht ERR_LIB_DHtDH_R_INVALID_PUBKEYR.(terrorsRR((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt_handle_dh_compute_key_errorUs   cC`sh|jjdƒ}|jj|||jj|jjƒ|j|d|jjkƒ|jj|dƒS(Ns BIGNUM **i(R RRRR R t BN_num_bits(RRR#((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt_get_dh_num_bitsas   t _DHPrivateKeycB`sMeZd„Zed„ƒZd„Zd„Zd„Zd„Zd„Z RS(cC`s7||_||_||_|jjj|ƒ|_dS(N(RR t _evp_pkeyRtDH_sizet_key_size_bytes(R!RRtevp_pkey((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyR"ls   cC`st|j|jƒS(N(R=RR (R!((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pytkey_sizersc C`sè|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 j dt j dt jd|jj |dƒd|jj |dƒd|ƒd|jj |dƒƒd |jj |dƒƒS( Ns BIGNUM **itpublic_numbersR)R#R$Rtytx(RR RRRR R R R%R&t DH_get0_keyRtDHPrivateNumberstDHPublicNumbersR'(R!R#R$RR(tpub_keytpriv_key((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pytprivate_numbersvs,## ##    cC`s,|jjjd|jƒ}|jjjdƒ}|jjj|j||jjjƒ|jj|d|jjjkƒ|jjj ||d|jƒ}|dkrÅ|jj ƒ}t ||jƒS|jj|dkƒ|jjj |ƒ| }|jt |ƒ}|dkr$d||}n|SdS(Nsunsigned char[]s BIGNUM **iiÿÿÿÿit(RR RRARRGR R R tDH_compute_keyt_consume_errorsR;tbuffertlen(R!tpeer_public_keytbufRJRR:tkeytpad((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pytexchange’s$#    cC`s t|j|jƒ}|jjjdƒ}|jjj|j||jjjƒ|jj|d|jjjkƒ|jjj |dƒ}|jj||jjjkƒ|jjj |||jjjƒ}|jj|dkƒ|jj |ƒ}t |j||ƒS(Ns BIGNUM **ii( RR RR RRRGR R Rt DH_set0_keyt_dh_cdata_to_evp_pkeyt _DHPublicKey(R!RRJt pub_key_dupRRB((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt public_key­s#cC`st|j|jƒS(N(RR R(R!((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt parameters½scC`sÉ|tjjk r!tdƒ‚n|jjjs§|jjjdƒ}|jjj |j |jjj ||jjj ƒ|d|jjj kr§t dt jƒ‚q§n|jj||||j|j ƒS(Ns0DH private keys support only PKCS8 serializations BIGNUM **is'DH X9.42 serialization is not supported(Rt PrivateFormattPKCS8R.RRR/R RRR R RRR0t_private_key_bytesR?(R!R2R3tencryption_algorithmR((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt private_bytesÀs&   ( R5R6R"tpropertyRCRLRVR[R\Ra(((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyR>js     RYcB`s;eZd„Zed„ƒZd„Zd„Zd„ZRS(cC`s7||_||_||_t|j|jƒ|_dS(N(RR R?R=t_key_size_bits(R!RRRB((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyR"Ûs   cC`s|jS(N(Rc(R!((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyRCásc C`s—|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 j dt j d|jj |dƒd|jj |dƒd|ƒd|jj |dƒƒS(Ns BIGNUM **iR)R#R$RRE(RR RRRR R R R%R&RGRRIR'(R!R#R$RR(RJ((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyRDås&## #   cC`st|j|jƒS(N(RR R(R!((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyR\ýscC`sÆ|tjjk r!tdƒ‚n|jjjs§|jjjdƒ}|jjj |j |jjj ||jjj ƒ|d|jjj kr§t dt jƒ‚q§n|jj||||jdƒS(Ns>DH public keys support only SubjectPublicKeyInfo serializations BIGNUM **is'DH X9.42 serialization is not supported(Rt PublicFormattSubjectPublicKeyInfoR.RRR/R RRR R RRR0t_public_key_bytesR?R%(R!R2R3R((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyt public_bytess&   (R5R6R"RbRCRDR\Rg(((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyRYÙs    N(t __future__RRRt cryptographyRtcryptography.exceptionsRRtcryptography.hazmat.primitivesRt)cryptography.hazmat.primitives.asymmetricRRRtregister_interfacetDHParametersWithSerializationtobjectRR;R=tDHPrivateKeyWithSerializationR>tDHPublicKeyWithSerializationRY(((sO/tmp/pip-install-KP2Jbq/cryptography/cryptography/hazmat/backends/openssl/dh.pyts  0 n