Skip to main content

SHA-3 (Keccak) for Python 2.6 - 3.4

Project description

pysha3
======

sha3 wrapper (keccak) for Python. The package is a wrapper around the
optimized reference implementation from http://keccak.noekeon.org/ . 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).


Usage
=====

>>> import sha3
>>> s = sha3.sha3_512()
>>> s.name
'sha3_512'
>>> s.digest_size
64
>>> s.update(b"data")
>>> s.hexdigest()
'1065aceeded3a5e4412e2187e919bffeadf815f5bd73d37fe00d384fe29f55f08462fdabe1007b993ce5b8119630e7db93101d9425d6e352e22ffe3dcb56b825'

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


hashlib monkeypatch
===================

The sha3 module monkey patches the hashlib module:

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

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


Comments from sha3module header
===============================

The code is based on KeccakReferenceAndOptimized-3.2.zip 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).

Common
------

Options:
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)

Other:
- 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

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

Changelog
=========

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 Distributions

pysha3-0.2.zip (57.0 kB view details)

Uploaded Source

pysha3-0.2.tar.gz (44.2 kB view details)

Uploaded Source

Built Distributions

pysha3-0.2.win-amd64-py3.3.exe (275.2 kB view details)

Uploaded Source

pysha3-0.2.win-amd64-py3.2.exe (277.7 kB view details)

Uploaded Source

pysha3-0.2.win-amd64-py2.7.exe (277.2 kB view details)

Uploaded Source

pysha3-0.2.win-amd64-py2.6.exe (245.5 kB view details)

Uploaded Source

pysha3-0.2.win32-py3.3.exe (211.6 kB view details)

Uploaded Source

pysha3-0.2.win32-py3.2.exe (216.7 kB view details)

Uploaded Source

pysha3-0.2.win32-py2.7.exe (216.7 kB view details)

Uploaded Source

pysha3-0.2.win32-py2.6.exe (215.7 kB view details)

Uploaded Source

File details

Details for the file pysha3-0.2.zip.

File metadata

  • Download URL: pysha3-0.2.zip
  • Upload date:
  • Size: 57.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pysha3-0.2.zip
Algorithm Hash digest
SHA256 1f0c97ba060288adf0fe25f6716d0c3106b04d39296416ecb3d3306e29185764
MD5 06e755a6bb710c166c5ad4138d093884
BLAKE2b-256 77bdd75760a539c69a91f42edc40b113d5c4d291d36d4246e55adcb491fa9f50

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pysha3-0.2.tar.gz
Algorithm Hash digest
SHA256 a31071422ed7af56ec4f3a7720012cd7fb998e75b63d111357acf9528666c9c8
MD5 dc9541b4ac67be40f8eb662143655ecd
BLAKE2b-256 7dc0a4bff3a36fad40da1288ca0667e5a56917023b6647717c557cb4aab2268a

See more details on using hashes here.

File details

Details for the file pysha3-0.2.win-amd64-py3.3.exe.

File metadata

File hashes

Hashes for pysha3-0.2.win-amd64-py3.3.exe
Algorithm Hash digest
SHA256 6910ead40e5bdbf9041ca02dabe2909f44949bcd5224a27b784c55a2aaab7aa8
MD5 b43315760b2f4a83ffeab124cae73f4c
BLAKE2b-256 051e65fac3c3a55c9ce102df039c8af36b6edf7dfb90c5bfef807b073e6db956

See more details on using hashes here.

File details

Details for the file pysha3-0.2.win-amd64-py3.2.exe.

File metadata

File hashes

Hashes for pysha3-0.2.win-amd64-py3.2.exe
Algorithm Hash digest
SHA256 d9ee5d22ae71e501f810e57e0653b2788f21a3afd9e4efe110fac6ce798b3b77
MD5 c67d376b9e0db22f0012252cf05ccf33
BLAKE2b-256 04eef3d6f7d23936503d25349639406cbf7491fa8b14161a3bedda235b2b2105

See more details on using hashes here.

File details

Details for the file pysha3-0.2.win-amd64-py2.7.exe.

File metadata

File hashes

Hashes for pysha3-0.2.win-amd64-py2.7.exe
Algorithm Hash digest
SHA256 7ddac51fd83a3322320845eae768cc90059dca7bfc7260556ac50241d0b17324
MD5 4469667fb254e9101944dc5413b52139
BLAKE2b-256 43c81d6016ca7b8a50979547f119c2f1394a3e4ea939547d167b85aa612fca53

See more details on using hashes here.

File details

Details for the file pysha3-0.2.win-amd64-py2.6.exe.

File metadata

File hashes

Hashes for pysha3-0.2.win-amd64-py2.6.exe
Algorithm Hash digest
SHA256 42dd57ddc3a5640489c4444ac9bd2aa0df4caad1ebab8a4d89a2c414f452f305
MD5 306152f666aa285994ad2d60e241ee2c
BLAKE2b-256 2677532903b1391e68d1bd921b5b50c1a9b381777d8b4887def56d134913baef

See more details on using hashes here.

File details

Details for the file pysha3-0.2.win32-py3.3.exe.

File metadata

File hashes

Hashes for pysha3-0.2.win32-py3.3.exe
Algorithm Hash digest
SHA256 195a1dda800a756e82c858497135e7682c8ae89e607548a6232174ee251e5a2e
MD5 e7ec6126ab822d456652f405966db67e
BLAKE2b-256 02925b5115a70bb3997ba834649c104ffa4ae9b0de4293b5aefd2ef630097b78

See more details on using hashes here.

File details

Details for the file pysha3-0.2.win32-py3.2.exe.

File metadata

File hashes

Hashes for pysha3-0.2.win32-py3.2.exe
Algorithm Hash digest
SHA256 108efe0c6c437b341b06084a233d7b4d8d710ee4aff4567de6e37758a7754d84
MD5 3e078bcc316dfbdcad767bfef17b2bcb
BLAKE2b-256 78afb7e0eb24492c87171b41f4d1860e322c5974acce7e2a8f2eda193d4d475e

See more details on using hashes here.

File details

Details for the file pysha3-0.2.win32-py2.7.exe.

File metadata

File hashes

Hashes for pysha3-0.2.win32-py2.7.exe
Algorithm Hash digest
SHA256 d2f6013623cf9a06b30cbd9eff764589f03e7e84403ad91564bb1ebce82488df
MD5 6df2221799c27a5541503f47ecbd650c
BLAKE2b-256 c6dac0c95ca97254137a861b287cee350f9b724c3b867f1b995258ef6f766f9d

See more details on using hashes here.

File details

Details for the file pysha3-0.2.win32-py2.6.exe.

File metadata

File hashes

Hashes for pysha3-0.2.win32-py2.6.exe
Algorithm Hash digest
SHA256 806ed71f712b5f6c53a61259d98e13d48c1eed4ee1f52a9069f080bb653ca7e9
MD5 bbbc6eba0497dc6b15576fff597d743a
BLAKE2b-256 692cbd0c03aff53fbb249c82bf3d6e26110b8b58ae31d78414f526b0768390c4

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