microsoft / EVA

Compiler for the SEAL homomorphic encryption library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Evaluate a function on a clear data chosen by the evaluator

Hjeljeli opened this issue · comments

Can Eva allow to run a function f on two variables a and b such that a is encrypted (chosen by the encryptor) and b is plaintext (chosen by the evaluator)?

Here is an example of a code (that does not compile) that shows what I would like to achieve

from eva import *
from time import time
add = EvaProgram('add', vec_size=16)
with add:
    a = Input('a', True)
    b = Input('b', False)
    Output('c', a+b)

# Scale of inputs/outputs
add.set_output_ranges(30)
add.set_input_scales(30)

from eva.ckks import *
compiler = CKKSCompiler()
compiled_add, params, signature = compiler.compile(add)

### Generating Keys and Encrypting Inputs
from eva.seal import *
public_ctx, secret_ctx = generate_keys(params)

# Encryptor chooses a 
#inputs = { 'a': [i for i in range(compiled_add.vec_size)], 'b': [i for i in range(compiled_add.vec_size)] }
inputs_a = { 'a': [i for i in range(compiled_add.vec_size)] }
encInputs = public_ctx.encrypt(inputs_a, signature)

# Evaluator chooses b
inputs_b = { 'b': [i for i in range(compiled_add.vec_size)] }
encInputs = inputs_a + inputs_b # This is what I would like to do

# Homomorphic Execution
encOutputs = public_ctx.execute(compiled_add, encInputs)

# Decryption of results
outputs = secret_ctx.decrypt(encOutputs, signature)

print(outputs)

Currently this functionality is not exposed through the python wrappers. The encrypt function returns a value of type SEALValuation, which does not expose any way to merge valuations. This is definitely a use case we want to enable, so we will be adding this as a feature.

In the meanwhile, if you want to add this function for yourself it would not be too complicated. The SEALValuation type defined in eva/seal/seal.h holds an std::unordered_map of the encrypted values plus a seal::EncryptionParameters. You would need to add a function for merging in another SEALValuation and then add an .def(...) entry in python/eva/wrapper.cpp after the py::class_<SEALValuation>(...) on line 178 exposing that function.

Hi Olli, thanks for your quick and clear reply. I will try to implement the functionality.

Great! By the way if you add this it would be great if you could do a pull request. And we can polish the code afterwards if need be.