U
    ÎZjJ  ã                	   @   s&  d dl mZ d dlZd dlZd dlmZ d dlmZ ej	j
Zej	jZej	jZej	jZej	jZej	jZed Zej	jZej	jZej	jZej	jZej	jZ ej	j!Z"ej	j#Z$ej	j%Z&ej	j'Z(ej	j)Z*de$ Z+de& Z,e(e*ej-j.fe/e0e0e/e/ej-j1e0dœdd	„Z2e$e&fe0e/e/e0d
œdd„Z3e0e0e4dœdd„Z5dS )é    )ÚcastN)Ú
exceptions)Úensureé   é   )ÚsizeÚpasswordÚsaltÚopslimitÚmemlimitÚencoderÚreturnc           
      C   sz   t tdtjd� t t|ƒtkdtt|ƒf tjd� tj 	||¡\}}}|d }	| 
tjj||ttd| ƒ|||	| d�¡S )al  
    Derive a ``size`` bytes long key from a caller-supplied
    ``password`` and ``salt`` pair using the scryptsalsa208sha256
    memory-hard construct.


    the enclosing module provides the constants

        - :py:const:`.OPSLIMIT_INTERACTIVE`
        - :py:const:`.MEMLIMIT_INTERACTIVE`
        - :py:const:`.OPSLIMIT_SENSITIVE`
        - :py:const:`.MEMLIMIT_SENSITIVE`
        - :py:const:`.OPSLIMIT_MODERATE`
        - :py:const:`.MEMLIMIT_MODERATE`

    as a guidance for correct settings respectively for the
    interactive login and the long term key protecting sensitive data
    use cases.

    :param size: derived key size, must be between
                 :py:const:`.BYTES_MIN` and
                 :py:const:`.BYTES_MAX`
    :type size: int
    :param password: password used to seed the key derivation procedure;
                     it length must be between
                     :py:const:`.PASSWD_MIN` and
                     :py:const:`.PASSWD_MAX`
    :type password: bytes
    :param salt: **RANDOM** salt used in the key derivation procedure;
                 its length must be exactly :py:const:`.SALTBYTES`
    :type salt: bytes
    :param opslimit: the time component (operation count)
                     of the key derivation procedure's computational cost;
                     it must be between
                     :py:const:`.OPSLIMIT_MIN` and
                     :py:const:`.OPSLIMIT_MAX`
    :type opslimit: int
    :param memlimit: the memory occupation component
                     of the key derivation procedure's computational cost;
                     it must be between
                     :py:const:`.MEMLIMIT_MIN` and
                     :py:const:`.MEMLIMIT_MAX`
    :type memlimit: int
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.

    .. versionadded:: 1.2
    úNot available in minimal build©Zraisingz.The salt must be exactly %s, not %s bytes longi   é   )ÚmaxmemZdklen)r   Ú	AVAILABLEÚexcÚUnavailableErrorÚlenÚ	SALTBYTESÚ
ValueErrorÚnaclÚbindingsZ nacl_bindings_pick_scrypt_paramsÚencodeZ%crypto_pwhash_scryptsalsa208sha256_llr   Úint)
r   r   r	   r
   r   r   Zn_log2ÚrÚpr   © r   úU/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/nacl/pwhash/scrypt.pyÚkdf;   s8    9ý

ÿü ÿ
öÿr    )r   r
   r   r   c                 C   s    t tdtjd� tj | ||¡S )a$  
    Hashes a password with a random salt, using the memory-hard
    scryptsalsa208sha256 construct and returning an ascii string
    that has all the needed info to check against a future password

    The default settings for opslimit and memlimit are those deemed
    correct for the interactive user login case.

    :param bytes password:
    :param int opslimit:
    :param int memlimit:
    :rtype: bytes
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.

    .. versionadded:: 1.2
    r   r   )r   r   r   r   r   r   Z&crypto_pwhash_scryptsalsa208sha256_str)r   r
   r   r   r   r   Ústr–   s    ý  ÿr!   )Úpassword_hashr   r   c                 C   s>   t tdtjd� t t| ƒtkdtjj tj	d� tj 
| |¡S )aW  
    Takes the output of scryptsalsa208sha256 and compares it against
    a user provided password to see if they are the same

    :param password_hash: bytes
    :param password: bytes
    :rtype: boolean
    :raises nacl.exceptions.UnavailableError: If called when using a
        minimal build of libsodium.

    .. versionadded:: 1.2
    r   r   z/The password hash must be exactly %s bytes long)r   r   r   r   r   ÚPWHASH_SIZEr   r   Ú+crypto_pwhash_scryptsalsa208sha256_STRBYTESr   Z-crypto_pwhash_scryptsalsa208sha256_str_verify)r"   r   r   r   r   Úverify·   s     ý
ÿü ÿr%   )6Útypingr   Znacl.bindingsr   Znacl.encodingr   r   Znacl.exceptionsr   r   r$   Z_strbytes_plus_oneZ&has_crypto_pwhash_scryptsalsa208sha256r   Z,crypto_pwhash_scryptsalsa208sha256_STRPREFIXZ	STRPREFIXZ,crypto_pwhash_scryptsalsa208sha256_SALTBYTESr   Z-crypto_pwhash_scryptsalsa208sha256_PASSWD_MINZ
PASSWD_MINZ-crypto_pwhash_scryptsalsa208sha256_PASSWD_MAXZ
PASSWD_MAXr#   Z,crypto_pwhash_scryptsalsa208sha256_BYTES_MINZ	BYTES_MINZ,crypto_pwhash_scryptsalsa208sha256_BYTES_MAXZ	BYTES_MAXZ/crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MINZMEMLIMIT_MINZ/crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAXZMEMLIMIT_MAXZ/crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MINZOPSLIMIT_MINZ/crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAXZOPSLIMIT_MAXZ7crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVEZOPSLIMIT_INTERACTIVEZ7crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVEZMEMLIMIT_INTERACTIVEZ5crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVEZOPSLIMIT_SENSITIVEZ5crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVEZMEMLIMIT_SENSITIVEZOPSLIMIT_MODERATEZMEMLIMIT_MODERATEÚencodingZ
RawEncoderr   ÚbytesZEncoderr    r!   Úboolr%   r   r   r   r   Ú<module>   s`   ÿÿÿÿúù]ýü!