Skip to main content

Python package implementing GM algorithms in C.

Project description

gmalglib

Unittest PyPI docs

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             : 2.391558s
SM2.decrypt             : 1.092445s
SM2.sign_digest         : 1.062552s
SM2.verify_digest       : 2.096187s
SM2.sign                : 1.067850s
SM2.verify              : 2.055190s
SM2.begin_key_exchange  : 1.159822s
SM2.end_key_exchange    : 1.633471s
==================== SM3 Benchmark Test (1,000,000,000 bytes data) ====================
SM3.update & SM3.digest : 5.118763s
==================== SM4 Benchmark Test (1000000 times) ====================
SM4.encrypt             : 0.369991s
SM4.decrypt             : 0.297077s
==================== ZUC Benchmark Test (1000000 times) ====================
zuc.generate            : 0.050301s

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

gmalglib-0.5.8.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

gmalglib-0.5.8-cp312-cp312-win_amd64.whl (829.8 kB view details)

Uploaded CPython 3.12 Windows x86-64

gmalglib-0.5.8-cp311-cp311-win_amd64.whl (829.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

gmalglib-0.5.8-cp310-cp310-win_amd64.whl (829.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

gmalglib-0.5.8-cp39-cp39-win_amd64.whl (829.7 kB view details)

Uploaded CPython 3.9 Windows x86-64

gmalglib-0.5.8-cp38-cp38-win_amd64.whl (829.7 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

Details for the file gmalglib-0.5.8.tar.gz.

File metadata

  • Download URL: gmalglib-0.5.8.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for gmalglib-0.5.8.tar.gz
Algorithm Hash digest
SHA256 ec3cebe7804cb3d605fc9ba4c65717914d6601d691a775c456cd7e24d8a6cf55
MD5 8c805dde1ab528d6f15540d38bda9cf5
BLAKE2b-256 d7f9490c2f8abd274f5f5f16b51c564a46cb6795cac801c8f4a1e8842b5983af

See more details on using hashes here.

File details

Details for the file gmalglib-0.5.8-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gmalglib-0.5.8-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 829.8 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for gmalglib-0.5.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7ceb6ca8bb60391c9407b950de5cb3a332153cffe1daa77e285b858a184c002f
MD5 7becbefe8e39b6656ca5c57a4812218c
BLAKE2b-256 bd8f6dc6c74ecc15dc6e2beefe5b4ef587ffb2607a79aad3e135622c6afab41b

See more details on using hashes here.

File details

Details for the file gmalglib-0.5.8-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gmalglib-0.5.8-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 829.7 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for gmalglib-0.5.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4dd2c5920836aed84c04dc118bad485520a3c42ef03fc5190a84227b5404b071
MD5 b39a34682c473e89150d187022454133
BLAKE2b-256 0784a8fa39fc0a3ab734c1a7ad5bc63e73b2dca468d23403bba106301fcdfab6

See more details on using hashes here.

File details

Details for the file gmalglib-0.5.8-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gmalglib-0.5.8-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 829.7 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.10.11

File hashes

Hashes for gmalglib-0.5.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f25185e3d985cdf10b8daded4f43c58c244e1144c9fc87f474ddba29154f4f21
MD5 9ce9d3e9ff1c87c0731d0d87ac72859f
BLAKE2b-256 9be551a06111722b564efdeeb8610e8658a306bfca355039e049e3e1e80a7bc8

See more details on using hashes here.

File details

Details for the file gmalglib-0.5.8-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: gmalglib-0.5.8-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 829.7 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.13

File hashes

Hashes for gmalglib-0.5.8-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 33d0a71fa166448651845db9e2d4ec1278a0d6fdfb0a262586c54c3f0c6b56b5
MD5 24805301ec6d7e03adb1730c7adf33f0
BLAKE2b-256 68ca24559f2d2f7503c0d2a19fe906d909e58a4dc828197177d6b8d67b6f8fd0

See more details on using hashes here.

File details

Details for the file gmalglib-0.5.8-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: gmalglib-0.5.8-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 829.7 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.8.10

File hashes

Hashes for gmalglib-0.5.8-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 10c3c3ac21364b37d78eb05e0287b5045c5a988562bba0a9bf04b9d7eb93e4a4
MD5 68be7d570ecb07e58ec08d1aa6b236b3
BLAKE2b-256 309702b0d9515fbe35cbba3848c42cdf6c99201aeee9e936efc468db773366ab

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