Sign inSign up

mmroshani/openfhe

By mmroshani

•Updated over 1 year ago

The Python build of the Open-FHE library exposes a Jupyter notebook on the 8888 port.

Image
Security
Internet of things
Machine learning & AI
0

1.1K

mmroshani/openfhe repository overview

⁠Pull image

docker pull mmroshani/openfhe

⁠Run as Docker container

docker run -d -p 8888:8888 mmroshani/openfhe:latest

The Jupiter notebook exposed port is 8888

⁠Command to check if the container is running

docker ps

You should see mmroshani/openfhe:latest is running.

⁠Install Python packages

One can install any Python package using pip in the Jupyter notebook, since the Docker base image is Ubuntu 22.04, you can also access the Debian-based Linux commands.

⁠Multi-party support

My goal in building this image is to use Homomorphic Encryption with Multi-party configuration, so I also provide my code in Python for researchers (I hope it will be helpful in your research and save you from troubles).

⁠CKKS context
def setup_ckks_context():
    parameters = CCParamsCKKSRNS()
    parameters.SetSecretKeyDist(SecretKeyDist.UNIFORM_TERNARY)
    parameters.SetSecurityLevel(SecurityLevel.HEStd_NotSet)
    parameters.SetRingDim(1 << 12)

    if get_native_int() == 128:
        rescale_tech = ScalingTechnique.FIXEDAUTO
        dcrt_bits = 78
        first_mod = 89
    else:
        rescale_tech = ScalingTechnique.FLEXIBLEAUTO
        dcrt_bits = 59
        first_mod = 60

    parameters.SetScalingModSize(dcrt_bits)
    parameters.SetScalingTechnique(rescale_tech)
    parameters.SetFirstModSize(first_mod)
    parameters.SetMultiplicativeDepth(4)

    cc = GenCryptoContext(parameters)
    cc.Enable(PKESchemeFeature.PKE)
    cc.Enable(PKESchemeFeature.KEYSWITCH)
    cc.Enable(PKESchemeFeature.LEVELEDSHE)
    cc.Enable(PKESchemeFeature.MULTIPARTY)
    return cc
⁠Example of Multi-party class
class MultiPartyHE:
    def __init__(self):
        self.cc = setup_ckks_context()
        self.keyPairs = []
        self.joint_public_key = None
        self.ring_dim = self.cc.GetRingDimension()
        self.num_slots = int(self.ring_dim / 2)

    def generate_keys(self, num_parties=2):
        keyPair1 = self.cc.KeyGen()
        self.keyPairs.append(keyPair1)
        for i in range(1, num_parties):
            keyPair = self.cc.MultipartyKeyGen(self.keyPairs[0].publicKey, False, True)
            self.keyPairs.append(keyPair)
        private_keys = [kp.secretKey for kp in self.keyPairs]
        self.joint_key_pair = self.cc.MultipartyKeyGen(private_keys)
        self.joint_public_key = self.joint_key_pair.publicKey
        self.cc.EvalMultKeyGen(self.joint_key_pair.secretKey)
        return self.joint_public_key

    def encrypt(self, data, level=1):
        if not isinstance(data, list):
            data = [float(data)]
        plaintext = self.cc.MakeCKKSPackedPlaintext(data, 1, level)
        plaintext.SetLength(len(data))
        return self.cc.Encrypt(self.joint_public_key, plaintext)

    def decrypt(self, ciphertext):
        result = self.cc.Decrypt(ciphertext, self.joint_key_pair.secretKey)
        return result

    def add(self, cipher1, cipher2):
        return self.cc.EvalAdd(cipher1, cipher2)

    def multiply(self, cipher1, cipher2):
        return self.cc.EvalMult(cipher1, cipher2)

Tag summary

Content type

Image

Digest

sha256:0447e7e87…

Size

321.7 MB

Last updated

over 1 year ago

docker pull mmroshani/openfhe