Skip to main content

Python scrypt bindings

This github is a clone of https://bitbucket.org/mhallin/py-scrypt. Please add issues and Pull-requests there.

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

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

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.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-python was created by Magnus Hallin and is licensed as 2-clause BSD.

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.

Badges

https://travis-ci.org/holgern/py-scrypt.svg?branch=master https://ci.appveyor.com/api/projects/status/h644bjbdawke9vf2?svg=true Latest Version https://anaconda.org/conda-forge/scrypt/badges/version.svg https://anaconda.org/conda-forge/scrypt/badges/downloads.svg

Metadata

Release files for scrypt 0.8.6

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.6
File Size Uploaded
scrypt-0.8.6.tar.gz 53.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for scrypt 0.8.6
File
scrypt-0.8.6-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
scrypt-0.8.6-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details
scrypt-0.8.6-cp36-cp36m-macosx_10_12_x86_64.whl CPython 3.6 CPython 3.6 pymalloc macOS 10.12+ x86-64 Details
scrypt-0.8.6-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
scrypt-0.8.6-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details
scrypt-0.8.6-cp35-cp35m-macosx_10_11_x86_64.whl CPython 3.5 CPython 3.5 pymalloc macOS 10.11+ x86-64 Details
scrypt-0.8.6-cp34-cp34m-win_amd64.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-64 Details
scrypt-0.8.6-cp34-cp34m-win32.whl CPython 3.4 CPython 3.4 pymalloc Windows x86-32 Details
scrypt-0.8.6-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details
scrypt-0.8.6-cp27-cp27m-win32.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-32 Details
scrypt-0.8.6-cp27-cp27m-macosx_10_11_x86_64.whl CPython 2.7 CPython 2.7 pymalloc macOS 10.11+ x86-64 Details

Total release size: 371.2 kB

Release files / scrypt-0.8.6.tar.gz

Download URL scrypt-0.8.6.tar.gz
Size 53.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f8239b2d47fa1d40bc27efd231dc7083695d10c1c2ac51a99380360741e0362d
BLAKE2b-256 checksum
How to use checksums
016f3c8dd0f18f73ceddfbdd606c0c895ebb66748606682d77da3743c7c0c56f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.6-cp36-cp36m-win_amd64.whl
Size 29.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
c23daecee405cb036845917295c76f8d747fc890158df40cb304b4b3c3640079
BLAKE2b-256 checksum
How to use checksums
3fcaa26ebe9fa5ec7775d4ee5923d919db62ef928be15f4a35a872eb4a43da94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.6-cp36-cp36m-win32.whl
Size 25.6 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
18ccbc63d87c6f89b753194194bb37aeaf1abc517e4b989461d115c1d93ce128
BLAKE2b-256 checksum
How to use checksums
b9c3e70500c1487eb670fd8b50510e36a4911bc7b8d58b809675e4e7f4341c5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.6-cp36-cp36m-macosx_10_12_x86_64.whl

Download URL scrypt-0.8.6-cp36-cp36m-macosx_10_12_x86_64.whl
Size 35.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
4ad7188f2e42dbee2ff1cd72e3da40b170ba41847effbf0d726444f62ae60f3a
BLAKE2b-256 checksum
How to use checksums
cb90ced5c397230b9ce714a41408c85ed99025a5090badb5a8e697dd0452cbed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.6-cp35-cp35m-win_amd64.whl
Size 29.8 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
475ac80239b3d788ae71a09c3019ca915e149aaa339adcdd1c9eef121293dc88
BLAKE2b-256 checksum
How to use checksums
c2fc2acee8366f4aea1fb4479c14d5d2d161a8beb34ff5bb3c3185202e9ba981
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.6-cp35-cp35m-win32.whl
Size 25.6 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
971db040d3963ebe4b919a203fe10d7d6659951d3644066314330983dc175ed4
BLAKE2b-256 checksum
How to use checksums
3bbb4bfa7d62384fab2bcee826925bb546dace661fcf38e7f7bc29fe91e9d876
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.6-cp35-cp35m-macosx_10_11_x86_64.whl

Download URL scrypt-0.8.6-cp35-cp35m-macosx_10_11_x86_64.whl
Size 35.1 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.11+ x86-64
SHA-256 checksum
How to use checksums
85919f023148cd9fb01d75ad4e3e061928c298fa6249a0cd6cd469c4b947595e
BLAKE2b-256 checksum
How to use checksums
d642e0feb7388cee66f98d6e9eef36ab19e86a70d32f7d4ae20e926fd796589c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.6-cp34-cp34m-win_amd64.whl

Download URL scrypt-0.8.6-cp34-cp34m-win_amd64.whl
Size 27.2 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
232acdbc3434d2de55def8d5dbf1bc4b9bfc50da7c5741df2a6eebc4e18d3720
BLAKE2b-256 checksum
How to use checksums
8b82822705509328c8a23886e0f6cf96a16d69ae6f863fe6951042f01b8de46e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.6-cp34-cp34m-win32.whl
Size 24.0 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
bc131f74a688fa09993c518ca666a2ebd4268b207e039cbab03a034228140d3e
BLAKE2b-256 checksum
How to use checksums
709f0f6e22f2793b6d9eb93796c153c67b1c1eb31769c6e04efc68f4e3c732e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.6-cp27-cp27m-win_amd64.whl

Download URL scrypt-0.8.6-cp27-cp27m-win_amd64.whl
Size 26.8 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
a124719c686f2b5957e392465147fb3fd6077e7c643e9538cab1ee631eb01dde
BLAKE2b-256 checksum
How to use checksums
446f098b98ff88e7c1dc0c6e2fabccc23ad7bc9f8f18984924fcc23fac44e2df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.6-cp27-cp27m-win32.whl
Size 23.9 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
a343c302b3e99dcb7fcbe57aa7919ed761f1568f854291ccebe1b5e6e2c9e509
BLAKE2b-256 checksum
How to use checksums
6fd2024d9891a71eb66f7f2414139788116385240097551ef5773db81db43faf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / scrypt-0.8.6-cp27-cp27m-macosx_10_11_x86_64.whl

Download URL scrypt-0.8.6-cp27-cp27m-macosx_10_11_x86_64.whl
Size 35.1 kB
Tags CPython 2.7 CPython 2.7 pymalloc macOS 10.11+ x86-64
SHA-256 checksum
How to use checksums
dc40f0e1a357a49ca62f30f2fc09e92e02c062a656f27949b436b2ba8002d9e1
BLAKE2b-256 checksum
How to use checksums
652755c6e3c8d65f5addd12a4312c9fa7f0f1a2297ea3c112744302b4eee1511
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.8.13

9 release files

0.8.12

9 release files

0.8.9

11 release files

0.8.8

11 release files

This release

0.8.6 This release

12 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