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

Uploaded Source

Built Distributions

gmalglib-0.5.5-cp312-cp312-win_amd64.whl (43.3 kB view details)

Uploaded CPython 3.12 Windows x86-64

gmalglib-0.5.5-cp311-cp311-win_amd64.whl (43.2 kB view details)

Uploaded CPython 3.11 Windows x86-64

gmalglib-0.5.5-cp310-cp310-win_amd64.whl (43.2 kB view details)

Uploaded CPython 3.10 Windows x86-64

gmalglib-0.5.5-cp39-cp39-win_amd64.whl (43.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

gmalglib-0.5.5-cp38-cp38-win_amd64.whl (43.3 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

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

File metadata

  • Download URL: gmalglib-0.5.5.tar.gz
  • Upload date:
  • Size: 31.6 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.5.tar.gz
Algorithm Hash digest
SHA256 63f4f9c5c009dd416cedd1dd389ad1447cb65fadd7b1a2193ae88de8d95ff961
MD5 d83b7746c22c808befef18a8dc9008a9
BLAKE2b-256 bdf3dff7070ac97a29ca24ce00436a0f4b4621e7f27ba3cc483898faa7630351

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 43.3 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.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5b177ef529955c54d7c17b6935ca6f4b35e9e6c48668401d25f8b98697d9191f
MD5 3c383be24c541c701bf4d004986bb2d9
BLAKE2b-256 61b0b81f3efb5c39b5ef31807e78beebd5bb036a7e7696a7789ff813a28f2a98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 43.2 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.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 1046ddf10140ffc1e81438c5e46bbbd32f731e5faf2498d4cdb9850decafb8c1
MD5 77abce7d90f0fe5479e72c7410ebb559
BLAKE2b-256 db45e0e112a6f279a630ce6a0ab2309d9a892711145785b2fa6fe01fcf334d32

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 43.2 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.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6eef120c4cd009bc229ef370f4dfed00ffb01d26e1c44a00ad88b0e7a71b25c3
MD5 176bdf90ca7f4cb7ea641dda6eb34be2
BLAKE2b-256 aaf151e9f9f320bf71e5c29b27fa011afacae9cbf3906ffeadc59fae810ba3d6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.5-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 43.3 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.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d7339558759ee36bad0ea72c3fefb403c0fbcd070d9c04dc1e660650e5e9208a
MD5 2a2d886a7e38871e4a4c265bd1451c93
BLAKE2b-256 3075622f8e79c875b71174d5044eccd294784044316eb0039fe4f11723de21b5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.5-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 43.3 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.5-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 81699795ec5e542fc22529d0f782443f9b45bf474937622952b5edd7d212c013
MD5 4cfa12bb398128794fefdcbb391829bb
BLAKE2b-256 1eaa09af525f37a1107951484631a0b383d212552c78b04199e3811d0dda35aa

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