3
ãê\ù  ã               @   sø  d dl mZmZmZ d dlZd dlZd dlmZ ejej	ƒG dd„ de
ƒƒZejej	ƒG dd„ de
ƒƒZejej	ƒG dd	„ d	e
ƒƒZejej	ƒG d
d„ de
ƒƒZejej	ƒG dd„ de
ƒƒZdd„ Zdd„ Zdd„ ZejeƒejeƒG dd„ de
ƒƒƒZejeƒejeƒG dd„ de
ƒƒƒZejeƒG dd„ de
ƒƒZejeƒejeƒG dd„ de
ƒƒƒZejeƒejeƒG dd„ de
ƒƒƒZejeƒejeƒG dd„ de
ƒƒƒZejeƒejeƒG d d!„ d!e
ƒƒƒZejeƒejeƒejeƒG d"d#„ d#e
ƒƒƒƒZdS )$é    )Úabsolute_importÚdivisionÚprint_functionN)Úutilsc               @   s(   e Zd Zejdd„ ƒZejdd„ ƒZdS )ÚModec             C   s   dS )z@
        A string naming this mode (e.g. "ECB", "CBC").
        N© )Úselfr   r   úN/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/ciphers/modes.pyÚname   s    z	Mode.namec             C   s   dS )zq
        Checks that all the necessary invariants of this (mode, algorithm)
        combination are met.
        Nr   )r   Ú	algorithmr   r   r	   Úvalidate_for_algorithm   s    zMode.validate_for_algorithmN)Ú__name__Ú
__module__Ú__qualname__ÚabcÚabstractpropertyr
   Úabstractmethodr   r   r   r   r	   r      s   r   c               @   s   e Zd Zejdd„ ƒZdS )ÚModeWithInitializationVectorc             C   s   dS )zP
        The value of the initialization vector for this mode as bytes.
        Nr   )r   r   r   r	   Úinitialization_vector    s    z2ModeWithInitializationVector.initialization_vectorN)r   r   r   r   r   r   r   r   r   r	   r      s   r   c               @   s   e Zd Zejdd„ ƒZdS )ÚModeWithTweakc             C   s   dS )z@
        The value of the tweak for this mode as bytes.
        Nr   )r   r   r   r	   Útweak)   s    zModeWithTweak.tweakN)r   r   r   r   r   r   r   r   r   r	   r   '   s   r   c               @   s   e Zd Zejdd„ ƒZdS )ÚModeWithNoncec             C   s   dS )z@
        The value of the nonce for this mode as bytes.
        Nr   )r   r   r   r	   Únonce2   s    zModeWithNonce.nonceN)r   r   r   r   r   r   r   r   r   r	   r   0   s   r   c               @   s   e Zd Zejdd„ ƒZdS )ÚModeWithAuthenticationTagc             C   s   dS )zP
        The value of the tag supplied to the constructor of this mode.
        Nr   )r   r   r   r	   Útag;   s    zModeWithAuthenticationTag.tagN)r   r   r   r   r   r   r   r   r   r	   r   9   s   r   c             C   s    |j dkr|jdkrtdƒ‚d S )Né   ZAESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)Úkey_sizer
   Ú
ValueError)r   r   r   r   r	   Ú_check_aes_key_lengthB   s    r   c             C   s0   t | jƒd |jkr,tdjt | jƒ| jƒƒ‚d S )Né   zInvalid IV size ({0}) for {1}.)Úlenr   Ú
block_sizer   Úformatr
   )r   r   r   r   r	   Ú_check_iv_lengthI   s    r#   c             C   s   t | |ƒ t| |ƒ d S )N)r   r#   )r   r   r   r   r	   Ú_check_iv_and_key_lengthP   s    
r$   c               @   s&   e Zd Zd Zdd„ ZejdƒZeZ	dS )ÚCBCc             C   s   t |tƒstdƒ‚|| _d S )Nz#initialization_vector must be bytes)Ú
isinstanceÚbytesÚ	TypeErrorÚ_initialization_vector)r   r   r   r   r	   Ú__init__Z   s    
zCBC.__init__r)   N)
r   r   r   r
   r*   r   Úread_only_propertyr   r$   r   r   r   r   r	   r%   U   s   
r%   c               @   s*   e Zd Zd Zdd„ ZejdƒZdd„ ZdS )ÚXTSc             C   s0   t |tƒstdƒ‚t|ƒdkr&tdƒ‚|| _d S )Nztweak must be bytesé   z!tweak must be 128-bits (16 bytes))r&   r'   r(   r    r   Ú_tweak)r   r   r   r   r	   r*   i   s
    
zXTS.__init__r.   c             C   s   |j dkrtdƒ‚d S )Nr   é   z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)r   r/   )r   r   )r   r   r   r   r	   r   t   s    
zXTS.validate_for_algorithmN)	r   r   r   r
   r*   r   r+   r   r   r   r   r   r	   r,   d   s   	
r,   c               @   s   e Zd Zd ZeZdS )ÚECBN)r   r   r   r
   r   r   r   r   r   r	   r0   |   s   r0   c               @   s&   e Zd Zd Zdd„ ZejdƒZeZ	dS )ÚOFBc             C   s   t |tƒstdƒ‚|| _d S )Nz#initialization_vector must be bytes)r&   r'   r(   r)   )r   r   r   r   r	   r*   ˆ   s    
zOFB.__init__r)   N)
r   r   r   r
   r*   r   r+   r   r$   r   r   r   r   r	   r1   ƒ   s   
r1   c               @   s&   e Zd Zd Zdd„ ZejdƒZeZ	dS )ÚCFBc             C   s   t |tƒstdƒ‚|| _d S )Nz#initialization_vector must be bytes)r&   r'   r(   r)   )r   r   r   r   r	   r*   —   s    
zCFB.__init__r)   N)
r   r   r   r
   r*   r   r+   r   r$   r   r   r   r   r	   r2   ’   s   
r2   c               @   s&   e Zd Zd Zdd„ ZejdƒZeZ	dS )ÚCFB8c             C   s   t |tƒstdƒ‚|| _d S )Nz#initialization_vector must be bytes)r&   r'   r(   r)   )r   r   r   r   r	   r*   ¦   s    
zCFB8.__init__r)   N)
r   r   r   r
   r*   r   r+   r   r$   r   r   r   r   r	   r3   ¡   s   
r3   c               @   s*   e Zd Zd Zdd„ ZejdƒZdd„ ZdS )ÚCTRc             C   s   t |tƒstdƒ‚|| _d S )Nznonce must be bytes)r&   r'   r(   Ú_nonce)r   r   r   r   r	   r*   µ   s    
zCTR.__init__r5   c             C   s:   t | |ƒ t| jƒd |jkr6tdjt| jƒ| jƒƒ‚d S )Nr   z!Invalid nonce size ({0}) for {1}.)r   r    r   r!   r   r"   r
   )r   r   r   r   r	   r   ½   s    
zCTR.validate_for_algorithmN)	r   r   r   r
   r*   r   r+   r   r   r   r   r   r	   r4   °   s   
r4   c               @   s>   e Zd Zd ZdZdZddd	„Zejd
ƒZ	ejdƒZ
dd„ ZdS )ÚGCMé   é'   r   r   é@   Nr-   c             C   sl   t |tƒstdƒ‚|| _|d k	r\t |tƒs2tdƒ‚|dk rBtdƒ‚t|ƒ|k r\tdj|ƒƒ‚|| _|| _d S )Nz#initialization_vector must be bytesztag must be bytes or Noneé   zmin_tag_length must be >= 4z/Authentication tag must be {0} bytes or longer.)	r&   r'   r(   r)   r   r    r"   Ú_tagZ_min_tag_length)r   r   r   Zmin_tag_lengthr   r   r	   r*   Í   s    

zGCM.__init__r;   r)   c             C   s   t | |ƒ d S )N)r   )r   r   r   r   r	   r   ä   s    zGCM.validate_for_algorithml        l    ÿÿl   àÿ? l            l            )Nr-   )r   r   r   r
   Z_MAX_ENCRYPTED_BYTESZ_MAX_AAD_BYTESr*   r   r+   r   r   r   r   r   r   r	   r6   Å   s   


r6   )Z
__future__r   r   r   r   ZsixZcryptographyr   Zadd_metaclassÚABCMetaÚobjectr   r   r   r   r   r   r#   r$   Zregister_interfacer%   r,   r0   r1   r2   r3   r4   r6   r   r   r   r	   Ú<module>   sP   





