Submit
Path:
~
/
/
opt
/
alt
/
python37
/
lib64
/
python3.7
/
site-packages
/
Crypto
/
Protocol
/
__pycache__
/
File Content:
AllOrNothing.cpython-37.pyc
B ��c�. � @ s d Z dZddlZddlZddlmZmZ ddlT ddlm Z dd� Z G d d � d �Zedk�r ddlZddl Z ddlZdZd ZdZd#dd�Zy$e � ejdd� dddg�\ZZW n. e jk r� Z zede� W ddZ[X Y nX er�edd� x@eD ]8\ZZedk�red� q�edk�reZq�edkr�dZq�W ede dddg�Zee�Zed� ee � ed� e�ee ��Z ed� x^e!e"e#e$e ���e �D ]D\Z%Z&ede% dd� e�r�eee&�� nee�'e&�dd � � �q�W ee�Z(e(�)e �Z*e*ee �k�red!� ned"� dS )$a� This file implements all-or-nothing package transformations. An all-or-nothing package transformation is one in which some text is transformed into message blocks, such that all blocks must be obtained before the reverse transformation can be applied. Thus, if any blocks are corrupted or lost, the original message cannot be reproduced. An all-or-nothing package transformation is not encryption, although a block cipher algorithm is used. The encryption key is randomly generated and is extractable from the message blocks. This class implements the All-Or-Nothing package transformation algorithm described in: Ronald L. Rivest. "All-Or-Nothing Encryption and The Package Transform" http://theory.lcs.mit.edu/~rivest/fusion.pdf z$Id$� N)� bytes_to_long� long_to_bytes)�*)�reducec C s* d}y|| 7 }W n t k r$ dS X dS )Nr � )� TypeError)�xZtest� r �O/opt/alt/python37/lib64/python3.7/site-packages/Crypto/Protocol/AllOrNothing.py�isInt5 s r c @ sB e Zd ZdZddd�Zed�Zdd� Zdd � Zd d� Z dd � Z dS )�AllOrNothingaV Class implementing the All-or-Nothing package transform. Methods for subclassing: _inventkey(key_size): Returns a randomly generated key. Subclasses can use this to implement better random key generating algorithms. The default algorithm is probably not very cryptographically secure. Nc C s8 || _ || _|| _|j| _t| j�r.| jdkr4d| _dS )aD AllOrNothing(ciphermodule, mode=None, IV=None) ciphermodule is a module implementing the cipher algorithm to use. It must provide the PEP272 interface. Note that the encryption key is randomly generated automatically when needed. Optional arguments mode and IV are passed directly through to the ciphermodule.new() method; they are the feedback mode and initialization vector to use. All three arguments must be the same for the object used to create the digest, and to undigest'ify the message blocks. r � N)�_AllOrNothing__ciphermodule�_AllOrNothing__mode�_AllOrNothing__IV�key_size�_AllOrNothing__key_sizer )�self�ciphermodule�modeZIVr r r �__init__I s zAllOrNothing.__init__�i c s� � � � j�}� j� j }� �|�}� �|�}� jj}|t|�| }|td�| }tt|�|�d }g } g } x�t d|d �D ]�}|d | }|| } ||| � }t|�|ks�t �|�t||��}t |�t |�A }| �|� |�t||A |��}| �t |�� q~W |d }|�t||��}|t |�A }| �|� |�t||A |��}| �t |�� t |�ttj| �A }| �|� � fdd�| D �S )a" digest(text:string) : [string] Perform the All-or-Nothing package transform on the given string. Output is a list of message blocks describing the transformed text, where each block is a string of bit length equal to the ciphermodule's block_size. � r r c s g | ]}t |� jj��qS r )r r � block_size)�.0�i)r r r � <listcomp>� s z'AllOrNothing.digest.<locals>.<listcomp>)� _inventkeyr �_AllOrNothing__K0digit�_AllOrNothing__newcipherr r �len�b�divmod�range�AssertionError�encryptr r �appendr �operator�xor)r �text�key�K0�mcipher�hcipherr �padbytes�s�blocks�hashesr �start�end�mi�cipherblock�mticki�hiZmtick_stickr )r r �digest` s: zAllOrNothing.digestc C s0 t |�dk rtd��ttt|��}| j| j }| �|�}| jj }g }xDt dt |��D ]2}||d |A }|�t||��}|� t|�� qTW |d ttj|�A } | �t| | j��} g }xDt dt |��D ]2}| �t||��}||d t|�A } |� | � q�W t|d �}td��tt|dd� ��}|d| � S )a5 undigest(blocks : [string]) : string Perform the reverse package transformation on a list of message blocks. Note that the ciphermodule used for both transformations must be the same. blocks is a list of strings of bit length equal to the ciphermodule's block_size. � zList must be at least length 2.r ���� N)r � ValueError�list�mapr r r r r r r# r% r r&