Skip to main content

GM algorithms implemented in pure python.

Project description

gmalg

GM algorithms implemented in pure python.

Install

pip install gmalg

Implemented Core Algorithms

  • ZUC Stream Cipher Algorithm
  • SM2 Public Key Cryptograhpic Algorithm Based on Elliptic Curves
  • SM3 Cryptogrpahic Hash Algorithm
  • SM4 Block Cipher Algorithm
  • SM9 Identification Cryptographic Algorithm

Usage

ZUC Generate pseudo-random key stream

import gmalg

zuc = gmalg.ZUC(bytes.fromhex("3d4c4be96a82fdaeb58f641db17b455b"),
                bytes.fromhex("84319aa8de6915ca1f6bda6bfbd8c766"))

print(zuc.generate().hex())
print(zuc.generate().hex())

SM3 Compute hash value

import gmalg

sm3 = gmalg.SM3()
print(sm3.value().hex())

sm3.update(b"I'm SM3 algorithm.")
print(sm3.value().hex())

SM4 Encrypt/Decrypt

import gmalg

sm4 = gmalg.SM4(bytes.fromhex("0123456789ABCDEFFEDCBA9876543210"))
cipher = sm4.encrypt(b"0102030405060708")
print(cipher.hex())
print(sm4.decrypt(cipher))

SM2 Sign/Verify

import gmalg

sm2 = gmalg.SM2(
    bytes.fromhex("3945208F 7B2144B1 3F36E38A C6D39F95 88939369 2860B51A 42FB81EF 4DF7C5B8"),
    b"1234567812345678",
    bytes.fromhex("04 09F9DF31 1E5421A1 50DD7D16 1E4BC5C6 72179FAD 1833FC07 6BB08FF3 56F35020"
                  "CCEA490C E26775A5 2DC6EA71 8CC1AA60 0AED05FB F35E084A 6632F607 2DA9AD13"),
)
msg = b"I'm SM2 sign/verify algorithm."
r, s = sm2.sign(msg)
print(r.hex())
print(s.hex())
print(sm2.verify(msg, r, s))

SM2 Encrypt/Decrypt

import gmalg

sm2 = gmalg.SM2(
    bytes.fromhex("3945208F 7B2144B1 3F36E38A C6D39F95 88939369 2860B51A 42FB81EF 4DF7C5B8"),
    P=bytes.fromhex("04 09F9DF31 1E5421A1 50DD7D16 1E4BC5C6 72179FAD 1833FC07 6BB08FF3 56F35020"
                    "CCEA490C E26775A5 2DC6EA71 8CC1AA60 0AED05FB F35E084A 6632F607 2DA9AD13"),
)

cipher = sm2.encrypt(b"I'm SM2 encrypt/decrypt algorithm.")
print(cipher.hex())
print(sm2.decrypt(cipher))

Go to [docs:TODO] see more detailed usages.


If you think this project is helpful to you, :star: it and let more people see!

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

gmalg-0.8.11.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gmalg-0.8.11-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file gmalg-0.8.11.tar.gz.

File metadata

  • Download URL: gmalg-0.8.11.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for gmalg-0.8.11.tar.gz
Algorithm Hash digest
SHA256 ec3e4127bf4d6ad869f9402341f2a6722a4044b73780e3807876ec986f4d4161
MD5 23148e752d5e9d8de9097cef1d8d62a5
BLAKE2b-256 1da31f02245b43202cd9ddb5eec8e5917b5154d24873247360b88169dc5b3c5f

See more details on using hashes here.

File details

Details for the file gmalg-0.8.11-py3-none-any.whl.

File metadata

  • Download URL: gmalg-0.8.11-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for gmalg-0.8.11-py3-none-any.whl
Algorithm Hash digest
SHA256 9761c0bada78493b0317815ee9f927231f93ff58238f6d4d76b2bb721a284e7e
MD5 66479be01d3a6fce61155d795a745e7d
BLAKE2b-256 9963072f90a980f9225b15d58884ee96521f525682e685db8d1cd5077df3848a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page