o
    )%a	                     @   s   d dl Z d dlZd dlmZ d dlmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZ dd	 ZG d
d deZdS )    N)utils)AlreadyFinalized
InvalidKeyUnsupportedAlgorithm_Reasons)_get_backend)HashBackend)constant_timehashes)KeyDerivationFunctionc                 C   s   t d| S )Nz>I)structpack)n r   L/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/kdf/x963kdf.py_int_to_u32be   s   r   c                   @   sV   e Zd Z	ddejdedeje fddZ	dedefd	d
Z
dededdfddZdS )X963KDFN	algorithmlength
sharedinfoc                 C   st   t |}|jd }||krtd||d urtd| || _|| _|| _t	|t
s2tdtj|| _d| _d S )Nl    z(Can not derive keys larger than {} bits.r   z.Backend object does not implement HashBackend.F)r   digest_size
ValueErrorformatr   _check_bytes
_algorithm_length_sharedinfo
isinstancer   r   r   BACKEND_MISSING_INTERFACE_backend_used)selfr   r   r   backendmax_lenr   r   r   __init__   s$   


zX963KDF.__init__key_materialreturnc                 C   s   | j rtd| _ td| dg}d}d}| j|krQt| j| j}|	| |	t
| | jd ur9|	| j ||  |t|d 7 }|d7 }| j|ksd|d | j S )NTr%       r      )r    r   r   _check_bytesliker   r
   Hashr   r   updater   r   appendfinalizelenjoin)r!   r%   outputoutlencounterhr   r   r   derive8   s$   




zX963KDF.deriveexpected_keyc                 C   s   t | ||std S N)r	   bytes_eqr5   r   )r!   r%   r6   r   r   r   verifyM   s   zX963KDF.verifyr7   )__name__
__module____qualname__r
   HashAlgorithminttypingOptionalbytesr$   r5   r9   r   r   r   r   r      s    
r   )r   r?   cryptographyr   cryptography.exceptionsr   r   r   r   cryptography.hazmat.backendsr   'cryptography.hazmat.backends.interfacesr   cryptography.hazmat.primitivesr	   r
   "cryptography.hazmat.primitives.kdfr   r   r   r   r   r   r   <module>   s   