Skip to main content

Bindings for the scrypt key derivation function library

Project description

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

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.7.tar.gz (53.2 kB view details)

Uploaded Source

Built Distributions

scrypt-0.8.7-py3.7-win-amd64.egg (30.6 kB view details)

Uploaded Source

scrypt-0.8.7-cp37-cp37m-win_amd64.whl (27.5 kB view details)

Uploaded CPython 3.7m Windows x86-64

scrypt-0.8.7-cp36-cp36m-win_amd64.whl (27.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

scrypt-0.8.7-cp36-cp36m-win32.whl (23.1 kB view details)

Uploaded CPython 3.6m Windows x86

scrypt-0.8.7-cp35-cp35m-win_amd64.whl (27.2 kB view details)

Uploaded CPython 3.5m Windows x86-64

scrypt-0.8.7-cp35-cp35m-win32.whl (23.1 kB view details)

Uploaded CPython 3.5m Windows x86

scrypt-0.8.7-cp34-cp34m-win_amd64.whl (24.6 kB view details)

Uploaded CPython 3.4m Windows x86-64

scrypt-0.8.7-cp34-cp34m-win32.whl (21.4 kB view details)

Uploaded CPython 3.4m Windows x86

scrypt-0.8.7-cp27-cp27m-win_amd64.whl (24.2 kB view details)

Uploaded CPython 2.7m Windows x86-64

scrypt-0.8.7-cp27-cp27m-win32.whl (21.4 kB view details)

Uploaded CPython 2.7m Windows x86

File details

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

File metadata

  • Download URL: scrypt-0.8.7.tar.gz
  • Upload date:
  • Size: 53.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7.tar.gz
Algorithm Hash digest
SHA256 b97744546656d98c4eff72da7856067ba21a538c34d519a346d4be3a66385342
MD5 dce717a833d88723c27a53ef5f2290b2
BLAKE2b-256 1faf70a7cb4f27f1673bc8b6af3587545eb0327e5823ab96b1eb81b541fe087e

See more details on using hashes here.

File details

Details for the file scrypt-0.8.7-py3.7-win-amd64.egg.

File metadata

  • Download URL: scrypt-0.8.7-py3.7-win-amd64.egg
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-py3.7-win-amd64.egg
Algorithm Hash digest
SHA256 3e99b3f79ba6df87201160cf61a119d13b760cd220ff815e805d1d3194a6d981
MD5 9f7d27d9a2c0f04aec9da41ad445dcf8
BLAKE2b-256 a6dd9d447dc4752c8337707a0169877d8d89146ba0380b6fdbe0c9384da7e057

See more details on using hashes here.

File details

Details for the file scrypt-0.8.7-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: scrypt-0.8.7-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 ef81802964a89427121abdc3691a013af1947a58d007be99711d2ed61dc5bc54
MD5 5e5de75ff281db98fa4184804f241c08
BLAKE2b-256 d50c07431ddb41ebd337c93939be3f63798b380d61f6171f275c8f8632f39dfd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.7-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c23533edf7be99e3697b260acf2ebd1fdbac6407944c9fa83d724f0dff891815
MD5 2b07ced0cadcabbf2c7be8c2847fc2ac
BLAKE2b-256 deeb7d9c977eb985c6599733aacb58f9dbf8ea751d042046b2cd3622efe1f0f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.7-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: CPython 3.6m, Windows x86
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 36786f03da25e699ee97bb3a050859c8c0aedaf7ca2e212f33253dfc775b46eb
MD5 58539270b974f790060c9ebd02adf3bc
BLAKE2b-256 ca2536677007f4de858ff54594491d7c028524d3dd4a9d843cb5825108eab925

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.7-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 c3e3f48ffbbe15c15ade1a59e317acde8742ffbf7dfcbe78ff1cf1d34da343c4
MD5 783027b5f378a7c520d7ddd61be15f57
BLAKE2b-256 ac68e302d7e37462f20e8cd7a1c1fea07574926c9832830d7dcfd39f1e683889

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.7-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: CPython 3.5m, Windows x86
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 5466ccff520df8ecf63bcbea71d0baea44bef6962d53dd03f706543a9aa07f57
MD5 8c80d810529cbc764cabf283d7abd664
BLAKE2b-256 3f50e6e57d9a80e328d1d0ae0849f5f0556803f26b4c158af5482c363565da91

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.7-cp34-cp34m-win_amd64.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: CPython 3.4m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 5c23e58e8baa557b4aa0fc5d565edc0892548464737cd81701fc96258eff72a5
MD5 1b18a64e811d2e93ecd25c394a288b29
BLAKE2b-256 98ccfe64b130dc2ea975ff6c6cfc2274d4bcaf38b902882358fe4fdb46829930

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.7-cp34-cp34m-win32.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: CPython 3.4m, Windows x86
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 36b0956335a196f99d07b6c123848d2e29434c00297a9ceb6d9ed909a0426fb0
MD5 b160fb79c1d3451d10af6d630c0b0411
BLAKE2b-256 594007a484cc66f25e78e7ae86880e380977220c4f46a292a1f5d30762eafdca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.7-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 9e739b829fcdc2228a6653c2fabea4833f110ea0c9387c6a0d394e47e3797e7a
MD5 43e9aab296886a05725f6105d978adb2
BLAKE2b-256 8c56ed65a29ff15274640aac0b2056d51353ed61bcb10adff5030de8ee98629a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.7-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: CPython 2.7m, Windows x86
  • Uploaded using 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

File hashes

Hashes for scrypt-0.8.7-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 d29b7d1f7fa3e67cd117b2f4fa26f27b5e0526f4040113ed78cdbe482a795393
MD5 3f4539e53a93f2589aa547c4e26c21db
BLAKE2b-256 7c463a8a19a804958e2f4a6170c4765af159a4768198b546599fa0b0cea7a66d

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