xtrace_sdk.crypto.encryption package

Submodules

xtrace_sdk.crypto.encryption.aes module

class xtrace_sdk.crypto.encryption.aes.AESClient(key: str)

Bases: object

This class wraps Crypto AES encryption lib.

decrypt(enc: bytes) str

AES decrypt a cipher

Parameters:

enc (bytes) – cipher in bytes

Returns:

plaintext

Return type:

string

encrypt(raw: bytes) bytes

AES encrypt a plaintext in bytes

Parameters:

raw (bytes) – plaintext to be encrypted with self.key

Returns:

cipher in bytes

Return type:

bytes

xtrace_sdk.crypto.encryption.damgard_jurik module

class xtrace_sdk.crypto.encryption.damgard_jurik.Damgard_Jurik(keys: dict[slice('sk', dict[slice('d', <class 'int'>, None)], None), slice('pk', dict[slice('g', <class 'int'>, None), slice('n', <class 'int'>, None)], None)])

Bases: HomomorphicBase

A self implemented Dammgard Jurik encryption scheme

static L(x: int, n: int) int

Helper method for decryption

static add(ciphertext1: int, ciphertext2: int, pk: dict[slice('g', <class 'int'>, None), slice('n', <class 'int'>, None)]) int

Homomorphic addition of Dammgard Jurik crypto system.

Parameters:
  • ciphertext1 (int) – one the ciphers to be added

  • ciphertext2 (int) – one the ciphers to be added

  • pk (DaJurPublicKey) – Damgard Jurik public key

Returns:

ciphertext3 such that decrypt(ct3,sk) = decrypt(ct1,sk) + decrypt(ct2,sk)

Return type:

int

static decrypt(ciphertext: int, keys: dict[slice('sk', dict[slice('d', <class 'int'>, None)], None), slice('pk', dict[slice('g', <class 'int'>, None), slice('n', <class 'int'>, None)], None)]) int

Decrypts a cihpher with Dammgard Jurik key pair and returns the plaintext

Parameters:
  • ciphertext (int) – cipher to be decrypted

  • keys (DaJurKeyPair) – pk,sk pair where sk is used to encrypt ct.

Returns:

plaintext

Return type:

int

static encrypt(plaintext: int, pk: dict[slice('g', <class 'int'>, None), slice('n', <class 'int'>, None)]) int

Encryption with PK

Parameters:
  • plaintext (int) – the plaintext to be encrypted.

  • pk (DaJurPublicKey) – the public key to be used for encryption

Returns:

Dammgard Jurik cipher

Return type:

int

static generate_random_r(pk: dict[slice('g', <class 'int'>, None), slice('n', <class 'int'>, None)]) int

Helper function for encryption required by Dammgard Jurik scheme

Parameters:

pk (DaJurPublicKey) – the public key

Returns:

a random r to be used for encryption.

Return type:

int

static key_gen(key_len: int) dict[slice('sk', dict[slice('d', <class 'int'>, None)], None), slice('pk', dict[slice('g', <class 'int'>, None), slice('n', <class 'int'>, None)], None)]

Key generation routine for the Damgard Jurik crypto scheme.

Parameters:

key_len (int) – the number of bits in PK SK

Returns:

Damgard Jurik PK, SK pair

Return type:

DaJurKeyPair

static multiply(ciphertext1: int, ciphertext2: int, pk: dict[slice('g', <class 'int'>, None), slice('n', <class 'int'>, None)]) int

Not supported for Dammgard Jurik.

static xor(ciphertext1: int, ciphertext2: int, pk: dict[slice('g', <class 'int'>, None), slice('n', <class 'int'>, None)]) int

Not supported for Dammgard Jurik.

xtrace_sdk.crypto.encryption.goldwasser_micali module

class xtrace_sdk.crypto.encryption.goldwasser_micali.Goldwasser_Micali(keys: dict[slice('sk', dict[slice('p', <class 'int'>, None), slice('q', <class 'int'>, None)], None), slice('pk', dict[slice('x', <class 'int'>, None), slice('n', <class 'int'>, None)], None)])

Bases: HomomorphicBase

A self implemented Goldwasser Micali encryption scheme

static L(x: int, n: int) int

Helper method for decryption

static add(ciphertext1: int, ciphertext2: int, pk: dict[slice('x', <class 'int'>, None), slice('n', <class 'int'>, None)]) int

Not supported for Goldwasser_Micali.

static decrypt(ciphertext: list, keys: dict[slice('sk', dict[slice('p', <class 'int'>, None), slice('q', <class 'int'>, None)], None), slice('pk', dict[slice('x', <class 'int'>, None), slice('n', <class 'int'>, None)], None)]) list

Decrypts a cihpher with Goldwasser Micali key pair and returns the plaintext

Parameters:
  • ciphertext (int) – cipher to be decrypted

  • keys (GoldwasserMicaliKeyPair) – pk,sk pair where sk is used to encrypt ct.

Returns:

plaintext

Return type:

int

static encrypt(plaintext: list, pk: dict[slice('x', <class 'int'>, None), slice('n', <class 'int'>, None)]) list

Encryption with PK

Parameters:
  • plaintext (int) – the plaintext to be encrypted.

  • pk (GoldwasserMicaliPublicKey) – the public key to be used for encryption

Returns:

Goldwasser Micali cipher

Return type:

int

static generate_random_r(pk: dict[slice('x', <class 'int'>, None), slice('n', <class 'int'>, None)]) int

Helper function for encryption required by Goldwasser_Micali scheme

Parameters:

pk (GoldwasserMicaliPublicKey) – the public key

Returns:

a random r to be used for encryption.

Return type:

int

static key_gen(key_len: int) dict[slice('sk', dict[slice('p', <class 'int'>, None), slice('q', <class 'int'>, None)], None), slice('pk', dict[slice('x', <class 'int'>, None), slice('n', <class 'int'>, None)], None)]

Key generation routine for the Goldwasser_Micali crypto scheme.

Parameters:

key_len (int) – the number of bits in PK SK

Returns:

Goldwasser_Micali PK, SK pair

Return type:

Goldwasser_MicaliKeyPair

static multiply(ciphertext1: int, ciphertext2: int, pk: dict[slice('x', <class 'int'>, None), slice('n', <class 'int'>, None)]) int

Not supported for Goldwasser_Micali.

static xor(ciphertext1: list, ciphertext2: list, pk: dict[slice('x', <class 'int'>, None), slice('n', <class 'int'>, None)]) list

Homomorphic xor of Goldwasser_Micali crypto system.

Parameters:
  • ciphertext1 (int) – one the ciphers to be xor’ed

  • ciphertext2 (int) – one the ciphers to be xor’ed

  • pk (GoldwasserMicaliPublicKey) – Pailier public key

Returns:

ciphertext3 such that decrypt(ct3,sk) = decrypt(ct1,sk) [xor] decrypt(ct2,sk)

Return type:

int

xtrace_sdk.crypto.encryption.homomorphic_base module

class xtrace_sdk.crypto.encryption.homomorphic_base.HomomorphicBase

Bases: ABC

The Interface which all homomorphic encryption primitives should implement.

Parameters:

ABC (abc.ABC) – Abstract class

abstractmethod static add(ct1, ct2, key)

homomorphically add two ciphers and return ct3 such that decrypt(ct3)= decrypt(ct1) + decrypt(ct2)

abstractmethod decrypt(key)

decrypts a cipher

abstractmethod encrypt(key)

Encrypts a plain text with key

abstractmethod static key_gen(**kwargs)

Key generation routine.

abstractmethod static multiply(ct1, ct2, key)

homomorphically multiply two ciphers and return ct3 such that decrypt(ct3)= decrypt(ct1) * decrypt(ct2)

abstractmethod static xor(ct1, ct2, key)

homomorphically xor two ciphers and return ct3 such that decrypt(ct3)= decrypt(ct1) ^ decrypt(ct2)

xtrace_sdk.crypto.encryption.paillier module

Module contents

This module provides encryption and decryption utilities for the XTrace SDK. It includes functions for encrypting and decrypting data using various encryption algorithms. The encryption algorithms supported include:

  1. aes: AES (Advanced Encryption Standard)

  2. paillier: Paillier Encryption

  3. goldwasser_micali: Goldwasser-Micali Encryption

  4. damgard_jurik: Damgard-Jurik Encryption

Besides, it also provides homomorphic_base: a base class for homomorphic encryption, which can be extended to implement specific homomorphic encryption schemes.