xtrace_sdk.x_vec.crypto.goldwasser_micali_client ================================================ .. py:module:: xtrace_sdk.x_vec.crypto.goldwasser_micali_client Classes ------- .. autoapisummary:: xtrace_sdk.x_vec.crypto.goldwasser_micali_client.GoldwasserMicaliClient Module Contents --------------- .. py:class:: 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. .. py:attribute:: keys .. py:attribute:: embd_len :value: 512 .. py:attribute:: chunk_num :value: 2 .. py:attribute:: chunk_len :value: 512 .. py:method:: serial_pk() Serialize the public key to a JSON string for networking or storage. :return: JSON-encoded public key. :rtype: str .. py:method:: serial_sk() Serialize the secret key to a JSON string for networking or storage. :return: JSON-encoded secret key. :rtype: str .. py:method:: dump_pk(file_path) Save the public key to disk using pickle. :param file_path: Destination file path. :type file_path: str .. py:method:: dump_sk(file_path) Save the secret key to disk using pickle. :param file_path: Destination file path. :type file_path: str .. py:method:: id2power(id_) Return the chunk index and bit position for a given embedding entry index. :param id_: Index of an entry in the padded embedding array. :type id_: int :return: Tuple of (chunk_index, bit_position). :rtype: tuple[int, int] .. py:method:: encrypt(embd) Encrypt a binary embedding vector using the Goldwasser-Micali scheme. :param embd: Binary embedding vector of length ``embd_len`` with values in {0, 1}. :type embd: list[int] :return: List of ``chunk_num`` Goldwasser-Micali ciphertexts. :rtype: list[int] .. py:method:: decode_hamming_client(cipher) Decrypt an encoded Hamming distance returned by the server. :param cipher: Encrypted Hamming encoding returned by the server. :type cipher: list[int] :return: Plain-text Hamming distance between the two original embeddings. :rtype: int