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.4.tar.gz (31.5 kB view details)

Uploaded Source

Built Distributions

gmalglib-0.5.4-cp312-cp312-win_amd64.whl (43.1 kB view details)

Uploaded CPython 3.12 Windows x86-64

gmalglib-0.5.4-cp311-cp311-win_amd64.whl (43.0 kB view details)

Uploaded CPython 3.11 Windows x86-64

gmalglib-0.5.4-cp310-cp310-win_amd64.whl (43.0 kB view details)

Uploaded CPython 3.10 Windows x86-64

gmalglib-0.5.4-cp39-cp39-win_amd64.whl (43.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

gmalglib-0.5.4-cp38-cp38-win_amd64.whl (43.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

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

File metadata

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

File hashes

Hashes for gmalglib-0.5.4.tar.gz
Algorithm Hash digest
SHA256 c6ff2de0a05288c13975f4e6aff3f028b1cabe204adb5557ea4f1560db3af3e3
MD5 2b9ad75cdfb25be5d668293e5b7e0091
BLAKE2b-256 be1f03f27e9f832327e08e53662da84a5f86b2666c5089fb6814b17a5529d4b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 43.1 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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dd5fc11c6b9703897da47f017d1e7f619bbec6b8223993124d5e5ed491b49474
MD5 5d448e4b54c448131593758cdd651ce8
BLAKE2b-256 8b8a433783f6445f9b4e480b7240e1e807da8e95887db0f80fd02d393206ac26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.4-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 43.0 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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 28cca88a3960f35c87ce4902361f477b172a83cc06067202357a0d52e3d1f2ce
MD5 79994bc3dbd14be681f2b1fca5507820
BLAKE2b-256 eb316971c7a3adf70008ba02a73b693510b780e0563d505db88e350488253b38

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.4-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 43.0 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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c5ce74154cfd1af47fec067e71d753cf70f8cb760135986e10ba650346fa3458
MD5 0ef0a65ee516b939db528ef0fc099591
BLAKE2b-256 242dd611d99b33cf27256bee3cbe6f290b42ee793ebeb60d0e09875a2dfbe93a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.4-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 43.0 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.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 041c55ef4fdfbe8319a5438f97637a68561bdbf851f0bba6b8729e1b1123ce48
MD5 13e8bf2a02517eec6873c618ca699362
BLAKE2b-256 0e0c3994a27f76b8a7067c492d8bf0e8ac6ddaefe322e8759c4037878c364bde

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.4-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 43.0 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.4-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 24c45aad2839e72235bd0682945dc6e2fa6e46b7770077a289401300eb6fa81b
MD5 ca2723ae7acbe0a6487807aecd77f6e5
BLAKE2b-256 ae981df7876f03f03cd3eb2284e48fd67f2c42ad1365a9d400ef525cbca034f1

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