U  `@sddlmZmZmZddlZddlZddlmZeej Gddde Z eej Gddde Z eej Gdd d e Z eej Gd d d e Zeej Gd d d e ZddZddZddZee ee Gddde Zee ee Gddde Zee Gddde Zee ee Gddde Zee ee Gddde Zee ee Gddde Zee eeGd d!d!e Zee ee eeGd"d#d#e ZdS)$)absolute_importdivisionprint_functionN)utilsc@s(eZdZejddZejddZdS)ModecCsdS)z@ A string naming this mode (e.g. "ECB", "CBC"). NselfrrV/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/ciphers/modes.pynamesz Mode.namecCsdS)zq Checks that all the necessary invariants of this (mode, algorithm) combination are met. Nrr algorithmrrr validate_for_algorithmszMode.validate_for_algorithmN)__name__ __module__ __qualname__abcabstractpropertyr abstractmethodrrrrr rs rc@seZdZejddZdS)ModeWithInitializationVectorcCsdS)zP The value of the initialization vector for this mode as bytes. Nrrrrr initialization_vector sz2ModeWithInitializationVector.initialization_vectorN)rrrrrrrrrr rsrc@seZdZejddZdS) ModeWithTweakcCsdS)z@ The value of the tweak for this mode as bytes. Nrrrrr tweak)szModeWithTweak.tweakN)rrrrrrrrrr r'src@seZdZejddZdS) ModeWithNoncecCsdS)z@ The value of the nonce for this mode as bytes. Nrrrrr nonce2szModeWithNonce.nonceN)rrrrrrrrrr r0src@seZdZejddZdS)ModeWithAuthenticationTagcCsdS)zP The value of the tag supplied to the constructor of this mode. Nrrrrr tag;szModeWithAuthenticationTag.tagN)rrrrrrrrrr r9srcCs |jdkr|jdkrtddS)NZAESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)key_sizer ValueErrorr rrr _check_aes_key_lengthBsr cCs0t|jd|jkr,tdt|j|jdS)NzInvalid IV size ({}) for {}.)lenr block_sizerformatr r rrr _check_iv_lengthIsr%cCst||t||dSN)r r%r rrr _check_iv_and_key_lengthRs r'c@s&eZdZdZddZedZeZ dS)CBCcCstd|||_dSNrr_check_byteslike_initialization_vectorr rrrr __init__\s z CBC.__init__r,N rrrr r.rread_only_propertyrr'rrrrr r(Ws r(c@s*eZdZdZddZedZddZdS)XTScCs*td|t|dkr td||_dS)Nrz!tweak must be 128-bits (16 bytes))rr+r"r_tweak)r rrrr r.is  z XTS.__init__r3cCs|jdkrtddS)N)riz\The XTS specification requires a 256-bit key for AES-128-XTS and 512-bit key for AES-256-XTS)rrr rrr rss zXTS.validate_for_algorithmN) rrrr r.rr0rrrrrr r1ds r1c@seZdZdZeZdS)ECBN)rrrr r rrrrr r4{sr4c@s&eZdZdZddZedZeZ dS)OFBcCstd|||_dSr)r*r-rrr r.s z OFB.__init__r,Nr/rrrr r5s r5c@s&eZdZdZddZedZeZ dS)CFBcCstd|||_dSr)r*r-rrr r.s z CFB.__init__r,Nr/rrrr r6s r6c@s&eZdZdZddZedZeZ dS)CFB8cCstd|||_dSr)r*r-rrr r.s z CFB8.__init__r,Nr/rrrr r7s r7c@s*eZdZdZddZedZddZdS)CTRcCstd|||_dS)Nr)rr+_nonce)r rrrr r.s z CTR.__init__r9cCs:t||t|jd|jkr6tdt|j|jdS)Nr!zInvalid nonce size ({}) for {}.)r r"rr#rr$r r rrr rs zCTR.validate_for_algorithmN) rrrr r.rr0rrrrrr r8s r8c@s>eZdZdZdZdZd ddZedZ edZ d d Z dS) GCMl?lNr2cCstd|t|dks$t|dkr,td||_|dk rptd||dkrVtdt||krptd|||_||_dS) Nrr!zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).rzmin_tag_length must be >= 4z.Authentication tag must be {} bytes or longer.) rr+r"rr, _check_bytesr$_tagZ_min_tag_length)r rrZmin_tag_lengthrrr r.s$   z GCM.__init__r>r,cCst||dSr&)r r rrr rszGCM.validate_for_algorithm)Nr2) rrrr Z_MAX_ENCRYPTED_BYTESZ_MAX_AAD_BYTESr.rr0rrrrrrr r:s   r:)Z __future__rrrrZsixZ cryptographyrZ add_metaclassABCMetaobjectrrrrrr r%r'Zregister_interfacer(r1r4r5r6r7r8r:rrrr sP