Skip to main content

SHA-3 (Keccak) for Python 2.7 - 3.5

Project description

SHA-3 wrapper (keccak) for Python. The package is a wrapper around the optimized Keccak Code Package, https://github.com/gvanas/KeccakCodePackage .

The module is a standalone version of my SHA-3 module from Python 3.6 (currently under development). The code in sha3module.c has been modified to be compatible with Python 2.7 to 3.5. Python 2.6 and earlier are not supported.

Updates since pysha 0.3

pysha3 1.0 is not compatible with pysha3 0.3!

pysha3 < 1.0 used the old Keccak implementation. During the finalization of SHA3, NIST changed the delimiter suffix from 0x01 to 0x06. The Keccak sponge function stayed the same. pysha3 1.0 provides the previous Keccak hash, too.

Platforms

pysha3 has been successfully tested on several platforms:

  • Linux (GCC, clang) on X86, X86_64 and ARMv6 (little endian)

  • Windows (VS 2008, VS 2010, VS2015) on X86 and X86_64

Usage

The sha3 module contains several constructors for hash objects with a PEP 247 compatible interface. The module provides SHA3, SHAKE and Keccak:

  • sha3_228(), sha3_256(), sha3_384(), and sha3_512()

  • shake_128(), shake_256()

  • keccak_228(), keccak_256(), keccak_384(), and keccak_512()

The sha3 module monkey patches the hashlib module . The monkey patch is automatically activated with the first import of the sha3 module. The hashlib module of Python 3.6 will support the four SHA-3 algorithms and the two SHAKE algorithms on all platforms. Therefore you shouldn’t use the sha3 module directly and rather go through the hashlib interface:

>>> import sys
>>> import hashlib
>>> if sys.version_info < (3, 6):
...    import sha3
>>> s = hashlib.sha3_512()
>>> s.name
'sha3_512'
>>> s.digest_size
64
>>> s.update(b"data")
>>> s.hexdigest()
'ceca4daf960c2bbfb4a9edaca9b8137a801b65bae377e0f534ef9141c8684c0fedc1768d1afde9766572846c42b935f61177eaf97d355fa8dc2bca3fecfa754d'

>>> s = hashlib.shake_256()
>>> s.update(b"data")
>>> s.hexdigest(4)
'c73dbed8'
>>> s.hexdigest(8)
'c73dbed8527f5ae0'
>>> s.hexdigest(16)
'c73dbed8527f5ae0568679f30ecc5cb6'

>>> import sha3
>>> k = sha3.keccak_512()
>>> k.update(b"data")
>>> k.hexdigest()
'1065aceeded3a5e4412e2187e919bffeadf815f5bd73d37fe00d384fe29f55f08462fdabe1007b993ce5b8119630e7db93101d9425d6e352e22ffe3dcb56b825'

Changelog

pysha3 1.0.1

Release: 24-Jan-2017

  • Fix github.org -> github.com (Pi Delport)

  • Fix endianness checks for Python 2 (William Grant)

  • Fix changelog, the Christmas release was 1.0.0, not 1.1.0

pysha3 1.0.0

Release date: 24-Dec-2016

  • Synchronize with Python 3.6.0 release

  • Move all backport related additions to backport.inc

  • Fix flake8 violations

pysha3 1.0b1

Release date: 01-May-2016

  • Update backend to use the latest Keccak Code Package. pysha3 now implements the official NIST standard. The old Keccak hashes are available with keccak prefix.

  • Add SHAKE support.

  • All sha3, shake and keccak variants are separate types instead of factory functions that return the same type.

  • Drop Python 2.6 and Python 3.0 to 3.3 support.

  • Fix typo that disabled threading optimization.

  • Add vector files for additional tests.

  • Add experimental HMAC support based on examples from http://wolfgang-ehrhardt.de/hmac-sha3-testvectors.html .

  • Test hashing of unaligned data.

  • Add ISO C11 memset_s() function as _Py_memset_s() in order to securely wipe memory that holds sensitive data. The page https://www.securecoding.cert.org/confluence/display/seccode/MSC06-C.+Be+aware+of+compiler+optimization+when+dealing+with+sensitive+data explains the motivation for memset_s().

  • Add tox support.

  • Add Travis and appveyor integration.

  • Add _capacity_bits, _rate_bits and _suffix attributes for diagnostic purposes.

pysha3 0.3

Release date: 14-Oct-2012

  • Fix 64bit big endian support

  • Add workaround for alignment error on 64bit SPARC machine by using the opt32 implementation.

  • block_size now returns NotImplemented to prevent users from using pysha3 with the hmac module.

pysha3 0.2.2

Release date: 07-Oct-2012

  • Re-add brg_endian.h to fix issue on Solaris (big endian platform)

pysha3 0.2.1

Release date: 06-Oct-2012

  • Fix MANIFEST.in to include Makefile and tests.py

  • Add setup.py test command with hack for inplace builds

  • Enhance README.txt and fixed its markup

pysha3 0.2

Release date: 06-Oct-2012

  • Change directory struct to use the same directory layout as Python 3.4.

  • Remove C++ comments from Keccak sources for ANSI C compatibility.

  • Declare all Keccak functions and globals as static to avoid name clashes.

  • Remove alias sha3() for sha3_512().

  • Add block_size attribute. Keccak has a internal sponge size of 1600 bits.

  • Release GIL around SHA3_update() calls.

  • Monkey patch the hashlib module to support, e.g. hashlib.sha3_512() and hashlib.new(“sha3_512”)

  • Release GIL around SHA3_update() when the data exceeds a certain size.

  • Fix build on platforms with an unsigned 64bit integer type (uint64_t). The module falls back to 32bit implementation of Keccak with interleave tables.

pysha3 0.1

Release date: 04-Oct-2012

  • first release

  • based on KeccakReferenceAndOptimized-3.2.zip

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

pysha3-1.0.1.tar.gz (829.1 kB view details)

Uploaded Source

Built Distributions

pysha3-1.0.1-cp35-cp35m-win_amd64.whl (35.8 kB view details)

Uploaded CPython 3.5m Windows x86-64

pysha3-1.0.1-cp35-cp35m-win32.whl (22.1 kB view details)

Uploaded CPython 3.5m Windows x86

pysha3-1.0.1-cp34-cp34m-win_amd64.whl (36.1 kB view details)

Uploaded CPython 3.4m Windows x86-64

pysha3-1.0.1-cp34-cp34m-win32.whl (21.7 kB view details)

Uploaded CPython 3.4m Windows x86

pysha3-1.0.1-cp33-cp33m-win_amd64.whl (36.1 kB view details)

Uploaded CPython 3.3m Windows x86-64

pysha3-1.0.1-cp33-cp33m-win32.whl (21.7 kB view details)

Uploaded CPython 3.3m Windows x86

pysha3-1.0.1-cp27-cp27m-win_amd64.whl (36.2 kB view details)

Uploaded CPython 2.7m Windows x86-64

pysha3-1.0.1-cp27-cp27m-win32.whl (20.0 kB view details)

Uploaded CPython 2.7m Windows x86

File details

Details for the file pysha3-1.0.1.tar.gz.

File metadata

  • Download URL: pysha3-1.0.1.tar.gz
  • Upload date:
  • Size: 829.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pysha3-1.0.1.tar.gz
Algorithm Hash digest
SHA256 89c334f783426da529005fb8e53b46c02e838979c04f097127a0108b01c370df
MD5 0293e3e8e788eee8da105a227c1fd062
BLAKE2b-256 54cbd41dd01f060adff284c75c4e7d13c74c2211eee444e30d1488985cc1598c

See more details on using hashes here.

File details

Details for the file pysha3-1.0.1-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for pysha3-1.0.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 5fff9129a43dcac05b31a13ba8bd0204b4a2408284009a0a80b40e07c13f8620
MD5 990fdd633d5ba1073c3bf11d19ec7567
BLAKE2b-256 022c591fd707ab2e2c8c5ee5a5fb2a6ad96ad0997d43f2dd0b8faa1c9baf7021

See more details on using hashes here.

File details

Details for the file pysha3-1.0.1-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for pysha3-1.0.1-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 65f11feb1c8732ab3d93b0a146673387544489f7d89b83175a1ed4285921f25f
MD5 6307a246b9e44672ec2b28e273421776
BLAKE2b-256 c1ca2bdb2b51c90f075923194c821be5efff9abefe4eecf92fe5dd56826bc0f9

See more details on using hashes here.

File details

Details for the file pysha3-1.0.1-cp34-cp34m-win_amd64.whl.

File metadata

File hashes

Hashes for pysha3-1.0.1-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 45c1f3a6acc8e762d12e13ff527bb45a19ccd5c9fe7a90eb29d66f3989ed8a13
MD5 93d3f9ff3075ff512d982f74d4f27cb0
BLAKE2b-256 4789a9390fa6f12d87dc42689e72dfa01cde86e860f13c41528a30fcf5d2ff85

See more details on using hashes here.

File details

Details for the file pysha3-1.0.1-cp34-cp34m-win32.whl.

File metadata

File hashes

Hashes for pysha3-1.0.1-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 0de7e0a5d6c02ba49ccbd70625a7abc4b3f3a8253b47b0ede2ae3e00e231fb81
MD5 f88296653fe4a3f7f77f74f19412d315
BLAKE2b-256 c0d7753cdf16ca22aaa712e6925365adadc765d95a21ea11649599a172a378c1

See more details on using hashes here.

File details

Details for the file pysha3-1.0.1-cp33-cp33m-win_amd64.whl.

File metadata

File hashes

Hashes for pysha3-1.0.1-cp33-cp33m-win_amd64.whl
Algorithm Hash digest
SHA256 653026af33d73135a2c023b3d16e7cde99edda6c2d9583efdff6053ad786ad3d
MD5 79f6d2519996b7a7c9f26256dd053ea2
BLAKE2b-256 7dfd9a5db056b72a02b50c76c6323d80c2611874f2ded7016b136de6ccb69594

See more details on using hashes here.

File details

Details for the file pysha3-1.0.1-cp33-cp33m-win32.whl.

File metadata

File hashes

Hashes for pysha3-1.0.1-cp33-cp33m-win32.whl
Algorithm Hash digest
SHA256 b3973953ed8607c50ea448996a70c8762082fcb14d43588680bba8df291f183f
MD5 d3b32a398a9b9640c85df8b824d29df2
BLAKE2b-256 62924f0ea35823bcfdb25392eaa84f62a7aeaa8ce85251f6f12d08667f09b674

See more details on using hashes here.

File details

Details for the file pysha3-1.0.1-cp27-cp27m-win_amd64.whl.

File metadata

File hashes

Hashes for pysha3-1.0.1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 f3abf7454a9d0c36bfc51f4d09f69ec27412d00941c39202d5fa33541dff4316
MD5 f0adf6035a2835b764546a55419c39b2
BLAKE2b-256 44a308e6e1b06824ab3380394393b3223c3f5764163495c6a429cb000d22b4e4

See more details on using hashes here.

File details

Details for the file pysha3-1.0.1-cp27-cp27m-win32.whl.

File metadata

File hashes

Hashes for pysha3-1.0.1-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 fd4257b1a33e449f31fd11d30b577f1927e3f2523b13e83ae2935831bcc03b31
MD5 4767aa0c471891a331b4cfa3894d1d1d
BLAKE2b-256 a944eb04ff1a8149a604188929ac1426e3957ad6601c990db90c6f0e46359824

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