+
    '(j#                     r    ^ RI Ht ^ RIHt ^ RIHtHt ^ RIHt	 R t
R t ! R R]4      t ! R	 R
]4      tR# )    )is_native_int)number)long_to_bytesbytes_to_long)get_random_bytesc                    W8  d   Yr^ pV'       d,   V^,          '       d	   W ,          pV ^,          p V^,          pK3  V# )z!Multiply two polynomials in GF(2) )f1f2zs   && R/home/ubuntu/cf-venv/lib/python3.14/site-packages/Crypto/Protocol/SecretSharing.py	_mult_gf2r   (   s=     
wB	A
66GA
q
qH    c                    W8  d   ^ V 3# \         P                  p^ pT pV! V4      pV! V4      V8  d3   ^V! V4      V,
          ,          pW6,          pV\        W4      ,          pK?  W43# )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   sizer   )abdegqrdss   &&     r   _div_gf2r   7   sg     	
!t
++C	A	AAA
a&A+#a&1*		Yq_6Mr   c                   t   a  ] tR t^Mt o Rt^^^,          ,           tR tR tR tR t	R t
R tR tR	 tR
tV tR# )_ElementzElement of GF(2^128) fieldc                    \        V4      '       d	   Wn        R# \        V4      ^8X  d   \        V4      V n        R# \	        R4      h)zInitialize 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___Element.__init__T   s9     '''K2%'6DKWXXr   c                4    V P                   VP                   8H  # Nr   )r    others   &&r   __eq___Element.__eq__c   s    {{ell**r   c                    V P                   # )z7Return the field element, encoded as a 128-bit integer.r&   r    s   &r   __int___Element.__int__f   s    {{r   c                .    \        V P                  ^4      # )z6Return the field element, encoded as a 16 byte string.)r   r   r+   s   &r   encode_Element.encodej   s    T[["--r   c                X   V P                   pVP                   pW28  d   Y2r2V P                  W#39   d   \        ^ 4      # ^^,          pT^ reV'       d   \        \	        V^,          4      R,          ^,          ^R7      pWvV,          ,          WG,
          ^,
          V,          ,          pV^,          p\        \	        V^,	          ^,          4      R,          ^,          ^R7      pWV P                  ,          ,          WH,
          ^,
          V,          ,          pV^,          pK  \        V4      # )r   :   NN)base)r   irr_polyr   intbin)	r    factorr
   r   mask1vr   mask2mask3s	   &&       r   __mul___Element.__mul__n   s    [[]] 7==RH$A;S11BFB#-A6Ea%ema&71%<=A!GAQ#XN+B/#5A>Edmm+,%-!2Cq1HIA1HB{r   c                N    \        V P                  VP                  ,          4      # r%   )r   r   )r    terms   &&r   __add___Element.__add__   s    dkk122r   c                   V P                   ^ 8X  d   \        R4      hV P                   V P                  r!^^ rCV^ 8  d9   \        W4      ^ ,          pY!\	        WR4      ,          r!YC\	        WT4      ,          rCK?  \        V4      # )z0Return the inverse of this element in GF(2^128).zInversion of zero)r   r   r4   r   r   r   )r    r0r1s0s1r   s   &     r   inverse_Element.inverse   sp     ;;!011dmmBAB1f #Ai..i..|r   c                r    \        V P                  4      p\        V^,
          4       F  pW ,          pK  	  V# )   )r   r   range)r    exponentresult_s   &&  r   __pow___Element.__pow__   s/    $++&x!|$A]F %r   r&   N)__name__
__module____qualname____firstlineno____doc__r4   r"   r(   r,   r/   r<   r@   rG   rO   __static_attributes____classdictcell____classdict__s   @r   r   r   M   sF     $ c)HY+.23" r   r   c                   L   a  ] tR t^t o Rt]RR l4       t]RR l4       tRtV t	R# )ShamirzShamir'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           	        \        V ^,
          4       Uu. uF  p\        \        ^4      4      NK  	  ppVP                  \        V4      4       R p\        ^V^,           4       Uu. uF  qDV! WEV4      3NK  	  up# u upi u upi )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)
c                     \        V 4      p\        ^ 4      pV F  pW4,          V,           pK  	  V'       d#   V\        V 4      \        V4      ,          ,          pVP                  4       # )r   )r   r   r/   )usercoeffsssssidxsharecoeffs   &&&   r   
make_share Shamir.split.<locals>.make_share   sT    4.C QKEe+   $3v;66<<>!r   )rK   r   rngappend)knsecretr`   ir_   rd   s   &&&&   r   splitShamir.split   sw    N .31q5\:\(3r7#\:hv&'
	"" ;@1q5/J/QJq$/0/JJ/ ;. Ks   A<&Bc                  a \        V 4      p. pV  F  p\        V^ ,          4      o\        V^,          4      p\        ;QJ d    V3R lV 4       F  '       g   K   RM	  RM! V3R lV 4       4      '       d   \        R4      hV'       d   VSV,          ,          pVP	                  SV34       K  	  \        ^ 4      p\        V4       F  pW7,          w  r\        ^4      p
\        ^4      p\        V4       F1  pW<,          ^ ,          pW8w  g   K  W,          p
WV,           ,          pK3  	  WiV
,          VP                  4       ,          ,          pK  	  VP                  4       # )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).
c              3   :   <"   T F  q^ ,          S8H  x  K  	  R# 5i)r   Nr	   ).0yra   s   & r   	<genexpr>!Shamir.combine.<locals>.<genexpr>  s     2	1Q43;	s   TFzDuplicate share)r   r   anyr   rg   rK   rG   r/   )sharesr`   rh   	gf_sharesxvaluerM   jx_jy_j	numeratordenominatormx_mra   s   &&            @r   combineShamir.combine   s   L K	A1Q4.CQqTNEs2	2sss2	222 !233!c5\*  !qA |HC I"1+K1Xl1o6$I9,K	 
 Io(;(;(===F  }}r   r	   N)F)
rQ   rR   rS   rT   rU   staticmethodrl   r   rV   rW   rX   s   @r   r[   r[      s5      =K =K~ ? ?r   r[   N)Crypto.Util.py3compatr   Crypto.Utilr   Crypto.Util.numberr   r   Crypto.Randomr   rf   r   r   objectr   r[   r	   r   r   <module>r      s;   D 0  ; 1,Rv RjGV Gr   