Skip to main content

Bindings for the scrypt key derivation function library

Project description

Python scrypt bindings

This github is a clone of https://bitbucket.org/mhallin/py-scrypt. Please add issues and Pull-requests there.

This is a set of Python bindings for the scrypt key derivation function.

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

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.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-python was created by Magnus Hallin and is licensed as 2-clause BSD.

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.

Badges

https://travis-ci.org/holgern/py-scrypt.svg?branch=master https://ci.appveyor.com/api/projects/status/h644bjbdawke9vf2?svg=true Latest Version https://anaconda.org/conda-forge/scrypt/badges/version.svg https://anaconda.org/conda-forge/scrypt/badges/downloads.svg

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

Uploaded Source

Built Distributions

scrypt-0.8.6-cp36-cp36m-win_amd64.whl (29.8 kB view details)

Uploaded CPython 3.6m Windows x86-64

scrypt-0.8.6-cp36-cp36m-win32.whl (25.6 kB view details)

Uploaded CPython 3.6m Windows x86

scrypt-0.8.6-cp36-cp36m-macosx_10_12_x86_64.whl (35.3 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

scrypt-0.8.6-cp35-cp35m-win_amd64.whl (29.8 kB view details)

Uploaded CPython 3.5m Windows x86-64

scrypt-0.8.6-cp35-cp35m-win32.whl (25.6 kB view details)

Uploaded CPython 3.5m Windows x86

scrypt-0.8.6-cp35-cp35m-macosx_10_11_x86_64.whl (35.1 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

scrypt-0.8.6-cp34-cp34m-win_amd64.whl (27.2 kB view details)

Uploaded CPython 3.4m Windows x86-64

scrypt-0.8.6-cp34-cp34m-win32.whl (24.0 kB view details)

Uploaded CPython 3.4m Windows x86

scrypt-0.8.6-cp27-cp27m-win_amd64.whl (26.8 kB view details)

Uploaded CPython 2.7m Windows x86-64

scrypt-0.8.6-cp27-cp27m-win32.whl (23.9 kB view details)

Uploaded CPython 2.7m Windows x86

scrypt-0.8.6-cp27-cp27m-macosx_10_11_x86_64.whl (35.1 kB view details)

Uploaded CPython 2.7m macOS 10.11+ x86-64

File details

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

File metadata

  • Download URL: scrypt-0.8.6.tar.gz
  • Upload date:
  • Size: 53.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for scrypt-0.8.6.tar.gz
Algorithm Hash digest
SHA256 f8239b2d47fa1d40bc27efd231dc7083695d10c1c2ac51a99380360741e0362d
MD5 ae8e3263aa31b040c1f9c7f1e1843a56
BLAKE2b-256 016f3c8dd0f18f73ceddfbdd606c0c895ebb66748606682d77da3743c7c0c56f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.6-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 c23daecee405cb036845917295c76f8d747fc890158df40cb304b4b3c3640079
MD5 cf1c288ea85f1d940cc649a7cf228c8c
BLAKE2b-256 3fcaa26ebe9fa5ec7775d4ee5923d919db62ef928be15f4a35a872eb4a43da94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.6-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 18ccbc63d87c6f89b753194194bb37aeaf1abc517e4b989461d115c1d93ce128
MD5 9e67d2e1fdfa1a19f42fb27570799e59
BLAKE2b-256 b9c3e70500c1487eb670fd8b50510e36a4911bc7b8d58b809675e4e7f4341c5c

See more details on using hashes here.

File details

Details for the file scrypt-0.8.6-cp36-cp36m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for scrypt-0.8.6-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4ad7188f2e42dbee2ff1cd72e3da40b170ba41847effbf0d726444f62ae60f3a
MD5 12fcff9dd59ace91364ea95e082f681d
BLAKE2b-256 cb90ced5c397230b9ce714a41408c85ed99025a5090badb5a8e697dd0452cbed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.6-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 475ac80239b3d788ae71a09c3019ca915e149aaa339adcdd1c9eef121293dc88
MD5 a96729689227da9c2900d700975821cd
BLAKE2b-256 c2fc2acee8366f4aea1fb4479c14d5d2d161a8beb34ff5bb3c3185202e9ba981

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.6-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 971db040d3963ebe4b919a203fe10d7d6659951d3644066314330983dc175ed4
MD5 438be758d1a6147e143307f2b403a944
BLAKE2b-256 3bbb4bfa7d62384fab2bcee826925bb546dace661fcf38e7f7bc29fe91e9d876

See more details on using hashes here.

File details

Details for the file scrypt-0.8.6-cp35-cp35m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for scrypt-0.8.6-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 85919f023148cd9fb01d75ad4e3e061928c298fa6249a0cd6cd469c4b947595e
MD5 20d239b9412746ce049f8cd3c042df11
BLAKE2b-256 d642e0feb7388cee66f98d6e9eef36ab19e86a70d32f7d4ae20e926fd796589c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.6-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 232acdbc3434d2de55def8d5dbf1bc4b9bfc50da7c5741df2a6eebc4e18d3720
MD5 bedbe474774c949951bae9a402995a80
BLAKE2b-256 8b82822705509328c8a23886e0f6cf96a16d69ae6f863fe6951042f01b8de46e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.6-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 bc131f74a688fa09993c518ca666a2ebd4268b207e039cbab03a034228140d3e
MD5 f0f50c1de11a1e0173bbcde98fff3c9b
BLAKE2b-256 709f0f6e22f2793b6d9eb93796c153c67b1c1eb31769c6e04efc68f4e3c732e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.6-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 a124719c686f2b5957e392465147fb3fd6077e7c643e9538cab1ee631eb01dde
MD5 28cb7a0fd9b484bdf35c21ad6f7804ae
BLAKE2b-256 446f098b98ff88e7c1dc0c6e2fabccc23ad7bc9f8f18984924fcc23fac44e2df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.6-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 a343c302b3e99dcb7fcbe57aa7919ed761f1568f854291ccebe1b5e6e2c9e509
MD5 5259bf5aa3f54cd4a94424d851f50edf
BLAKE2b-256 6fd2024d9891a71eb66f7f2414139788116385240097551ef5773db81db43faf

See more details on using hashes here.

File details

Details for the file scrypt-0.8.6-cp27-cp27m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for scrypt-0.8.6-cp27-cp27m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 dc40f0e1a357a49ca62f30f2fc09e92e02c062a656f27949b436b2ba8002d9e1
MD5 289454cf5646338fab3cb2bc1d82fc3e
BLAKE2b-256 652755c6e3c8d65f5addd12a4312c9fa7f0f1a2297ea3c112744302b4eee1511

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