lamport-256

Simple single use Lamport signature scheme


License
MIT
Install
pip install lamport-256==0.1

Documentation

codecov tests upload to pypi

lamport-256

Simple single use Lamport signature scheme in python

Great for building toy blockchains and the like.

DO NOT use in a security conscious production environment!

Usage:

Library

To install run

> pip install lamport-256

Import

import lamport_256

Generate a private/public key pair

key_pair = lamport_256.generate_keys()
private_key = key_pair.priv
public_key = key_pair.pub

from here on out the library functions will appear as if they were imported directly e.g. from lamport_256 import sign_message

Sign a message

signature = sign_message(private_key, 'Hello, World')

Verify a message

if not verify_signature(public_key, 'Hello, World', signature):
    raise Exception('Invalid signature')

Dump keys to files

# together
export_key_pair(key_pair, 'pub.key', 'priv.key') #filenames can be named anything you'd like

# or individually:
export_key(key_pair.priv, 'priv.key')

Read keys from file

# together
key_pair = parse_key_pair('location/of/pub.key', 'location/of/priv.key')

# or individually:
pub = parse_key('pub.key')

CLI

Although you can simply run python location/to/lamport_256.py generate_keys, it's best to create an alias to run the python script.

# In your .bashrc or equivalent
alias lamp='python location/of/lamport_256.py'

Now you can run the script more concisely

lamp generate_keys

To specify where to save keys use the appropriate options

lamp generate_keys --priv location/to/save/key --pub location/to/save/key

Sign a message

lamp sign --priv location/of/private/key --msg 'Hello, world' > signature.txt

# or pass the message in as a file
lamp sign --priv location/of/private/key --msg location/of/message > signature.txt

Verify a signature

lamp verify --pub location/of/public/key --msg 'message' --sig location/of/signature 

# you can pass the message as a file here as well
lamp verify --pub location/of/public/key --msg location/of/message --sig location/of/signature