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:
$ 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
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file scrypt-0.8.3.tar.gz
.
File metadata
- Download URL: scrypt-0.8.3.tar.gz
- Upload date:
- Size: 45.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24c68246049a955dd8f56d4aba70a66a6b752af228be12e6ae54b77df5a9dec0 |
|
MD5 | b421fa6eba91876298fa8f1e889aaa5e |
|
BLAKE2b-256 | c95f64774eb27427710537b49ffc4a515d4ef66d4321c2833335859fe516512e |
File details
Details for the file scrypt-0.8.3.win-amd64-py3.6.exe
.
File metadata
- Download URL: scrypt-0.8.3.win-amd64-py3.6.exe
- Upload date:
- Size: 619.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb40189daecebd73eacbc67376991140e27c6e28e03197628fe68ff311856936 |
|
MD5 | 5a32d906e0a1f3935b705db5bb3c0576 |
|
BLAKE2b-256 | 1b96fbe58cd2f76ee27486c52f685de7e452520ec1a7a3665e003c3c5727c342 |
File details
Details for the file scrypt-0.8.3.win-amd64-py3.5.exe
.
File metadata
- Download URL: scrypt-0.8.3.win-amd64-py3.5.exe
- Upload date:
- Size: 619.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2c1b8c30a36415a9ded306eb77acd7067045ab63b4cc3b917fedfe1e6c962b |
|
MD5 | 28e0ca99501f948fbadf7b7ab5a5ed6e |
|
BLAKE2b-256 | c05bb5b33c97ea90142ae551a530ef1540a526a7daaf50106fcdf8702f987cbd |
File details
Details for the file scrypt-0.8.3.win-amd64-py3.4.exe
.
File metadata
- Download URL: scrypt-0.8.3.win-amd64-py3.4.exe
- Upload date:
- Size: 251.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df8f87b6afecae9c6559b25819cb11512b5bbb276ee0d413d353cf2e539079c2 |
|
MD5 | 04d850d547de774c1e886dfea48d4b15 |
|
BLAKE2b-256 | 78f2946d558093ec8a6c25f73cceab6191ef38b49307a8421133012197283ecf |
File details
Details for the file scrypt-0.8.3.win-amd64-py2.7.exe
.
File metadata
- Download URL: scrypt-0.8.3.win-amd64-py2.7.exe
- Upload date:
- Size: 252.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 211292367e284fba47d591b5c59e88c70c68862b9e049d049aae72a66e635b32 |
|
MD5 | f83938071122af2b9419c4e98283cc67 |
|
BLAKE2b-256 | 9aff3800784fc87b379498e3586a1b27d90b049dde29c9ee6bdf66ba82d121d7 |
File details
Details for the file scrypt-0.8.3.win32-py3.6.exe
.
File metadata
- Download URL: scrypt-0.8.3.win32-py3.6.exe
- Upload date:
- Size: 485.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7870c52417224051fad40853d108c897ca5dca79ba41a22d23f401eaa812e2eb |
|
MD5 | e48c8e14759eed3bb26dcd0bd3639345 |
|
BLAKE2b-256 | 68036933ae52cde7966bd8d735cfbc15cdfac5140277ce17fa08299553a6e68c |
File details
Details for the file scrypt-0.8.3.win32-py3.5.exe
.
File metadata
- Download URL: scrypt-0.8.3.win32-py3.5.exe
- Upload date:
- Size: 485.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 206d81607dccf8336930c4d2487009b74f19dbe8519c843b9ce08daf32983469 |
|
MD5 | 392e9c2e4f762da14f98da1261572ca1 |
|
BLAKE2b-256 | b6785316e88a3a0c528abbac61bda52b4fd4674113daeee985878ae88cf31036 |
File details
Details for the file scrypt-0.8.3.win32-py3.4.exe
.
File metadata
- Download URL: scrypt-0.8.3.win32-py3.4.exe
- Upload date:
- Size: 216.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2fd67b752fb408571766eebae8d708e665d94b5d48ff2976b40d559398724fd6 |
|
MD5 | c42208f062bc38e663ae9e532e543bad |
|
BLAKE2b-256 | 8d3518f12d99ccc9c0dbd68f11a426669d1f529e3a92fa1e431902057b009682 |
File details
Details for the file scrypt-0.8.3.win32-py2.7.exe
.
File metadata
- Download URL: scrypt-0.8.3.win32-py2.7.exe
- Upload date:
- Size: 221.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8ea535cd6b15ef583d534efe551b095f47aa2193ca8b93c43b462740d91b5c6 |
|
MD5 | 1899df555a1795a1898d77ea9dd995dc |
|
BLAKE2b-256 | 0bf9c75396e42f241356c6cd8f4567a209744604f0c292551c993ba6bee96296 |
File details
Details for the file scrypt-0.8.3-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 28.4 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdaff92b279aecdec4a7fb1a8bcb45e3c2276df724069ca644d7229089a90afc |
|
MD5 | fe145ec1402d754fea249be63e058156 |
|
BLAKE2b-256 | b05f254f518844e541948855ebe75b47b3971214c7d5b0e24d5a14bf32dc54a3 |
File details
Details for the file scrypt-0.8.3-cp36-cp36m-win32.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp36-cp36m-win32.whl
- Upload date:
- Size: 24.3 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf9e2ae48b0adf80554f8987a83e5b838f9f5bdefd09defbdc09ee23de8a58b6 |
|
MD5 | bc38f0f8e4fdfecc5a9a4be060a45584 |
|
BLAKE2b-256 | d5be55c845f1bed9c2882fcb63578165577b460ebe80a71ab7f726f935ad25d4 |
File details
Details for the file scrypt-0.8.3-cp36-cp36m-macosx_10_6_intel.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp36-cp36m-macosx_10_6_intel.whl
- Upload date:
- Size: 45.0 kB
- Tags: CPython 3.6m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5d18444f651b5b469d83e8ea1b00e9cc2e58dca0073674c56b8e6a9a9ebd608 |
|
MD5 | d112aaefa0a654bfe4f0a12e4c0f570e |
|
BLAKE2b-256 | fb6444461d420c0368dd77bffddda311664699eedd67a08c21ff7f36d17055de |
File details
Details for the file scrypt-0.8.3-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 28.4 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06cfa7baab3158c1349671768288e682f4f31f810d37ad01edb4d570f69fbbd5 |
|
MD5 | 2a89a384cdeeb562185dbf2a9ca6b927 |
|
BLAKE2b-256 | ba984e0044f7085597cf89683d53ca63a6db3f34ab471758359b05ed24b7a8fa |
File details
Details for the file scrypt-0.8.3-cp35-cp35m-win32.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp35-cp35m-win32.whl
- Upload date:
- Size: 24.3 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eeee74d56fb7b11fed6f0badf3c02327df80c9c11b684d8974073d3371ab15c4 |
|
MD5 | 4dad05738976ec814bd63a1b74a20619 |
|
BLAKE2b-256 | 78725bb17cf9a4e2719fa7d80709179e7e33e474ef39ae8d53d45685d7fbc5a7 |
File details
Details for the file scrypt-0.8.3-cp35-cp35m-macosx_10_6_intel.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp35-cp35m-macosx_10_6_intel.whl
- Upload date:
- Size: 44.9 kB
- Tags: CPython 3.5m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25f726feedca5ab9056ae840ba6b9975adf891611926e7c9e95cb05c444995b6 |
|
MD5 | abadf72a5bbebf39a2eee124eade4dc4 |
|
BLAKE2b-256 | b686a95d5da6ab56c5c063585e5b6bdb2b5c3e2ee4cfeb267c80e9fed1e6ac6b |
File details
Details for the file scrypt-0.8.3-cp34-cp34m-win_amd64.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp34-cp34m-win_amd64.whl
- Upload date:
- Size: 25.8 kB
- Tags: CPython 3.4m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e4d44dcef6d92b389f51c9258cf934db911da0adf6e073fa13209259ec8252a |
|
MD5 | 5c2122912a268193d5176a870a3b040b |
|
BLAKE2b-256 | 93b57cdf21fd71778d787c2899ea2b79159343324bff0eb4ed7f277824a6ef5f |
File details
Details for the file scrypt-0.8.3-cp34-cp34m-win32.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp34-cp34m-win32.whl
- Upload date:
- Size: 22.6 kB
- Tags: CPython 3.4m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c97f3564f376d56a9b84596787a61f2ba28fca8ecdfc71c477796b281268b508 |
|
MD5 | 274d08e8599e8bfdf423fee1b8504964 |
|
BLAKE2b-256 | 6a25a0a49b9762dca71fce91229154e1170f9549cbc44c9991655e983c810533 |
File details
Details for the file scrypt-0.8.3-cp27-cp27m-win_amd64.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp27-cp27m-win_amd64.whl
- Upload date:
- Size: 25.4 kB
- Tags: CPython 2.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ac4cd21f5e467cb64a0c85d8c93b884e25e3f59b0fee6b034da232063fec35d |
|
MD5 | 00ac685997e948753f2153d2284987c7 |
|
BLAKE2b-256 | 82a6e612a3a933c1e605b065e215750427550bff5ecd07f2827517d711f645d9 |
File details
Details for the file scrypt-0.8.3-cp27-cp27m-win32.whl
.
File metadata
- Download URL: scrypt-0.8.3-cp27-cp27m-win32.whl
- Upload date:
- Size: 22.6 kB
- Tags: CPython 2.7m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7848a9572106b178d47ff247fdd2c49e7e69662125bed4fa69b831adf0a0320 |
|
MD5 | 5dbfb4fd5d6bebbbbd6891836618b53b |
|
BLAKE2b-256 | a3c48180f5a125583f54c8cb6f486127e57fe23a8bb4fd4c94e97539877b1300 |