SHA-3 (Keccak) for Python 2.6 - 3.4
Project description
pysha3
======
SHA-3 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). The code in sha3module.c has been modified to
be compatible with Python 2.6 to 3.4. Python 2.5 and earlier are not
supported.
Platforms
=========
pysha3 has been successfully tested on several platforms and architectures:
- Linux (GCC 4.3, GCC 4.6, clang 3.0) on X86, X86_64 and ARMv6
- Windows (VS 2008, VS 2010) on X86 and X86_64
- FreeBSD (clang) on X86 and X86_64
- HP-UX (HP C/aC++) on IA64
- Solaris 10 (Oracle Solaris Studio 12.3) on SPARC (big endian)
- AIX (XLC 12.1) on PowerPC (big endian)
Thank you very much to Trent Nelson for the Snakebite network.
Usage
=====
The `sha3` module contains several constructors for hash objects with a
PEP 247 compatible interface. The module provides `sha3_228()`, `sha3_256()`,
`sha3_384()`, and `sha3_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.4 will support the four SHA-3 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, 4):
... import sha3
>>> s = hashlib.new("sha3_512")
>>> s = hashlib.sha3_512() # alternative
>>> s.name
'sha3_512'
>>> s.digest_size
64
>>> s.update(b"data")
>>> s.hexdigest()
'1065aceeded3a5e4412e2187e919bffeadf815f5bd73d37fe00d384fe29f55f08462fdabe1007b993ce5b8119630e7db93101d9425d6e352e22ffe3dcb56b825'
**Don't use SHA-3 for HMAC!** HMAC hasn't been specified for SHA-3 yet and no
test vectors are available, too.
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
------
`Unrolling`
loop unrolling (24, 12, 8, 6, 4, 3, 2, 1)
`UseBebigokimisa`
lane complementing
64bit platforms
---------------
default settings of common options
`Unrolling`
24
`UseBebigokimisa`
enabled
Additional optimiation instructions (disabled by default):
`UseSSE`
use Stream SIMD extensions
`UseOnlySIMD64`
limit to 64bit instructions, otherwise 128bit
`w/o UseOnlySIMD64`
requires compiler argument `-mssse3` or `-mtune=core2` or better
`UseMMX`
use 64bit MMX instructions
`UseXOP`
use AMD's eXtended Operations (128bit SSE extension)
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
---------------
default settings of common options
`Unrolling`
2
`UseBebigokimisa`
disabled
`UseSchedule`
`1`
unknown
`2`
unknown
`3` [default]
unknown, no `UseBebigokimisa`, `Unrolling` must be 2
`UseInterleaveTables`
use two 64k lookup tables for (de)interleaving (disabled by default)
Changelog
=========
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
======
SHA-3 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). The code in sha3module.c has been modified to
be compatible with Python 2.6 to 3.4. Python 2.5 and earlier are not
supported.
Platforms
=========
pysha3 has been successfully tested on several platforms and architectures:
- Linux (GCC 4.3, GCC 4.6, clang 3.0) on X86, X86_64 and ARMv6
- Windows (VS 2008, VS 2010) on X86 and X86_64
- FreeBSD (clang) on X86 and X86_64
- HP-UX (HP C/aC++) on IA64
- Solaris 10 (Oracle Solaris Studio 12.3) on SPARC (big endian)
- AIX (XLC 12.1) on PowerPC (big endian)
Thank you very much to Trent Nelson for the Snakebite network.
Usage
=====
The `sha3` module contains several constructors for hash objects with a
PEP 247 compatible interface. The module provides `sha3_228()`, `sha3_256()`,
`sha3_384()`, and `sha3_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.4 will support the four SHA-3 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, 4):
... import sha3
>>> s = hashlib.new("sha3_512")
>>> s = hashlib.sha3_512() # alternative
>>> s.name
'sha3_512'
>>> s.digest_size
64
>>> s.update(b"data")
>>> s.hexdigest()
'1065aceeded3a5e4412e2187e919bffeadf815f5bd73d37fe00d384fe29f55f08462fdabe1007b993ce5b8119630e7db93101d9425d6e352e22ffe3dcb56b825'
**Don't use SHA-3 for HMAC!** HMAC hasn't been specified for SHA-3 yet and no
test vectors are available, too.
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
------
`Unrolling`
loop unrolling (24, 12, 8, 6, 4, 3, 2, 1)
`UseBebigokimisa`
lane complementing
64bit platforms
---------------
default settings of common options
`Unrolling`
24
`UseBebigokimisa`
enabled
Additional optimiation instructions (disabled by default):
`UseSSE`
use Stream SIMD extensions
`UseOnlySIMD64`
limit to 64bit instructions, otherwise 128bit
`w/o UseOnlySIMD64`
requires compiler argument `-mssse3` or `-mtune=core2` or better
`UseMMX`
use 64bit MMX instructions
`UseXOP`
use AMD's eXtended Operations (128bit SSE extension)
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
---------------
default settings of common options
`Unrolling`
2
`UseBebigokimisa`
disabled
`UseSchedule`
`1`
unknown
`2`
unknown
`3` [default]
unknown, no `UseBebigokimisa`, `Unrolling` must be 2
`UseInterleaveTables`
use two 64k lookup tables for (de)interleaving (disabled by default)
Changelog
=========
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
Release history Release notifications | RSS feed
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.3.zip
(61.2 kB
view hashes)
pysha3-0.3.tar.gz
(47.5 kB
view hashes)
Built Distributions
pysha3-0.3.win-amd64-py3.4.exe
(278.6 kB
view hashes)
pysha3-0.3.win-amd64-py3.3.exe
(277.8 kB
view hashes)
pysha3-0.3.win-amd64-py3.2.exe
(280.2 kB
view hashes)
pysha3-0.3.win-amd64-py2.7.exe
(279.7 kB
view hashes)
pysha3-0.3.win-amd64-py2.6.exe
(248.0 kB
view hashes)
pysha3-0.3.win32-py3.4.exe
(215.0 kB
view hashes)
pysha3-0.3.win32-py3.3.exe
(214.1 kB
view hashes)
pysha3-0.3.win32-py3.2.exe
(219.2 kB
view hashes)
pysha3-0.3.win32-py2.7.exe
(219.2 kB
view hashes)
pysha3-0.3.win32-py2.6.exe
(218.2 kB
view hashes)
pysha3-0.3-cp34-none-win32.whl
(20.5 kB
view hashes)
pysha3-0.3-cp33-none-win32.whl
(20.5 kB
view hashes)
pysha3-0.3-cp32-none-win32.whl
(20.4 kB
view hashes)
pysha3-0.3-cp27-none-win32.whl
(20.5 kB
view hashes)
pysha3-0.3-cp26-none-win32.whl
(19.5 kB
view hashes)
Close
Hashes for pysha3-0.3-cp34-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac6a8219d44b106cc3ddb48d7ded6f0b081d160665efad4b42268d21a953d958 |
|
MD5 | 47a9403b214c8a43d19e681daf86ce42 |
|
BLAKE2b-256 | 5aae53f9430a53765636c11ad75ffc55052a81da5a3774884b42d50a4ae595a5 |
Close
Hashes for pysha3-0.3-cp33-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 198f643efc7843fcd4079ffef442f73844a15b0e39669e61805dd349458ce3e3 |
|
MD5 | 25d28636975ea090c63482abd22ef4f6 |
|
BLAKE2b-256 | 298fd585360a786d94307c7d977fe566dc9ff0ccd08d559ca3aaf099dab4cfb5 |
Close
Hashes for pysha3-0.3-cp32-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3af0dcb92519cd22fd0fbe8e5de7fe1f0d999a1acc6cc3885c86496818e47f3b |
|
MD5 | f1ba94bedb8f9633e713e15a44141703 |
|
BLAKE2b-256 | c89db297426692a943bf16462ec93ce9ddee956b08b0c932d45cb0d9425f6387 |
Close
Hashes for pysha3-0.3-cp27-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4878634abbbfa5b8ca02507591cb18ee403a8f372e373b422ecca60ef26b239 |
|
MD5 | 743292eeed061ad9b1a77f39820f882c |
|
BLAKE2b-256 | b529d5b7a4cf2bed13c32c9c88391393b9dcd0adcb97c5ab71a1a77d0e3d52b1 |
Close
Hashes for pysha3-0.3-cp26-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31828f44cc75288dd20c3c6c111dd6a372331fc68d44a0584e8f352b9d92efbb |
|
MD5 | 7f546ef211fee5143ff9f23554be2141 |
|
BLAKE2b-256 | 1455896242757c10184010e8873478425c9190500d40f62e2ac170eb4989c401 |