OwlCyberSecurity - MANAGER
Edit File: SecretSharing.cpython-311.pyc
� �������hJ"�����������������������~�����d�dl�mZ�d�dlmZ�d�dlmZmZ�d�dlmZ �d��Z d��Z�G�d��de������������Z �G�d ��d e������������ZdS�)�����)� is_native_int)�number)� long_to_bytes� bytes_to_long)�get_random_bytesc������������������N�����||�k����r||�}}�d}|r|dz��r||�z��}|�dz��}�|dz��}|�|S�)z!Multiply two polynomials in GF(2)r���������)�f1�f2�zs��� �/builddir/build/BUILD/imunify360-venv-2.5.2/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Protocol/SecretSharing.py� _mult_gf2r���(���s[������� �B�w�w��R�B�� �A� ��� ��6�� � ��G�A� �q��� �q��� � ��� � �H�����c������������������������|�|k�����rd|�fS�t�����������j��������}d}|�}�||������������}�||������������|k����r8d�||������������|z ��z��}||z��}|t����������||������������z��}�||������������|k�����8||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)<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��������������������R�����e�Zd�ZdZdddz��z���Zd��Zd��Zd��Zd��Zd ��Z d ��Z d��Zd��Zd S�)�_ElementzElement of GF(2^128) field������������c�����������������������t����������|������������r ||�_��������dS�t����������|������������dk����rt����������|������������|�_��������dS�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__S���sU���������'�'�� Y�'�D�K�K�K� �� � �2� %� %�'� �6�6�D�K�K�K��W�X�X�Xr���c������������������"�����|�j���������|j���������k����S��N�r"���)r%����others��� r����__eq__z_Element.__eq__b���s�������{�e�l�*�*r���c�����������������������|�j���������S�)z7Return the field element, encoded as a 128-bit integer.r*����r%���s��� r����__int__z_Element.__int__e���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.encodei���s�������T�[�"�-�-�-r���c�����������������������|�j���������}|j���������}||k����r||}}|�j��������||fv�rt����������d������������S�ddz��}|d}}|r�t����������t ����������|dz��������������dd�����������dz��d�������������}|||z��z��||z ��dz ��|z��z��}|dz��}t����������t ����������|dz ��dz��������������dd�����������dz��d�������������}|||�j��������z��z��||z ��dz ��|z��z��}|dz��}|��t����������|������������S�)Nr���r���r���r ���)�base)r"����irr_polyr����int�bin) r%����factorr���r����mask1�vr ����mask2�mask3s ��� r����__mul__z_Element.__mul__m���s"����� �[�� �]�����7�7����B��=�R��H�$�$��A�;�;���S����1�1���� ���B��F���A�B�B��#�-�A�6�6�6�E��!�a�%��e�e�m�a�&7�1�%<�=�A� �!�G�A���Q�#�X��N�+�+�A�B�B�/�#�5�A�>�>�>�E��!�d�m�+�,�%�%�-�!�2C�q�1H�I�A��1�H�B���� ����{�{�r���c������������������:�����t����������|�j��������|j��������z��������������S�r)���)r���r"���)r%����terms��� r����__add__z_Element.__add__����s���������d�k�1�2�2�2r���c����������������������|�j���������dk����rt����������d�������������|�j���������|�j��������}}d\��}}|dk����rFt����������||������������d���������}||t ����������||������������z��}}||t ����������||������������z��}}|dk�����Ft����������|������������S�)z0Return the inverse of this element in GF(2^128).r���zInversion of zero)r ���r���)r"���r$���r4���r���r���r���)r%����r0�r1�s0�s1r���s��� r����inversez_Element.inverse����s���������;�!����0�1�1�1���d�m�B�����B��1�f�f���R� � ��#�A���i��2�.�.�.��B���i��2�.�.�.��B���1�f�f����|�|�r���c������������������b�����t����������|�j��������������������}t����������|dz ��������������D�]}||�z��}�|S�)Nr ���)r���r"����range)r%����exponent�result�_s��� r����__pow__z_Element.__pow__����s<�������$�+�&�&���x�!�|�$�$�� #�� #�A��d�]�F�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�� Y�� Y�+��+��+������.��.��.������23��3��3������"��������r���r���c��������������������B�����e�Zd�ZdZedd���������������Zedd���������������ZdS�)�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. Fc���������������������������d��t����������|�dz ��������������D��������������������������������������t����������|�������������������������d������fd�t����������d|dz���������������D���������������S�)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 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) c������������������F�����g�|�]}t����������t����������d���������������������������S�)r!���)r����rng)�.0�is��� r���� <listcomp>z Shamir.split.<locals>.<listcomp>����s&������:�:�:��(�3�r�7�7�#�#�:�:�:r���r ���c������������������������t����������|�������������}t����������d������������}|D�] }||z��|z���}�|r"|t����������|�������������t����������|������������z��z ��}|�����������������������������������S�)Nr���)r���r#���r1���)�user�coeffs�ssss�idx�share�coeffs��� r���� make_sharez Shamir.split.<locals>.make_share����sh�������4�.�.�C��Q�K�K�E��� ,�� ,���e��e�+����� 7���$���3�v�;�;�6�6���<�<�>�>�!r���c������������������.������g�|�]}|��|��������������f��S�r ���r ���)rU���rV���rZ���r_���r[���s��� ���r���rW���z Shamir.split.<locals>.<listcomp>����s,�������J�J�J�Q��J�J�q�&�$�/�/�0�J�J�Jr���)rG����appendr���)�k�n�secretr[���rZ���r_���s��� `@@r����splitzShamir.split����s}���������J�;�:�U�1�q�5�\�\�:�:�:��� � �h�v�&�&�'�'�'� "�� "�� "��K�J�J�J�J�J�%��1�q�5�/�/�J�J�J�Jr���c������������������v�����t����������|�������������}g�}|�D�]w}t����������|d����������������������t����������|d���������������������}t�����������fd�|D���������������������������rt����������d�������������|r|�|z��z ��}|����������������������|f��������������xt����������d������������}t����������|������������D�]{}||���������\��}} t����������d������������} t����������d������������}t����������|������������D�]#}||���������d���������} ||k����r | | z��} ||| z���z��}�$|| | z��|�����������������������������������z��z ��}�||�����������������������������������S�)a���Recombine 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). r���r ���c��������������3����0����K����|�]}|d�����������k����V����dS�)r���Nr ���)rU����yr\���s��� �r���� <genexpr>z!Shamir.combine.<locals>.<genexpr>��s+�����������2�2�1�1�Q�4�3�;�2�2�2�2�2�2r���zDuplicate share)r#���r����anyr$���ra���rG���rE���r1���)�sharesr[���rb���� gf_shares�x�valuerI����j�x_j�y_j� numerator�denominator�m�x_mr\���s��� @r����combinezShamir.combine����s]������>� ��K�K��� ��� +�� +�A��1�Q�4�.�.�C��Q�q�T�N�N�E��2�2�2�2� �2�2�2�2�2�� 4� �!2�3�3�3��� "�����!�����c�5�\�*�*�*�*��!�����q���� >�� >�A� ��|�H�C�� ����I�"�1�+�+�K��1�X�X�� -�� -����l�1�o����6�6���$�I��3��9�,�K���c�I�o��(;�(;�(=�(=�=�=�F�F��}�}���r���N)F)rL���rM���rN���rO����staticmethodre���rv���r ���r���r���rQ���rQ�������sc�������������������3K��3K��3K���\�3K�j��7��7��7���\�7��7��7r���rQ���N)�Crypto.Util.py3compatr����Crypto.Utilr����Crypto.Util.numberr���r���� Crypto.Randomr���rT���r���r����objectr���rQ���r ���r���r����<module>r}������s������D�0��/��/��/��/��/��������������;��;��;��;��;��;��;��;��1��1��1��1��1��1� �� �� ������,Q��Q��Q��Q��Q�v��Q��Q��Q�hu��u��u��u��u�V��u��u��u��u��ur���