3 l�_J�@s�ddlmZmZmZddlZddlZddlmZejej �Gdd�de ��Z ejej �Gdd�de ��Z ejej �Gdd �d e ��Z ejej �Gd d �d e ��Zejej �Gd d �d e ��Zdd�Zdd�Zdd�Zeje �eje �Gdd�de ���Zeje �eje �Gdd�de ���Zeje �Gdd�de ��Zeje �eje �Gdd�de ���Zeje �eje �Gdd�de ���Zeje �eje �Gdd�de ���Zeje �eje�Gd d!�d!e ���Zeje �eje �eje�Gd"d#�d#e ����ZdS)$�)�absolute_import�division�print_functionN)�utilsc@s(eZdZejdd��Zejdd��ZdS)�ModecCsdS)z@ A string naming this mode (e.g. "ECB", "CBC"). N�)�selfrr�/usr/lib64/python3.6/modes.py�namesz Mode.namecCsdS)zq Checks that all the necessary invariants of this (mode, algorithm) combination are met. Nr)r� algorithmrrr �validate_for_algorithmszMode.validate_for_algorithmN)�__name__� __module__� __qualname__�abc�abstractpropertyr �abstractmethodr rrrr rsrc@seZdZejdd��ZdS)�ModeWithInitializationVectorcCsdS)zP The value of the initialization vector for this mode as bytes. Nr)rrrr �initialization_vector sz2ModeWithInitializationVector.initialization_vectorN)r rrrrrrrrr rsrc@seZdZejdd��ZdS)� ModeWithTweakcCsdS)z@ The value of the tweak for this mode as bytes. Nr)rrrr �tweak)szModeWithTweak.tweakN)r rrrrrrrrr r'src@seZdZejdd��ZdS)� ModeWithNoncecCsdS)z@ The value of the nonce for this mode as bytes. Nr)rrrr �nonce2szModeWithNonce.nonceN)r rrrrrrrrr r0src@seZdZejdd��ZdS)�ModeWithAuthenticationTagcCsdS)zP The value of the tag supplied to the constructor of this mode. Nr)rrrr �tag;szModeWithAuthenticationTag.tagN)r rrrrrrrrr r9srcCs |jdkr|jdkrtd��dS)N�ZAESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)�key_sizer � ValueError)rr rrr �_check_aes_key_lengthBsrcCs0t|j�d|jkr,tdjt|j�|j���dS)N�zInvalid IV size ({}) for {}.)�lenr� block_sizer�formatr )rr rrr �_check_iv_lengthIsr#cCst||�t||�dS)N)rr#)rr rrr �_check_iv_and_key_lengthRs r$c@s&eZdZdZdd�Zejd�ZeZ dS)�CBCcCstjd|�||_dS)Nr)r�_check_byteslike�_initialization_vector)rrrrr �__init__\s z CBC.__init__r'N) r rrr r(r�read_only_propertyrr$r rrrr r%Ws r%c@s*eZdZdZdd�Zejd�Zdd�ZdS)�XTScCs*tjd|�t|�dkr td��||_dS)Nr�z!tweak must be 128-bits (16 bytes))rr&r r�_tweak)rrrrr r(is  z XTS.__init__r,cCs|jdkrtd��dS)Nr�z\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)rr-)rr)rr rrr r ss zXTS.validate_for_algorithmN) r rrr r(rr)rr rrrr r*ds r*c@seZdZdZeZdS)�ECBN)r rrr rr rrrr r.{sr.c@s&eZdZdZdd�Zejd�ZeZ dS)�OFBcCstjd|�||_dS)Nr)rr&r')rrrrr r(�s z OFB.__init__r'N) r rrr r(rr)rr$r rrrr r/�s r/c@s&eZdZdZdd�Zejd�ZeZ dS)�CFBcCstjd|�||_dS)Nr)rr&r')rrrrr r(�s z CFB.__init__r'N) r rrr r(rr)rr$r rrrr r0�s r0c@s&eZdZdZdd�Zejd�ZeZ dS)�CFB8cCstjd|�||_dS)Nr)rr&r')rrrrr r(�s z CFB8.__init__r'N) r rrr r(rr)rr$r rrrr r1�s r1c@s*eZdZdZdd�Zejd�Zdd�ZdS)�CTRcCstjd|�||_dS)Nr)rr&�_nonce)rrrrr r(�s z CTR.__init__r3cCs:t||�t|j�d|jkr6tdjt|j�|j���dS)NrzInvalid nonce size ({}) for {}.)rr rr!rr"r )rr rrr r �s  zCTR.validate_for_algorithmN) r rrr r(rr)rr rrrr r2�s r2c@s>eZdZdZdZdZddd �Zejd �Z ejd �Z d d �Z dS)�GCM��'rr�@Nr+cCsttjd|�t|�dkr td��||_|dk rdtjd|�|dkrJtd��t|�|krdtdj|���||_||_dS)Nrrz-initialization_vector must be at least 1 byter�zmin_tag_length must be >= 4z.Authentication tag must be {} bytes or longer.) rr&r rr'� _check_bytesr"�_tagZ_min_tag_length)rrrZmin_tag_lengthrrr r(�s    z GCM.__init__r:r'cCst||�dS)N)r)rr rrr r �szGCM.validate_for_algorithmll��l��?ll)Nr+) r rrr Z_MAX_ENCRYPTED_BYTESZ_MAX_AAD_BYTESr(rr)rrr rrrr r4�s   r4)Z __future__rrrrZsixZ cryptographyrZ add_metaclass�ABCMeta�objectrrrrrrr#r$Zregister_interfacer%r*r.r/r0r1r2r4rrrr �sP