.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/privacy/signatures/plot_01_ring_signatures.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_privacy_signatures_plot_01_ring_signatures.py: Ring signatures: leaking a secret for a group (2001) ==================================================== Rivest, Shamir and Tauman titled their paper *How to Leak a Secret*: a cabinet member wants to prove a leak comes from the cabinet without saying who leaked it. A ring signature does that. The signer lists any public keys, its own among them, and signs so that the signature checks against the whole list but not against any one key. The signature is a ring of challenges. Starting after the signer, each member's challenge hashes the previous member's commitment, .. math:: c_{i+1} = H\big(m,\; g^{r_i} y_i^{c_i}\big), with random responses :math:`r_i` for everyone else. The ring closes only if the signer answers :math:`r_s = u - x_s c_s`, which needs its secret key. A verifier recomputes the ring from :math:`c_0` and checks it closes. .. GENERATED FROM PYTHON SOURCE LINES 24-30 .. code-block:: Python import matplotlib.pyplot as plt import blockchainkit as bk G = bk.crypto.TEACHING_GROUP .. GENERATED FROM PYTHON SOURCE LINES 31-33 A cabinet of five ----------------- .. GENERATED FROM PYTHON SOURCE LINES 33-42 .. code-block:: Python secrets = [101, 202, 303, 404, 505] cabinet = [G.public(x) for x in secrets] leak = b"the budget will be cut by 10%" signature = bk.privacy.ring_sign(leak, cabinet, 3, secrets[3], seed=1) assert bk.privacy.ring_verify(leak, cabinet, signature) assert not bk.privacy.ring_verify(b"the budget will grow", cabinet, signature) print("first challenge:", signature.challenge) .. rst-class:: sphx-glr-script-out .. code-block:: none first challenge: 117910248720381278 .. GENERATED FROM PYTHON SOURCE LINES 43-46 Every member's signature looks alike ------------------------------------ The responses are uniform whoever signs, so no response stands out. .. GENERATED FROM PYTHON SOURCE LINES 46-64 .. code-block:: Python signatures = { signer: bk.privacy.ring_sign(leak, cabinet, signer, secrets[signer], seed=signer) for signer in range(5) } assert all(bk.privacy.ring_verify(leak, cabinet, s) for s in signatures.values()) responses = {signer: s.responses for signer, s in signatures.items()} fig, ax = plt.subplots(figsize=(7, 3.5)) for signer, r in responses.items(): ax.scatter(range(5), [x / G.q for x in r], label=f"signed by member {signer}") ax.set(xlabel="ring member", ylabel="response / q", ylim=(0, 1)) ax.set_title("Responses carry no trace of the signer") ax.legend(fontsize="small", ncol=2) fig.tight_layout() plt.show() .. image-sg:: /api/gallery/privacy/signatures/images/sphx_glr_plot_01_ring_signatures_001.png :alt: Responses carry no trace of the signer :srcset: /api/gallery/privacy/signatures/images/sphx_glr_plot_01_ring_signatures_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 65-71 Exercise -------- The leaker signs twice, with two different rings that share only the leaker's own key. Why does that reveal the leaker, and what would a careful leaker do instead? A worked solution is in :doc:`/exercises/privacy`. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.085 seconds) .. _sphx_glr_download_api_gallery_privacy_signatures_plot_01_ring_signatures.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/privacy/signatures/plot_01_ring_signatures.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_ring_signatures.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_ring_signatures.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_ring_signatures.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_