Package: scrypt
This is a set ofPythonbindings for thescryptkey derivation
function.Scrypt is useful when encrypting password as it is possible to specify
aminimumamount of time to use when encrypting and decrypting. If,
for example, a password takes 0.05 seconds to verify, a user won’t
notice the slight delay when signing in, but doing a brute force
search of several billion passwords will take a considerable amount of
time. This is in contrast to more traditional hash functions such as
MD5 or the SHA family which can be implemented extremely fast on cheap
hardware.InstallationFor Debian and Ubuntu, please ensure that the following packages are installed:$sudoapt-getinstallbuild-essentiallibssl-devpython-devFor Fedora and RHEL-derivatives, please ensure that the following packages are installed:$sudoyuminstallgccopenssl-develpython-develFor OSX, please do the following:$ brew install openssl
$ export CFLAGS="-I$(brew --prefix openssl)/include $CFLAGS"
$ export LDFLAGS="-L$(brew --prefix openssl)/lib $LDFLAGS"For OSX, you can also use the precompiled wheels. They are installed by:$ pip install scryptFor Windows, please use the precompiled wheels. They are installed by:$ pip install scryptFor Windows, when the package should be compiled, the development package fromhttps://slproweb.com/products/Win32OpenSSL.htmlis needed.
It needs to be installed to C:OpenSSL-Win64.You can install py-scrypt from this repository if you want the latest
but possibly non-compiling version:$ git clone https://github.com/holgern/py-scrypt.git
$ cd py-scrypt
$ python setup.py build

Become superuser (or use virtualenv):
# python setup.py install

Run tests after install:
$ python setup.py testOr you can install the latest release from PyPi:$ pip install scryptUsers of theAnacondaPython distribution can directly obtain pre-built
Windows, Intel Linux or macOS / OSX binaries from the conda-forge channel.
This can be done via:$ conda install -c conda-forge scryptIf you want py-scrypt for your Python 3 environment, just run the
above commands with your Python 3 interpreter. Py-scrypt supports both
Python 2 and 3.From version 0.6.0 (not available on PyPi yet), py-scrypt supports
PyPy as well.Changelog0.8.20Fix #8 by adding missing gettimeofday.c to MANIFEST.in0.8.19Use RtlGenRandom instead of CryptGenRandom on windows (Thanks tohttps://github.com/veorq/cryptocoding/)Add check for c:Program FilesOpenSSL-Win64 and c:Program FilesOpenSSL-Win320.8.18add wheel for python 3.90.8.17add_dll_directory for python 3.8 on windows, as importlib.util.find_spec does not search all paths anymore0.8.16Add additional test vector from RFC (thanks to @ChrisMacNaughton)0.8.15Fix missing import0.8.14fix imp deprecation warning0.8.13improve build for conda forge0.8.12Add SCRYPT_WINDOWS_LINK_LEGACY_OPENSSL environment variable, when set, openssl 1.0.2 is linked0.8.11fix build for conda feedstock0.8.10fix typo0.8.9use the static libcrypto_static for windows and openssl 1.1.10.8.8setup.py for windows improved, works with openssl 1.0.2 and 1.1.10.8.7setup.py for windows fixed0.8.6setup.py fixed, scrypt could not be imported in version 0.8.50.8.5MANIFEST.in fixedscrypt.py moved into own scrypt directory with __init__.pyopenssl library path for osx wheel repaired0.8.4__version__ added to scryptmissing void in sha256.c fixed0.8.3scrypt updated to 1.2.1Wheels are created for python 3.6UsageFore encryption/decryption, the library exports two functionsencryptanddecrypt:>>> import scrypt
>>> data = scrypt.encrypt('a secret message', 'password', maxtime=0.1) # This will take at least 0.1 seconds
>>> data[:20]
'scrypt\x00\r\x00\x00\x00\x08\x00\x00\x00\x01RX9H'
>>> scrypt.decrypt(data, 'password', maxtime=0.1) # This will also take at least 0.1 seconds
'a secret message'
>>> scrypt.decrypt(data, 'password', maxtime=0.05) # scrypt won't be able to decrypt this data fast enough
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
scrypt.error: decrypting file would take too long
>>> scrypt.decrypt(data, 'wrong password', maxtime=0.1) # scrypt will throw an exception if the password is incorrect
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
scrypt.error: password is incorrectFrom these, one can make a simple password verifier using the following
functions:def hash_password(password, maxtime=0.5, datalength=64):
    return scrypt.encrypt(os.urandom(datalength), password, maxtime=maxtime)

def verify_password(hashed_password, guessed_password, maxtime=0.5):
    try:
        scrypt.decrypt(hashed_password, guessed_password, maxtime)
        return True
    except scrypt.error:
        return FalseBut, if you want output that is deterministic and constant in size,
you can use thehashfunction:>>> import scrypt
>>> h1 = scrypt.hash('password', 'random salt')
>>> len(h1)  # The hash will be 64 bytes by default, but is overridable.
64
>>> h1[:10]
'\xfe\x87\xf3hS\tUo\xcd\xc8'
>>> h2 = scrypt.hash('password', 'random salt')
>>> h1 == h2 # The hash function is deterministic
TrueAcknowledgementsScryptwas created by Colin Percival and is licensed as 2-clause BSD.
Since scrypt does not normally build as a shared library, I have included
the source for the currently latest version of the library in this
repository. When a new version arrives, I will update these sources.Kelvin Wongon Bitbucket provided changes to make the library
available on Mac OS X 10.6 and earlier, as well as changes to make the
library work more like the command-line version of scrypt by
default. Kelvin also contributed with the unit tests, lots of cross
platform testing and work on thehashfunction.Burstaholicon Bitbucket provided the necessary changes to make
the library build on Windows.Thepython-appveyor-demorepository for setting up automated Windows
builds for a multitude of Python versions.LicenseThis library is licensed under the same license as scrypt; 2-clause BSD.