Skip to content

lokingdav/Pure-Python-Witnes-Encryption

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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([random.randint(0, 255) for _ in range(32)])

# 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

About

Witness Encryption Scheme Based On BLS Signatures

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages