Beispiel #1
0
    def reencrypt(
        self, rekey: Tuple[tuple, Tuple[bytes,
                                        bytes]], ciphertext: Tuple[bytes,
                                                                   bytes]
    ) -> Tuple[Tuple[bytes, bytes], Tuple[bytes, bytes]]:
        """
        Re-encrypt for public key
        rekey is (rk, encrypted_eph), same as output of rekey()
        ciphertext is a tuple in the same format as output of encrypt()

        Output is two tuples: data encrypted with an ephemeral key
        and the ephemeral private key encrypted for recepient (Bob)
        """
        rk, encrypted_eph = rekey
        rk = umbral.RekeyFrag(rk[0],
                              ec.deserialize(self.pre.ecgroup, rk[1]),
                              pre=PRE)
        ekey, edata = ciphertext
        ekey = umbral.EncryptedKey(ekey=ec.deserialize(self.pre.ecgroup,
                                                       ekey[0]),
                                   re_id=ekey[1])

        ekey = self.pre.reencrypt(rk, ekey)

        ekey = (ec.serialize(ekey.ekey), ekey.re_id)
        return (ekey, edata), encrypted_eph
Beispiel #2
0
def ecies_reencrypt(
    rekey: Union[bytes, umbral.RekeyFrag],
    enc_key: Union[bytes, umbral.EncryptedKey],
) -> umbral.EncryptedKey:
    """
    Re-encrypts the key provided.

    :param rekey: Re-encryption key to use
    :param enc_key: Encrypted key to re-encrypt

    :return: The re-encrypted key
    """
    if type(rekey) == bytes:
        rekey = umbral.RekeyFrag(None, priv_bytes2ec(rekey))
    if type(enc_key) == bytes:
        enc_key = umbral.EncryptedKey(priv_bytes2ec(enc_key), None)
    return PRE.reencrypt(rekey, enc_key)