xtrace_sdk.x_vec.crypto.goldwasser_micali_client

Classes

GoldwasserMicaliClient

Goldwasser-Micali homomorphic encryption client optimised for computing

Module Contents

class xtrace_sdk.x_vec.crypto.goldwasser_micali_client.GoldwasserMicaliClient(chunk_num=2, embd_len=512, key_len=1024)

Goldwasser-Micali homomorphic encryption client optimised for computing encrypted Hamming distances between binary embedding vectors.

Parameters:
  • chunk_num (int)

  • embd_len (int)

  • key_len (int)

keys
embd_len = 512
chunk_num = 2
chunk_len = 512
serial_pk()

Serialize the public key to a JSON string for networking or storage.

Returns:

JSON-encoded public key.

Return type:

str

serial_sk()

Serialize the secret key to a JSON string for networking or storage.

Returns:

JSON-encoded secret key.

Return type:

str

dump_pk(file_path)

Save the public key to disk using pickle.

Parameters:

file_path (str) – Destination file path.

Return type:

None

dump_sk(file_path)

Save the secret key to disk using pickle.

Parameters:

file_path (str) – Destination file path.

Return type:

None

id2power(id_)

Return the chunk index and bit position for a given embedding entry index.

Parameters:
  • id (int) – Index of an entry in the padded embedding array.

  • id_ (int)

Returns:

Tuple of (chunk_index, bit_position).

Return type:

tuple[int, int]

encrypt(embd)

Encrypt a binary embedding vector using the Goldwasser-Micali scheme.

Parameters:

embd (list[int]) – Binary embedding vector of length embd_len with values in {0, 1}.

Returns:

List of chunk_num Goldwasser-Micali ciphertexts.

Return type:

list[int]

decode_hamming_client(cipher)

Decrypt an encoded Hamming distance returned by the server.

Parameters:

cipher (list[int]) – Encrypted Hamming encoding returned by the server.

Returns:

Plain-text Hamming distance between the two original embeddings.

Return type:

int