gmalglib
Python extension library for GM (GuoMi) cryptographic algorithms, providing a set of fundamental cryptographic algorithms.
Implemented in C language, encapsulated based on the native CPython interface, without dependencies on any third-party libraries.
Installation
pip install gmalglib
Core Algorithms Implemented
- SM2 Public Key Cryptograhpic Algorithm Based on Elliptic Curves
- Sign/Verify
- Key exchange
- Encrypt/Decrypt
- SM3 Cryptogrpahic Hash Algorithm
- SM4 Block Cipher Algorithm
- ZUC Stream Cipher Algorithm
Usage
For submodules under gmalglib, different algorithm encapsulations are respectively exported, and can be utilized in an object-oriented manner.
from gmalglib.sm3 import SM3
obj = SM3()
obj.update(b"message")
obj.update(b"digest")
print(obj.digest().hex())
Under gmalglib.wrapped, member methods of all algorithm objects are encapsulated, providing a procedural call method. Furthermore, the gmalglib namespace is imported, enabling direct usage.
import gmalglib
print(gmalglib.sm3_digest(b"messagedigest").hex())
About Random Number Generators
For all sections involving random number generators, custom parameters for random number generation are provided, implemented in the form of callback functions. The function type is Callable[[int], bytes], meaning it generates a byte string of a specified length.
def rnd_fn(n: int) -> bytes: ...
If no random number generator is passed, the default system-related random number generator is used. On Windows, it utilizes BCryptGenRandom, while other systems use /dev/urandom for implementation, which is similar to the Python standard library function os.urandom.
For specific implementation details, refer to random.c under the OsRandomProc function.
Benchmark Test
The benchmark test code can be found in benchmark.py. The test results on the 13th Gen Intel(R) Core(TM) i7-13700H are as follows:
==================== SM2 Benchmark Test (1000 times, 32 bytes data) ====================
SM2.encrypt : 0.454363s (2200.88 times/s)
SM2.decrypt : 0.356014s (2808.88 times/s)
SM2.sign_digest : 0.088565s (11291.12 times/s)
SM2.verify_digest : 0.409243s (2443.54 times/s)
SM2.sign : 0.087475s (11431.80 times/s)
SM2.verify : 0.404026s (2475.09 times/s)
SM2.begin_key_exchange : 0.086665s (11538.62 times/s)
SM2.end_key_exchange : 0.536552s (1863.75 times/s)
==================== SM3 Benchmark Test (1,000,000,000 bytes data) ====================
SM3.update & SM3.digest : 3.083487s (324,308,109 B/s)
==================== SM4 Benchmark Test (1000000 times) ====================
SM4.encrypt : 0.197393s (5066040.91 times/s)
SM4.decrypt : 0.185619s (5387391.13 times/s)
==================== ZUC Benchmark Test (1000000 times) ====================
zuc.generate : 0.028821s (34696561.22 times/s)
Metadata
Release files for gmalglib 0.5.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gmalglib-0.5.9.tar.gz | 1.2 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| gmalglib-0.5.9-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| gmalglib-0.5.9-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details |
| gmalglib-0.5.9-cp310-cp310-win_amd64.whl | CPython 3.10 | CPython 3.10 | Windows x86-64 | Details |
| gmalglib-0.5.9-cp39-cp39-win_amd64.whl | CPython 3.9 | CPython 3.9 | Windows x86-64 | Details |
| gmalglib-0.5.9-cp38-cp38-win_amd64.whl | CPython 3.8 | CPython 3.8 | Windows x86-64 | Details |
Total release size: 5.3 MB
Release files / gmalglib-0.5.9.tar.gz
| Download URL | gmalglib-0.5.9.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6466d4d3cabb40270a1f267b6057fd1d7db50105c16719d1bf0dbd1fe66dffcf
|
|
BLAKE2b-256 checksum How to use checksums |
af65abef0a132e119930e5503d072f559bc7425a128c52c64513bcd14231f8f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.19
|
Release files / gmalglib-0.5.9-cp312-cp312-win_amd64.whl
| Download URL | gmalglib-0.5.9-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 829.9 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
94ded211c3127c45132acf864509a31e3f87eb150ef71f585ff7945f6d42ed05
|
|
BLAKE2b-256 checksum How to use checksums |
30d9b437aa5dfa9bea154346afa8bab3b0c292fd8d2e2d6d5e2cf1dfde16e0da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.3
|
Release files / gmalglib-0.5.9-cp311-cp311-win_amd64.whl
| Download URL | gmalglib-0.5.9-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 829.7 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7eea271e532282807c1ae21fde77a07ace52da1416b19029e682c43577a9447b
|
|
BLAKE2b-256 checksum How to use checksums |
43d5921cf30769ef3778f3b31c8f6dfe0f36eb500b60657006fc777da29d6450
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.9
|
Release files / gmalglib-0.5.9-cp310-cp310-win_amd64.whl
| Download URL | gmalglib-0.5.9-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 829.7 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1d0739db523695d760a1aa38bd800439bbfa664c5c1fcc43d2af3f7b2ff7519b
|
|
BLAKE2b-256 checksum How to use checksums |
02962bf25f627de4eb8eb210e24e1edb65d72a9facf50b89e15f14821a6176e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.10.11
|
Release files / gmalglib-0.5.9-cp39-cp39-win_amd64.whl
| Download URL | gmalglib-0.5.9-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 829.8 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6b3cabc66e2e25a7a60a0d9992ff3897b7f191f3beed252a18b45f7a5179f42d
|
|
BLAKE2b-256 checksum How to use checksums |
2e6c05955f988411e4d53d44168a575de7f078b02d9c8fcdb9837a72d6659227
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.9.13
|
Release files / gmalglib-0.5.9-cp38-cp38-win_amd64.whl
| Download URL | gmalglib-0.5.9-cp38-cp38-win_amd64.whl |
|---|---|
| Size | 829.8 kB |
| Tags | CPython 3.8 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6cafc9b6cf2ab6ffd319a6d656471299768c62b0ac918963cb9c187e9dabfdf1
|
|
BLAKE2b-256 checksum How to use checksums |
be1cb7001625218090bd5b16dc3d2ab2092289406e34463a55db60ded6dff06e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.8.10
|