3 l_4'@sddlmZmZmZddlmZddlmZddlm Z m Z m Z ddl m Z ddlmZmZmZddZd d ZejeGd d d eZejeGd ddeZejejGdddeZejejGdddeZejejGdddeZdS))absolute_importdivisionprint_function)utils)InvalidSignature)_calculate_digest_and_algorithm_check_not_prehashed_warn_sign_verify_deprecated)hashes)AsymmetricSignatureContextAsymmetricVerificationContextdsacCsx|jj|j}|jjd|}|jjd}|jjd|t||||j}|j|dk|j|d|jj|d|dS)Nzunsigned char[]zunsigned int *r) _libZDSA_size _dsa_cdata_ffinewZDSA_signlenopenssl_assertbuffer)backend private_keydataZ sig_buf_lenZsig_bufZbuflenresr/usr/lib64/python3.6/dsa.py _dsa_sig_signs rcCs8|jjd|t||t||j}|dkr4|jtdS)Nrr)rZ DSA_verifyrrZ_consume_errorsr)r public_key signaturerrrrr_dsa_sig_verify&s rc@s$eZdZddZddZddZdS)_DSAVerificationContextcCs.||_||_||_||_tj|j|j|_dS)N)_backend _public_key _signature _algorithmr Hash _hash_ctx)selfrrr algorithmrrr__init__4s z _DSAVerificationContext.__init__cCs|jj|dS)N)r&update)r'rrrrr*<sz_DSAVerificationContext.updatecCs"|jj}t|j|j|j|dS)N)r&finalizerr!r"r#)r'Zdata_to_verifyrrrverify?s z_DSAVerificationContext.verifyN)__name__ __module__ __qualname__r)r*r,rrrrr 2sr c@s$eZdZddZddZddZdS)_DSASignatureContextcCs(||_||_||_tj|j|j|_dS)N)r! _private_keyr$r r%r&)r'rrr(rrrr)Isz_DSASignatureContext.__init__cCs|jj|dS)N)r&r*)r'rrrrr*Osz_DSASignatureContext.updatecCs|jj}t|j|j|S)N)r&r+rr!r1)r'Z data_to_signrrrr+Rs z_DSASignatureContext.finalizeN)r-r.r/r)r*r+rrrrr0Gsr0c@s$eZdZddZddZddZdS)_DSAParameterscCs||_||_dS)N)r!r)r'r dsa_cdatarrrr)Ysz_DSAParameters.__init__cCs|jjjd}|jjjd}|jjjd}|jjj|j||||jj|d|jjjk|jj|d|jjjk|jj|d|jjjktj |jj |d|jj |d|jj |ddS)Nz BIGNUM **r)pqg) r!rrr DSA_get0_pqgrrNULLr DSAParameterNumbers _bn_to_int)r'r4r5r6rrrparameter_numbers]sz _DSAParameters.parameter_numberscCs |jj|S)N)r!Zgenerate_dsa_private_key)r'rrrgenerate_private_keyksz#_DSAParameters.generate_private_keyN)r-r.r/r)r;r<rrrrr2Wsr2c@sNeZdZddZejdZddZddZdd Z d d Z d d Z ddZ dS)_DSAPrivateKeycCsp||_||_||_|jjjd}|jjj|||jjj|jjj|jj|d|jjk|jjj |d|_ dS)Nz BIGNUM **r) r!r _evp_pkeyrrrr7r8r BN_num_bits _key_size)r'rr3evp_pkeyr4rrrr)qsz_DSAPrivateKey.__init__r@cCstt|t|j||S)N)r rr0r!)r'signature_algorithmrrrsignersz_DSAPrivateKey.signercCsR|jjjd}|jjjd}|jjjd}|jjjd}|jjjd}|jjj|j||||jj|d|jjjk|jj|d|jjjk|jj|d|jjjk|jjj|j|||jj|d|jjjk|jj|d|jjjkt j t j t j |jj |d|jj |d|jj |dd|jj |dd|jj |ddS)Nz BIGNUM **r)r4r5r6)r;y)public_numbersx)r!rrrr7rrr8 DSA_get0_keyr ZDSAPrivateNumbersDSAPublicNumbersr9r:)r'r4r5r6pub_keyZpriv_keyrrrprivate_numberss(z_DSAPrivateKey.private_numberscCs|jjj|j}|jj||jjjk|jjj||jjj}|jjj d}|jjj |j||jjj|jj|d|jjjk|jjj |d}|jjj |||jjj}|jj|dk|jj |}t|j||S)Nz BIGNUM **rr)r!r DSAparams_duprrrr8gcDSA_freerrGZBN_dupZ DSA_set0_keyZ_dsa_cdata_to_evp_pkey _DSAPublicKey)r'r3rIZ pub_key_duprrArrrrs z_DSAPrivateKey.public_keycCsH|jjj|j}|jj||jjjk|jjj||jjj}t |j|S)N) r!rrKrrrr8rLrMr2)r'r3rrr parameterss z_DSAPrivateKey.parameterscCs|jj|||||j|jS)N)r!Z_private_key_bytesr>r)r'encodingformatZencryption_algorithmrrr private_bytessz_DSAPrivateKey.private_bytescCs t|j||\}}t|j||S)N)rr!r)r'rr(rrrsignsz_DSAPrivateKey.signN) r-r.r/r)rread_only_propertykey_sizerCrJrrOrRrSrrrrr=os  r=c@sFeZdZddZejdZddZddZdd Z d d Z d d Z dS)rNcCsp||_||_||_|jjjd}|jjj|||jjj|jjj|jj|d|jjk|jjj |d|_ dS)Nz BIGNUM **r) r!rr>rrrr7r8rr?r@)r'rr3rAr4rrrr)sz_DSAPublicKey.__init__r@cCs*ttjd|t|t|j|||S)Nr)r r _check_bytesrr r!)r'rrBrrrverifiers  z_DSAPublicKey.verifiercCs|jjjd}|jjjd}|jjjd}|jjjd}|jjj|j||||jj|d|jjjk|jj|d|jjjk|jj|d|jjjk|jjj|j||jjj|jj|d|jjjkt j t j |jj |d|jj |d|jj |dd|jj |ddS)Nz BIGNUM **r)r4r5r6)r;rD) r!rrrr7rrr8rGr rHr9r:)r'r4r5r6rIrrrrEs"z_DSAPublicKey.public_numberscCs2|jjj|j}|jjj||jjj}t|j|S)N)r!rrKrrrLrMr2)r'r3rrrrOsz_DSAPublicKey.parameterscCs|jj||||jdS)N)r!Z_public_key_bytesr>)r'rPrQrrr public_bytessz_DSAPublicKey.public_bytescCs"t|j||\}}t|j|||S)N)rr!r)r'rrr(rrrr,sz_DSAPublicKey.verifyN) r-r.r/r)rrTrUrWrErOrXr,rrrrrNs  rNN)Z __future__rrrZ cryptographyrZcryptography.exceptionsrZ*cryptography.hazmat.backends.openssl.utilsrrr Zcryptography.hazmat.primitivesr Z)cryptography.hazmat.primitives.asymmetricr r r rrZregister_interfaceobjectr r0ZDSAParametersWithNumbersr2ZDSAPrivateKeyWithSerializationr=ZDSAPublicKeyWithSerializationrNrrrrs"    Y