Implements a signature based witness encryption scheme based on the BLS signatures
Project description
Witness Encryption based on BLS signatures
Implements a signature based witness encryption scheme based on the BLS signatures.
Uses the following implementations from Chia-Network/bls-signatures
- BLS12 curve and optimal ate pairing
- BLS signatures
- Other useful helper methods
Installation
Requires Python 3.8 or later
pip install witenc
Import the library
from witenc import bls, utils, encrypt, decrypt
Generate Keys
# Example seed, used to generate private key. Always use
# a secure RNG with sufficient entropy to generate a seed (at least 32 bytes).
seed: bytes = bytes([0, 50, 6, 244, 24, 199, 1, 25, 52, 88, 192,
19, 18, 12, 89, 6, 220, 18, 102, 58, 209, 82,
12, 62, 89, 110, 182, 9, 44, 20, 254, 22])
# Generate secret key and public key
sk, pk = bls.key_gen(seed)
Export and Import Secret keys
# Export and import secret key
sk = utils.export_sk(sk) # only when storing, default type is 'hex'
sk = utils.import_sk(sk) # only when loading, default type is 'hex'
Export and Import Public Keys
# Export and import public key
pk = utils.export_pk(pk) # only when storing, default type is 'hex'
pk = utils.import_pk(pk) # only when loading, default type is 'hex'
The export_* and import_* funtions accept a type parameter that specifies the output encoding (hex, bytes).
The default is hex and the only implemented now.
Sign a message
# Tag to be signed, it's signature is required for decrypting the message
tag: str = 'tag'
# Message to be encrypted
message: str = 'Hello, world!'
# Sign the tag
signature = bls.sign(sk, tag)
Export and Import Signatures
# Export and import signature
signature = utils.export_sig(signature) # only when storing, default type is 'hex'
signature = utils.import_sig(signature) # only when loading, default type is 'hex'
Verify Signature
# Verify the signature
ok: bool = bls.verify(pk, tag, signature)
assert ok
print("Signature verified")
Encrypt and Decrypt Message with a tag
# Encrypt the message
ciphertext: str = encrypt(pk, tag, message)
print("Ciphertext:\n" + ciphertext)
# Decrypt the message
decrypted_message: str = decrypt(signature, ciphertext)
assert message == decrypted_message
print("Decrypted message\n" + decrypted_message)
Full example can be found in example.py.
Witenc license
Witenc uses code from Chia-Network/bls-signatures and licensed under the Apache 2.0 license
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file witenc-0.1.1.tar.gz.
File metadata
- Download URL: witenc-0.1.1.tar.gz
- Upload date:
- Size: 25.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/5.15.0-83-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
507e9c48518d9b64d2ed132bfa30d33e4fb6568f29f9150ea85ed8be34d98f6f
|
|
| MD5 |
78681f731aee2605cb163451c8d314ff
|
|
| BLAKE2b-256 |
7f4e973ab2b8db5da0f6d6080c0c262aa1126e80a6caa0f365a05dc610568ddb
|
File details
Details for the file witenc-0.1.1-py3-none-any.whl.
File metadata
- Download URL: witenc-0.1.1-py3-none-any.whl
- Upload date:
- Size: 32.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.10.12 Linux/5.15.0-83-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dc8fe255a6d169c5f9be005208329f5fe1834d80c38f9332ad07b86a7be4cbe
|
|
| MD5 |
80888c7af9cae4aa37b9da2b508f595b
|
|
| BLAKE2b-256 |
7e8344507be3d9d286752eefc83f1970e76fe79fa64bb0b3ad5dfcdfa04dba5f
|