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.

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

Uploaded Source

Built Distributions

scrypt-0.8.0.win-amd64-py3.6.exe (617.0 kB view details)

Uploaded Source

scrypt-0.8.0.win-amd64-py3.5.exe (619.0 kB view details)

Uploaded Source

scrypt-0.8.0.win-amd64-py3.4.exe (248.8 kB view details)

Uploaded Source

scrypt-0.8.0.win-amd64-py2.7.exe (250.1 kB view details)

Uploaded Source

scrypt-0.8.0.win32-py3.6.exe (485.1 kB view details)

Uploaded Source

scrypt-0.8.0.win32-py3.5.exe (487.1 kB view details)

Uploaded Source

scrypt-0.8.0.win32-py3.4.exe (216.4 kB view details)

Uploaded Source

scrypt-0.8.0.win32-py2.7.exe (221.4 kB view details)

Uploaded Source

scrypt-0.8.0-cp36-cp36m-win_amd64.whl (26.5 kB view details)

Uploaded CPython 3.6m Windows x86-64

scrypt-0.8.0-cp36-cp36m-win32.whl (24.1 kB view details)

Uploaded CPython 3.6m Windows x86

scrypt-0.8.0-cp35-cp35m-win_amd64.whl (26.5 kB view details)

Uploaded CPython 3.5m Windows x86-64

scrypt-0.8.0-cp35-cp35m-win32.whl (24.2 kB view details)

Uploaded CPython 3.5m Windows x86

scrypt-0.8.0-cp35-cp35m-macosx_10_11_x86_64.whl (23.5 kB view details)

Uploaded CPython 3.5m macOS 10.11+ x86-64

scrypt-0.8.0-cp34-cp34m-win_amd64.whl (23.9 kB view details)

Uploaded CPython 3.4m Windows x86-64

scrypt-0.8.0-cp34-cp34m-win32.whl (22.7 kB view details)

Uploaded CPython 3.4m Windows x86

scrypt-0.8.0-cp27-cp27m-win32.whl (22.7 kB view details)

Uploaded CPython 2.7m Windows x86

scrypt-0.8.0-cp27-cp27m-macosx_10_11_x86_64.whl (23.4 kB view details)

Uploaded CPython 2.7m macOS 10.11+ x86-64

File details

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

File metadata

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

File hashes

Hashes for scrypt-0.8.0.tar.gz
Algorithm Hash digest
SHA256 d4a5a4f53450b8ef629bbf1ee4be6105c69936e49b3d8bc621ac2287f0c86020
MD5 0704e59cc3afb3845c27bb3827baeea9
BLAKE2b-256 af8244b030646b9de44ba5a5c7e87b0419a4d44318ba18468f5292b9c16737ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0.win-amd64-py3.6.exe
Algorithm Hash digest
SHA256 c10758dcad897e20de93100a2c908746c4b4955d00fca2ac3d6aa83abc92f804
MD5 94bc8c1eb9fd69eff092fd19a4cd2fd6
BLAKE2b-256 4afdbc6e148165fc55e0731bc1d61c91269ff536d940554c1940fa721dbef155

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0.win-amd64-py3.5.exe
Algorithm Hash digest
SHA256 bb141584fa0ebdfb8a2a1fc7ddcf119ee18b1b9cd0fb3e4df9615760648b9d49
MD5 83fd4677cc0fa05f8c9bf262ce4bdba0
BLAKE2b-256 9fd73e1ac996ca962f3be6c31fce30e7e68c9e832bd66da48e49b037336251bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0.win-amd64-py3.4.exe
Algorithm Hash digest
SHA256 aeab005a8ae43a6e5d0165ce433a15955b151045d2bbfc52a8c96f100f825323
MD5 68b9de73f25d40322f5bf11e29c52827
BLAKE2b-256 ce558382b9d87625627a522e9ec3deca416160b7a16a3e03ef8095f5d98e6bca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 4333b67f190e5eaddc8800aefe33abd7e81b589bbe84a84be66872a4955dad6e
MD5 f5faeecfcd9be3412a6d10ec2e5a373b
BLAKE2b-256 3eb8e09f4f557ce21459a691d8bf3072affac31379941586229f857788b2034a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0.win32-py3.6.exe
Algorithm Hash digest
SHA256 a11f408ffcf7bd9867c4a6e3f5f0782f5f5ba53da375dc0400855b200070376b
MD5 ce02ff12c207407c2442fcffbf03c572
BLAKE2b-256 6d13d0d8f1cd61fb4002df99e472027d116d040cb9ac82496254283c7f04cfd0

See more details on using hashes here.

File details

Details for the file scrypt-0.8.0.win32-py3.5.exe.

File metadata

File hashes

Hashes for scrypt-0.8.0.win32-py3.5.exe
Algorithm Hash digest
SHA256 c8909a2089fd1199781aa7ce2cb66b8866d40a9f9e1fba082e067ed9524d87e9
MD5 ca27dea8308a65d2dac867f8493eb3b4
BLAKE2b-256 66ab33c328c4524fe5fd351bab4b7ac75bbb424dc3e3bb3720b08b258ef93dbe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0.win32-py3.4.exe
Algorithm Hash digest
SHA256 136f7d1caf596c5ee1fc7eab223605e956c3f61f77090fd9ea4e3e57a2040b78
MD5 4e715eef999d222efbf2b50630317cc7
BLAKE2b-256 fc20a33b760556071e4ff8a247369667c0d1b085c91c8fcab2158d9821f47b4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0.win32-py2.7.exe
Algorithm Hash digest
SHA256 6109a4df8c88f851df18a1a451e533dcc47e17cfe0e4561f4e08a82669ddc942
MD5 db04ef2223c0594e4429698744690d99
BLAKE2b-256 b74bb11eac2aa846231ade35f323e7ad5c98f3c5f77c3b6b2ca33e24afe9518c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 7e3be5fe70f74a01a83c60da0b010b2fe6c3d3a11b8a1c9532b583c9a440d529
MD5 834aada81e3911c2675854df4039cfbb
BLAKE2b-256 a9fd3f566dfd4d0586a5d9cad49dd3505ce03a0955ddcef43d8c1fd364c2551a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp36-cp36m-win32.whl
Algorithm Hash digest
SHA256 59a03822df232a30246b59a3801292a350d19fa636f11ea86df2214f35dade22
MD5 4333e501b9ca948e81985729bdf4cccd
BLAKE2b-256 66e66299f57d422ad5d214f485775534b9aaaf5b09f883b728273be39a5c325f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 3422d11652cd12550540675e9fb54a1de6d60f3cbfedfb067284ef028589e2ee
MD5 be6d6e895b68cdb4307450443c6e5173
BLAKE2b-256 b63c86905ae974620275039785bdf54cc44dcaae97dcc04335a134998672cef5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 c37a1f8440d7c621d9f23f3c1f2a28848bc50fefbca581fd7a1b01583a083c07
MD5 e564ba7b8f8b9b26552edcf6cc2789d1
BLAKE2b-256 ec8f89ee71b476225707a5c84b78545e0af837d275fd863d7a41c1444191822f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 c0f90cabb8f6eaec05de5ce9aa9a9b67dc63d644e6b803beb1c43ae9b9452b65
MD5 4e3095c6d7829719377c4ebaf770c242
BLAKE2b-256 06b132fd6710517e852b4bd17cc0d4233c5d857940fe280f599d90350e5530e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 60e8c96a287ab892d9c7e1523d157ccfbdbe66da0c31738c8ed5732c2eea6a23
MD5 e6fd0ea8f71c5f3b59d952c3993bc888
BLAKE2b-256 f477bc0e0998bffd6825f3c392ddef078ade69e1ad99c8b111f7f2df91ea6c84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 ae2fd88756fb4d98ccc5e2639af55eeb80863b3f9f6e0f539e5ce050964cdd5e
MD5 1c1eecd3f767d0ae638688a941c28576
BLAKE2b-256 7f8224ea13e114337a9fa73b39c74f1fe4ce686e793361b80da7946820b3999c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 4e3cd639cc83e3f2c2241a01ebef9487c48b1ddf2d78f430d82d8f9ef60c6271
MD5 3adddbae07f37b129c8460eca4e73473
BLAKE2b-256 a8dbbd9f8ed6ac8293c957646053139e569b4c9fd2a5f7b95d1d70be3ee8fc72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scrypt-0.8.0-cp27-cp27m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 dc9abe69799ca423b938a06ddc33e5873e493ffcd68dbb9ba48396979b210d39
MD5 bbdc011430e18382fbd534717c7ef8b3
BLAKE2b-256 c2116656172288c2cc647d9606b163f43293859777bf3206c78d7f36e89fbb9e

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