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

Uploaded Source

Built Distributions

pysha3-1.0.0-cp35-cp35m-win_amd64.whl (35.6 kB view details)

Uploaded CPython 3.5m Windows x86-64

pysha3-1.0.0-cp35-cp35m-win32.whl (21.9 kB view details)

Uploaded CPython 3.5m Windows x86

pysha3-1.0.0-cp34-cp34m-win_amd64.whl (35.9 kB view details)

Uploaded CPython 3.4m Windows x86-64

pysha3-1.0.0-cp34-cp34m-win32.whl (21.5 kB view details)

Uploaded CPython 3.4m Windows x86

pysha3-1.0.0-cp33-cp33m-win_amd64.whl (35.9 kB view details)

Uploaded CPython 3.3m Windows x86-64

pysha3-1.0.0-cp33-cp33m-win32.whl (21.5 kB view details)

Uploaded CPython 3.3m Windows x86

pysha3-1.0.0-cp27-cp27m-win_amd64.whl (36.0 kB view details)

Uploaded CPython 2.7m Windows x86-64

pysha3-1.0.0-cp27-cp27m-win32.whl (19.8 kB view details)

Uploaded CPython 2.7m Windows x86

File details

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

File metadata

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

File hashes

Hashes for pysha3-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2d2f681a6b1941ad1f778ad0ce69120389a456e0fe12623f16c15c517a1b9a95
MD5 dda7d6c10df9a7e3997894e1cc1e8197
BLAKE2b-256 1cfdec5ebe88c71f04f71e8e4e50e0a037fa4975f70f508fd6e622b186831a28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysha3-1.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 6f8ccfaaa142042431fdd89f2fad2109ecee73c28ea8a35897a1ff82014f062b
MD5 fd4a7b72aad89af0f12c2950b3d78090
BLAKE2b-256 585d7ed32b40b1610f10560d177e8844a8bb4483771ad6421599c62986d8b7d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysha3-1.0.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 263ae07d1cb93e98d788ffc60798bc5379cb1e0f622c72191ecf2439390fcbae
MD5 e0ef8366a7020ce1aa4fad0af7de6a79
BLAKE2b-256 ceece743106bd48d168f809262c311fc5cdf58e690c4111371e720b60ec9874c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysha3-1.0.0-cp34-cp34m-win_amd64.whl
Algorithm Hash digest
SHA256 05c1859f8b034f10cc5d9affb228a8aecb547129969469f98116a0c289a1d7e0
MD5 96d125bdb4a0d24cc35c298ee36d3ea7
BLAKE2b-256 536dffa66b8e7c2907234d72f99f177b79786594322c3c2a3e512692b69e8410

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysha3-1.0.0-cp34-cp34m-win32.whl
Algorithm Hash digest
SHA256 f1aa095930817a7777ce0dec479bd79116c60239fb54ae39f75ad0752c93c0d0
MD5 b36b0f3b24cec016f08c020e26a47523
BLAKE2b-256 43a6982a76e06924c890bc792299fbb0f449d4bf3e72135cd0dc772246fdf420

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysha3-1.0.0-cp33-cp33m-win_amd64.whl
Algorithm Hash digest
SHA256 684c552258ca9b183fd952ec571c9bbab3582bd22156ccb6f74ddb61da76b9fc
MD5 dd5947c9d22324f23fe016f91cf968f3
BLAKE2b-256 38ac7f9e4f5ebdf48fc3f96f40de1c6c9962dba72affd2e736a4569d007eb9a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysha3-1.0.0-cp33-cp33m-win32.whl
Algorithm Hash digest
SHA256 ef5a251b3ed4c9c865d0677c2104e7534a9f5f1cf628ca7605218d38e20bb49c
MD5 97edea96cd395bead27b438dea6f6a09
BLAKE2b-256 30398c90f4157c20a3915d3fd9ddd92f299534f3a80695408f7d82d2e2d8fb2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysha3-1.0.0-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 9193c3e5462e032fcc3e44c8fcc2f84525002cd9af5ab16a94768349b70283f9
MD5 789ceb84a9be6002bfdf04408b3c4dce
BLAKE2b-256 00d815494ac2caa3699a3fc881ebfa6b0a52791a497a9cb4b82c9095ad48a4bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pysha3-1.0.0-cp27-cp27m-win32.whl
Algorithm Hash digest
SHA256 de05c915a664b203f692be6a9ce73a7301b283eb8a1621f1ff5ec7ced12eccaf
MD5 05149c332b2a79925a10e9a11c638e54
BLAKE2b-256 8d4bc5556ab1174f377abffedca9f36f72c66de286f4df5176f00cd5c4321582

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