xtrace_sdk.crypto package

Subpackages

Submodules

xtrace_sdk.crypto.damgard_jurik_client module

class xtrace_sdk.crypto.damgard_jurik_client.DamgardJurikClient(chunk_num=2, embd_len=512, key_len=1024)

Bases: HammingClientBase

This is an implementation of damgard jurik cryptography system optimized for calculating hamming distance between two binary vectors.

decode_hamming_client(cipher)

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

Parameters:

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

Returns:

hamming distance encoded by cipher

Return type:

int

dump_pk(file_path)

saves publick key to disk

Parameters:

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

dump_sk(file_path)

saves secret key to disk

Parameters:

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

encode_hamming_client(ct1, ct2)

This function is called from server side.

Parameters:
  • ct1 (_type_) – _description_

  • ct2 (_type_) – _description_

  • pk (_type_) – _description_

Returns:

_description_

Return type:

_type_

static encode_hamming_server(ct1, ct2, pk)

This function is called from server side.

Parameters:
  • ct1 (_type_) – _description_

  • ct2 (_type_) – _description_

  • pk (_type_) – _description_

Returns:

_description_

Return type:

_type_

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 Damgard_JurikEncryptedNumber

Return type:

list[Damgard_JurikEncryptedNumber]

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

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

xtrace_sdk.crypto.goldwasser_micali_client module

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

Bases: HammingClientBase

This is an implementation of goldwasser micali cryptography system optimized for calculating hamming distance between two binary vectors.

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

dump_pk(file_path)

saves publick key to disk

Parameters:

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

dump_sk(file_path)

saves secret key to disk

Parameters:

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

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

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

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]

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

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

xtrace_sdk.crypto.hamming_client_base module

class xtrace_sdk.crypto.hamming_client_base.HammingClientBase

Bases: ABC

abstractmethod decode_hamming_client(**kwargs)
abstractmethod static encode_hamming_server(self, **kwargs)

This static function is called from server side.

abstractmethod encrypt(**kwargs)

xtrace_sdk.crypto.paillier_client module

xtrace_sdk.crypto.paillier_intel module

Module contents

This Module provides cryptographic utilities for the XTrace SDK. It includes classes and functions for generating and managing cryptographic keys, as well as for performing encryption and decryption operations. It contains the following modules:

  1. commitment: A module for computing commitment over data.

  2. encryption: A module for performing encryption and decryption operations.

  3. signature: A module for generating and verifying digital signatures.

In addition, it provides hamming_client_base as a base class for crytpographic clients that compute hamming distance between two ciphers.