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

  • fix typo

0.8.9

  • use the static libcrypto_static for windows and openssl 1.1.1

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

Uploaded Source

Built Distributions

scrypt-0.8.10-cp37-cp37m-win_amd64.whl (27.3 kB view details)

Uploaded CPython 3.7m Windows x86-64

scrypt-0.8.10-cp37-cp37m-win32.whl (29.6 kB view details)

Uploaded CPython 3.7m Windows x86

scrypt-0.8.10-cp36-cp36m-win_amd64.whl (27.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

scrypt-0.8.10-cp36-cp36m-win32.whl (29.6 kB view details)

Uploaded CPython 3.6m Windows x86

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

Uploaded CPython 3.5m Windows x86-64

scrypt-0.8.10-cp35-cp35m-win32.whl (29.6 kB view details)

Uploaded CPython 3.5m Windows x86

scrypt-0.8.10-cp34-cp34m-win_amd64.whl (24.7 kB view details)

Uploaded CPython 3.4m Windows x86-64

scrypt-0.8.10-cp34-cp34m-win32.whl (28.0 kB view details)

Uploaded CPython 3.4m Windows x86

scrypt-0.8.10-cp27-cp27m-win_amd64.whl (24.3 kB view details)

Uploaded CPython 2.7m Windows x86-64

scrypt-0.8.10-cp27-cp27m-win32.whl (28.0 kB view details)

Uploaded CPython 2.7m Windows x86

File details

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

File metadata

  • Download URL: scrypt-0.8.10.tar.gz
  • Upload date:
  • Size: 53.4 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.10.tar.gz
Algorithm Hash digest
SHA256 d6b62fcd2de0be89bd38cf63ef2982b7ab8ae904305bfbbb1f4026c6b79f8c6b
MD5 a21dfc3a520fb725be3a62a2fec2c4f8
BLAKE2b-256 97c6ce1a3b4c45e4564c121752c7cb34eaae40d029bae46c880063f9424037f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 27.3 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.10-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 71b961592dd690572a78cc9947c356aebfb28bb0dfbc4b5a5fbab5d3b853f5f9
MD5 468ec815de8e8aefc5fd272f4b811868
BLAKE2b-256 36aa4b7560841fbb7a51ad52fc5a4a77b17a5333d60dc9b467a0539c0ecfa72a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 29.6 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.10-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 ddb1185d5e12ee201c19ee69f82daab6b19a3236a7c180adb3bdc3c2e5dc7fce
MD5 3d5a001e9845267797cb4d0047ba5493
BLAKE2b-256 12400f25e9234a96095ea4247ca88c97415f7b1f161a14c4dbca9c74701583f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 27.3 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.10-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 793f25cdc040359729cab349ed6cc25f22feb9f2fe0bcc0f4fb8eb597a400f53
MD5 fe4a3a042ec4116bba0f8b892246ae25
BLAKE2b-256 38c7e571d17216cbfc7e48071e464830fdc6965ee1a913fa77d66115f6e24edd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 29.6 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.10-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 8de2a10f531e3b2580c79562910452fc19ee830be214431f5740ae3f8fe2c14e
MD5 6872360547dbf1a53a82dbbcd7ad7af3
BLAKE2b-256 7663b1ad2400f6a62be393d102b2524c68754174f79ba0778f97e3bb9ce19f47

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-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.10-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 40fa47fee48aeadd6eefe02cff397931d6af7c92a4770d1a644ff5f7bd6166a4
MD5 e12e1f4a0479433d665ff0e65ccdccda
BLAKE2b-256 259a70179eb5b5f2934ebd0fe527b83b7bae16eb636c509c240343e36b9e4eb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 29.6 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.10-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 2bf2b27c68ee1077bfb71e45f8bea8108398bd503a524c089f9b71c7f864fd53
MD5 9d2a64bf23c19d7abb280d96de9e7b3c
BLAKE2b-256 701ebde4669a26f5dd4369ba12f134595fe5c6ba1056e80363a7f057cb4451de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp34-cp34m-win_amd64.whl
  • Upload date:
  • Size: 24.7 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.10-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 c8c4cec880ea039e1158f45fe274a2af5fb07506f099b7fcf71d7c250ea38386
MD5 aeef52fcbc722e0462bd2c28d64acc33
BLAKE2b-256 8e7f2b19c683b36945228834fd6ec14627e23441f58f36e97cb8d4a295986e46

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp34-cp34m-win32.whl
  • Upload date:
  • Size: 28.0 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.10-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 5ce021730e679b729c32178678414c253e8da2b744ecd4764c1b92745645f272
MD5 7fea33c2f893ceedaaae96556e394510
BLAKE2b-256 e751d4f9f10393a5d6f780f46b6c7979762d99297a1ab12274f69cddc6a7d7df

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 24.3 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.10-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 26298fec664ca5ab72bdb701fe994cbdbf4d2af98749a015d0750b837e9e9bcc
MD5 eb617b03ae25b1974c5b6415325ab419
BLAKE2b-256 0f0141054e2ac130d9ab093381ba959f28e1b384f590e81ca853dfdfb8a6168a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.10-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 28.0 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.10-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 a0f836af51f4fff3eb7fb9bb03beb112607640626d2a0867c1db4cbdaeb96e0c
MD5 154178dd240932087f3622ef9c711f74
BLAKE2b-256 9dbb660f5cda92f957ec609821b775092ac53bd9f2d3f8b552dc3211a67c27a0

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