Skip to main content

Bindings for the scrypt key derivation function library

Project description

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:

$ brew install openssl
$ 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.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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrypt-0.8.4.tar.gz (47.3 kB view details)

Uploaded Source

Built Distributions

scrypt-0.8.4-cp36-cp36m-win_amd64.whl (29.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

scrypt-0.8.4-cp36-cp36m-win32.whl (25.3 kB view details)

Uploaded CPython 3.6m Windows x86

scrypt-0.8.4-cp36-cp36m-macosx_10_6_intel.whl (27.9 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

scrypt-0.8.4-cp35-cp35m-win_amd64.whl (29.5 kB view details)

Uploaded CPython 3.5m Windows x86-64

scrypt-0.8.4-cp35-cp35m-win32.whl (25.3 kB view details)

Uploaded CPython 3.5m Windows x86

scrypt-0.8.4-cp35-cp35m-macosx_10_6_intel.whl (27.8 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

scrypt-0.8.4-cp34-cp34m-win_amd64.whl (26.9 kB view details)

Uploaded CPython 3.4m Windows x86-64

scrypt-0.8.4-cp34-cp34m-win32.whl (23.6 kB view details)

Uploaded CPython 3.4m Windows x86

scrypt-0.8.4-cp27-cp27m-win_amd64.whl (26.4 kB view details)

Uploaded CPython 2.7m Windows x86-64

scrypt-0.8.4-cp27-cp27m-win32.whl (23.6 kB view details)

Uploaded CPython 2.7m Windows x86

scrypt-0.8.4-cp27-cp27m-macosx_10_6_intel.whl (27.7 kB view details)

Uploaded CPython 2.7m macOS 10.6+ intel

File details

Details for the file scrypt-0.8.4.tar.gz.

File metadata

  • Download URL: scrypt-0.8.4.tar.gz
  • Upload date:
  • Size: 47.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for scrypt-0.8.4.tar.gz
Algorithm Hash digest
SHA256 4c7a8099fd5da237de8f7b9bbe92aa6df070f70f12cc419cb8ce6eba275ddfaf
MD5 d7ec87049792659f0497d2f0d8f749ce
BLAKE2b-256 0b7c08afeb4f194f5316251b848c5400fb864781dec2f8d0550d22ebae835bbd

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp36-cp36m-win_amd64.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c9f6e96e54c5fec226ef81b44d795193d42cf6911bf702d08a0a29a711773325
MD5 a9e22988718bdfceb1ab4ea0afb300c7
BLAKE2b-256 44a58f7b43e1ebfe9239da92c08aacd6cf61d81c31d2d7a4501050c85d61fc77

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp36-cp36m-win32.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 f2211517c884dd81984d36a5843e1dd19e195ee6a22f942a7a650738563ce12e
MD5 a5fd1034a36364c4342cb4d5aff9c16a
BLAKE2b-256 997afdc47af020f822ae26f82c7f5adc8ee5c9b5b1297f6e5d49473f03bbea05

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 5b3b0134ca7bd1ed78cd9ba1fca7438380812ac99a1d4fb5411846b1f6bac72d
MD5 1dab5544a7d068e0509f3d5036d01336
BLAKE2b-256 2b730ea58726ebad0f01d5dea09ddfdb84804e42ad3a3444cdd8f4d038f16bc2

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 ff4b6c88ee6646b08c0b771adcd9ebd3da0a752a54157793f7b773e9ad21cf6c
MD5 4dee07bcea509ede2a1cb276380dc92b
BLAKE2b-256 76e60d919a81ed315c1a7635a79e31c85195c46cd3afe8960e21c910ad46e0c0

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 a76ac26f93bf564cb6c1c635eda37b26a45e2668dc82c45f2b8cc8505a4025e5
MD5 84e79324a1ed33ae2f9aa290786bedf8
BLAKE2b-256 ebf738eedfd40cedc7505fd6d13103e85745c843f806a5facbc5dce600e35398

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 d26a0d8dcc1e2ec0e5367ca05543879155fccb3951d682a4d08ae0ed0334bae0
MD5 19deedb045917914e22b56fc3f274f24
BLAKE2b-256 8001f9ad70b626b7e0775303294d0c2b9e371bc61cb3e6a9ea4ed4b7544dcdbe

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 f3a600defe5c97ab93e8d9fc779c5d0090cea80e721dc3001465075922bcad9a
MD5 3907815fc42924009f6f78b6b4072f81
BLAKE2b-256 2a0153d7cba81dd9a096464847275cecce0cc82c8a6a247b60666c93297ac5d0

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 8d6718c052111d76b9272614fe32f59d4cb5d67732a1fb5d6cac5b3072ab3d53
MD5 2999e428ccd7bfb28a3399457b06a6ae
BLAKE2b-256 89d6c762f9f394d5cc205d25d397529aef57288ec98a074395c5fb0539e9fef4

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 a39dfb7f8dbb5c0cf69ec45d8df759bb257dcfc776ab7790155a2f8c48d0e09a
MD5 05f4f8cd9905592886b0c67380504bbe
BLAKE2b-256 769041a5189d27ab318ef48b8a60802ebfe86d144aa29344168880eec0b1f62e

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 20219da3bcede843e14c8021b87d477e5ad06c2c7148ec7e334bc8651c1cca3b
MD5 79df1040cf367dea3f39b4649f97d6d0
BLAKE2b-256 b9e80e3924c028eab8047fe56c6c4946ed2072131961f3029d69641160d378e4

See more details on using hashes here.

File details

Details for the file scrypt-0.8.4-cp27-cp27m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for scrypt-0.8.4-cp27-cp27m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 1e7e99f07e20539ba14de55761fd6093658f401fcee9c780c18ccae83ea73f3b
MD5 8419875adc091fc7114e5d3e1acde0a7
BLAKE2b-256 35849becd56c2698983d577de64e3d7172ff7c4872fdae5cc68413dbc0eb9c8b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page