ecc_linkable_ring_signatures
ecc_linkable_ring_signatures copied to clipboard
Please for core review to file ring_signature_factory.py
Hi Fernando,
I rewrited your code to the project python-ecdsa
in branch ring-signature
.
https://github.com/zbohm/python-ecdsa/compare/master...ring-signature
Please, would you be so kind to make me code review? Especialy file ring_signature_factory.py
.
Thanks a lot. Zdeněk
I recommend the code for easy viewing pycco
:
$ git clone https://github.com/zbohm/python-ecdsa
$ cd python-ecdsa/
$ git checkout ring-signature
$ pip install --user pycco
$ pycco src/ecdsa/ring_signature_factory.py
$ firefox docs/ring_signature_factory.html
Example of usage:
$ virtualenv --python=python3 env
$ source env/bin/activate
$ pip install git+https://github.com/zbohm/python-ecdsa.git@ring-signature
$ cat > example.py
import hashlib
from ecdsa.curves import SECP256k1
from ecdsa.ecdsa import Private_key, Public_key
from ecdsa.ring_signature import signature_from_pem
from ecdsa.ring_signature_factory import (
RingSignatureFactory,
get_ring_signature_factory
)
from ecdsa.util import randrange
curve = SECP256k1
g = curve.generator
n = g.order()
number_participants = 10
my_private_key_position = 2
# Generate private and public keys:
private_keys, public_keys = [], []
for i in range(number_participants):
secret = randrange(n)
pubkey = Public_key(g, g * secret)
privkey = Private_key(pubkey, secret)
public_keys.append(pubkey)
private_keys.append(privkey)
message = b"Life, the Universe and Everything."
# Make signature:
factory = RingSignatureFactory(curve, hashlib.sha3_256)
signature = factory.sign(
message,
private_keys[my_private_key_position],
public_keys,
my_private_key_position,
)
# Export to PEM:
pem = signature.to_pem()
print(pem.decode())
# Import from PEM:
sig = signature_from_pem(pem)
# Verify signature:
factory2 = get_ring_signature_factory(sig)
if factory2.verify(message, sig, public_keys):
print("OK. Signature is valid.")
else:
print("Error. Invalid signature.")
$ python example.py
$ deactivate