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

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.5
File Size Uploaded Provenance Actions
scrypt-0.8.5.tar.gz 53.0 kB Without provenance Details for scrypt-0.8.5.tar.gz

Built distributions (wheels)

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

Total release size: 345.7 kB

Release files / scrypt-0.8.5.tar.gz

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

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

Download URL scrypt-0.8.5-cp36-cp36m-win_amd64.whl
Size 27.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
069ed7c4edd9fb770f9d1f60ff697b981911195c1b7e3b315ed576ccc41e0aa7
BLAKE2b-256 checksum
How to use checksums
63340372de2d0dfaa2410212ec2f76a14b62b2a7897d00dc9a2951267c3af666
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.5-cp36-cp36m-win32.whl
Size 23.3 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
6b3dbad6e1c13b1447e5c7902915dd92821842ca0a4cf042add44ba9e8c5b3fd
BLAKE2b-256 checksum
How to use checksums
ea49daef77e7fc2daa4426cdf81f2a45ec2fb24014598ed9393672035653c336
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

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

Download URL scrypt-0.8.5-cp35-cp35m-win_amd64.whl
Size 27.5 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
282f0cb877f0c33dd4f4f8d20b8368c3f493675ddee4492ca80345359c1ab524
BLAKE2b-256 checksum
How to use checksums
f0d2db2c56afa064428d19eefef88f9cee08f662833d13f174ed58ca3a4b050c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.5-cp35-cp35m-win32.whl
Size 23.3 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
a7671c6aed55fc042f7aca8e159c4d20dd68dd0f6381984f5a8fb602ee133f4b
BLAKE2b-256 checksum
How to use checksums
190233f23fac6c88192600e6cf03d3031775735b30c639e5d8080fbe7659d157
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.5-cp35-cp35m-macosx_10_11_x86_64.whl
Size 32.8 kB
Tags CPython 3.5 CPython 3.5 pymalloc macOS 10.11+ x86-64
SHA-256 checksum
How to use checksums
1b1b04c2a917896a946e2c7443311920670757b815ae087440335acf48859cd5
BLAKE2b-256 checksum
How to use checksums
11c759cf42a3fdd2291aa38043a762028f01f19ee00c039b9622f019704f38ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.5-cp34-cp34m-win_amd64.whl
Size 24.9 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
e69892e69abcb0e9629d021101a668f0169a3bc51e075e11a81ceb3e33a69c04
BLAKE2b-256 checksum
How to use checksums
3fabba7168edc6527cbbe8c68e7f8325f616ef4f2ed0d38b29cce857aab53d82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.5-cp34-cp34m-win32.whl
Size 21.6 kB
Tags CPython 3.4 CPython 3.4 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
1d5e81b894e4c6a29e6a3e18ea0135c452dd3c55dd1bc73ad39680de655af9ba
BLAKE2b-256 checksum
How to use checksums
32562fc8827e61baa0bce7bd77c787edc0444f588e802e1b80f25d3fd666b8cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.5-cp27-cp27m-win_amd64.whl
Size 24.4 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
54387becb536162099ecaf30c5c45609673e9a0a846302d8384ae0aaab80f4cd
BLAKE2b-256 checksum
How to use checksums
c7737b767719af7ee227237796f22148a8b3a85f34a2b1ca53c5d051bf6894b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

Download URL scrypt-0.8.5-cp27-cp27m-win32.whl
Size 21.6 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
d978ed7e2b02ece5e0061bd5d92502fe636eafbdeb13ac4171ce3238cb89b6d9
BLAKE2b-256 checksum
How to use checksums
04fb393bf978fe6a607b87b358bdee8901afec15b80079c31bf2d183bd8c27ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

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

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

Security for scrypt 0.8.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.8.5 This release

12 release files No provenance

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