xtrace_sdk.crypto.goldwasser_micali_client ========================================== .. py:module:: xtrace_sdk.crypto.goldwasser_micali_client Classes ------- .. autoapisummary:: xtrace_sdk.crypto.goldwasser_micali_client.GoldwasserMicaliClient Module Contents --------------- .. py:class:: GoldwasserMicaliClient(chunk_num = 2, embd_len = 512, key_len = 1024) Bases: :py:obj:`xtrace_sdk.crypto.hamming_client_base.HammingClientBase` This is an implementation of goldwasser micali cryptography system optimized for calculating hamming distance between two binary 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() serialzation of public key for networking/storage purpose :return: serialized pk :rtype: bytes .. py:method:: serial_sk() serialzation of secret key for networking/storage purpose :return: serialized sk :rtype: bytes .. py:method:: dump_pk(file_path) saves publick key to disk :param file_path: the path to which public key will be saved on disk :type file_path: str .. py:method:: dump_sk(file_path) saves secret key to disk :param file_path: the path to which secret key will be saved on disk :type file_path: str .. py:method:: id2power(id_) helper: return chunk id & corresponding power of 2 given an id in the original padded arr :param id_: id_ of an entry in an embedding vector :type id_: int .. py:method:: encrypt(embd) This function implements the encryption scheme on embedding vectors that needs to be run on client side. :param embd: the embedding vector to be encrypted :type embd: iterable[0,1] :return: return a list of length chunk_num contaning Goldwasser_MicaliEncryptedNumber :rtype: list[Goldwasser_MicaliEncryptedNumber] .. py:method:: encode_hamming_client(ct1, ct2) This function is called from client side. :param embd1: ciphertext of embedding 1 :type embd1: Goldwasser_MicaliEncryptedNumber :param embd2: ciphertext of embedding 2 :type embd2: Goldwasser_MicaliEncryptedNumber :return: return a list of length chunk_num contaning large int :rtype: Goldwasser_MicaliEncryptedNumber .. py:method:: encode_hamming_server(ct1, ct2, pk) :staticmethod: This function is called from server side. :param ct1: ciphertext of embedding 1 :type ct1: Goldwasser_MicaliEncryptedNumber :param ct2: ciphertext of embedding 2 :type ct2: Goldwasser_MicaliEncryptedNumber :param pk: public key :type pk: Goldwasser_MicaliEncryptedNumber :return: return a list of length chunk_num contaning large int :rtype: Goldwasser_MicaliEncryptedNumber .. py:method:: decode_hamming_client(cipher) Given a Goldwasser_MicaliEncryptedNumber returned from server, calculate the hamming distance encoded :param cipher: a cipher regturned by server which encodes the hamming distance between two encrypted embeddings :type cipher: Goldwasser_MicaliEncryptedNumber :return: hamming distance encoded by cipher :rtype: int