Ë
    (üàg¢#  ã                   óp   — d dl mZ d dlmZ d dlmZmZ d dlmZ	 d„ Z
d„ Z G d„ de«      Z G d	„ d
e«      Zy)é    )Úis_native_int)Únumber)Úlong_to_bytesÚbytes_to_long)Úget_random_bytesc                 óN   — || kD  r|| }} d}|r|dz  r|| z  }| dz  } |dz  }|rŒ|S )z!Multiply two polynomials in GF(2)r   é   © )Úf1Úf2Úzs      ú[/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/Crypto/Protocol/SecretSharing.pyÚ	_mult_gf2r   (   sJ   € ð 
ˆB‚wØ�RˆBˆØ	€AÙ
Ø�Š6Ø�‰GˆAØ
ˆq‰ˆØ
ˆq‰ˆò	 ð
 €Hó    c                 óÆ   — | |k  rd| fS t         j                  }d}| } ||«      } ||«      |k\  r.d ||«      |z
  z  }||z  }|t        ||«      z  } ||«      |k\  rŒ.||fS )z˜
    Compute division of polynomials over GF(2).
    Given a and b, it finds two polynomials q and r such that:

    a = b*q + r with deg(r)<deg(b)
    r   r	   )r   Úsizer   )ÚaÚbÚdegÚqÚrÚdÚss          r   Ú_div_gf2r   7   s~   € ð 	
ˆAŠØ�!ˆtˆä
�+‰+€CØ	€AØ	€AÙˆA‹€AÙ
ˆa‹&�AŠ+Ø‘#�a“&˜1‘*ÑˆØ	ˆQ‰ˆØ	ŒY�q˜!‹_Ñˆñ ˆa‹&�A‹+ð ˆqˆ6€Mr   c                   óP   — e Zd ZdZdddz  z   Zd„ Zd„ Zd„ Zd„ Zd	„ Z	d
„ Z
d„ Zd„ Zy)Ú_ElementzElement of GF(2^128) fieldé‡   é   é€   c                 ó|   — t        |«      r|| _        yt        |«      dk(  rt        |«      | _        yt	        d«      ‚)zïInitialize the element to a certain value.

        The value passed as parameter is internally encoded as
        a 128-bit integer, where each bit represents a polynomial
        coefficient. The LSB is the constant coefficient.
        é   z8The encoded value must be an integer or a 16 byte stringN)r   Ú_valueÚlenr   Ú
ValueError)ÚselfÚencoded_values     r   Ú__init__z_Element.__init__T   s8   € ô ˜Ô'Ø'ˆD�KÜ�Ó 2Ò%Ü'¨Ó6ˆD�KäÐWÓXÐXr   c                 ó4   — | j                   |j                   k(  S ©N©r"   )r%   Úothers     r   Ú__eq__z_Element.__eq__c   s   € Ø�{‰{˜eŸl™lÑ*Ð*r   c                 ó   — | j                   S )z7Return the field element, encoded as a 128-bit integer.r*   ©r%   s    r   Ú__int__z_Element.__int__f   s   € à�{‰{Ðr   c                 ó.   — t        | j                  d«      S )z6Return the field element, encoded as a 16 byte string.r!   )r   r"   r.   s    r   Úencodez_Element.encodej   s   € ä˜TŸ[™[¨"Ó-Ð-r   c                 ó¦  — | j                   }|j                   }||kD  r||}}| j                  ||fv rt        d«      S ddz  }|d}}|r€t        t	        |dz  «      dd  dz  d¬«      }|||z  z  ||z
  dz
  |z  z  }|dz  }t        t	        |dz	  dz  «      dd  dz  d¬«      }||| j                  z  z  ||z
  dz
  |z  z  }|dz  }|rŒ€t        |«      S )Nr   r   r   r	   )Úbase)r"   Úirr_polyr   ÚintÚbin)	r%   Úfactorr   r   Úmask1Úvr   Úmask2Úmask3s	            r   Ú__mul__z_Element.__mul__n   s  € à�[‰[ˆØ�]‰]ˆð �Š7Ø˜�ˆBà�=‰=˜R ˜HÑ$Ü˜A“;Ðà�S‘ˆØ�1ˆ1ˆÙäœ˜B ™F› A B˜¨#Ñ-°AÔ6ˆEØ˜!˜a™%‘ e¨e¡m°aÑ&7¸1Ñ%<Ñ=ˆAØ�!‰GˆAäœ˜Q #™X¨™NÓ+¨A¨BÐ/°#Ñ5¸AÔ>ˆEØ˜!˜dŸm™mÑ+Ñ,°%¸%±-À!Ñ2CÀqÑ1HÑIˆAØ�1‰HˆBò ô ˜‹{Ðr   c                 óF   — t        | j                  |j                  z  «      S r)   )r   r"   )r%   Úterms     r   Ú__add__z_Element.__add__‡   s   € Ü˜Ÿ™ d§k¡kÑ1Ó2Ð2r   c                 óþ   — | j                   dk(  rt        d«      ‚| j                   | j                  }}d\  }}|dkD  r7t        ||«      d   }||t	        ||«      z  }}||t	        ||«      z  }}|dkD  rŒ7t        |«      S )z0Return the inverse of this element in GF(2^128).r   zInversion of zero)r	   r   )r"   r$   r4   r   r   r   )r%   Úr0Úr1Ús0Ús1r   s         r   Úinversez_Element.inverseŠ   s�   € ð �;‰;˜!ÒÜÐ0Ó1Ð1à—‘˜dŸm™mˆBˆØ‰ˆˆBØ�1ŠfÜ˜˜RÓ  Ñ#ˆAØ˜œi¨¨2Ó.Ñ.�ˆBØ˜œi¨¨2Ó.Ñ.�ˆBð �1‹fô ˜‹|Ðr   c                 ó`   — t        | j                  «      }t        |dz
  «      D ]  }|| z  }Œ	 |S )Nr	   )r   r"   Úrange)r%   ÚexponentÚresultÚ_s       r   Ú__pow__z_Element.__pow__›   s6   € Ü˜$Ÿ+™+Ó&ˆÜ�x !‘|Ó$ò 	#ˆAØ˜d‘]‰Fð	#àˆr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r4   r'   r,   r/   r1   r<   r?   rE   rK   r
   r   r   r   r   M   s>   „ Ù$ð   c¡Ñ)€HòYò+òò.òò23òó"r   r   c                   ó4   — e Zd ZdZedd„«       Zedd„«       Zy)ÚShamirz›Shamir's secret sharing scheme.

    A secret is split into ``n`` shares, and it is sufficient to collect
    ``k`` of them to reconstruct the secret.
    c           	      óø   — t        | dz
  «      D �cg c]  }t        t        d«      «      ‘Œ }}|j                  t        |«      «       d„ }t        d|dz   «      D �cg c]  }| ||||«      f‘Œ c}S c c}w c c}w )a½  Split a secret into ``n`` shares.

        The secret can be reconstructed later using just ``k`` shares
        out of the original ``n``.
        Each share must be kept confidential to the person it was
        assigned to.

        Each share is associated to an index (starting from 1).

        Args:
          k (integer):
            The number of shares needed to reconstruct the secret.
          n (integer):
            The number of shares to create (at least ``k``).
          secret (byte string):
            A byte string of 16 bytes (e.g. an AES 128 key).
          ssss (bool):
            If ``True``, the shares can be used with the ``ssss`` utility
            (without using the "diffusion layer").
            Default: ``False``.

        Return (tuples):
            ``n`` tuples, one per participant.
            A tuple contains two items:

            1. the unique index (an integer)
            2. the share (16 bytes)
        r	   r!   c                 ó¤   — t        | «      }t        d«      }|D ]
  }||z  |z   }Œ |r|t        | «      t        |«      z  z  }|j                  «       S )Nr   )r   r#   r1   )ÚuserÚcoeffsÚssssÚidxÚshareÚcoeffs         r   Ú
make_sharez Shamir.split.<locals>.make_shareÖ   s[   € Ü˜4“.ˆCô ˜Q“KˆEØò ,�Ø˜e™ eÑ+‘ð,ñ Øœ $›¬3¨v«;Ñ6Ñ6�à—<‘<“>Ð!r   )rG   r   ÚrngÚappend)ÚkÚnÚsecretrV   ÚirU   rZ   s          r   ÚsplitzShamir.split©   sv   € ôN .3°1°q±5«\Ö:¨”(œ3˜r›7Õ#Ð:ˆÐ:Ø�‰”h˜vÓ&Ô'ò
	"ô" ;@ÀÀ1ÀqÁ5»/ÖJ°Q�‘J˜q &¨$Ó/Ò0ÒJÐJùò/ ;ùò. Ks   ‘A2ÁA7c                 óö  ‡— t        | «      }g }| D ]Z  }t        |d   «      Št        |d   «      }t        ˆfd„|D «       «      rt        d«      ‚|r|‰|z  z  }|j	                  ‰|f«       Œ\ t        d«      }t        |«      D ]d  }||   \  }}	t        d«      }
t        d«      }t        |«      D ]  }||   d   }||k7  sŒ|
|z  }
|||z   z  }Œ ||	|
z  |j                  «       z  z  }Œf |j                  «       S )a’  Recombine a secret, if enough shares are presented.

        Args:
          shares (tuples):
            The *k* tuples, each containing the index (an integer) and
            the share (a byte string, 16 bytes long) that were assigned to
            a participant.

            .. note::

                Pass exactly as many share as they are required,
                and no more.

          ssss (bool):
            If ``True``, the shares were produced by the ``ssss`` utility
            (without using the "diffusion layer").
            Default: ``False``.

        Return:
            The original secret, as a byte string (16 bytes long).
        r   r	   c              3   ó.   •K  — | ]  }|d    ‰k(  –— Œ y­w)r   Nr
   )Ú.0ÚyrW   s     €r   ú	<genexpr>z!Shamir.combine.<locals>.<genexpr>  s   øè ø€ Ò2 1�1�Q‘4˜3•;Ñ2ùs   ƒzDuplicate share)r#   r   Úanyr$   r\   rG   rE   r1   )ÚsharesrV   r]   Ú	gf_sharesÚxÚvaluerI   ÚjÚx_jÚy_jÚ	numeratorÚdenominatorÚmÚx_mrW   s                 @r   ÚcombinezShamir.combineé   s"  ø€ ôL �‹Kˆàˆ	Øò 	+ˆAÜ˜1˜Q™4“.ˆCÜ˜Q˜q™T“NˆEÜÓ2¨	Ô2Ô2Ü Ð!2Ó3Ð3ÙØ˜ ™Ñ!�Ø×Ñ˜c 5˜\Õ*ð	+ô ˜!“ˆÜ�q“ò 	>ˆAØ  ‘|‰HˆC�ä  ›ˆIÜ" 1›+ˆKä˜1“Xò -�Ø ‘l 1‘o�Ø˜“6Ø Ñ$�IØ 3¨¡9Ñ,‘Kð	-ð
 �c˜I‘o¨×(;Ñ(;Ó(=Ñ=Ñ=‰Fð	>ð �}‰}‹Ðr   N)F)rL   rM   rN   rO   Ústaticmethodra   rs   r
   r   r   rQ   rQ   ¢   s2   „ ñð ò=Kó ð=Kð~ ò?ó ñ?r   rQ   N)ÚCrypto.Util.py3compatr   ÚCrypto.Utilr   ÚCrypto.Util.numberr   r   ÚCrypto.Randomr   r[   r   r   Úobjectr   rQ   r
   r   r   ú<module>rz      s;   ðõD 0Ý ß ;Ý 1òòô,Rˆvô RôjGˆVõ Gr   