xtrace_sdk.crypto.goldwasser_micali_client

Classes

GoldwasserMicaliClient

This is an implementation of goldwasser micali cryptography system optimized for calculating hamming distance between

Module Contents

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

Bases: 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.

Parameters:
  • chunk_num (int)

  • embd_len (int)

  • key_len (int)

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

serialzation of public key for networking/storage purpose

Returns:

serialized pk

Return type:

bytes

serial_sk()

serialzation of secret key for networking/storage purpose

Returns:

serialized sk

Return type:

bytes

dump_pk(file_path)

saves publick key to disk

Parameters:

file_path (str) – the path to which public key will be saved on disk

Return type:

None

dump_sk(file_path)

saves secret key to disk

Parameters:

file_path (str) – the path to which secret key will be saved on disk

Return type:

None

id2power(id_)

helper: return chunk id & corresponding power of 2 given an id in the original padded arr

Parameters:
  • id (int) – id_ of an entry in an embedding vector

  • id_ (int)

Return type:

tuple[int, int]

encrypt(embd)

This function implements the encryption scheme on embedding vectors that needs to be run on client side.

Parameters:

embd (iterable[0,1]) – the embedding vector to be encrypted

Returns:

return a list of length chunk_num contaning Goldwasser_MicaliEncryptedNumber

Return type:

list[Goldwasser_MicaliEncryptedNumber]

encode_hamming_client(ct1, ct2)

This function is called from client side.

Parameters:
  • embd1 (Goldwasser_MicaliEncryptedNumber) – ciphertext of embedding 1

  • embd2 (Goldwasser_MicaliEncryptedNumber) – ciphertext of embedding 2

  • ct1 (list)

  • ct2 (list)

Returns:

return a list of length chunk_num contaning large int

Return type:

Goldwasser_MicaliEncryptedNumber

static encode_hamming_server(ct1, ct2, pk)

This function is called from server side.

Parameters:
  • ct1 (Goldwasser_MicaliEncryptedNumber) – ciphertext of embedding 1

  • ct2 (Goldwasser_MicaliEncryptedNumber) – ciphertext of embedding 2

  • pk (Goldwasser_MicaliEncryptedNumber) – public key

Returns:

return a list of length chunk_num contaning large int

Return type:

Goldwasser_MicaliEncryptedNumber

decode_hamming_client(cipher)

Given a Goldwasser_MicaliEncryptedNumber returned from server, calculate the hamming distance encoded

Parameters:

cipher (Goldwasser_MicaliEncryptedNumber) – a cipher regturned by server which encodes the hamming distance between two encrypted embeddings

Returns:

hamming distance encoded by cipher

Return type:

int