o )%a @sddlZddlZddlmZddlmZmZmZmZddl m Z ddl m Z ddl mZmZddlmZdd ZGd d d eZdS) N)utils)AlreadyFinalized InvalidKeyUnsupportedAlgorithm_Reasons) _get_backend) HashBackend) constant_timehashes)KeyDerivationFunctioncCs td|S)Nz>I)structpack)nrL/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/kdf/x963kdf.py _int_to_u32bes rc@sVeZdZ ddejdedejefddZ dedefd d Z ded eddfd d Z dS)X963KDFN algorithmlength sharedinfocCstt|}|jd}||krtd||durtd|||_||_||_t |t s2t dt j ||_d|_dS)Nlz(Can not derive keys larger than {} bits.rz.Backend object does not implement HashBackend.F)r digest_size ValueErrorformatr _check_bytes _algorithm_length _sharedinfo isinstancerrrBACKEND_MISSING_INTERFACE_backend_used)selfrrrbackendmax_lenrrr__init__s$    zX963KDF.__init__ key_materialreturncCs|jrtd|_td|dg}d}d}|j|krQt|j|j}| || t ||j dur9| |j | | |t|d7}|d7}|j|ksd|d|jS)NTr%r)r rr_check_byteslikerr Hashrrupdaterrappendfinalizelenjoin)r!r%outputoutlencounterhrrrderive8s$       zX963KDF.derive expected_keycCst|||s tdSN)r bytes_eqr5r)r!r%r6rrrverifyMszX963KDF.verifyr7) __name__ __module__ __qualname__r HashAlgorithminttypingOptionalbytesr$r5r9rrrrrs r)r r? cryptographyrcryptography.exceptionsrrrrcryptography.hazmat.backendsr'cryptography.hazmat.backends.interfacesrcryptography.hazmat.primitivesr r "cryptography.hazmat.primitives.kdfr rrrrrrs