Fix methods in EncryptingKeypair and fix split key reencryption tests

pull/55/head
tuxxy 2017-09-25 16:28:53 -07:00
parent 0e9315cd22
commit a43c587d0d
2 changed files with 13 additions and 11 deletions

View File

@ -47,10 +47,8 @@ class EncryptingKeypair(object):
def split_rekey(self, privkey_a, privkey_b, min_shares, num_shares):
"""
Generates a re-encryption key in interactive mode using the split-key
method. This will require the re-encryption key to be reconstructed by
with a threshold of shares `min_shares`. This generates a total of
`num_shares` that can be used to reconstruct the key.
Generates key shares that can be used to re-encrypt data. Requires
`min_shares` to be able to successfully combine data for full key.
:param int privkey_a: Alice's private key
:param int privkey_b: Bob's private key (or an ephemeral privkey)
@ -63,11 +61,11 @@ class EncryptingKeypair(object):
return self.pre.split_rekey(privkey_a, privkey_b, min_shares,
num_shares)
def build_rekey(self, shares):
def build_secret(self, shares):
"""
Reconstructs a re-encryption key with the key shares provided.
Reconstructs a secret from the given shares.
:param list shares: List of re-encryption key shares
:param list shares: List of secret share fragments.
:rtype: EncryptedKey
:return: EncryptedKey from `shares`

View File

@ -79,10 +79,14 @@ class TestEncryptingKeypair(unittest.TestCase):
self.assertEqual(10, len(enc_shares))
rand_shares = random.sample(enc_shares, 4)
reenc_key = self.send_keypair.build_rekey(rand_shares)
self.assertEqual(4, len(rand_shares))
reenc_data = self.send_keypair.reencrypt(reenc_key, enc_symm)
self.assertTrue(reenc_data != enc_symm)
frags = [self.send_keypair.reencrypt(rk, enc_symm) for rk in rand_shares]
self.assertEqual(4, len(frags))
dec_key = self.recv_keypair.decrypt_key(reenc_data)
enc_key = self.recv_keypair.build_secret(frags)
self.assertTrue(raw_symm != enc_key)
self.assertTrue(enc_symm != enc_key)
dec_key = self.recv_keypair.decrypt_key(enc_key)
self.assertTrue(dec_key == raw_symm)