skip to navigation
skip to content

Not Logged In

pysha3 0.2

SHA-3 (Keccak) for Python 2.6 - 3.4

Latest Version: 0.3


sha3 wrapper (keccak) for Python. The package is a wrapper around the
optimized reference implementation from . Only
the optimizations for 32 and 64bit platforms are used. The optimized SSE and
ARM assembly variants are ignored for now.

The module is a standalone version of the SHA-3 implemention of Python 3.4
(currently under development).


  >>> import sha3
  >>> s = sha3.sha3_512()
  >>> s.digest_size
  >>> s.update(b"data")
  >>> s.hexdigest()

The module contains the constructors sha3_228(), sha3_256(), sha3_384 and

hashlib monkeypatch

The sha3 module monkey patches the hashlib module:

  >>> import hashlib
  >>> s ="sha3_512")
  Traceback (most recent call last):
  ValueError: unsupported hash type sha3_512

  >>> import sha3
  >>> s ="sha3_512")
  >>> s = hashlib.sha3_512()

Comments from sha3module header

The code is based on from 29 May 2012.

The reference implementation is altered in this points:
  - C++ comments are converted to ANSI C comments.
  - All functions and globals are declared static.
  - The typedef for UINT64 is commented out.
  - brg_endian.h is removed.
  - KeccakF-1600-opt[32|64]-settings.h are commented out
  - Some unused functions are commented out to silence compiler warnings.

In order to avoid name clashes with other software I have to declare all
Keccak functions and global data as static. The C code is directly
included into this file in order to access the static functions.

Keccak can be tuned with several paramenters. I try to explain all options
as far as I understand them. The reference implementation also contains
assembler code for ARM platforms (NEON instructions).


  UseBebigokimisa, Unrolling

- Unrolling: loop unrolling (24, 12, 8, 6, 4, 3, 2, 1)
- UseBebigokimisa: lane complementing

64bit platforms

Additional options:
  UseSSE, UseOnlySIMD64, UseMMX, UseXOP, UseSHLD

Optimized instructions (disabled by default):
  - UseSSE: use Stream SIMD extensions
    o UseOnlySIMD64: limit to 64bit instructions, otherwise 128bit
    o w/o UseOnlySIMD64: requires compiler agument -mssse3 or -mtune
  - UseMMX: use 64bit MMX instructions
  - UseXOP: use AMD's eXtended Operations (128bit SSE extension)

  - Unrolling: default 24
  - UseBebigokimisa: default 1

When neither UseSSE, UseMMX nor UseXOP is configured, ROL64 (rotate left
64) is implemented as:
  - Windows: _rotl64()
  - UseSHLD: use shld (shift left) asm optimization
  - otherwise: shift and xor

UseBebigokimisa can't be used in combination with UseSSE, UseMMX or
UseXOP. UseOnlySIMD64 has no effect unless UseSSE is specified.

Tests have shown that UseSSE + UseOnlySIMD64 is about three to four
times SLOWER than UseBebigokimisa. UseSSE and UseMMX are about two times
slower. (tested by CH and AP)

32bit platforms

Additional options:
  UseInterleaveTables, UseSchedule

  - Unrolling: default 2
  - UseBebigokimisa: default n/a
  - UseSchedule: ???, (1, 2, 3; default 3)
  - UseInterleaveTables: use two 64k lookup tables for (de)interleaving
    default: n/a

  - 3: no UseBebigokimisa, Unrolling must be 2
  - 2 + 1: ???


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"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
File Type Py Version Uploaded on Size
pysha3-0.2.tar.gz (md5) Source 2012-10-06 43KB (md5) MS Windows installer 2.6 2012-10-06 239KB (md5) MS Windows installer 2.7 2012-10-06 270KB (md5) MS Windows installer 3.2 2012-10-06 271KB (md5) MS Windows installer 3.3 2012-10-06 268KB
pysha3-0.2.win32-py2.6.exe (md5) MS Windows installer 2.6 2012-10-06 210KB
pysha3-0.2.win32-py2.7.exe (md5) MS Windows installer 2.7 2012-10-06 211KB
pysha3-0.2.win32-py3.2.exe (md5) MS Windows installer 3.2 2012-10-06 211KB
pysha3-0.2.win32-py3.3.exe (md5) MS Windows installer 3.3 2012-10-06 206KB (md5) Source 2012-10-06 55KB
  • Downloads (All Versions):
  • 91 downloads in the last day
  • 1297 downloads in the last week
  • 6770 downloads in the last month