Ë
    (üàgÈ;  ã                   ó´   — d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ ddgZ G d	„ de«      Z G d
„ de«      Z G d„ de«      Z G d„ de«      Zdd„Zy)é    )ÚDerSequence)Úlong_to_bytes)ÚInteger)ÚHMAC)ÚEccKey)ÚDsaKeyÚDssSigSchemeÚnewc                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	r	   zkA (EC)DSA signature object.
    Do not instantiate directly.
    Use :func:`Crypto.Signature.DSS.new`.
    c                 ó    — || _         || _        || _        | j                  j                  «       | _        | j                  dz
  dz  dz   | _        y)z Create 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)ÚselfÚkeyÚencodingÚorders       úR/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/Crypto/Signature/DSS.pyÚ__init__zDssSigScheme.__init__3   sK   € ð ˆŒ	Ø!ˆŒØˆŒàŸ;™;×3Ñ3Ó5ˆÔØ!×-Ñ-°Ñ1°aÑ7¸!Ñ;ˆÕó    c                 ó6   — | j                   j                  «       S )zRReturn ``True`` if this signature object can be used
        for signing messages.)r   Úhas_private)r   s    r   Úcan_signzDssSigScheme.can_signA   s   € ð �y‰y×$Ñ$Ó&Ð&r   c                 ó   — t        d«      ‚©NzTo be provided by subclasses©ÚNotImplementedError©r   Úmsg_hashs     r   Ú_compute_noncezDssSigScheme._compute_nonceG   ó   € Ü!Ð"@ÓAÐAr   c                 ó   — t        d«      ‚r    r!   r#   s     r   Ú_valid_hashzDssSigScheme._valid_hashJ   r&   r   c           	      ó  — | j                   j                  «       st        d«      ‚| j                  |«      st	        d«      ‚| j                  |«      }t        j                  |j                  «       d| j                   «      }| j                   j                  ||«      }| j                  dk(  r5dj                  |D �cg c]  }t        || j                  «      ‘Œ c}«      }|S t        |«      j                  «       }|S c c}w )a  Compute 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
        zPrivate key is needed to signúHash is not sufficiently strongNÚbinaryr   )r   r   Ú	TypeErrorr(   Ú
ValueErrorr%   r   Ú
from_bytesÚdigestr   Ú_signr   Újoinr   r   Úencode)r   r$   ÚnonceÚzÚsig_pairÚxÚoutputs          r   ÚsignzDssSigScheme.signM   sì   € ð �y‰y×$Ñ$Ô&ÜÐ;Ó<Ð<à×Ñ Ô)ÜÐ>Ó?Ð?ð ×#Ñ# HÓ-ˆô ×Ñ˜xŸ™Ó0Ð1C°$×2CÑ2CÐDÓEˆØ—9‘9—?‘? 1 eÓ,ˆð �>‰>˜XÒ%Ø—X‘XØ(0ö2Ø#$ô  -¨Q°×0AÑ0AÕBò 2ó 3ˆFð ˆô ! Ó*×1Ñ1Ó3ˆFàˆùò2s   Â=C>c                 ó†  — | j                  |«      st        d«      ‚| j                  dk(  rit        |«      d| j                  z  k7  rt        d«      ‚|d| j                   || j                  d fD �cg c]  }t        j                  |«      ‘Œ c}\  }}na	 t        «       j                  |d¬«      }t        |«      dk7  s|j                  «       st        d	«      ‚t        |d
   «      t        |d   «      }}d
|cxk  r| j                  k  r.n t        d«      ‚d
|cxk  r| j                  k  st        d«      ‚ t        d«      ‚t        j                  |j                  «       d| j                   «      }| j                  j                  |||f«      }|st        d«      ‚yc c}w # t        t        f$ r t        d«      ‚w xY w)aü  Check 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)NT)Ústrictz$The signature is not authentic (DER)z,The signature is not authentic (DER content)r   r   z"The signature is not authentic (d)zThe signature is not authenticF)r(   r-   r   Úlenr   r   r.   r   ÚdecodeÚ
IndexErrorÚhasOnlyIntsr   r/   r   Ú_verify)	r   r$   Ú	signaturer6   Úr_primeÚs_primeÚder_seqr4   Úresults	            r   ÚverifyzDssSigScheme.verifyz   sÃ  € ð  ×Ñ Ô)ÜÐ>Ó?Ð?à�>‰>˜XÒ%Ü�9‹~ ! d×&7Ñ&7Ñ"7Ò8Ü Ð!JÓKÐKà*3Ð4F°T×5FÑ5FÐ*GØ*3°D×4EÑ4EÐ4FÐ*Gð*Iö JØ$%ô !(× 2Ñ 2°1Õ 5ò  JÑˆG‘WðIÜ%›-×.Ñ.¨yÀÐ.ÓF�ô �7‹|˜qÒ ¨×(;Ñ(;Ô(=Ü Ð!OÓPÐPÜ& w¨q¡zÓ2´G¸GÀA¹JÓ4G�WˆGà�GÔ)˜dŸk™kÔ)ÜÐAÓBÐBð 45°wÔ3LÀÇÁÒ3LÜÐAÓBÐBð 4MÜÐAÓBÐBä×Ñ˜xŸ™Ó0Ð1C°$×2CÑ2CÐDÓEˆØ—‘×"Ñ" 1 w°Ð&8Ó9ˆÙÜÐ=Ó>Ð>àùò) Jøô ¤
Ð+ò IÜ Ð!GÓHÐHðIús   Á2F ÂF% Æ%G N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r%   r(   r8   rF   © r   r   r	   r	   -   s(   „ ñò
<ò'òBòBò+óZ*r   c                   ó<   ‡ — e Zd Zˆ fd„Zd„ Zd„ Zd„ Zd„ Zd„ Zˆ xZ	S )ÚDeterministicDsaSigSchemec                 ó>   •— t         t        | �  |||«       || _        y ©N)ÚsuperrM   r   Ú_private_key)r   r   r   r   Úprivate_keyÚ	__class__s        €r   r   z"DeterministicDsaSigScheme.__init__ª   s   ø€ ÜÔ'¨Ñ7¸¸XÀuÔMØ'ˆÕr   c                 óš   — t        j                  |«      }| j                  j                  «       }t	        |«      dz  }||kD  r|||z
  z  }|S )zSee 2.3.2 in RFC6979r   )r   r.   r   r   r<   )r   ÚbstrrE   Úq_lenÚb_lens        r   Ú	_bits2intz#DeterministicDsaSigScheme._bits2int®   sM   € ô ×#Ñ# DÓ)ˆØ—‘×(Ñ(Ó*ˆÜ�D“	˜A‘ˆØ�5Š=à˜ ™Ñ&ˆFØˆr   c                 ób   — d|cxk  r| j                   k  sJ ‚ J ‚t        || j                  «      S )zSee 2.3.3 in RFC6979r   )r   r   r   )r   Ú	int_mod_qs     r   Ú_int2octetsz%DeterministicDsaSigScheme._int2octets¹   s4   € ð �9Ô*˜tŸ{™{Ò*Ð*Ñ*Ð*Ð*Ü˜Y¨×(9Ñ(9Ó:Ð:r   c                 óˆ   — | j                  |«      }|| j                  k  r|}n|| j                  z
  }| j                  |«      S )zSee 2.3.4 in RFC6979)rX   r   r[   )r   rU   Úz1Úz2s       r   Ú_bits2octetsz&DeterministicDsaSigScheme._bits2octets¿   sB   € ð �^‰^˜DÓ!ˆØ�—‘ÒØ‰Bà�d—k‘kÑ!ˆBØ×Ñ Ó#Ð#r   c                 óL  — |j                  «       }d|j                  z  }d|j                  z  }dD ]}  }t        j                  |||z   | j	                  | j
                  «      z   | j                  |«      z   |«      j                  «       }t        j                  |||«      j                  «       }Œ d}d|cxk  r| j                  k  sÜn |dk7  rMt        j                  ||dz   |«      j                  «       }t        j                  |||«      j                  «       }d}t        |«      | j                  k  rCt        j                  |||«      j                  «       }||z  }t        |«      | j                  k  rŒC| j                  |«      }d|cxk  r| j                  k  sŒÖ|S  ŒÚ|S )z!Generate k in a deterministic wayó   ó    )rb   ra   éÿÿÿÿr   r   )r/   Údigest_sizer   r
   r[   rQ   r_   r   r<   r   rX   )r   ÚmhashÚh1Úmask_vÚnonce_kÚint_octr3   Úmask_ts           r   r%   z(DeterministicDsaSigScheme._compute_nonceÉ   s˜  € ð
 �\‰\‹^ˆà˜5×,Ñ,Ñ,ˆà˜E×-Ñ-Ñ-ˆà)ò 	?ˆGä—h‘h˜wØ%¨Ñ/Ø#×/Ñ/°×0AÑ0AÓBñ Cà#×0Ñ0°Ó4ñ 5à6;ó=÷ >D¹V»Xð ô
 —X‘X˜g v¨uÓ5×<Ñ<Ó>‰Fð	?ð ˆØ�uÔ*˜tŸ{™{Ô*à˜Š{ÜŸ(™( 7¨F°WÑ,<Ø#(ó*ß*0©&«(ð äŸ™ '¨6°5Ó9×@Ñ@ÓB�ð ˆFô �f“+ × 1Ñ 1Ò1ÜŸ™ '¨6°5Ó9×@Ñ@ÓB�Ø˜&Ñ �ô �f“+ × 1Ñ 1Ó1ð
 —N‘N 6Ó*ˆEð! �uÔ*˜tŸ{™{Ó*ð" ˆñ# +ð" ˆr   c                  ó   — y)NTrK   r#   s     r   r(   z%DeterministicDsaSigScheme._valid_hashñ   s   € Ør   )
rG   rH   rI   r   rX   r[   r_   r%   r(   Ú__classcell__©rS   s   @r   rM   rM   §   s"   ø„ ô(ò	ò;ò$ò&öPr   rM   c                   ó.   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zˆ xZS )ÚFipsDsaSigScheme))i   é    )é   éà   )rq   é   )i   rs   c                 óð   •— t         t        | �  |||«       || _        t	        |j
                  «      j                  «       }|| j                  f| j                  vrd|| j                  fz  }t        |«      ‚y )Nz+L/N (%d, %d) is not compliant to FIPS 186-3)
rP   ro   r   Ú	_randfuncr   Úpr   r   Ú_fips_186_3_L_Nr-   )r   r   r   r   ÚrandfuncÚLÚerrorrS   s          €r   r   zFipsDsaSigScheme.__init__  su   ø€ ÜÔ Ñ.¨s°H¸eÔDØ!ˆŒä�C—E‘E‹N×'Ñ'Ó)ˆØˆt×ÑÐ ¨×(<Ñ(<Ñ<ØBØ˜4×+Ñ+Ð,ñ-ˆEä˜UÓ#Ð#ð =r   c                 óZ   — t        j                  d| j                  | j                  ¬«      S ©Nr   )Úmin_inclusiveÚmax_exclusiverx   )r   Úrandom_ranger   ru   r#   s     r   r%   zFipsDsaSigScheme._compute_nonce  s%   € ä×#Ñ#°!Ø26·+±+Ø-1¯^©^ô=ð 	=r   c                 óZ   — |j                   dk(  xs |j                   j                  d«      S )z*Verify that SHA-1, SHA-2 or SHA-3 are usedz1.3.14.3.2.26z2.16.840.1.101.3.4.2.)ÚoidÚ
startswithr#   s     r   r(   zFipsDsaSigScheme._valid_hash  s-   € à—‘ Ñ/ò AØ—‘×'Ñ'Ð(?Ó@ð	Br   )rG   rH   rI   rw   r   r%   r(   rl   rm   s   @r   ro   ro   õ   s   ø„ ð
€Oô$ò=öBr   ro   c                   ó*   ‡ — e Zd Zˆ fd„Zd„ Zd„ Zˆ xZS )ÚFipsEcDsaSigSchemec                 ó>   •— t         t        | �  |||«       || _        y rO   )rP   r„   r   ru   )r   r   r   r   rx   rS   s        €r   r   zFipsEcDsaSigScheme.__init__  s   ø€ ÜÔ  $Ñ0°°hÀÔFØ!ˆ�r   c                 ó‚   — t        j                  d| j                  j                  j                  | j
                  ¬«      S r|   )r   r   r   Ú_curver   ru   r#   s     r   r%   z!FipsEcDsaSigScheme._compute_nonce  s1   € Ü×#Ñ#°!Ø26·)±)×2BÑ2B×2HÑ2HØ-1¯^©^ô=ð 	=r   c                 ó¶   — | j                   j                  j                  «       }d}d}d}d}||z   |z   |z   }	 |j                  |v }|S # t        $ r d}Y |S w xY w)zxVerify that the strength of the hash matches or exceeds
        the strength of the EC. We fail if the hash is too weak.)z2.16.840.1.101.3.4.2.4z2.16.840.1.101.3.4.2.7z2.16.840.1.101.3.4.2.5)z2.16.840.1.101.3.4.2.1z2.16.840.1.101.3.4.2.8z2.16.840.1.101.3.4.2.6)z2.16.840.1.101.3.4.2.2z2.16.840.1.101.3.4.2.9)z2.16.840.1.101.3.4.2.3z2.16.840.1.101.3.4.2.10F)r   ÚpointQr   r�   ÚAttributeError)	r   r$   Úmodulus_bitsÚsha224Úsha256Úsha384Úsha512ÚshsrE   s	            r   r(   zFipsEcDsaSigScheme._valid_hash"  s{   € ð —y‘y×'Ñ'×4Ñ4Ó6ˆð `ˆØ_ˆØEˆØFˆØ�v‰o Ñ&¨Ñ/ˆð	Ø—\‘\ SÐ(ˆFð ˆøô ò 	Ø‰FØˆð	ús   ¹A	 Á	AÁA)rG   rH   rI   r   r%   r(   rl   rm   s   @r   r„   r„     s   ø„ ô"ò=ö
r   r„   Nc                 ó4  — |dvrt        d|z  «      ‚t        | t        «      r>| j                  j                  }d}| j
                  j                  d«      sSt        d«      ‚t        | t        «      rt        | j                  «      }d}n t        dt        t        | «      «      z   «      ‚| j                  «       rt        | |«      }nd}|d	k(  rt        | |||«      S |d
k(  r,t        | t        «      rt        | |||«      S t!        | |||«      S t        d|z  «      ‚)a§
  Create a signature object :class:`DssSigScheme` that
    can perform (EC)DSA signature or verification.

    .. note::
        Refer to `NIST SP 800 Part 1 Rev 4`_ (or newer release) for an
        overview of the recommended key lengths.

    Args:
        key (:class:`Crypto.PublicKey.DSA` or :class:`Crypto.PublicKey.ECC`):
            The key to use for computing the signature (*private* keys only)
            or for verifying one.
            For DSA keys, let ``L`` and ``N`` be the bit lengths of the modulus ``p``
            and of ``q``: the pair ``(L,N)`` must appear in the following list,
            in compliance to section 4.2 of `FIPS 186-4`_:

            - (1024, 160) *legacy only; do not create new signatures with this*
            - (2048, 224) *deprecated; do not create new signatures with this*
            - (2048, 256)
            - (3072, 256)

            For ECC, only keys over P-224, P-256, P-384, and P-521 are accepted.

        mode (string):
            The parameter can take these values:

            - ``'fips-186-3'``. The signature generation is randomized and carried out
              according to `FIPS 186-3`_: the nonce ``k`` is taken from the RNG.
            - ``'deterministic-rfc6979'``. The signature generation is not
              randomized. See RFC6979_.

        encoding (string):
            How the signature is encoded. This value determines the output of
            :meth:`sign` and the input to :meth:`verify`.

            The following values are accepted:

            - ``'binary'`` (default), the signature is the raw concatenation
              of ``r`` and ``s``. It is defined in the IEEE P.1363 standard.
              For DSA, the size in bytes of the signature is ``N/4`` bytes
              (e.g. 64 for ``N=256``).
              For ECDSA, the signature is always twice the length of a point
              coordinate (e.g. 64 bytes for P-256).

            - ``'der'``, the signature is a ASN.1 DER SEQUENCE
              with two INTEGERs (``r`` and ``s``). It is defined in RFC3279_.
              The size of the signature is variable.

        randfunc (callable):
            A function that returns random ``bytes``, of a given length.
            If omitted, the internal RNG is used.
            Only applicable for the *'fips-186-3'* mode.

    .. _FIPS 186-3: http://csrc.nist.gov/publications/fips/fips186-3/fips_186-3.pdf
    .. _FIPS 186-4: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf
    .. _NIST SP 800 Part 1 Rev 4: http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf
    .. _RFC6979: http://tools.ietf.org/html/rfc6979
    .. _RFC3279: https://tools.ietf.org/html/rfc3279#section-2.2.2
    )r+   ÚderzUnknown encoding '%s'ÚdÚNISTz ECC key is not on a NIST P curver6   zUnsupported key type Nzdeterministic-rfc6979z
fips-186-3zUnknown DSS mode '%s')r-   Ú
isinstancer   r‡   r   Úcurver‚   r   r   ÚqÚstrÚtyper   ÚgetattrrM   r„   ro   )r   Úmoder   rx   r   Úprivate_key_attrrR   s          r   r
   r
   6  s  € ðD Ð(Ñ(ÜÐ0°8Ñ;Ó<Ð<ä�#”vÔØ—
‘
× Ñ ˆØÐØ�y‰y×#Ñ# FÔ+ÜÐ?Ó@Ð@Ü	�CœÔ	 Ü˜Ÿ™“ˆØÑäÐ0´3´t¸C³y³>ÑAÓBÐBà
‡�ÔÜ˜cÐ#3Ó4‰àˆàÐ&Ò&Ü(¨¨h¸¸{ÓKÐKØ	�Ò	Ü�cœ6Ô"Ü% c¨8°U¸HÓEÐEä# C¨°5¸(ÓCÐCäÐ0°4Ñ7Ó8Ð8r   )r+   N)ÚCrypto.Util.asn1r   ÚCrypto.Util.numberr   ÚCrypto.Math.Numbersr   ÚCrypto.Hashr   ÚCrypto.PublicKey.ECCr   ÚCrypto.PublicKey.DSAr   Ú__all__Úobjectr	   rM   ro   r„   r
   rK   r   r   ú<module>r¥      sc   ðõD )Ý ,Ý 'å Ý 'Ý 'à˜5Ð
!€ôw�6ô wôtK ô Kô\B�|ô BôD˜ô ô>]9r   