a °…b× ã@shddlZddlmZddlmZmZddlmZmZm Z ddl m Z Gdd„de ƒZ Gdd „d e ƒZ dS) éN)Úutils)ÚAlreadyFinalizedÚ InvalidKey)Ú constant_timeÚhashesÚhmac)ÚKeyDerivationFunctionc@sfeZdZd ejeejeejeej dœdd„Z eedœdd„Z eedœdd „Z eedd œd d „Z dS)ÚHKDFN)Ú algorithmÚlengthÚsaltÚinfoÚbackendcCsB||_|durd|jj}n t d|¡||_t|j||ƒ|_dS)Nór )Ú _algorithmÚ digest_sizerÚ _check_bytesÚ_saltÚ HKDFExpandÚ _hkdf_expand)Úselfr r r r r©rúN/tmp/pip-target-98j97qn4/lib/python/cryptography/hazmat/primitives/kdf/hkdf.pyÚ__init__s  z HKDF.__init__©Ú key_materialÚreturncCs"t |j|j¡}| |¡| ¡S©N)rÚHMACrrÚupdateÚfinalize)rrÚhrrrÚ_extract%s z HKDF._extractcCst d|¡|j | |¡¡S)Nr)rÚ_check_byteslikerÚderiver"©rrrrrr$*s z HKDF.derive©rÚ expected_keyrcCst | |¡|¡st‚dSr©rZbytes_eqr$r©rrr'rrrÚverify.sz HKDF.verify)N)Ú__name__Ú __module__Ú __qualname__rÚ HashAlgorithmÚintÚtypingÚOptionalÚbytesÚAnyrr"r$r*rrrrr súú r c@s^eZdZd ejeejeej dœdd„Z eedœdd„Z eedœdd „Z eedd œd d „Z dS)rN)r r r rcCsV||_d|j}||kr&td |¡ƒ‚||_|dur:d}n t d|¡||_d|_dS)Néÿz)Cannot derive keys larger than {} octets.ór F) rrÚ ValueErrorÚformatÚ_lengthrrÚ_infoÚ_used)rr r r rÚ max_lengthrrrr4s ÿ zHKDFExpand.__init__rcCsˆdg}d}|jjt|ƒd|jkrtt ||j¡}| |d¡| |j¡| t|gƒ¡|  |  ¡¡|d7}q d  |¡d|j…S)Nr5ééÿÿÿÿ) rrÚlenr8rrrr9r2Úappendr Újoin)rrÚoutputÚcounterr!rrrÚ_expandOs  zHKDFExpand._expandcCs&t d|¡|jrt‚d|_| |¡S)NrT)rr#r:rrCr%rrrr$]s  zHKDFExpand.deriver&cCst | |¡|¡st‚dSrr(r)rrrr*eszHKDFExpand.verify)N)r+r,r-rr.r/r0r1r2r3rrCr$r*rrrrr3sûû r)r0Z cryptographyrZcryptography.exceptionsrrZcryptography.hazmat.primitivesrrrZ"cryptography.hazmat.primitives.kdfrr rrrrrÚs   "