Skip to main content

This is a set of Python bindings for the scrypt key derivation function.

Latest Version https://anaconda.org/conda-forge/scrypt/badges/version.svg https://anaconda.org/conda-forge/scrypt/badges/downloads.svg

Scrypt is useful when encrypting password as it is possible to specify a minimum amount 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.

Installation

For Debian and Ubuntu, please ensure that the following packages are installed:

$ sudo apt-get install build-essential libssl-dev python-dev

For Fedora and RHEL-derivatives, please ensure that the following packages are installed:

$ sudo yum install gcc openssl-devel python-devel

For 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 scrypt

For Windows, please use the precompiled wheels. They are installed by:

$ pip install scrypt

For Windows, when the package should be compiled, the development package from https://slproweb.com/products/Win32OpenSSL.html is 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:

$ hg clone http://bitbucket.org/mhallin/py-scrypt
$ cd py-scrypt
$ python setup.py build

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

Run tests after install:
$ python setup.py test

Or you can install the latest release from PyPi:

$ pip install scrypt

Users of the Anaconda Python 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 scrypt

If 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.

Changelog

0.8.13

  • improve build for conda forge

0.8.12

  • Add SCRYPT_WINDOWS_LINK_LEGACY_OPENSSL environment variable, when set, openssl 1.0.2 is linked

0.8.11

  • fix build for conda feedstock

0.8.10

  • fix typo

0.8.9

  • use the static libcrypto_static for windows and openssl 1.1.1

0.8.8

  • setup.py for windows improved, works with openssl 1.0.2 and 1.1.1

0.8.7

  • setup.py for windows fixed

0.8.6

  • setup.py fixed, scrypt could not be imported in version 0.8.5

0.8.5

  • MANIFEST.in fixed

  • scrypt.py moved into own scrypt directory with __init__.py

  • openssl library path for osx wheel repaired

0.8.4

  • __version__ added to scrypt

  • missing void in sha256.c fixed

0.8.3

  • scrypt updated to 1.2.1

  • Wheels are created for python 3.6

Usage

Fore encryption/decryption, the library exports two functions encrypt and decrypt:

>>> 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 incorrect

From 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 False

But, if you want output that is deterministic and constant in size, you can use the hash function:

>>> 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
True

Acknowledgements

Scrypt was 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 Wong on 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 the hash function.

Burstaholic on Bitbucket provided the necessary changes to make the library build on Windows.

The python-appveyor-demo repository for setting up automated Windows builds for a multitude of Python versions.

License

This library is licensed under the same license as scrypt; 2-clause BSD.

Metadata

Release files for scrypt 0.8.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrypt 0.8.13
File Size Uploaded
scrypt-0.8.13.tar.gz 53.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for scrypt 0.8.13
File
scrypt-0.8.13-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details
scrypt-0.8.13-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details
scrypt-0.8.13-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
scrypt-0.8.13-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
scrypt-0.8.13-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
scrypt-0.8.13-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details
scrypt-0.8.13-cp34-cp34m-win32.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-32 Details
scrypt-0.8.13-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details

Total release size: 304.9 kB

Release files / scrypt-0.8.13.tar.gz

Download URL scrypt-0.8.13.tar.gz
Size 53.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1377b1adc98c4152694bf5d7e93b41a9d2e9060af69b747cfad8c93ac426f9ea
BLAKE2b-256 checksum
How to use checksums
803d141eb80e754b86f6c25a2ffaf6c3af3acdb65a3e3700829a05ab0c5d965d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / scrypt-0.8.13-cp37-cp37m-win_amd64.whl

Download URL scrypt-0.8.13-cp37-cp37m-win_amd64.whl
Size 35.3 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
a12930a9942774dbaebe0ae4e3d089a6ea158daf7fc6d9b81aba47bcb73103ff
BLAKE2b-256 checksum
How to use checksums
af4d06b8b97b5db55619a98cc09b2670e69220d228c973b47e15bef6409504fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / scrypt-0.8.13-cp37-cp37m-win32.whl

Download URL scrypt-0.8.13-cp37-cp37m-win32.whl
Size 29.7 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
96ef78c99b324000cadf019c6af1f6cd2fefc1048951fc07365ec74bf99c17f9
BLAKE2b-256 checksum
How to use checksums
b31dd47432be62bc71eaeacfea2abcfbb4c39decff7afd5ce4750d3cb0a3bdcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / scrypt-0.8.13-cp36-cp36m-win_amd64.whl

Download URL scrypt-0.8.13-cp36-cp36m-win_amd64.whl
Size 35.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
336a76da970674206591a9d1092b165a6792eadeaed5fd8fd0d7e367ea0cd74a
BLAKE2b-256 checksum
How to use checksums
15b850068cf98dbe6fff1761d53dbb164535f38da54711a5e33cd900981893c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / scrypt-0.8.13-cp36-cp36m-win32.whl

Download URL scrypt-0.8.13-cp36-cp36m-win32.whl
Size 29.7 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
d5acc01c27048ad5f5477aeaa97c8faa1bd739f0a915d31b4526e18609fd9df1
BLAKE2b-256 checksum
How to use checksums
7f611401c9d692debd96bd1432d251980185402c6996ffce96a2ae5eb6ffd228
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / scrypt-0.8.13-cp35-cp35m-win_amd64.whl

Download URL scrypt-0.8.13-cp35-cp35m-win_amd64.whl
Size 35.3 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
e1d24b8dd8a4451745a0f99c6bf356475fa822e5ebdeb207ea99f0fdab54c909
BLAKE2b-256 checksum
How to use checksums
1a528eb8fc0de5e6ffaf6dbaf3d2d32685065cd8296043ed78ab4e7c3b6e16cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / scrypt-0.8.13-cp35-cp35m-win32.whl

Download URL scrypt-0.8.13-cp35-cp35m-win32.whl
Size 29.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
40fcaecc2e6cc3f9d200c7fb111454f4b584dcde3cf1242d0730ca299fb08553
BLAKE2b-256 checksum
How to use checksums
3dc3458873bae3c561fa6aa61be71c922b62e8a9490a0c8c1b9b7bae601463c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / scrypt-0.8.13-cp34-cp34m-win32.whl

Download URL scrypt-0.8.13-cp34-cp34m-win32.whl
Size 28.1 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
b9da3cd041efdbfde0f353351b6f8a8e0b7b7b4e8d95a29e59f77c48e2cee96d
BLAKE2b-256 checksum
How to use checksums
5d4dad21a8ae134d17a2316d5750d8463791e37bb5876f59ad61ee841672cda9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release files / scrypt-0.8.13-cp27-cp27m-win32.whl

Download URL scrypt-0.8.13-cp27-cp27m-win32.whl
Size 28.1 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
b5434eb5608d491abf42bdacb5dea2103ff25d4e42c0a2b574bd74c7789bbb37
BLAKE2b-256 checksum
How to use checksums
b905b1dbefa436725c32fcfb8459fc0444982323b026c0c806666ec3ed693370
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.8.13 This release

9 release files

0.8.12

9 release files

0.8.9

11 release files

0.8.8

11 release files

0.8.0

18 release files

0.7.1

7 release files

0.7.0

5 release files

0.6.1

1 release file

0.6.0

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

2 release files

0.5.0

1 release file

0.4.0

0.3.0

0.1.0

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page