Add the encryption code so far

pull/79/head
tuxxy 2017-10-11 16:51:27 -06:00
parent dcbc6341fc
commit 228974001b
No known key found for this signature in database
GPG Key ID: 7BB971A0E89144D9
1 changed files with 20 additions and 2 deletions

View File

@ -200,7 +200,7 @@ class EncryptingPower(CryptoPowerUp):
M: int,
N: int,
path: bytes = None
) -> Tuple:
) -> Tuple[bytes, List[Tuple[bytes, bytes]], List[umbral.RekeyFrag]]:
"""
Encrypts data using ECIES.
@ -210,4 +210,22 @@ class EncryptingPower(CryptoPowerUp):
:param N: Total number of kFrags to generate.
:param path: Path of file to generate pathkey(s) for
"""
pass
# Encrypt plaintext data with nacl.SecretBox (symmetric)
data_key = API.secure_random(EncryptingPower.KEYSIZE)
enc_data = API.symm_encrypt(data_key, data)
# Derive path keys, if path. If not, use our public key
if path:
subpaths = self._split_path(path)
path_keys = [self._derive_path_key(subpath) for subpath in subpaths]
else:
path_keys = [self.pub_key]
# Encrypt the data key with the path keys
enc_keys = self._encrypt_key(data_key, path_keys)
# Generate ephemeral key and encrypt it
eph_priv_key = API.ecies.gen_priv()
symm_key_eph, enc_symm_key_eph = API.ecies_encaspulate(
recp_keypair.pubkey)
enc_eph_key = API.symm_encrypt(symm_key_eph, eph_priv_key)