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

Uploaded Source

Built Distributions

gmalglib-0.5.7-cp312-cp312-win_amd64.whl (829.7 kB view details)

Uploaded CPython 3.12 Windows x86-64

gmalglib-0.5.7-cp311-cp311-win_amd64.whl (829.5 kB view details)

Uploaded CPython 3.11 Windows x86-64

gmalglib-0.5.7-cp310-cp310-win_amd64.whl (829.5 kB view details)

Uploaded CPython 3.10 Windows x86-64

gmalglib-0.5.7-cp39-cp39-win_amd64.whl (829.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

gmalglib-0.5.7-cp38-cp38-win_amd64.whl (829.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

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

File metadata

  • Download URL: gmalglib-0.5.7.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.7.tar.gz
Algorithm Hash digest
SHA256 15664169400ef6e870aaa010b819e799c49de2408f201b6a55c999a9680ea603
MD5 274145172ac3e31d94753c472798dc16
BLAKE2b-256 47b7918751a81e5adf5180449f1ec6bc1cdbaf27b6b45c60803bcaeda2ab1d3d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 829.7 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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4542467b80d00028ee3ee72a568e5e2eb09f186fa030fbd01b5b247ccf5d50b9
MD5 180c2238c06089e63f75e6eb0e39edac
BLAKE2b-256 85d7e23512f5f5fe36b3c4ddb4142717805f104a892b4eb800a2c3b91be2e894

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.7-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 829.5 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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8ee2cd47f103faa643690c6690810550a6c51d913b8f906cafde56adecdea318
MD5 ff2f9f3fc6f546d004484f6ff8ccaa9a
BLAKE2b-256 9e2542fc2b4cf3c941c7082b52b4f09efa2635505dae2911f14b70cd24a18e20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.7-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 829.5 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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e7d21963261495811d49e549811ba5f34a33cf1e1340f4ce6d3f2b2c4d52fe33
MD5 ac3b96539afa72e1484758e210bdfe70
BLAKE2b-256 376d462b3afe8aebc2002331cbfc44156c9d99104618ff28e82d5823e675b495

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.7-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 829.6 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.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f5020160af05063bbbcacc8a7b4dacfb026f69d7180d02ae7dbbe46c5b2f36c7
MD5 43556ac9978d8bc064fa82700478080b
BLAKE2b-256 5c29b94bcf7d818623e68909e7c7993c1704e8be12ca08800cf0e67b7cb851f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.7-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 829.6 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.7-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 1e6d61a4f287edd55be86825361a970bad6059cc3f42eb296a35b841391cfb43
MD5 8ad60c9d0c40af7df16f20e5baf606dd
BLAKE2b-256 2f755490ca2e0bde750f8756668ff22d10e1e59143351d989cfc526b40d6efb5

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