How to encrypt a byte vector

Hello,

I’m a beginner so very sorry about my ignorance (I’m even not sure if my question makes sense).

Using Zama’s concrete, I write the following function:

import numpy as np
@fhe.function({"v": "encrypted"})
def count(v):
  return np.sum(v == 1)

which aims to count the number of element of value 1 in a vector v. Then use a data set:

inputset = [np.random.randint(0, 256, size=(100)) for _ in 200]

to compile a circuit:

circuit = count. Compile(inputset)

and play with it:

v_plain = np.random.randint(0, 256, size=(100))
v_enc = circuit.client.encrypt(v_plain)
c = count(v_enc)

Now I want to implement the function count using Zama’s tfhe-rs, an imagined implementation is as follows:

fn count(v: Vec<uint8>) -> usize {
  v.iter().....
}

Since tfhe-rs supports basically primitive types, then I cannot have an FHE type of Vec, so what should I do? Could I naively use v as Vec<FheUint8> or is there a specific data type for an encrypted vector of data?

Obviously, if I do that then at least the length of vector is leaked. I suppose that it is not the case for the Python version.

I may imagine that FHE simply does not care about that since it focuses on operations on data and the way data is encrypted depends on the users. If this is not true, then what happens under the hood for the initial case of v? Concretely, in the call to encrypt

v_enc = circuit.client.encrypt(v)

does Zama’s concrete encrypts element by element of v?

Many thanks for help.

tfhe-rs does not expose its own vector types, so you have to use a Vec<FheUint8>, yes the len is ‘leaked’, by I’m pretty sure that is also the case for concrete array.

And the count would be computed as

let clear_data: Vec<u8> = //...
let encrypted_data = clear_data.iter().copied().map(|v| FheUint8::encrypt(v, &client_key)).collect::<Vec<_>>();

let count = encrypted_data.iter().sum();

1 Like