Skip to content

madsugar/GmSSL-Python

This branch is 20 commits behind GmSSL/GmSSL-Python:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1caa612 · Mar 3, 2023

History

3 Commits
Mar 3, 2023
Mar 3, 2023
Mar 3, 2023
Mar 3, 2023

Repository files navigation

pyGmSSL

pyGmSSL is the Python binding to the GmSSL library.

The Python wrappers of pyGmSSL are very similar to the GmSSL v3 C API. Most class/struct and function names are the same, and the arguments are in the same order. Here is an example of encrypting a block of message by SM4 cipher in both C and Python.

#include <gmssl/sm4.h>
#include <gmssl/rand.h>

unsigned char key[SM4_KEY_SIZE] = "1234567812345678";
rand_bytes(key, sizeof(key));

unsigned char block[SM4_BLOCK_SIZE] = "1234567812345678";

SM4_KEY sm4_key;
sm4_set_encrpt_key(&sm4_key, key);
sm4_encrypt(&sm4_key, block, block);

sm4_set_decrpt_key(&sm4_key, key);
sm4_decrypt(&sm4_key, block, block);

The corresponding Python code:

import GmSSL

sm4_key = GmSSL.SM4_KEY()
sm4_key.set_encrypt_key(b"1234567812345678")
ciphertext = sm4_key.encrypt(b"1234567812345678")

sm4_key.set_decrypt_key(b"1234567812345678")
plaintext = sm4_key.decrypt(ciphertext)

About

Python binding to the GmSSL library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%