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

Uploaded Source

Built Distributions

scrypt-0.8.5-cp36-cp36m-win_amd64.whl (27.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

scrypt-0.8.5-cp36-cp36m-win32.whl (23.3 kB view details)

Uploaded CPython 3.6m Windows x86

scrypt-0.8.5-cp36-cp36m-macosx_10_12_x86_64.whl (33.0 kB view details)

Uploaded CPython 3.6m macOS 10.12+ x86-64

scrypt-0.8.5-cp35-cp35m-win_amd64.whl (27.5 kB view details)

Uploaded CPython 3.5m Windows x86-64

scrypt-0.8.5-cp35-cp35m-win32.whl (23.3 kB view details)

Uploaded CPython 3.5m Windows x86

scrypt-0.8.5-cp35-cp35m-macosx_10_11_x86_64.whl (32.8 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

scrypt-0.8.5-cp34-cp34m-win_amd64.whl (24.9 kB view details)

Uploaded CPython 3.4m Windows x86-64

scrypt-0.8.5-cp34-cp34m-win32.whl (21.6 kB view details)

Uploaded CPython 3.4m Windows x86

scrypt-0.8.5-cp27-cp27m-win_amd64.whl (24.4 kB view details)

Uploaded CPython 2.7m Windows x86-64

scrypt-0.8.5-cp27-cp27m-win32.whl (21.6 kB view details)

Uploaded CPython 2.7m Windows x86

scrypt-0.8.5-cp27-cp27m-macosx_10_11_x86_64.whl (32.7 kB view details)

Uploaded CPython 2.7m macOS 10.11+ x86-64

File details

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

File metadata

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

File hashes

Hashes for scrypt-0.8.5.tar.gz
Algorithm Hash digest
SHA256 cdc276fed2096f039575633499ecbe92c8eddf09aa12598a11a22f56f898539f
MD5 d5b057e11b62ca1e350bd79fe803fa70
BLAKE2b-256 cbc22efdd4dfaf8f6ad95e7ee5916ab3070008dffb8be4055fb9aa01cde0c1ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 069ed7c4edd9fb770f9d1f60ff697b981911195c1b7e3b315ed576ccc41e0aa7
MD5 b5a9bea08273d023723cea89133a77eb
BLAKE2b-256 63340372de2d0dfaa2410212ec2f76a14b62b2a7897d00dc9a2951267c3af666

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 6b3dbad6e1c13b1447e5c7902915dd92821842ca0a4cf042add44ba9e8c5b3fd
MD5 f30ce5792e06f55afe4a0038556d0da5
BLAKE2b-256 ea49daef77e7fc2daa4426cdf81f2a45ec2fb24014598ed9393672035653c336

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 71aaf5b12c6bdb6c972c17b3a4668301f5ac50fe6bce55f6270356ff7082dbbb
MD5 c74304e442ea82a0fff408d7f3bfc408
BLAKE2b-256 a442eb1e61c8b6d3bfa534a4792490b1c6d8b2b894da8d6981422866973c7695

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 282f0cb877f0c33dd4f4f8d20b8368c3f493675ddee4492ca80345359c1ab524
MD5 861cf092220ebfb21e257e891d2667db
BLAKE2b-256 f0d2db2c56afa064428d19eefef88f9cee08f662833d13f174ed58ca3a4b050c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 a7671c6aed55fc042f7aca8e159c4d20dd68dd0f6381984f5a8fb602ee133f4b
MD5 1591a2aa2bf03613cee431ac07243ebd
BLAKE2b-256 190233f23fac6c88192600e6cf03d3031775735b30c639e5d8080fbe7659d157

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 1b1b04c2a917896a946e2c7443311920670757b815ae087440335acf48859cd5
MD5 67b99ffd76f9d8b57e488f6c43880910
BLAKE2b-256 11c759cf42a3fdd2291aa38043a762028f01f19ee00c039b9622f019704f38ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 e69892e69abcb0e9629d021101a668f0169a3bc51e075e11a81ceb3e33a69c04
MD5 d48fbc896de788c956a1b325bc4c0ec0
BLAKE2b-256 3fabba7168edc6527cbbe8c68e7f8325f616ef4f2ed0d38b29cce857aab53d82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 1d5e81b894e4c6a29e6a3e18ea0135c452dd3c55dd1bc73ad39680de655af9ba
MD5 68704f6b6d9d2afcf6f1d0038e807537
BLAKE2b-256 32562fc8827e61baa0bce7bd77c787edc0444f588e802e1b80f25d3fd666b8cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 54387becb536162099ecaf30c5c45609673e9a0a846302d8384ae0aaab80f4cd
MD5 ac7510a9f83b09c19ac703fea0f76160
BLAKE2b-256 c7737b767719af7ee227237796f22148a8b3a85f34a2b1ca53c5d051bf6894b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 d978ed7e2b02ece5e0061bd5d92502fe636eafbdeb13ac4171ce3238cb89b6d9
MD5 1790d33f34567d2a5ce34fef223f6618
BLAKE2b-256 04fb393bf978fe6a607b87b358bdee8901afec15b80079c31bf2d183bd8c27ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.5-cp27-cp27m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 ea4c6bfe21e3f3ea95bcf196eedcdab36a96e993d4a951702f013494e207ff7c
MD5 bab1b23aaa3c17296c8a38140e5ef255
BLAKE2b-256 b40e1ae83e26cdf2c81f81daf4c8ba74ac2aef5350cd7442fbbc6aad18aefee1

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