Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

witenc-0.1.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

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

witenc-0.1.1-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

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

Hashes for witenc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 507e9c48518d9b64d2ed132bfa30d33e4fb6568f29f9150ea85ed8be34d98f6f
MD5 78681f731aee2605cb163451c8d314ff
BLAKE2b-256 7f4e973ab2b8db5da0f6d6080c0c262aa1126e80a6caa0f365a05dc610568ddb

See more details on using hashes here.

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

Hashes for witenc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc8fe255a6d169c5f9be005208329f5fe1834d80c38f9332ad07b86a7be4cbe
MD5 80888c7af9cae4aa37b9da2b508f595b
BLAKE2b-256 7e8344507be3d9d286752eefc83f1970e76fe79fa64bb0b3ad5dfcdfa04dba5f

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