ffJ"~ddlmZddlmZddlmZmZddlmZ dZ dZ Gdde Z Gd d e Zd S) ) is_native_int)number) long_to_bytes bytes_to_long)get_random_bytescN||kr||}}d}|r|dzr||z}|dz}|dz}||S)z!Multiply two polynomials in GF(2)r)f1f2zs /builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Protocol/SecretSharing.py _mult_gf2r(s[ BwwRB A  6  GA q q  Hc||krd|fStj}d}|}||}|||kr8d|||z z}||z}|t||z}|||k8||fS)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)>>E!dm+,%%-!2Cq1HIA 1HB {{rc:t|j|jz Sr))rr")r%terms r__add__z_Element.__add__s dk1222rc|jdkrtd|j|j}}d\}}|dkrFt||d}||t ||z }}||t ||z }}|dkFt |S)z0Return the inverse of this element in GF(2^128).rzInversion of zero)r r)r"r$r4rrr)r%r0r1s0s1rs rinversez_Element.inverses ;!  011 1dmBB1ffR  #Ai2...Bi2...B1ff||rcbt|j}t|dz D]}||z}|S)Nr )rr"range)r%exponentresult_s r__pow__z_Element.__pow__s<$+&&x!|$$ # #Ad]FF rN) __name__ __module__ __qualname____doc__r4r'r,r/r1r<r?rErKr rrrrMs$$c)H Y Y Y+++...2333"rrcBeZdZdZeddZeddZdS)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. Fcdt|dz Dt|dfdtd|dzDS)aSplit 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 sufficient number of shares to reconstruct the secret (``k < n``). n (integer): The number of shares that this method will create. secret (byte string): A byte string of 16 bytes (e.g. the AES 128 key). ssss (bool): If ``True``, the shares can be used with the ``ssss`` utility. Default: ``False``. Return (tuples): ``n`` tuples. A tuple is meant for each participant and it contains two items: 1. the unique index (an integer) 2. the share (a byte string, 16 bytes) cFg|]}ttdS)r!)rrng).0is r z Shamir.split..s&:::(3r77##:::rr ct|}td}|D] }||z|z} |r"|t|t|zz }|S)Nr)rr#r1)usercoeffsssssidxsharecoeffs r make_sharez Shamir.split..make_sharesh4..CQKKE , ,e e+ 7$3v;;66<<>> !rc.g|]}||fSr r )rUrVrZr_r[s rrWz Shamir.split..s,JJJQJJq&$//0JJJr)rGappendr)knsecretr[rZr_s `@@rsplitz Shamir.splits}J;:U1q5\\::: hv&&'''  " " "KJJJJJ%1q5//JJJJrcvt|}g}|D]w}t|dt|d}tfd|Drtd|r||zz }||fxtd}t |D]{}||\}} td} td} t |D]#} || d} | |kr | | z} | || zz} $|| | z| zz }||S)aRecombine a secret, if enough shares are presented. Args: shares (tuples): The *k* tuples, each containin the index (an integer) and the share (a byte string, 16 bytes long) that were assigned to a participant. ssss (bool): If ``True``, the shares were produced by the ``ssss`` utility. Default: ``False``. Return: The original secret, as a byte string (16 bytes long). rr c30K|]}|dkVdS)rNr )rUyr\s r z!Shamir.combine..s+2211Q43;222222rzDuplicate share)r#ranyr$rarGrEr1)sharesr[rb gf_sharesxvaluerIjx_jy_j numerator denominatormx_mr\s @rcombinezShamir.combines]> KK  + +A1Q4..CQqTNNE2222 22222 4 !2333 "!   c5\ * * * *!q > >A |HC  I"1++K1XX - -l1o66$I39,K cIo (;(;(=(== =FF}}rN)F)rLrMrNrO staticmethodrervr rrrQrQsc 3K3K3K\3Kj777\777rrQN)Crypto.Util.py3compatr Crypto.UtilrCrypto.Util.numberrr Crypto.RandomrrTrrobjectrrQr rrr}sD0/////;;;;;;;;111111    ,QQQQQvQQQhuuuuuVuuuuur