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.6.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

gmalglib-0.5.6-cp312-cp312-win_amd64.whl (829.2 kB view details)

Uploaded CPython 3.12 Windows x86-64

gmalglib-0.5.6-cp311-cp311-win_amd64.whl (829.1 kB view details)

Uploaded CPython 3.11 Windows x86-64

gmalglib-0.5.6-cp310-cp310-win_amd64.whl (829.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

gmalglib-0.5.6-cp39-cp39-win_amd64.whl (829.2 kB view details)

Uploaded CPython 3.9 Windows x86-64

gmalglib-0.5.6-cp38-cp38-win_amd64.whl (829.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

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

File metadata

  • Download URL: gmalglib-0.5.6.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.6.tar.gz
Algorithm Hash digest
SHA256 9ed54b20ce7407eb98c04289bce6fb53ed43a20ca6af5e8780de93c253558da2
MD5 66d3dbb1ec37255670bf7b7fba592d9f
BLAKE2b-256 62c931b7f816b5e0ba1728ccaf39921a36e3ecd167d4c7ed822b4e579a989051

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 829.2 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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 21a26e0695ee00eb4d711c478f686c5a2a50074cca2e3d7a69aff288b0c458a8
MD5 55e141609c07c4ca913553ac8b238a27
BLAKE2b-256 4a53d31c9b6213cb6e4c71779329f4eb41cba77dbb2159cc73cdc62372ea9c01

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 829.1 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.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1f4d183da3a73a13ae1a4dca0b55c1d991a6827adddfa4ab12c0b6613af67fef
MD5 e9d90f0c5ccd5f141146b7b19c097fb7
BLAKE2b-256 e69ee23cdebdd7a731b6ea9adba924f44ab29187d3c9a1993779c98d4fe1c8d1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 829.1 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.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0f988c1b8461cb8496e7d17a197ad70578333e444be3dd330acbd0e677f48271
MD5 b14ed3c3ffa9f0b9543ded03733bafeb
BLAKE2b-256 0984c391064829d1163067ac19ea51101c08f3847865ac47e3b6df381b4bb1ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.6-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 829.2 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.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a80b2e0bb967033ea45de822d088906246d8f880bfbb54743a45da44f913d982
MD5 3a13b6cac4261f4b39c97e1695d98b4b
BLAKE2b-256 de243415d720a18578267a4c61074e28455803791c59d64e0b22c5e988ce6fea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.6-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 829.2 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.6-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6b6c63f09420d0f9706bb97ecba541d17b080097e4706dd93d2b7818c12bc404
MD5 6eb7c67b7fe55567f121981514a395db
BLAKE2b-256 aa5a8e34234f49824a71b6e703c0636c5f2f933fd7971c798fcab25aaa749f3d

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