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

  • Add SCRYPT_WINDOWS_LINK_LEGACY_OPENSSL environment variable, when set, openssl 1.0.2 is linked

0.8.11

  • fix build for conda feedstock

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

Uploaded Source

Built Distributions

scrypt-0.8.12-cp37-cp37m-win_amd64.whl (35.3 kB view details)

Uploaded CPython 3.7m Windows x86-64

scrypt-0.8.12-cp37-cp37m-win32.whl (29.7 kB view details)

Uploaded CPython 3.7m Windows x86

scrypt-0.8.12-cp36-cp36m-win_amd64.whl (35.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

scrypt-0.8.12-cp36-cp36m-win32.whl (29.7 kB view details)

Uploaded CPython 3.6m Windows x86

scrypt-0.8.12-cp35-cp35m-win_amd64.whl (35.3 kB view details)

Uploaded CPython 3.5m Windows x86-64

scrypt-0.8.12-cp35-cp35m-win32.whl (29.7 kB view details)

Uploaded CPython 3.5m Windows x86

scrypt-0.8.12-cp34-cp34m-win32.whl (28.1 kB view details)

Uploaded CPython 3.4m Windows x86

scrypt-0.8.12-cp27-cp27m-win32.whl (28.1 kB view details)

Uploaded CPython 2.7m Windows x86

File details

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

File metadata

  • Download URL: scrypt-0.8.12.tar.gz
  • Upload date:
  • Size: 53.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.12.tar.gz
Algorithm Hash digest
SHA256 8314137ef8c370d30be919a1421200399eed1e5a2a1e66a18e29aec79c0191ee
MD5 d5da25a80e55485caebf46091931cc29
BLAKE2b-256 58c13257f3641ac40f62d1666bf46bfc011427857abb87b74aaf05c34870b0f2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.12-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 35.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.12-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 42c58ef9e8d087b03028798c0d0b62882a4b4d809829b131dbf35970534c54cd
MD5 90708478b2e1c777838309e527f00bcd
BLAKE2b-256 98aad52a4dbc87f3520543540c85c33c9254468842c6c53a1bafccf3e6513bab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.12-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 29.7 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.12-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 5ce1dc818b196d27a48f3b0f10299eb22c77f36b86a1c5671759f3c1009708d2
MD5 fb45f8270f480a00fbee164c30d90857
BLAKE2b-256 e78b96767de41c0c27d095f09c0a0d2cc47374368bfc1ac668d1d3d515ebc30f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.12-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 35.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.12-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 db802cfdd5090ebab5095805cb6c236af2ff7ef50aeff67002e39491eda92876
MD5 88102b15f19daa3941288b2fe40edf7b
BLAKE2b-256 084392a170b2965e386ecbb673a35e467bc89cf4eef6d6f0a07d7d2286bb6a9e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.12-cp36-cp36m-win32.whl
  • Upload date:
  • Size: 29.7 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.12-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 5133d67934a4cb86b347115d648ffa795180bb9f1c3af4448d04fc53c82c37de
MD5 00ac8685e472c47422881f136ff544c0
BLAKE2b-256 eef3f2b18640bab23019fdea4030ae5f9ffa9a402f3364f2b2be363179a5b9d6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.12-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 35.3 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.12-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 f1f203cef438430a850e33e2d078229cddca15d435ec3f2358a19efe8703b545
MD5 d2486d679c853b31db8917f83ebdd6c2
BLAKE2b-256 4807f923439f9bbd09a2a2f7df9606551f62c8e3b4c0041c1d0a244d217816b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.12-cp35-cp35m-win32.whl
  • Upload date:
  • Size: 29.7 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.12-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 fd5d5dd6d842c84b6ee58d07af32abf8e6090cb33440a068157e8411d272fbfc
MD5 c61a28a10adf66f6040c0817237bceb5
BLAKE2b-256 5621c0ae3644d5586cbc148b5e8b756b7077e38b314197e67c307c77e2cab7f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.12-cp34-cp34m-win32.whl
  • Upload date:
  • Size: 28.1 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.12-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 f1475d858ab9773821376462b0928d22b51dbd1eedd38c9b63e62681ceec7751
MD5 c9faafa042cb27ecb4fa7fcb79dc1a5e
BLAKE2b-256 f74c07fb859043a6fb1d539bf4a1d2e16369007573ccfd3519df511e9b008895

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.12-cp27-cp27m-win32.whl
  • Upload date:
  • Size: 28.1 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.12-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 3b3ec49e9ff4bea9c3bcda970a82aede693139056a29b9b60b6f5c5d3927076c
MD5 9a1eee1d8e70ad4582ec3dab1085ea51
BLAKE2b-256 60c4e7599e1117c4cf12b136484de372de80a6d405c154772f593b44f0259412

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