o
    �)%aÈ  ã                   @   sz   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 d dlmZ e jd ZG d	d
„ d
eƒZdS )é    N)Úutils)ÚAlreadyFinalizedÚ
InvalidKeyÚUnsupportedAlgorithmÚ_Reasons)Ú_get_backend)ÚScryptBackend)Úconstant_time)ÚKeyDerivationFunctioné   c                   @   sV   e Zd Z	ddedededed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 )ÚScryptNÚsaltÚlengthÚnÚrÚpc                 C   s˜   t |ƒ}t|tƒstdtjƒ‚|| _t d|¡ |dk s$||d @ dkr(t	dƒ‚|dk r0t	dƒ‚|dk r8t	dƒ‚d	| _
|| _|| _|| _|| _|| _d S )
Nz0Backend object does not implement ScryptBackend.r   r   é   r   z-n must be greater than 1 and be a power of 2.z%r must be greater than or equal to 1.z%p must be greater than or equal to 1.F)r   Ú
isinstancer   r   r   ÚBACKEND_MISSING_INTERFACEÚ_lengthr   Ú_check_bytesÚ
ValueErrorÚ_usedÚ_saltÚ_nÚ_rÚ_pÚ_backend)Úselfr   r   r   r   r   Úbackend© r    úK/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/kdf/scrypt.pyÚ__init__   s(   
þ
zScrypt.__init__Úkey_materialÚreturnc                 C   s@   | j rtdƒ‚d| _ t d|¡ | j || j| j| j| j	| j
¡S )Nz'Scrypt instances can only be used once.Tr#   )r   r   r   Ú_check_bytesliker   Úderive_scryptr   r   r   r   r   )r   r#   r    r    r!   Úderive7   s   ÿzScrypt.deriveÚexpected_keyc                 C   s"   |   |¡}t ||¡stdƒ‚d S )NzKeys do not match.)r'   r	   Úbytes_eqr   )r   r#   r(   Úderived_keyr    r    r!   ÚverifyA   s   
ÿzScrypt.verify)N)Ú__name__Ú
__module__Ú__qualname__ÚbytesÚintr"   r'   r+   r    r    r    r!   r      s    ÿÿÿÿÿ
ÿ
r   )ÚsysÚcryptographyr   Úcryptography.exceptionsr   r   r   r   Úcryptography.hazmat.backendsr   Ú'cryptography.hazmat.backends.interfacesr   Úcryptography.hazmat.primitivesr	   Ú"cryptography.hazmat.primitives.kdfr
   ÚmaxsizeÚ
_MEM_LIMITr   r    r    r    r!   Ú<module>   s   
