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
    • 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.

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.3.tar.gz (29.5 kB view hashes)

Uploaded Source

Built Distributions

gmalglib-0.5.3-cp312-cp312-win_amd64.whl (40.6 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

gmalglib-0.5.3-cp311-cp311-win_amd64.whl (40.5 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

gmalglib-0.5.3-cp310-cp310-win_amd64.whl (40.5 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

gmalglib-0.5.3-cp39-cp39-win_amd64.whl (40.6 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

gmalglib-0.5.3-cp38-cp38-win_amd64.whl (40.6 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

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