Metadata-Version: 2.5
Name: sm3hash
Version: 0.0.1
Summary: Pure-Python SM3 hash (GB/T 32905-2016). Zero dependencies.
Project-URL: Homepage, https://github.com/lqxnjk/sm3hash
Project-URL: Source, https://github.com/lqxnjk/sm3hash
Author: lqxnjk
License: MIT
License-File: LICENSE
Keywords: cryptography,digest,gm,hash,sm3,国密
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Security :: Cryptography
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# sm3hash

Pure-Python implementation of **SM3**, the Chinese national cryptographic hash
standard (GB/T 32905-2016). No compiled extensions, no dependencies, works
anywhere Python 3.10+ runs.

Produces the standard 256-bit (64 hex character) digest.

## Install

```console
pip install sm3hash
```

## Usage

```python
from sm3hash import sm3_hex, sm3_of_file

# text or bytes
assert sm3_hex("abc") == "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0"

# bytes are hashed as-is
sm3_hex(b"abc")

# large files, streamed in 1 MiB chunks
sm3_of_file("big.iso")
sm3_of_file("big.iso", n_chunk=4 * 1024 * 1024)
```

## API

| Function | Description |
| --- | --- |
| `sm3_hex(data)` | Digest a `str` (UTF-8 encoded) or `bytes`, returns hex string |
| `sm3_of_file(path, chunk=1 MiB)` | Digest a file by streaming, returns hex string |

Strings are encoded as UTF-8 before hashing. Pass `bytes` to control the
encoding yourself.

## Performance

Pure Python, roughly an order of magnitude slower than `hashlib.sha256` on the
same input. Fine for hashing tokens, small payloads and verifying signatures;
for bulk throughput consider a C-backed SM3 binding instead.

## License

MIT
