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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.7m Windows x86-64

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

Uploaded CPython 3.7m Windows x86

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

Uploaded CPython 3.6m Windows x86-64

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

Uploaded CPython 3.6m Windows x86

scrypt-0.8.11-cp35-cp35m-win_amd64.whl (27.3 kB view details)

Uploaded CPython 3.5m Windows x86-64

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

Uploaded CPython 3.5m Windows x86

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

Uploaded CPython 3.4m Windows x86-64

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

Uploaded CPython 3.4m Windows x86

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

Uploaded CPython 2.7m Windows x86-64

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

Uploaded CPython 2.7m Windows x86

File details

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

File metadata

  • Download URL: scrypt-0.8.11.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.11.tar.gz
Algorithm Hash digest
SHA256 470ea51685da39f4160e85035e328169e147b1e03980c90588695854937724d5
MD5 c4e3d6629cd5a6225818faded8689aca
BLAKE2b-256 f3d8cda4db0b16e3ce831064e92f12a1b9806276f41a90a82895368f95978288

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 4dfa510089d1bfccde2694480717357149b81156d2804f6a68941edf166c6e5c
MD5 58d14693e2246369836bc0d472d5e920
BLAKE2b-256 f3a491e3549f2f5c632a5ade1749ac5ebe159664e40cd9dbaa2a87c44cf309a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 6c36b328f572ee58ee1dc9fe5dfd0c1562c01bfaf984eb44d7d8dc541632de67
MD5 97d452489b58eb5aa6eb26618962dbd7
BLAKE2b-256 2595a1f3eaf494c12d890ed48401fb147d68624a90c73bbae3fc8599e75bbeda

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 affa1a8c050b886772b60356f84915e925d2e22ffe656283db9f05fbea5dc798
MD5 1e9e87043339671e49574bb5100f0bcf
BLAKE2b-256 036d91b24a19872331980399ff9e1fcd51fe53cddf2b9e5c19bfd8836e604a98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 7033855589396e3c8946128f2e0deb355776966ebafa2775032708efae9074ff
MD5 00c5564c6e1727a76639503dec0ba3b8
BLAKE2b-256 1432c02aa9aa57a72bce4abf1c85de5825db449f0c9e1cb26ccd71f8f50e9fe3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 27.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.11-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 3ec106ff29a28471c568a7a2d8d942baa294b6b41ca391ded30eb8447aced0d9
MD5 93561d58591d6c990a4e3214f4d0c555
BLAKE2b-256 fb786795be6994615d6dc93b18ce2df436ff58a62fbfe57cd2dc167a4e6b4b60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 47c553fdc938583c17ff9aae6bba9349b54ad581d6deeb3c7e7c84fa80c38647
MD5 3b7faea6e8d5bcaa8cbaad6608e7f065
BLAKE2b-256 ea83dc1df356c7b6e0be37c823961a321085ba245f1b00af4719349ad15ad5c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 56f7e1a29d3a76ce5dadaa47931b7f817e8f4a3b5b7b7ea6fbf1e4a921b27102
MD5 66ed6bab5384a5460448283ecb85979c
BLAKE2b-256 b305a7da78036ec1ca1d8ff87499e5483b1496def25767c02549956955c19fa5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 d9ae52fc46003ad2d2864e2b40c364a7b2849dd4ee420a88097625fa8fd4bc4e
MD5 99df5dc6d8221cfe45a181bc361d1805
BLAKE2b-256 8ac22cd2e71231397bdf30fcfe0be19fe69c22e22702555c8c3deaed994be0f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 960d408c04c76f6d219bf70c0badbb6ba995ab3e9723b2a41f7352e15fed1be7
MD5 404a47aad9ee7d50530fc4038b1a8920
BLAKE2b-256 ba898b9843729ee837ebd01f5987d95212709815738c31c7f23ff478db68e177

See more details on using hashes here.

File details

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

File metadata

  • Download URL: scrypt-0.8.11-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.11-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 99634852c34d4a929a54d5df4101c34bfaf41a5b5191d663bd350e102a2947fa
MD5 f15b8211b50e0cfadc425c6f1ff373eb
BLAKE2b-256 ce736a49f2fdbdce3b76309c6c8d5abbb94cfbedd9acd758a747a36ee247cc0a

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