Skip to main content

Bindings for the scrypt key derivation function library

Project description

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

You can install py-scrypt from this repository if you want the latest but possibly non-compiling version:

$ git clone https://github.com/holgern/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

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.

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

scrypt-0.8.2.win-amd64-py3.6.exe (619.4 kB view details)

Uploaded Source

scrypt-0.8.2.win-amd64-py3.5.exe (619.4 kB view details)

Uploaded Source

scrypt-0.8.2.win-amd64-py3.4.exe (251.3 kB view details)

Uploaded Source

scrypt-0.8.2.win-amd64-py2.7.exe (252.3 kB view details)

Uploaded Source

scrypt-0.8.2.win32-py3.6.exe (485.7 kB view details)

Uploaded Source

scrypt-0.8.2.win32-py3.5_2.exe (485.7 kB view details)

Uploaded Source

scrypt-0.8.2.win32-py3.4.exe (216.8 kB view details)

Uploaded Source

scrypt-0.8.2.win32-py2.7.exe (221.9 kB view details)

Uploaded Source

scrypt-0.8.2-cp36-cp36m-win_amd64.whl (28.4 kB view details)

Uploaded CPython 3.6m Windows x86-64

scrypt-0.8.2-cp36-cp36m-win32.whl (24.3 kB view details)

Uploaded CPython 3.6m Windows x86

scrypt-0.8.2-cp36-cp36m-macosx_10_6_intel.whl (45.0 kB view details)

Uploaded CPython 3.6m macOS 10.6+ intel

scrypt-0.8.2-cp35-cp35m-win_amd64.whl (28.4 kB view details)

Uploaded CPython 3.5m Windows x86-64

scrypt-0.8.2-cp35-cp35m-win32.whl (24.3 kB view details)

Uploaded CPython 3.5m Windows x86

scrypt-0.8.2-cp35-cp35m-macosx_10_6_intel.whl (44.9 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

scrypt-0.8.2-cp34-cp34m-win_amd64.whl (25.8 kB view details)

Uploaded CPython 3.4m Windows x86-64

scrypt-0.8.2-cp34-cp34m-win32.whl (22.6 kB view details)

Uploaded CPython 3.4m Windows x86

scrypt-0.8.2-cp27-cp27m-win_amd64.whl (25.4 kB view details)

Uploaded CPython 2.7m Windows x86-64

scrypt-0.8.2-cp27-cp27m-win32.whl (22.6 kB view details)

Uploaded CPython 2.7m Windows x86

File details

Details for the file scrypt-0.8.2.win-amd64-py3.6.exe.

File metadata

File hashes

Hashes for scrypt-0.8.2.win-amd64-py3.6.exe
Algorithm Hash digest
SHA256 80cc2a8fce8d7c0c1fa03def3f678fd6f2c51b55f04c8c14eeb7e6b77197ed9c
MD5 52c6ed57d65cdacefc510c1b25e7575d
BLAKE2b-256 112d0d6b68d3a7f51e0774331a42cb36537e9ed5b09bc8477866eae74440e241

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2.win-amd64-py3.5.exe.

File metadata

File hashes

Hashes for scrypt-0.8.2.win-amd64-py3.5.exe
Algorithm Hash digest
SHA256 cbb46cd2a6d01e700e2d192965b63e77bbda5aa55a6d4218db60221ebd642d34
MD5 74d65770e78b0372979e76aa8dd1662d
BLAKE2b-256 da423bbc123f6928baf496fd7e73dbc30af299942bc1b06796cb30b954144cc6

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2.win-amd64-py3.4.exe.

File metadata

File hashes

Hashes for scrypt-0.8.2.win-amd64-py3.4.exe
Algorithm Hash digest
SHA256 ead6330c39ec39c80b59739bad7d0211de119f0193d614f820c6ce7fc5b47372
MD5 df4da9f4591d0d0c4b5bcad780412f6f
BLAKE2b-256 1ee68400e01d2d33403dcbaded74308f43279088c5e1754384fe5c7ad4efeaca

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for scrypt-0.8.2.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 b615ed7e81623fd8bd4fb8fab158c54e6ccbf388b295523d3b677ff3bf72582d
MD5 e3efb60c3d141b636e787713e37a7bf3
BLAKE2b-256 db2781ea7d333de5addccf7e264a71ab2ed3cd3d0043eb53f323b1733fbddfa9

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2.win32-py3.6.exe.

File metadata

File hashes

Hashes for scrypt-0.8.2.win32-py3.6.exe
Algorithm Hash digest
SHA256 40c9d861ae5a065800b6afcc8d8fac171b1b326e5ce1dd5b18b7f01da9d5a2e9
MD5 ed0230434428e0b5a76250a958c761cb
BLAKE2b-256 be1b06ebc20acc6739f9a08084e0795a4c2de1d6cf9cbbbec7b95e6aa5eca497

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2.win32-py3.5_2.exe.

File metadata

File hashes

Hashes for scrypt-0.8.2.win32-py3.5_2.exe
Algorithm Hash digest
SHA256 ef22551731a8007f11433becd505edb83a87181f5f303ca09d816065c6174b86
MD5 f5d89e7c4c7fd2e062348864f89cf26e
BLAKE2b-256 eb94cade1771044560bf185cdfcce1721645b236d70d815300600e8851e8b8d4

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2.win32-py3.4.exe.

File metadata

File hashes

Hashes for scrypt-0.8.2.win32-py3.4.exe
Algorithm Hash digest
SHA256 22631b4d5da7b3881bca34e7a0a519dc0a71271f47e2c2c73c7cb4573efdeed5
MD5 aa5e32bf736f0c043ed489e6214d00b8
BLAKE2b-256 52aecb9ec75bc6ba5bf6dfa38538ab6ac77229f050ef7d7ce0d01e4165f41298

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2.win32-py2.7.exe.

File metadata

File hashes

Hashes for scrypt-0.8.2.win32-py2.7.exe
Algorithm Hash digest
SHA256 f537bfd4547cbfad872c9324ea35b19c81e38ffceb1778bbaa3820517803fe6b
MD5 3591b4c85f8e2c406479d50d679008fd
BLAKE2b-256 4d9660864151eaa372498b1a560541e60f301ea40a3fdb80e1d8e3280418239a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 2da82b740b22d49010c3951ff0aa2a05f6fbd5073b1a0c07e5b882290d88ac9d
MD5 e02f8790913544d87134e7b2b774f570
BLAKE2b-256 593b82493e2ec001f3b770f2da17b71a73131625630d7ac38ddcd2968fa659b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.2-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 7670a9497d777e79caf0b066aa433756230f1a8162230a6dab517f71dea00b65
MD5 0806a52102de46736651ab17c2fb1151
BLAKE2b-256 f03614bb5c624d18f049bc016e1b406bcd19db78c9af0dc92ab9bea88c4131bd

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2-cp36-cp36m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for scrypt-0.8.2-cp36-cp36m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 aa4a25250aee1c424fabec90b4ada06f6687d071f66061e5f9a3926db50e02e5
MD5 7a1243074f608a2a62d43aacd55b25c2
BLAKE2b-256 344d3b97e5f56560eb48d06144047e5980ee72dac718c45e323457f4c7562452

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.2-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 90512045b35766f36a32f14ea811455597338bcaf766d63355781530e99c59e7
MD5 bdca981b7b3107729dc07b93efc701b8
BLAKE2b-256 19fc2f0677012caa729bbf71ccae795512095b49010a37ae18fd8a23027c6039

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.2-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 ed8b1ac20c9713a3cc3d0a44caf140bd1c80ff6bbf4ca61f3b7de793d8bb184f
MD5 c14c97e27991d910fab48252961b4187
BLAKE2b-256 cb592d998158ea7b3ee13ad5ea7b033b4c56d314c13f23f6e21fdbcebb6f936c

See more details on using hashes here.

File details

Details for the file scrypt-0.8.2-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for scrypt-0.8.2-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 b06728bcdb429eb9686b01b3a79cacca153e1120194e0616e319e72f4691be5d
MD5 14f8dd31c44c3ea8fac4192ec4089985
BLAKE2b-256 df1dccb285da23b3e28fa44f968e96fceccc4c89639da16a7a9f3c34342b8127

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.2-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 874fb61f9020e86b212d271808af3c061bacf6eace5f71f2de2c91e921e6ceee
MD5 d69ace37e6194b170a947e83d6d4ab51
BLAKE2b-256 8c232bc26904d5f035a91741b2a21de5d9289ac5f95eb28edb40197c73f2b87f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.2-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 e880524c23f52783f289d47e71231631d1889dc749ef5e54fb422c34d0684af6
MD5 3ac24daa476a42c0f011b8138e61d240
BLAKE2b-256 6b9e22ca8c7b5424524d33a8b069d1dfc2c20d3a169eb1f86d198ca38d3d8e0c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.2-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 737eb4421013b27f9ee13fdc42544b79977eba74e254eec037c9a207e105fd27
MD5 929c590d7c66b3f4d1ef9624e62a6f60
BLAKE2b-256 998c441473bb0f8e6b24ee853b2518fb1db8cc84d3017ff7801d1c3dfae96779

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.2-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 b22e49242fed57a23f02dc294a562591b63aa317c5b41ba4b3673e3f73dd26a1
MD5 6ec2e6529b460129a5e233efa2857f91
BLAKE2b-256 1e7f3eeb63e009c8b065089da19b63268043adafd01436e53caf95558b7c0539

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