3 œäL]ñã@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úV/tmp/pip-install-wfra5znf/cryptography/cryptography/hazmat/primitives/ciphers/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_lengthPs r$c@s&eZdZdZdd„ZejdƒZeZ dS)ÚCBCcCstjd|ƒ||_dS)Nr)rÚ_check_byteslikeÚ_initialization_vector)rrrrr Ú__init__Zs z CBC.__init__r'N) r rrr r(rÚread_only_propertyrr$r rrrr r%Us 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(gs  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 qs zXTS.validate_for_algorithmN) r rrr r(rr)rr rrrr r*bs r*c@seZdZdZeZdS)ÚECBN)r rrr rr rrrr r.ysr.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 r0s 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)Ú __future__rrrrÚsixZ cryptographyrÚ add_metaclassÚABCMetaÚobjectrrrrrrr#r$Zregister_interfacer%r*r.r/r0r1r2r4rrrr ÚsP