ff;ddlmZddlmZddlmZddlmZddlm Z ddl m Z ddgZ Gd de ZGd d eZGd d eZGddeZddZdS)) DerSequence) long_to_bytes)Integer)HMAC)EccKey)DsaKey DssSigSchemenewc6eZdZdZdZdZdZdZdZdZ dS) r zkA (EC)DSA signature object. Do not instantiate directly. Use :func:`Crypto.Signature.DSS.new`. c||_||_||_|j|_|jdz dzdz|_dS)zCreate a new Digital Signature Standard (DSS) object. Do not instantiate this object directly, use `Crypto.Signature.DSS.new` instead. N)_key _encoding_order size_in_bits _order_bits _order_bytes)selfkeyencodingorders v/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Signature/DSS.py__init__zDssSigScheme.__init__3sO ! ;3355!-1a7!;c4|jS)zRReturn ``True`` if this signature object can be used for signing messages.)r has_private)rs rcan_signzDssSigScheme.can_signAsy$$&&&rc tdNzTo be provided by subclassesNotImplementedErrorrmsg_hashs r_compute_noncezDssSigScheme._compute_nonceG!"@AAArc tdr r!r#s r _valid_hashzDssSigScheme._valid_hashJr&rcjstd|st d|}t j|dj }j ||}j dkr"d fd|D}n!t|}|S)aCompute the DSA/ECDSA signature of a message. Args: msg_hash (hash object): The hash that was carried out over the message. The object belongs to the :mod:`Crypto.Hash` package. Under mode ``'fips-186-3'``, the hash must be a FIPS approved secure hash (SHA-2 or SHA-3). :return: The signature as ``bytes`` :raise ValueError: if the hash algorithm is incompatible to the (EC)DSA key :raise TypeError: if the (EC)DSA key has no private half zPrivate key is needed to signHash is not sufficiently strongNbinaryrc:g|]}t|jS)rr).0xrs r z%DssSigScheme.sign..ks6222#$ -Q0ABB222r)rr TypeErrorr( ValueErrorr%r from_bytesdigestr_signrjoinrencode)rr$noncezsig_pairoutputs` rsignzDssSigScheme.signMsy$$&& =;<< <)) @>?? ?##H--  x001C$2C1CD E E9??1e,, >X % %XX2222(022233FF!**1133F rc||std|jdkrVt|d|jzkrtdd|d|j||jdfD\}}n t |d}n$#ttf$rtd wxYwt|dks|std t|d t|d }}d |cxkr |j krnnd |cxkr |j ksntd tj | d|j}|j |||f}|stddS)aCheck if a certain (EC)DSA signature is authentic. Args: msg_hash (hash object): The hash that was carried out over the message. This is an object belonging to the :mod:`Crypto.Hash` module. Under mode ``'fips-186-3'``, the hash must be a FIPS approved secure hash (SHA-2 or SHA-3). signature (``bytes``): The signature that needs to be validated. :raise ValueError: if the signature is not authentic r*r+z'The signature is not authentic (length)c6g|]}tj|Sr-)rr3)r.r/s rr0z'DssSigScheme.verify..s9 J J J$%!( 21 5 5 J J JrNT)strictz$The signature is not authentic (DER)z,The signature is not authentic (DER content)rr z"The signature is not authentic (d)zThe signature is not authenticF)r(r2rlenrrdecode IndexError hasOnlyIntsrrr3r4r_verify)rr$ signaturer_primes_primeder_seqr9results rverifyzDssSigScheme.verifyzs  )) @>?? ? >X % %9~~!d&7"788 !JKKK J J*34FT5F4F*G*3D4E4F4F*G*I J J J GWW I%--..y.FF + I I I !GHHH I7||q  (;(;(=(=  !OPPP&wqz22GGAJ4G4GWGG))))dk)))))1w3L3L3L3L3L3L3L3LABB B  x001C$2C1CD E E""1w&899 ?=>> >us #B++!C N) __name__ __module__ __qualname____doc__rrr%r(r<rKr-rrr r -s < < <''' BBBBBB+++Z*****rc<eZdZfdZdZdZdZdZdZxZ S)DeterministicDsaSigSchemecjtt||||||_dSN)superrQr _private_key)rrrr private_key __class__s rrz"DeterministicDsaSigScheme.__init__s4 '..77XuMMM'rctj|}|j}t |dz}||kr|||z z}|S)zSee 2.3.2 in RFC6979r)rr3rrrA)rbstrrJq_lenb_lens r _bits2intz#DeterministicDsaSigScheme._bits2intsR#D)) ((**D A  5==  &F rcXd|cxkr |jksnJt||jS)zSee 2.3.3 in RFC6979r)rrr)r int_mod_qs r _int2octetsz%DeterministicDsaSigScheme._int2octetss>9****t{******Y(9:::rc||}||jkr|}n ||jz }||S)zSee 2.3.4 in RFC6979)r\rr_)rrYz1z2s r _bits2octetsz&DeterministicDsaSigScheme._bits2octetssI^^D ! !   BBdk!B###rcX|}d|jz}d|jz}dD]}tj|||z||jz||z|}tj|||}d}d|cxkr |jksn|dkrStj||dz|}tj|||}d}t||j krEtj|||}||z }t||j kE| |}d|cxkr |jkn|S)z!Generate k in a deterministic way)rfrerr) r4 digest_sizerr r_rUrcrrArr\)rmhashh1mask_vnonce_kint_octr8mask_ts rr%z(DeterministicDsaSigScheme._compute_nonces \\^^5,,E--) ? ?Ghw%/#//0ABB C#0044 56;==>DVXX  Xgvu55<<>>FFu****t{****{{(7FW,<#(***0&(('6599@@BBFf++ 111'6599@@BB& f++ 111 NN6**E!u****t{*****" rcdS)NTr-r#s rr(z%DeterministicDsaSigScheme._valid_hashstr) rLrMrNrr\r_rcr%r( __classcell__rWs@rrQrQs(((((   ;;; $$$&&&PrrQc.eZdZdZfdZdZdZxZS)FipsDsaSigScheme))i))ru)i rwc tt||||||_t |j}||jf|jvrd||jfz}t|dS)Nz+L/N (%d, %d) is not compliant to FIPS 186-3) rTrsr _randfuncrprr_fips_186_3_L_Nr2)rrrrrandfuncLerrorrWs rrzFipsDsaSigScheme.__init__s %%..sHeDDD! CENN ' ' ) ) t (< < <B4+,-EU## # = >ABBB c#344   &&&(h{KKK    c6 " " D%c8UHEE E#C5(CC C047888r)r+N)Crypto.Util.asn1rCrypto.Util.numberrCrypto.Math.Numbersr Crypto.HashrCrypto.PublicKey.ECCrCrypto.PublicKey.DSAr__all__objectr rQrsrr r-rrrseD)(((((,,,,,,'''''''''''''''''' 5 !wwwww6wwwtKKKKK KKK\BBBBB|BBBD>]9]9]9]9]9]9r