Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please for core review to file ring_signature_factory.py #5

Open
zbohm opened this issue Jan 7, 2021 · 0 comments
Open

Please for core review to file ring_signature_factory.py #5

zbohm opened this issue Jan 7, 2021 · 0 comments

Comments

@zbohm
Copy link

zbohm commented Jan 7, 2021

Hi Fernando,
I rewrited your code to the project python-ecdsa in branch ring-signature.
zbohm/python-ecdsa@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant