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             : 0.454363s (2200.88 times/s)
SM2.decrypt             : 0.356014s (2808.88 times/s)
SM2.sign_digest         : 0.088565s (11291.12 times/s)
SM2.verify_digest       : 0.409243s (2443.54 times/s)
SM2.sign                : 0.087475s (11431.80 times/s)
SM2.verify              : 0.404026s (2475.09 times/s)
SM2.begin_key_exchange  : 0.086665s (11538.62 times/s)
SM2.end_key_exchange    : 0.536552s (1863.75 times/s)
==================== SM3 Benchmark Test (1,000,000,000 bytes data) ====================
SM3.update & SM3.digest : 3.083487s (324,308,109 B/s)
==================== SM4 Benchmark Test (1000000 times) ====================
SM4.encrypt             : 0.197393s (5066040.91 times/s)
SM4.decrypt             : 0.185619s (5387391.13 times/s)
==================== ZUC Benchmark Test (1000000 times) ====================
zuc.generate            : 0.028821s (34696561.22 times/s)

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

Uploaded Source

Built Distributions

gmalglib-0.5.9-cp312-cp312-win_amd64.whl (829.9 kB view details)

Uploaded CPython 3.12 Windows x86-64

gmalglib-0.5.9-cp311-cp311-win_amd64.whl (829.7 kB view details)

Uploaded CPython 3.11 Windows x86-64

gmalglib-0.5.9-cp310-cp310-win_amd64.whl (829.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

gmalglib-0.5.9-cp39-cp39-win_amd64.whl (829.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

gmalglib-0.5.9-cp38-cp38-win_amd64.whl (829.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

File details

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

File metadata

  • Download URL: gmalglib-0.5.9.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.9.tar.gz
Algorithm Hash digest
SHA256 6466d4d3cabb40270a1f267b6057fd1d7db50105c16719d1bf0dbd1fe66dffcf
MD5 f55df38a0b80903d4c15c133a8f6a16a
BLAKE2b-256 af65abef0a132e119930e5503d072f559bc7425a128c52c64513bcd14231f8f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.9-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 829.9 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.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 94ded211c3127c45132acf864509a31e3f87eb150ef71f585ff7945f6d42ed05
MD5 4947ca5674d48b211a047d72e16a5499
BLAKE2b-256 30d9b437aa5dfa9bea154346afa8bab3b0c292fd8d2e2d6d5e2cf1dfde16e0da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.9-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 829.7 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.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7eea271e532282807c1ae21fde77a07ace52da1416b19029e682c43577a9447b
MD5 c284f2e8904b4cea2fb829fa24913be8
BLAKE2b-256 43d5921cf30769ef3778f3b31c8f6dfe0f36eb500b60657006fc777da29d6450

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.9-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 829.7 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.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1d0739db523695d760a1aa38bd800439bbfa664c5c1fcc43d2af3f7b2ff7519b
MD5 82e302e6b2cd3bfc4dd17c684b79c60a
BLAKE2b-256 02962bf25f627de4eb8eb210e24e1edb65d72a9facf50b89e15f14821a6176e0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.9-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 829.8 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.9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 6b3cabc66e2e25a7a60a0d9992ff3897b7f191f3beed252a18b45f7a5179f42d
MD5 8dd07ef3e3990a0fe0ff4fc2444900aa
BLAKE2b-256 2e6c05955f988411e4d53d44168a575de7f078b02d9c8fcdb9837a72d6659227

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gmalglib-0.5.9-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 829.8 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.9-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6cafc9b6cf2ab6ffd319a6d656471299768c62b0ac918963cb9c187e9dabfdf1
MD5 5a8ba71968ff4d12b7fc3978b3355010
BLAKE2b-256 be1cb7001625218090bd5b16dc3d2ab2092289406e34463a55db60ded6dff06e

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