sha256bit
| CI/CD | |
| Package | |
| Meta |
Pure python implementation of SHA256 and SHA224 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
User documentation is hosted on readthedocs.
Installation
Command line tool
Install with pipx, it puts the sha256bit command in its own isolated environment:
pipx install sha256bit
The message is given as a hex string:
$ sha256bit 616263
BA 78 16 BF 8F 01 CF EA 41 41 40 DE 5D AE 22 23 B0 03 61 A3 96 17 7A 9C B4 10 FF 61 F2 00 15 AD
$ sha256bit --algo sha224 616263
23 09 7D 22 34 05 D8 22 86 42 A4 77 BD A2 55 B3 2A AD BC E4 BD A0 B3 F7 E3 6C 9D A7
$ sha256bit --bit-length 1 00
BD 4F 9E 98 BE B6 8C 6E AD 32 43 B1 B4 C7 FE D7 5F A4 FE AA B1 F8 47 95 CB D8 A9 86 76 A2 A3 75
If pipx is missing, on Debian/Ubuntu: sudo apt install pipx && pipx ensurepath.
Python API
Add it to your project with pipenv:
pipenv install sha256bit
If pipenv is missing: pipx install pipenv.
Usage
One liner
>>> from sha256bit import Sha256bit
>>> Sha256bit("abc".encode()).hexdigest()
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
SHA-224
Sha224bit has the same API as Sha256bit.
>>> from sha256bit import Sha224bit
>>> Sha224bit("abc".encode()).hexdigest()
'23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7'
Bit length capability
>>> from sha256bit import Sha256bit
>>> Sha256bit(b'\x00',bitlen=1).hexdigest()
'bd4f9e98beb68c6ead3243b1b4c7fed75fa4feaab1f84795cbd8a98676a2a375'
Import/export
>>> from sha256bit import Sha256bit
>>> h1 = Sha256bit("a".encode())
>>> state = h1.export_state()
>>> h2 = Sha256bit.import_state(state)
>>> h2.update("bc".encode())
>>> h2.hexdigest()
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
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_cavp
python3 -m test.test_hardcoded
python3 -m test.test_vs_hashlib
Generate the doc
pipenv sync --dev
pipenv run make -C docs clean doctest html
Update pipenv
The root Pipfile holds the tools for building, linting and the doc, all in [dev-packages] since the package itself has no dependencies. CI and Read the Docs install the versions pinned in Pipfile.lock, so commit it after updating:
pipenv update --dev
Build the package
Build is done using hatchling.
pipenv sync --dev
pipenv run ./build
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
pipenv sync --dev
pipenv run ./lint
Metadata
Release files for sha256bit 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sha256bit-0.2.4.tar.gz | 3.9 MB | With provenance | Details for sha256bit-0.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sha256bit-0.2.4-py3-none-any.whl | Python 3 | none | any | Details for sha256bit-0.2.4-py3-none-any.whl |
Total release size: 4.0 MB
Release files / sha256bit-0.2.4.tar.gz
| Download URL | sha256bit-0.2.4.tar.gz |
|---|---|
| Size | 3.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f41e5789c500391483e7899a43b1f91449fd784c2cc841a9273e36eb58f25da
|
|
BLAKE2b-256 checksum How to use checksums |
f68a2cdb6d4ccf90a3607e0640d1c5ee5acc1d122c77cab9b714c478e0dcc19b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / sha256bit-0.2.4-py3-none-any.whl
| Download URL | sha256bit-0.2.4-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b114902c2b62c183053f412ce1fbe57e6eb3b8906376f09d74237dd48bf40130
|
|
BLAKE2b-256 checksum How to use checksums |
7267ace55824c581e3aba3a1a1e7ad8f4aeffa8e581f55d3b6c1d1bf962a97f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logSecurity for sha256bit 0.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for sha256bit-0.2.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.