Rename pre.split_rekey to pre.generate_kfrags. Introduce changes in args

pull/220/head
David Núñez 2018-10-04 11:30:47 +02:00
parent d6ee0cc4e5
commit 4e331f3010
10 changed files with 37 additions and 31 deletions

View File

@ -90,11 +90,11 @@ except:
# She uses her private key, and Bob's public key, and she sets a minimum
# threshold of 10, for 20 total shares
kfrags = pre.split_rekey(delegating_privkey=alices_private_key,
signer=alices_signer,
receiving_pubkey=bobs_public_key,
threshold=10,
N=20)
kfrags = pre.generate_kfrags(delegating_privkey=alices_private_key,
signer=alices_signer,
receiving_pubkey=bobs_public_key,
threshold=10,
N=20)
#9

View File

@ -108,12 +108,14 @@ def prepared_capsule(alices_keys, bobs_keys):
@pytest.fixture(scope='function')
def kfrags(alices_keys, bobs_keys):
delegating_privkey, signing_privkey = alices_keys
delegating_pubkey = delegating_privkey.get_pubkey()
signer_alice = Signer(signing_privkey)
receiving_privkey, receiving_pubkey = bobs_keys
yield pre.split_rekey(delegating_privkey, signer_alice, receiving_pubkey, 6, 10)
yield pre.generate_kfrags(delegating_privkey=delegating_privkey,
signer=signer_alice,
receiving_pubkey=receiving_pubkey,
threshold=6, N=10)

View File

@ -135,13 +135,13 @@ def test_kfrags_signed_without_correctness_keys(alices_keys, bobs_keys, capsule)
receiving_privkey, receiving_pubkey = bobs_keys
kfrags = pre.split_rekey(delegating_privkey=delegating_privkey,
signer=Signer(signing_privkey),
receiving_pubkey=receiving_pubkey,
threshold=6,
N=10,
sign_delegating_key=False,
sign_receiving_key=False)
kfrags = pre.generate_kfrags(delegating_privkey=delegating_privkey,
signer=Signer(signing_privkey),
receiving_pubkey=receiving_pubkey,
threshold=6,
N=10,
sign_delegating_key=False,
sign_receiving_key=False)
for kfrag in kfrags:
# You can verify the KFrag specifying only the verifying key

View File

@ -37,5 +37,9 @@ def test_wrong_N_M_in_split_rekey(N, M, alices_keys, bobs_keys):
_receiving_privkey, receiving_pubkey = bobs_keys
with pytest.raises(ValueError):
_kfrags = pre.split_rekey(delegating_privkey, signer, receiving_pubkey, M, N)
_kfrags = pre.generate_kfrags(delegating_privkey=delegating_privkey,
signer=signer,
receiving_pubkey=receiving_pubkey,
threshold=M,
N=N)

View File

@ -93,7 +93,7 @@ def test_split_rekey_performance(benchmark, m: int, n: int) -> None:
return args, kwargs
print("\nBenchmarking {function} with M:{M} of N:{N}...".format(function="pre.split_rekey", M=m, N=n))
benchmark.pedantic(pre.split_rekey, setup=__setup, rounds=1000)
benchmark.pedantic(pre.generate_kfrags, setup=__setup, rounds=1000)
assert True # ensure function finishes and succeeds.
@ -111,7 +111,7 @@ def test_random_frag_reencryption_performance(benchmark, m: int, n: int) -> None
def __setup():
delegating_privkey, signer, receiving_pubkey, ciphertext, capsule = __standard_encryption_api()
kfrags = pre.split_rekey(delegating_privkey, signer, receiving_pubkey, m, n)
kfrags = pre.generate_kfrags(delegating_privkey, signer, receiving_pubkey, m, n)
one_kfrag, *remaining_kfrags = kfrags
args, kwargs = tuple(), {"kfrag": one_kfrag, "capsule": capsule},
return args, kwargs
@ -133,7 +133,7 @@ def test_random_frag_reencryption_performance(benchmark, m: int, n: int) -> None
def test_single_frag_reencryption_performance(benchmark, m: int, n: int) -> None:
delegating_privkey, signer, receiving_pubkey, ciphertext, capsule = __standard_encryption_api()
kfrags = pre.split_rekey(delegating_privkey, signer, receiving_pubkey, m, n)
kfrags = pre.generate_kfrags(delegating_privkey, signer, receiving_pubkey, m, n)
one_kfrag, *remaining_kfrags = kfrags
args, kwargs = tuple(), {"kfrag": one_kfrag, "capsule": capsule},

View File

@ -49,7 +49,7 @@ def __produce_kfrags_and_capsule(m: int, n: int) -> Tuple[List[KFrag], Capsule]:
plain_data = os.urandom(32)
ciphertext, capsule = pre.encrypt(delegating_pubkey, plain_data)
kfrags = pre.split_rekey(delegating_privkey, signer, receiving_pubkey, m, n)
kfrags = pre.generate_kfrags(delegating_privkey, signer, receiving_pubkey, m, n)
capsule.set_correctness_keys(delegating=delegating_pubkey,
receiving=receiving_pubkey,

View File

@ -64,7 +64,7 @@ def test_lifecycle_with_serialization(N, M, curve=default_curve()):
receiving_pubkey = UmbralPublicKey.from_bytes(receiving_pubkey_bytes, params)
signer = Signer(signing_privkey)
kfrags = pre.split_rekey(delegating_privkey, signer, receiving_pubkey, M, N)
kfrags = pre.generate_kfrags(delegating_privkey, receiving_pubkey, M, N, signer)
kfrags_bytes = tuple(map(bytes, kfrags))
del kfrags

View File

@ -64,7 +64,7 @@ def test_simple_api(N, M, curve=default_curve()):
assert cleartext == plain_data
# Split Re-Encryption Key Generation (aka Delegation)
kfrags = pre.split_rekey(delegating_privkey, signer, receiving_pubkey, M, N)
kfrags = pre.generate_kfrags(delegating_privkey, receiving_pubkey, M, N, signer)
# Capsule preparation (necessary before re-encryotion and activation)

View File

@ -192,20 +192,20 @@ class Capsule(object):
return "{}:{}".format(self.__class__.__name__, hex(int(self._bn_sig))[2:17])
def split_rekey(delegating_privkey: UmbralPrivateKey,
signer: Signer,
receiving_pubkey: UmbralPublicKey,
threshold: int,
N: int,
sign_delegating_key : Optional[bool] = True,
sign_receiving_key : Optional[bool] = True,
) -> List[KFrag]:
def generate_kfrags(delegating_privkey: UmbralPrivateKey,
receiving_pubkey: UmbralPublicKey,
threshold: int,
N: int,
signer: Signer,
sign_delegating_key: Optional[bool] = True,
sign_receiving_key: Optional[bool] = True,
) -> List[KFrag]:
"""
Creates a re-encryption key from Alice's delegating public key to Bob's
receiving public key, and splits it in KFrags, using Shamir's Secret Sharing.
Requires a threshold number of KFrags out of N.
Returns a dictionary which includes the list of N KFrags
Returns a list of N KFrags
"""
if threshold <= 0 or threshold > N:

View File

@ -53,7 +53,7 @@ receiving_key = receiving_privkey.get_pubkey()
signer = Signer(signing_privkey)
kfrags = pre.split_rekey(delegating_privkey, signer, receiving_key, 6, 10)
kfrags = pre.generate_kfrags(delegating_privkey, signer, receiving_key, 6, 10)
plain_data = b'peace at dawn'