3Tf$ddlmZddlZddlmZddlmZmZmZm Z ddl m Z m Z m Z mZmZddlmZGddej$ZGd d ej$ZGd d ZGd deZGddeZy)) annotationsN)utils)AlreadyFinalized InvalidKeyUnsupportedAlgorithm_Reasons)cipherscmac constant_timehasheshmac)KeyDerivationFunctionceZdZdZy)ModectrN)__name__ __module__ __qualname__ CounterModeJ/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/kdf/kbkdf.pyrrsKrrceZdZdZdZdZy)CounterLocation before_fixed after_fixed middle_fixedN)rrr BeforeFixed AfterFixed MiddleFixedrrrrrs KJ Krrc^eZdZ ddZeddZddZd dZy) _KBKDFDeriverc t|sJt|ts tdt|ts td||tj ur t d||tj k7r t d|t|ts td||dkr t d|s| r | r t d||j|s t d | | t d |t|ts td |d }| d } tjd |tjd| ||_ ||_ ||_ ||_||_||_||_||_| |_d|_| |_y)Nzmode must be of type Modez(location must be of type CounterLocationzPlease specify a break_locationzJbreak_location is ignored when location is not CounterLocation.MiddleFixedz!break_location must be an integerrz)break_location must be a positive integerz9When supplying fixed data, label and context are ignored.zrlen must be between 1 and 4zPlease specify an llenzllen must be an integerrlabelcontextF)callable isinstancer TypeErrorrr ValueErrorint_valid_byte_lengthr _check_bytes_prf_mode_length_rlen_llen _location_break_location_label_context_used _fixed_data) selfprfmodelengthrlenllenlocationbreak_locationr$r%fixeds r__init__z_KBKDFDeriver.__init__%s}}$%78 8(O4FG G  !h/2M2M&M>? ?  &O777/   %j.M?@ @  %.1*<HI I W%N   len(fixed))r6rr_check_bytesliker/rEr0powrFr)_generate_fixed_inputr2rrrr'r3r*ranger-updateappendfinalizejoin) r8rJprf_output_sizeroundsoutputr_binr@data_before_ctrdata_after_ctrihcounter input_datas rderivez_KBKDFDeriver.derivexs ::" " ~|< LL=O34 ""1djj1 C3u:>*Q. .=> >**, >>_88 8!O"N ^^99 9#O N$$c&&U3 !EFF#$:d&:&:;O"4#7#7#9:Nq&1*% (A ,'A((DJJ7G(72^CJ HHZ MM!**, ' (xx$,,//rc|jr&t|jtr |jStj|j dz|j }dj|jd|j|gS)NrLr) r7r'bytesrrEr/r1rTr4r5)r8l_vals rrOz#_KBKDFDeriver._generate_fixed_inputse    4+;+;U C## #""4<rr?rdr$typing.Optional[bytes]r%rer@re)rGr*returnbool)rJrbrUr*rfrb)rfrb)rrrrA staticmethodr+r_rOrrrr"r"$sG! G!G! G!  G! # G!"G!-G!&G!(G!&G!R.0`Frr"c`eZdZ ddd ddZd dZd dZd dZy) KBKDFHMACNr?c  "t|tjstdtj ddlm} | j|stdtj ||_ t|j|||||| ||| |_ y)Nz5Algorithm supplied is not a supported hash algorithm.rbackendz5Algorithm supplied is not a supported hmac algorithm.) r'r HashAlgorithmrrUNSUPPORTED_HASH,cryptography.hazmat.backends.openssl.backendrnhmac_supported _algorithmr"r-_deriver) r8 algorithmr:r;r<r=r>r$r%r@rnr?ossls rrAzKBKDFHMAC.__init__s)V%9%9:&G))   ""9-&G))  $% II            rcBtj||jSN)r HMACrsr8rJs rr-zKBKDFHMAC._prfsyyt77rcb|jj||jjSrx)rtr_rs digest_sizerzs rr_zKBKDFHMAC.derives#}}##L$//2M2MNNrcZtj|j||styrxr bytes_eqr_rr8rJ expected_keys rverifyzKBKDFHMAC.verify'%%dkk,&?N Orrx)ruzhashes.HashAlgorithmr:rr;r*r<r*r=rdr>rr$rer%rer@rern typing.Anyr?rd)rJrbrfz hmac.HMACrJrbrfrbrJrbrrbrfNonerrrrAr-r_rrrrrjrjs#, 04, ', ,  ,  , # , ", &, (, &, , -, \8Orrjc\eZdZ ddd ddZd dZd dZd dZy) KBKDFCMACNrkc  t|tjrt|tjst dt j ||_d|_t|j|||||| ||| |_ y)N7Algorithm supplied is not a supported cipher algorithm.) issubclassr BlockCipherAlgorithmCipherAlgorithmrrUNSUPPORTED_CIPHERrs_cipherr"r-rt) r8rur:r;r<r=r>r$r%r@rnr?s rrAzKBKDFCMAC.__init__s~ w33 Iw'>'>?&I++  $FJ % II            rc\|jJtj|jSrx)rr CMAC)r8_s rr-zKBKDFCMAC._prfs%||'''yy&&rc&|j||_|jJddlm}|j |jst dt j|jj||jjdzS)NrrmrrL) rsrrqrncmac_algorithm_supportedrrrrtr_ block_size)r8rJrvs rr_zKBKDFCMAC.derives||4 ||''' ,,T\\:&I++  }}##L$,,2I2IQ2NOOrcZtj|j||styrxr~rs rrzKBKDFCMAC.verify)rrrx)r:rr;r*r<r*r=rdr>rr$rer%rer@rernrr?rd)rrbrfz cmac.CMACrrrrrrrrs#% 04% %  %  % # % "% &% (% &% % -% N' P"rr) __future__rtyping cryptographyrcryptography.exceptionsrrrrcryptography.hazmat.primitivesr r r r r "cryptography.hazmat.primitives.kdfrEnumrrr"rjrrrrrsv #  E5::!ejj! JFJFZ7%7t@%@r