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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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