3
X                 @   s   d dl mZ d dl mZ d dlZd dlZd dljZd dlm	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eejjfddZeefdd	Zd
d ZdS )    )absolute_import)divisionN)ensure   c       
   
   C   sd   t t|tkdtt|f tjd tjj||\}}}|d }	|jtjj	||d| |||	| dS )a  
    Makes a key defined from ``password`` and ``salt`` that is
    ``size`` bytes long

    the enclosing module provides the constants

        - :py:const:`.SCRYPT_OPSLIMIT_INTERACTIVE`
        - :py:const:`.SCRYPT_MEMLIMIT_INTERACTIVE`
        - :py:const:`.SCRYPT_OPSLIMIT_SENSITIVE`
        - :py:const:`.SCRYPT_MEMLIMIT_SENSITIVE`

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

    :param int size: int
    :param bytes password: bytes
    :param bytes salt: bytes
    :param int opslimit:
    :param int memlimit:
    :rtype: bytes
    z.The salt must be exactly %s, not %s bytes long)raising      )maxmemZdkleni   )
r   lenSCRYPT_SALTBYTESexc
ValueErrornaclbindingsZ nacl_bindings_pick_scrypt_paramsencodeZ%crypto_pwhash_scryptsalsa208sha256_ll)
sizepasswordZsaltopslimitmemlimitencoderZn_log2rpr	    r   -/usr/lib/python3/dist-packages/nacl/pwhash.pykdf_scryptsalsa208sha256%   s    

r   c             C   s   t jj| ||S )ac  
    Hashes a password with a random salt, 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
    )r   r   Z&crypto_pwhash_scryptsalsa208sha256_str)r   r   r   r   r   r   scryptsalsa208sha256_strQ   s    r   c             C   s.   t t| tkdtjj tjd tjj| |S )z
    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
    z/The password hash must be exactly %s bytes long)r   )	r   r
   SCRYPT_PWHASH_SIZEr   r   +crypto_pwhash_scryptsalsa208sha256_STRBYTESr   r   Z-crypto_pwhash_scryptsalsa208sha256_str_verify)Zpassword_hashr   r   r   r   verify_scryptsalsa208sha256f   s    

r   )Z
__future__r   r   Znacl.bindingsr   Znacl.encodingZnacl.exceptions
exceptionsr   r   r   r   Z_strbytes_plus_oneZ,crypto_pwhash_scryptsalsa208sha256_SALTBYTESr   r   Z7crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVEZSCRYPT_OPSLIMIT_INTERACTIVEZ7crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVEZSCRYPT_MEMLIMIT_INTERACTIVEZ5crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVEZSCRYPT_OPSLIMIT_SENSITIVEZ5crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVEZSCRYPT_MEMLIMIT_SENSITIVEencodingZ
RawEncoderr   r   r   r   r   r   r   <module>   s$   
*