관리-도구
편집 파일: scrypt.cpython-39.pyc
a f�WcB7 � @ s� d Z ddlmZmZ ddlZe�e�Zddlm Z ddlmZm Z ddlmZmZmZ ddlmZmZmZ ddlmZ ddlm mZ d gZed �Zed�Zed�ZG d d � d ejej ej!ej"ej#ej$�Z dS )z/passlib.handlers.scrypt -- scrypt password hash� )�with_statement�absolute_importN)�scrypt)�h64�to_bytes)r �b64s_decode�b64s_encode)�u� bascii_to_str�suppress_cause)� classpropertyr z$scrypt$z$7$�$c s e Zd ZdZd ZdZdZeZee fZ dZdZdZ dZdZdZdZd Zed+� fdd� �Zed d� �Zedd� �Zedd� �Zedd� �Zdd� Zd,� fdd� Zed-dd��Z� fdd�Zedd� �Zed d!� �Zed.d#d$��Z ed/d%d&��Z!d'd(� Z"� fd)d*�Z#� Z$S )0r a� This class implements an SCrypt-based password [#scrypt-home]_ hash, and follows the :ref:`password-hash-api`. It supports a variable-length salt, a variable number of rounds, as well as some custom tuning parameters unique to scrypt (see below). The :meth:`~passlib.ifc.PasswordHash.using` method accepts the following optional keywords: :type salt: str :param salt: Optional salt string. If specified, the length must be between 0-1024 bytes. If not specified, one will be auto-generated (this is recommended). :type salt_size: int :param salt_size: Optional number of bytes to use when autogenerating new salts. Defaults to 16 bytes, but can be any value between 0 and 1024. :type rounds: int :param rounds: Optional number of rounds to use. Defaults to 16, but must be within ``range(1,32)``. .. warning:: Unlike many hash algorithms, increasing the rounds value will increase both the time *and memory* required to hash a password. :type block_size: int :param block_size: Optional block size to pass to scrypt hash function (the ``r`` parameter). Useful for tuning scrypt to optimal performance for your CPU architecture. Defaults to 8. :type parallelism: int :param parallelism: Optional parallelism to pass to scrypt hash function (the ``p`` parameter). Defaults to 1. :type relaxed: bool :param relaxed: By default, providing an invalid value for one of the other keywords will result in a :exc:`ValueError`. If ``relaxed=True``, and the error can be corrected, a :exc:`~passlib.exc.PasslibHashWarning` will be issued instead. Correctable errors include ``rounds`` that are too small or too large, and ``salt`` strings that are too long. .. note:: The underlying scrypt hash function has a number of limitations on it's parameter values, which forbids certain combinations of settings. The requirements are: * ``linear_rounds = 2**<some positive integer>`` * ``linear_rounds < 2**(16 * block_size)`` * ``block_size * parallelism <= 2**30-1`` .. todo:: This class currently does not support configuring default values for ``block_size`` or ``parallelism`` via a :class:`~passlib.context.CryptContext` configuration. )�ident�saltZ salt_size�rounds� block_size�parallelism� � i � � Zlog2� Nc s� t t| �jf i |��}|d urHt|tj�r2t|�}|j||�d�d�|_ zt �d| j>