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

Interfacing with Rust, part 2 #267

Merged
merged 24 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
dd76047
test/keys: fix a test name
fjarri Apr 19, 2021
c4626fa
Extract signing code into a separate module
fjarri Apr 19, 2021
4f6f174
keys: correct phrasing in error messages
fjarri Apr 19, 2021
768ac3a
keys: adjust error type
fjarri Apr 19, 2021
6545eac
Move SecretKey signing capabilities to a Signer class
fjarri Apr 19, 2021
a2d4bfd
Resolve circular dependency keys-signing-hashing
fjarri Apr 19, 2021
8186884
Use signer instead of signer_sk in generate_kfrags() and rename signi…
fjarri Apr 19, 2021
54b9ee0
Change the order of parameters in CapsuleFrag.verify() to match that …
fjarri Apr 19, 2021
cae5457
Update TODO in CurveScalar.from_digest()
fjarri May 18, 2021
c46fdf6
Add a TODO in CapsuleFrag.verify() and bail early if the signature is…
fjarri May 18, 2021
89e6ea1
Leave only secp256k1 as a supported curve
fjarri Apr 19, 2021
f31a3ad
Add a comment about normalizing s in signatures
fjarri Apr 19, 2021
b03c83e
Don't use DST when hashing for signing
fjarri Apr 19, 2021
65d32fd
Enforce KeyFrag verification before reencryption
fjarri Apr 20, 2021
84883b8
Enforce CapsuleFrag verification before decryption
fjarri Apr 20, 2021
023e813
Remove excess default exports
fjarri Apr 20, 2021
9744906
Move generate_kfrags() to the pre module
fjarri Apr 20, 2021
9570035
Move backend-related parts of signing to the openssl module
fjarri Apr 20, 2021
48c3441
Style fixes + pylint config
fjarri Apr 21, 2021
4e0b6a5
Remove Point.from_affine(), add a check for calling to_affine() on th…
fjarri May 18, 2021
d5b9d7c
Add a unit test for a part of SecretKey API
fjarri Apr 25, 2021
0a972aa
Add a check to cover Signature.__eq__
fjarri Apr 25, 2021
96251cf
Fix CI build
fjarri May 27, 2021
edbf953
Add myself to the list of authors
fjarri May 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ commands:
- run:
name: Install Python dependencies with Pipenv
command: pipenv install --python << parameters.python_version >> --dev --skip-lock --pre
# Workaround for pipenv check erroneously requiring pip>=21.1,
# even if it is in fact installed and that version is fixed in Pipfile.
# See https://github.com/pypa/pipenv/issues/4147
- run:
name: Check PEP 508 Requirements
command: pipenv check
command: pipenv check --ignore 40291
- persist_to_workspace:
root: ~/.local/share/virtualenvs/
paths:
Expand Down
5 changes: 3 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ Additionally, users that delegate access to their data (like Alice, in this exam

.. code-block:: python

from umbral import SecretKey, PublicKey
from umbral import SecretKey, PublicKey, Signer

# Generate Umbral keys for Alice.
alices_secret_key = SecretKey.random()
alices_public_key = PublicKey.from_secret_key(alices_secret_key)

alices_signing_key = SecretKey.random()
alices_signer = Signer(alices_signing_key)
alices_verifying_key = PublicKey.from_secret_key(alices_signing_key)

# Generate Umbral keys for Bob.
Expand Down Expand Up @@ -112,7 +113,7 @@ which are next sent to N proxies or *Ursulas*.
# In this example, 10 out of 20.
kfrags = generate_kfrags(delegating_sk=alices_secret_key,
receiving_pk=bobs_public_key,
signing_sk=alices_signing_key,
signer=alices_signer,
threshold=10,
num_kfrags=20)

Expand Down
23 changes: 14 additions & 9 deletions docs/examples/umbral_simple_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random
from umbral import (
SecretKey, PublicKey, GenericError,
SecretKey, PublicKey, Signer, GenericError, CapsuleFrag,
encrypt, generate_kfrags, reencrypt, decrypt_original, decrypt_reencrypted)

# Generate an Umbral key pair
Expand All @@ -13,6 +13,7 @@

alices_signing_key = SecretKey.random()
alices_verifying_key = PublicKey.from_secret_key(alices_signing_key)
alices_signer = Signer(alices_signing_key)

# Encrypt some data for Alice
# ---------------------------
Expand Down Expand Up @@ -58,7 +59,7 @@

kfrags = generate_kfrags(delegating_sk=alices_secret_key,
receiving_pk=bobs_public_key,
signing_sk=alices_signing_key,
signer=alices_signer,
threshold=10,
num_kfrags=20)

Expand All @@ -85,14 +86,18 @@

# Bob checks the capsule fragments
# --------------------------------
# Bob can verify that the capsule fragments are valid and really originate from Alice,
# If Bob received the capsule fragments in serialized form,
# he can verify that they are valid and really originate from Alice,
# using Alice's public keys.

assert all(cfrag.verify(capsule,
delegating_pk=alices_public_key,
receiving_pk=bobs_public_key,
signing_pk=alices_verifying_key)
for cfrag in cfrags)
suspicious_cfrags = [CapsuleFrag.from_bytes(bytes(cfrag)) for cfrag in cfrags]

cfrags = [cfrag.verify(capsule,
verifying_pk=alices_verifying_key,
delegating_pk=alices_public_key,
receiving_pk=bobs_public_key,
)
for cfrag in suspicious_cfrags]

# Bob opens the capsule
# ------------------------------------
Expand All @@ -101,7 +106,7 @@
bob_cleartext = decrypt_reencrypted(decrypting_sk=bobs_secret_key,
delegating_pk=alices_public_key,
capsule=bob_capsule,
cfrags=cfrags,
verified_cfrags=cfrags,
ciphertext=ciphertext)
print(bob_cleartext)
assert bob_cleartext == plaintext
34 changes: 20 additions & 14 deletions docs/notebooks/pyUmbral Simple API.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
"metadata": {},
"outputs": [],
"source": [
"from umbral import SecretKey, PublicKey\n",
"from umbral import SecretKey, PublicKey, Signer\n",
"\n",
"\n",
"# Alice's Keys\n",
"alices_private_key = SecretKey.random()\n",
"alices_public_key = PublicKey.from_secret_key(alices_private_key)\n",
"\n",
"alices_signing_key = SecretKey.random()\n",
"alices_verifying_key = PublicKey.from_secret_key(alices_signing_key)"
"alices_verifying_key = PublicKey.from_secret_key(alices_signing_key)\n",
"alices_signer = Signer(alices_signing_key)"
]
},
{
Expand All @@ -55,7 +56,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"b'\\x1c\\xa0\\xa83\\x0cv\\x97\\x02d\\xe9\\xe9\\xc5_\\x9d5NRGRx\\xd4\\xc9\\x17%\\x9b\\xb4\\x05\\xd1\\xc2\\x1e\\x9d\\x0b\\xbf\\xb4g\\xf0n\\xfe\\x9eM\\x93\\xe0\\xbf#l\\xf9\\x033\\xb00\\xf5\\r\\xff\\xc9\\x133C\\xf0\\xa3\\xc0\\xd1e\\xdb~.E$%'\n"
"b'\\xfb\\xc3T\\xb2\\x89=\\x08X\\xb1<\\xd0G/\\xab\\x8c\\xac\\x7f\\xd4)\\xcbB\\xcb^\\x99;P\\x9c\\xbf\\xaaf\\x03\\xdd\\n\\x1f$\\x1b\\xfb\\x88\\xfa\\xcd\\xe2\\x11\\x8d\\xcf\\xe5\\x88\\xaf\\x00\\xfe\\xcb\\x9d\\xf83\\x17\\x9b\\xdd\\xba\\xab\\x8b\\x08\\xbe\\xb1M\\x80\\xf1<S#'\n"
]
}
],
Expand Down Expand Up @@ -169,7 +170,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -179,7 +180,7 @@
"M, N = 10, 20 # the threshold and the total number of fragments\n",
"kfrags = generate_kfrags(delegating_sk=alices_private_key,\n",
" receiving_pk=bobs_public_key,\n",
" signing_sk=alices_signing_key,\n",
" signer=alices_signer,\n",
" threshold=M,\n",
" num_kfrags=N)"
]
Expand All @@ -195,7 +196,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -218,22 +219,27 @@
"metadata": {},
"source": [
"## Bob checks the capsule fragments\n",
"Bob can verify that the capsule fragments are valid and really originate from Alice, using Alice's public keys."
"If Bob received the capsule fragments in serialized form, he can verify that they are valid and really originate from Alice, using Alice's public keys."
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"assert all(cfrag.verify(capsule,\n",
" delegating_pk=alices_public_key,\n",
" receiving_pk=bobs_public_key,\n",
" signing_pk=alices_verifying_key)\n",
" for cfrag in cfrags)"
"from umbral import CapsuleFrag\n",
"\n",
"suspicious_cfrags = [CapsuleFrag.from_bytes(bytes(cfrag)) for cfrag in cfrags]\n",
"\n",
"cfrags = [cfrag.verify(capsule,\n",
" verifying_pk=alices_verifying_key,\n",
" delegating_pk=alices_public_key,\n",
" receiving_pk=bobs_public_key,\n",
" )\n",
" for cfrag in suspicious_cfrags]"
]
},
{
Expand Down Expand Up @@ -263,7 +269,7 @@
"bob_cleartext = decrypt_reencrypted(decrypting_sk=bobs_private_key,\n",
" delegating_pk=alices_public_key,\n",
" capsule=capsule,\n",
" cfrags=cfrags,\n",
" verified_cfrags=cfrags,\n",
" ciphertext=ciphertext)\n",
"\n",
"print(bob_cleartext)\n",
Expand Down
19 changes: 18 additions & 1 deletion docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ Keys
:members:
:show-inheritance:

.. autoclass:: Signer
:members:

.. autoclass:: Signature()
:members:
:special-members: __eq__, __hash__
:show-inheritance:

Intermediate objects
--------------------

Expand All @@ -31,11 +39,17 @@ Intermediate objects
:special-members: __eq__, __hash__
:show-inheritance:

.. autoclass:: VerifiedKeyFrag()
:special-members: __eq__, __hash__

.. autoclass:: CapsuleFrag()
:members: verify
:members:
:special-members: __eq__, __hash__
:show-inheritance:

.. autoclass:: VerifiedCapsuleFrag()
:special-members: __eq__, __hash__

Encryption, re-encryption and decryption
----------------------------------------

Expand All @@ -55,6 +69,9 @@ Utilities
.. autoclass:: umbral.GenericError
:show-inheritance:

.. autoclass:: umbral.VerificationError
:show-inheritance:

.. autoclass:: umbral.serializable.Serializable
:members: from_bytes
:special-members: __bytes__
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
# -- Project information -----------------------------------------------------

project = 'pyUmbral'
copyright = u'2019, Michael Egorov, Justin Myles Holmes, David Nuñez, John Pacific, Kieran Prasch'
author = u'Michael Egorov, Justin Myles Holmes, David Nuñez, John Pacific, Kieran Prasch'
copyright = u'2019, Michael Egorov, Justin Myles Holmes, David Nuñez, John Pacific, Kieran Prasch, Bogdan Opanchuk'
author = u'Michael Egorov, Justin Myles Holmes, David Nuñez, John Pacific, Kieran Prasch, Bogdan Opanchuk'

# The short X.Y version
version = '0.1'
Expand Down Expand Up @@ -133,7 +133,7 @@
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pyUmbral.tex', 'pyUmbral Documentation',
u'Michael Egorov, Justin Myles Holmes, David Nuñez, John Pacific, Kieran Prasch', 'manual'),
u'Michael Egorov, Justin Myles Holmes, David Nuñez, John Pacific, Kieran Prasch, Bogdan Opanchuk', 'manual'),
]


Expand Down
24 changes: 14 additions & 10 deletions docs/source/using_pyumbral.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ A delegating key pair and a signing key pair.

.. doctest:: capsule_story

>>> from umbral import SecretKey, PublicKey
>>> from umbral import SecretKey, PublicKey, Signer

>>> alices_secret_key = SecretKey.random()
>>> alices_public_key = PublicKey.from_secret_key(alices_secret_key)

>>> alices_signing_key = SecretKey.random()
>>> alices_verifying_key = PublicKey.from_secret_key(alices_signing_key)
>>> alices_signer = Signer(alices_signing_key)


Encrypt with a public key
Expand Down Expand Up @@ -105,7 +106,7 @@ but Bob needs to get only 10 re-encryptions to activate the capsule.
>>> from umbral import generate_kfrags
>>> kfrags = generate_kfrags(delegating_sk=alices_secret_key,
... receiving_pk=bobs_public_key,
... signing_sk=alices_signing_key,
... signer=alices_signer,
... threshold=10,
... num_kfrags=20)

Expand Down Expand Up @@ -172,17 +173,20 @@ Decryption

Bob checks the capsule fragments
--------------------------------
Bob can verify that the capsule fragments are valid and really originate from Alice,
If Bob received the capsule fragments in serialized form,
he can verify that they are valid and really originate from Alice,
using Alice's public keys.

.. doctest:: capsule_story

>>> all(cfrag.verify(capsule,
... delegating_pk=alices_public_key,
... receiving_pk=bobs_public_key,
... signing_pk=alices_verifying_key)
... for cfrag in cfrags)
True
>>> from umbral import CapsuleFrag
>>> suspicious_cfrags = [CapsuleFrag.from_bytes(bytes(cfrag)) for cfrag in cfrags]
>>> cfrags = [cfrag.verify(capsule,
... verifying_pk=alices_verifying_key,
... delegating_pk=alices_public_key,
... receiving_pk=bobs_public_key,
... )
... for cfrag in suspicious_cfrags]


Bob opens the capsule
Expand All @@ -195,7 +199,7 @@ Finally, Bob decrypts the re-encrypted ciphertext using his key.
>>> cleartext = decrypt_reencrypted(decrypting_sk=bobs_secret_key,
... delegating_pk=alices_public_key,
... capsule=capsule,
... cfrags=cfrags,
... verified_cfrags=cfrags,
... ciphertext=ciphertext)


Expand Down
Loading