pgj TddlZddlZddlmZddlmZmZddlmZm Z ddl m Z Gddej Z Gd d e ej ZGd d e ej ZGd de ej ZGdde ej Zde de ddfdZdededdfdZdedede ddfdZdede ddfdZGddeZGddeZGdde ZGd d!eZGd"d#eZGd$d%eZGd&d'eZGd(d)eeZdS)*N)utils)UnsupportedAlgorithm_Reasons)BlockCipherAlgorithmCipherAlgorithm) algorithmsc^eZdZejdefdZejdeddfdZ dS)ModereturncdS)z@ A string naming this mode (e.g. "ECB", "CBC"). Nselfs N/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/ciphers/modes.pynamez Mode.name algorithmNcdS)zq Checks that all the necessary invariants of this (mode, algorithm) combination are met. Nr rrs rvalidate_for_algorithmzMode.validate_for_algorithmrr) __name__ __module__ __qualname__abcabstractpropertystrrabstractmethodrrr rrr r so c       D      rr ) metaclassc4eZdZejdefdZdS)ModeWithInitializationVectorr cdS)zP The value of the initialization vector for this mode as bytes. Nr rs rinitialization_vectorz2ModeWithInitializationVector.initialization_vector"rrN)rrrrrbytesr#r rrr!r!!s= u      rr!c4eZdZejdefdZdS) ModeWithTweakr cdS)z@ The value of the tweak for this mode as bytes. Nr rs rtweakzModeWithTweak.tweak*rrN)rrrrrr$r(r rrr&r&)= u      rr&c4eZdZejdefdZdS) ModeWithNoncer cdS)z@ The value of the nonce for this mode as bytes. Nr rs rnoncezModeWithNonce.nonce2rrN)rrrrrr$r-r rrr+r+1r)rr+cJeZdZejdejefdZdS)ModeWithAuthenticationTagr cdS)zP The value of the tag supplied to the constructor of this mode. Nr rs rtagzModeWithAuthenticationTag.tag:rrN) rrrrrtypingOptionalr$r1r rrr/r/9sD V_U+      rr/rrr cT|jdkr|jdkrtddSdS)NAESz=Only 128, 192, and 256 bit keys are allowed for this AES mode)key_sizer ValueErrorrs r_check_aes_key_lengthr9As?CINe$;$; K    $;$;rct|jdz|jkr:tdt|j|jdS)NzInvalid IV size ({}) for {}.)lenr# block_sizer8formatrrs r_check_iv_lengthr?Hsb 4 %&&*i.BBB * 1 1D.//     CBrr-rct|tst|dtjt |dz|jkr0tdt ||dS)N" requires a block cipher algorithmr;zInvalid nonce size ({}) for {}.) isinstancerrrUNSUPPORTED_CIPHERr<r=r8r>)r-rrs r_check_nonce_lengthrDSs i!5 6 6 " 7 7 7  '    5zzA~--- - 4 4SZZ F F   .-rct|tst|dtjt ||t ||dS)NrA)rBrrrrCr9r?rs r_check_iv_and_key_lengthrFasc i!5 6 6 " 7 7 7  '   $ ***T9%%%%%rc>eZdZdZdefdZedefdZeZ dS)CBCr#c>tjd|||_dSNr#r_check_byteslike_initialization_vectorrr#s r__init__z CBC.__init__p% 68MNNN&;###rr c|jSNrMrs rr#zCBC.initialization_vectort **rN rrrrr$rOpropertyr#rFrr rrrHrHm_ DeZdZdZdefdZedefdZeZ dS)OFBr#c>tjd|||_dSrJrKrNs rrOz OFB.__init__rPrr c|jSrRrSrs rr#zOFB.initialization_vectorrTrNrUr rrrfrfrWrrfc>eZdZdZdefdZedefdZeZ dS)CFBr#c>tjd|||_dSrJrKrNs rrOz CFB.__init__rPrr c|jSrRrSrs rr#zCFB.initialization_vectorrTrNrUr rrrjrjrWrrjc>eZdZdZdefdZedefdZeZ dS)CFB8r#c>tjd|||_dSrJrKrNs rrOz CFB8.__init__rPrr c|jSrRrSrs rr#zCFB8.initialization_vectorrTrNrUr rrrnrns_ Dtjd|||_dS)Nr-)rrL_nonce)rr-s rrOz CTR.__init__s  w... rr c|jSrR)rtrs rr-z CTR.noncer^rrNc\t||t|j|j|dSrR)r9rDr-rrs rrzCTR.validate_for_algorithms.dI...DJ 9=====r) rrrrr$rOrVr-rrr rrrrrrs} DeuX>>D>>>>>>rrrceZdZdZdZdZ ddedejede fdZ e d ejefd Z e d efd Z d ed dfd ZdS)GCMl?lNr[r#r1min_tag_lengthctjd|t|dkst|dkrtd||_|_tjd||dkrtdt||kr"td|||_||_dS) Nr#r;zIinitialization_vector must be between 8 and 128 bytes (64 and 1024 bits).r1zmin_tag_length must be >= 4z.Authentication tag must be {} bytes or longer.) rrLr<r8rM _check_bytesr>_tag_min_tag_length)rr#r1rys rrOz GCM.__init__s 68MNNN $ % % ) )S1F-G-G#-M-M" '<# ?  uc * * *!! !>???3xx.(( DKK&  -rr c|jSrR)r~rs rr1zGCM.tags yrc|jSrRrSrs rr#zGCM.initialization_vectorrTrrct||t|tstdtj|jdz}|j:t|j|kr$td |dSdS)Nz%GCM requires a block cipher algorithmr;z0Authentication tag cannot be more than {} bytes.) r9rBrrrrCr=r~r<r8r>)rrblock_size_bytess rrzGCM.validate_for_algorithmsdI...)%9:: &7+ %/14 9 S^^6F%F%FBII$  ! %F%Fr)Nr[)rrrr_MAX_ENCRYPTED_BYTES_MAX_AAD_BYTESr$r2r3intrOrVr1r#rrr rrrxrxs D-!N '+ ..$._U #. ....8V_U+X+u+++X+  D      rrx) rr2 cryptographyrcryptography.exceptionsrr/cryptography.hazmat.primitives._cipheralgorithmrr&cryptography.hazmat.primitives.ciphersrABCMetar r!r&r+r/r9r?r$rrDrFrHrYrdrfrjrnrrrxr rrrs  BBBBBBBB>=====      S[          43;         DCK         DCK                 T     & 3G            (7         & & &3B &  & & & & 6 6 6 6 6 & 6 6 6-:33333$333 6 6 6 6 6 & 6 6 6 6 6 6 6 6 & 6 6 6 6 6 6 6 6 ' 6 6 6 > > > > >- > > > 66666 &(A66666r