Skip to main content

SHA3 with bit granularity for message input length

Project description

sha3bit

CI/CD CI - Test CD - Build Documentation Status
Package PyPI - Version PyPI - Python Version
Meta Hatch project linting - Ruff code style - Black types - Mypy License - apache-2.0

Pure python implementation of SHA3 with features which are often lacking:

  • Bit granularity for message input length
  • Import/export API to "persist" the state in the middle of a hash computation
  • Real squeez function in addition of hashlib's digest
  • Builtin logging to see compression function IOs or even internal steps

User documentation is hosted on readthedocs.

Installation

python3 -m pip install sha3bit

Usage

One liner

>>> from sha3bit import sha3_256
>>> print(sha3_256("abc".encode()).hexdigest())
'3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532'

Bit length capability

>>> from sha3bit import sha3_256
>>> print(sha3_256(b'\x00',bitlen=1).hexdigest())
'1b2e61923578e35f3b4629e04a0ff3b73daa571ae01130d9c16ef7da7a4cfdc2'

Import/export

>>> from sha3bit import sha3_256
>>> h1 = sha3_256("a".encode())
>>> state = h1.export_state()
>>> h2 = sha3_256.import_state(state)
>>> h2.update("bc".encode())
>>> print(h2.hexdigest())
'3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532'

Test with pytest

pytest-3

Test without pytest

Tests can run without creating/installing the package:

python3 -m test.test

you can also run each test separately:

python3 -m test.test_api
python3 -m test.test_api_xof_absorb
python3 -m test.test_cavp
python3 -m test.test_cavp_xof
python3 -m test.test_hardcoded
python3 -m test.test_sha3_vs_hashlib
python3 -m test.test_shake_vs_hashlib

Generate the doc

cd docs
pipenv shell
make clean doctest html

Update pipenv for the doc

cd docs
pipenv shell
#use pip to update whatever ou want
pip freeze > requirements.txt
pipenv update

Build the package

Build is done using hatchling. The script build allows to build for different version of python3:

./build python3.9

Create a new version

Version is managed by hatch-vcs, you just need to create a tag in github.

Launch linters

They use the configuration from pyproject.toml

./lint

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

sha3bit-0.3.0.tar.gz (6.0 MB view details)

Uploaded Source

Built Distribution

sha3bit-0.3.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file sha3bit-0.3.0.tar.gz.

File metadata

  • Download URL: sha3bit-0.3.0.tar.gz
  • Upload date:
  • Size: 6.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for sha3bit-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f7c4882af5471e1b481608e77ad9642578c560f4f72f576b9a2679d5b7b5431e
MD5 972215e2d5d614e49fe8d62ee2da2430
BLAKE2b-256 ba12b48e26e320931b7d999fbae22b4f57dcffb2172d9e246493edee7b002f83

See more details on using hashes here.

File details

Details for the file sha3bit-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: sha3bit-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for sha3bit-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ff073a40e794a88b44eec386eae21646ba925d683538b2d326ae0a007aec2df
MD5 c8455263d4bcc3a4559db6f27c3b98eb
BLAKE2b-256 7794e6246e567d88b000e9169b9b1da1bbbca1884c16e811fdf7da2ecf7ec76b

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