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

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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.7m Windows x86-64

scrypt-0.8.8-cp37-cp37m-win32.whl (24.5 kB view details)

Uploaded CPython 3.7m Windows x86

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

Uploaded CPython 3.6m Windows x86-64

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

Uploaded CPython 3.6m Windows x86

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

Uploaded CPython 3.5m Windows x86-64

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

Uploaded CPython 3.5m Windows x86

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

Uploaded CPython 3.4m Windows x86-64

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

Uploaded CPython 3.4m Windows x86

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

Uploaded CPython 2.7m Windows x86-64

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

Uploaded CPython 2.7m Windows x86

File details

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

File metadata

  • Download URL: scrypt-0.8.8.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.8.tar.gz
Algorithm Hash digest
SHA256 bfbb764d2af8a79bb9cacb1fc32a9d85eac8fd1ff7ca8d66cf03dc255305b836
MD5 6b5f7dfca973119f1a98d0c0efd09665
BLAKE2b-256 f10290b3b4a51aeafae418bcc5a0c03617477005e2ac613c4091cec6205f6c66

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 30c8233891805009e84936ad41341fb958e1295d3a4a9b72cc260332a1f432cb
MD5 9342618c9da53df3b18ce6a1b789b2c8
BLAKE2b-256 d6b3a7091d33f9ed3a8abdd7a19070e1771ac0fa5847944b8e61f70a85818ffc

See more details on using hashes here.

File details

Details for the file scrypt-0.8.8-cp37-cp37m-win32.whl.

File metadata

  • Download URL: scrypt-0.8.8-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: CPython 3.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.8-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 857abc6c9eca16f3b79fea4d2d9a0dc03ebea15f0656f3e6053fcd56ac1e5634
MD5 883f0fecf810e2b5632f37d95be6fb01
BLAKE2b-256 2e609b0f81eb10fe414b1e0a8b195f48bf83434e07156ea104fe60b10569a3d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 209d7ba3deb205bfc5a02bbe317aa1bac8f8215235ebc336cd056891f0e9dafe
MD5 4e92aa03b760ec3ad0a935c2f05df7ee
BLAKE2b-256 8bf2668d6343b101162298de15ab311a4b26acd65bbc781da00e22d236dfcee5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 cb80489987870f83532c463c22ba6b1f67987c5c492cb6d485fc45fe55cf0d3f
MD5 07631c35227400939ec0d82669b38c8b
BLAKE2b-256 189ee0c2e3d64f01422e2e4650426ede39456490c80ef83359dde15b888479c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 791321d122aa3f0299705c097be30d1449e997df950b6170aac527fa35954fca
MD5 f3107f474b57f3b1a7812fcb6cbb428b
BLAKE2b-256 940128a8ec9b65e63273b8a48a7125a8b2a9a649e214c6b8aeec633f7059d06c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 96bc13f55bd772638e28ac5f8b4ded5745ee865e8e77b94733901ae86410b1a5
MD5 f70d48dd3919b74a271779013aed4029
BLAKE2b-256 58d0c4a3a96fdc49a2d45ed029fd66ec7a3b7a8fec45f7f19b3ae68bafeb2617

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 648566f0fc4c179ecbd711a6eb70f71832fc2f46dfb9eba6998da0b63c7ec59e
MD5 abbab2135a8bc6d87b439578f98665aa
BLAKE2b-256 d872447859dcc8daad044387f42405fabee0e547e86c15e1aec12a0c0040c227

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 18e3bbe405c365a32d6c99b2ec494e2c2e38eb0318578c588c1861920dc4d32a
MD5 583cea9e283b9751fe6c8710aec336c7
BLAKE2b-256 abcb3c375c44d7dcf50d238c4ab72c7792470082876cea8285d8656f71cb134d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 6c760ebc7b5cdf9a539202d4ee867b9a1a7db84bdd19360a25ec270f57b11b65
MD5 aac8e734e028044a2aaaab11a7ced4f6
BLAKE2b-256 3c4108da522d9542be709ccbea0ee22f16d4c69e88eeaf736d83ec23643ed1ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.8-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.8-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 5c82a5e327dfe877f813f828dc4c7b6bcc15ae1ee6c0e4992ea5f7cd440640be
MD5 c672b7d8fb10610d0a80db7fb8b8830b
BLAKE2b-256 252ad9461884d67602fa77c67421c8186a813fdd2dbcb3f4bf123d21ae31a6b2

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