Skip to main content

easy post quantum cryptography library

Project description

PQCryptography

This library was written due to rising threat of quantum computing. It main goal is to create easy wrapper of liboqs to spread post quantum cryptography

Installation

pip install pqcryptography

How to use pqcryptography

Importing

import pqcryptography as pqc

Generating keys / signs

public_key, private_key = pqc.encryption.generate_keypair()
public_sign, private_sign = pqc.signing.generate_signs()

Just like in any other asymmetric encryption library.

Encryption and decryption

How encryption work

message = "Test Message"
encrypted_message = pqc.encryption.encrypt(public_key, message.encode("utf-8"))

Please take into consideration that message needs to be encoded before encryption. Here I used utf-8 encoding. Alternatively you can use raw bytes for message. Also encryption of message increases its size exactly by 1600 bytes. This is because AES-256 nonce and tag is stored at the beginning of the message. encrypted_message type is bytes. How decryption work

retrieved_message = pqc.encryption.decrypt(private_key, encrypted_message)
print(retrieved_message.decode("utf-8"))

retrieved_message needs to be decoded if you didn't encrypt raw bytes. Output is "Test Message"

Signing and verifying

How signing works

signed_message = pqc.signing.sign(private_sign, message.encode("utf-8"))

signed_message type is bytes. Signature is appended to the message and its size will vary from algorithm to algorithm. Here's how to get it's size:

print(pqc.signing.get_details()["length_signature"])

How verification works So we got our message. That is how we should verify that it is legit:

verified_message = pqc.signing.verify(public_sign, signed_message)
print(verified_message.decode("utf-8"))

verified_message is just encoded message with signature stripped. If message was tampered with verify function will raise AssertionError

Using non-default algorithm

So you want to change encryption/signing algorithm? Sure! Just use keyword algorithm. It is supported for every function except get_algorithms()

Default algorithms

Default encryption algorithm is Kyber1024. Default signing algorithm is Dilithium5

Algorithms

If you don't want to use default algorithm you can pick one from the algorithm list.

print(pqc.encryption.get_algorithms())
print(pqc.signing.get_algorithms())

Note: Results are incomplete and probably outdated. You should run the code yourself

['BIKE-L1', 'BIKE-L3', ..., 'FrodoKEM-1344-AES', 'FrodoKEM-1344-SHAKE']
['Dilithium2', 'Dilithium3', ..., 'SPHINCS+-SHAKE-256f-simple', 'SPHINCS+-SHAKE-256s-simple']

so you don't trust me bro?

This package uses unofficial liboqs python package which is shipped with precompiled oqs libraries. You can not be certain that those binaries aren't malicious so you want to build your own. You can build binaries by following build instructions at oqs official repository and replace .so/.dll files in the package folder (python_directory/site-packages/liboqs/).

Im using pyinstaller / nuitka and it doesnt work

Just copy .so/.dll files from liboqs package folder (python_directory/site-packages/liboqs/) to your executable folder and it will load files from your local directory.

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

pqcryptography-0.0.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

pqcryptography-0.0.2-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file pqcryptography-0.0.2.tar.gz.

File metadata

  • Download URL: pqcryptography-0.0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pqcryptography-0.0.2.tar.gz
Algorithm Hash digest
SHA256 05908b8af70b2ca8375c99571d93b34d424ae2cd29823777c5ffa85ffbd68576
MD5 00162ef2b403c06738f60b98751805a5
BLAKE2b-256 82fcdc4166b5c894513ac585671da0ab13af6a4a0451850cea71858786099c8e

See more details on using hashes here.

File details

Details for the file pqcryptography-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pqcryptography-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for pqcryptography-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1b3a09883b43309e00a2c841008bbf1e2e7e28d40f2bbbfb245c5532b2758382
MD5 e138592778d855564a077d271db85f72
BLAKE2b-256 60838fcb3e6ba491d7ae0a52367502e3e9f1871fe47c4aec0ecbbaa90fa47298

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