�
�*�Xc@@s�dZddlmZddlZeje�ZddlmZddl m
Z
ddlmZddl
mZdd gZdZdZd
�Zdadad
dd�Zd�Zd�ZdZed ede�Zed�Zed�d�ZdS(s?passlib.utils.scrypt -- scrypt hash frontend and help utilitiesi(tabsolute_importN(twarn(texc(tto_bytes(tPYPYtvalidatetscryptii icC@s�|dkrtd|��n|dkr>td|��n||tkrgtd||f��n|dks�||d@r�td|��ntS(sI
helper which validates a set of scrypt config parameters.
scrypt will take ``O(n * r * p)`` time and ``O(n * r)`` memory.
limitations are that ``n = 2**<positive integer>``, ``n < 2**(16*r)``, ``r * p < 2 ** 30``.
:param n: scrypt rounds
:param r: scrypt block size
:param p: scrypt parallel factor
isr must be > 0: r=%rsp must be > 0: p=%rs!r * p must be < 2**30: r=%r, p=%ris%n must be > 1, and a power of 2: n=%r(t
ValueErrortMAX_RPtTrue(tntrtp((sB/usr/lib/python2.7/site-packages/passlib/crypto/scrypt/__init__.pyRs
cC@s�t|||�t|dd�}t|dd�}|dkrOtd��n|tkrntdt��nt||||||�S(s4run SCrypt key derivation function using specified parameters.
:arg secret:
passphrase string (unicode is encoded to bytes using utf-8).
:arg salt:
salt string (unicode is encoded to bytes using utf-8).
:arg n:
integer 'N' parameter
:arg r:
integer 'r' parameter
:arg p:
integer 'p' parameter
:arg keylen:
number of bytes of key to generate.
defaults to 32 (the internal block size).
:returns:
a *keylen*-sized bytes instance
SCrypt imposes a number of constraints on it's input parameters:
* ``r * p < 2**30`` -- due to a limitation of PBKDF2-HMAC-SHA256.
* ``keylen < (2**32 - 1) * 32`` -- due to a limitation of PBKDF2-HMAC-SHA256.
* ``n`` must a be a power of 2, and > 1 -- internal limitation of scrypt() implementation
:raises ValueError: if the provided parameters are invalid (see constraints above).
.. warning::
Unless the third-party ``scrypt <https://pypi.python.org/pypi/scrypt/>``_ package
is installed, passlib will use a builtin pure-python implementation of scrypt,
which is *considerably* slower (and thus requires a much lower / less secure
``n`` value in order to be usuable). Installing the :mod:`!scrypt` package
is strongly recommended.
tparamtsecrettsaltiskeylen must be at least 1skeylen too large, must be <= %d(RRRt
MAX_KEYLENt_scrypt(RRR
RRtkeylen((sB/usr/lib/python2.7/site-packages/passlib/crypto/scrypt/__init__.pyREs)cC@s=trdnd}td|tj�ddlm}|jS(sD
Load pure-python scrypt implementation built into passlib.
i
ids�Using builtin scrypt backend, which is %dx slower than is required for adequate security. Installing scrypt support (via 'pip install scrypt') is strongly recommendedi(tScryptEngine(RRRtPasslibSecurityWarningt_builtinRtexecute(tslowdownR((sB/usr/lib/python2.7/site-packages/passlib/crypto/scrypt/__init__.pyt_load_builtin_backendxs
cC@s�yddlm}|SWntk
r+nXyddl}Wn8tk
rv}dt|�kr�tdtj�q�nXtdtj�dS(s�
Try to import the ctypes-based scrypt hash function provided by the
``scrypt <https://pypi.python.org/pypi/scrypt/>``_ package.
i(thashNRsJ'scrypt' package failed to import correctly (possible installation issue?)s5'scrypt' package is too old (lacks ``hash()`` method)(RRtImportErrortstrRRtPasslibWarningtNone(RRterr((sB/usr/lib/python2.7/site-packages/passlib/crypto/scrypt/__init__.pyt_load_cffi_backend�s
tbuiltincC@s�|dkrdS|dkrmx<tD]4}yt|d|�SWq#tjk
rVq#q#Xq#Wtjd��nftj|�}|s�td|f��n|�}|s�tjd|��n|r�dS|a|adS(s�
set backend for scrypt(). if name not specified, loads first available.
:raises ~passlib.exc.MissingBackendError: if backend can't be found
.. note:: mainly intended to be called by unittests, and scrypt hash handler
tanyNtdefaulttdryrunsno scrypt backends availablesunknown scrypt backend: %rsscrypt backend %r not available( tbackend_valuest_set_backendRtMissingBackendErrort_backend_loaderstgetRtbackendR(tnameR#tloaderR((sB/usr/lib/python2.7/site-packages/passlib/crypto/scrypt/__init__.pyR%�s&
R"cC@s4yt|dt�tSWntjk
r/tSXdS(NR#(R%R RR&tFalse(R*((sB/usr/lib/python2.7/site-packages/passlib/crypto/scrypt/__init__.pyt_has_backend�s
II����I��i@i���?(sscryptsbuiltin(t__doc__t
__future__Rtloggingt getLoggert__name__tlogtwarningsRtpasslibRt
passlib.utilsRtpasslib.utils.compatRt__all__RRRRRR)RRRR$tdictR'R,R%R-(((sB/usr/lib/python2.7/site-packages/passlib/crypto/scrypt/__init__.pyt<module>s0 "3
|