xtrace_sdk.crypto.encryption.paillier_lookup

Attributes

MSG_BITS

NOISE_TABLE_SIZE

NOISE_MULTIPLES

Classes

Paillier_Lookup

A self implemented paillier encryption scheme

Module Contents

xtrace_sdk.crypto.encryption.paillier_lookup.MSG_BITS = 8
xtrace_sdk.crypto.encryption.paillier_lookup.NOISE_TABLE_SIZE = 256
xtrace_sdk.crypto.encryption.paillier_lookup.NOISE_MULTIPLES = 14
class xtrace_sdk.crypto.encryption.paillier_lookup.Paillier_Lookup(keys)

Bases: xtrace_sdk.crypto.encryption.homomorphic_base.HomomorphicBase[int, int, xtrace_sdk.utils.xtrace_types.PaillierKeyPair, xtrace_sdk.utils.xtrace_types.PaillierPublicKey]

A self implemented paillier encryption scheme

Parameters:

keys (xtrace_sdk.utils.xtrace_types.PaillierKeyPair)

keys
static key_gen(key_len, alpha_len)

Key generation routine for the Paillier crypto scheme.

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

  • alpha_len (int)

Returns:

Paillier PK, SK pair

Return type:

PaillierKeyPair

static precompute_g_table(g, n, key_len, msg_bits=MSG_BITS)
Parameters:
  • g (gmpy2.mpz)

  • n (gmpy2.mpz)

  • key_len (int)

  • msg_bits (int)

Return type:

dict[int, list[int]]

static precompute_noise_table(g, n, size=NOISE_TABLE_SIZE)
Parameters:
  • g (gmpy2.mpz)

  • n (gmpy2.mpz)

  • size (int)

Return type:

list[int]

static gen_dsa_params_custom(p_bits, q_bits)

1024-bit DSA => q is 160-bit (FIPS 186-4).

Parameters:
  • p_bits (int) – The number of bits for the keys

  • q_bits (int) – The number of bits in alpha

Returns:

mpz(P), mpz(Q), mpz(G).

Return type:

int

static generate_random_r(pk)

Helper function for encryption required by Paillier scheme

Parameters:

pk (PaillierPublicKey) – the public key

Returns:

a random r to be used for encryption.

Return type:

int

static encrypt(plaintext, pk, g_table=None, noise_table=None, message_chunks=0)

Encryption with PK

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

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

  • g_table (Optional[dict[int, list[gmpy2.mpz]]])

  • noise_table (Optional[list[gmpy2.mpz]])

  • message_chunks (int)

Returns:

Paillier cipher

Return type:

int

static decrypt(ciphertext, keys)

Decrypts a cihpher with paillier key pair and returns the plaintext

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

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

Returns:

plaintext

Return type:

int

static add(ciphertext1, ciphertext2, pk)

Homomorphic addition of Paillier crypto system.

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

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

  • pk (PaillierPublicKey) – Pailier public key

Returns:

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

Return type:

int

static multiply(ciphertext1, ciphertext2, pk)
Abstractmethod:

Parameters:
  • ciphertext1 (int)

  • ciphertext2 (int)

  • pk (xtrace_sdk.utils.xtrace_types.PaillierPublicKey)

Return type:

int

Not supported for Paillier.

static xor(ciphertext1, ciphertext2, pk)
Abstractmethod:

Parameters:
  • ciphertext1 (int)

  • ciphertext2 (int)

  • pk (xtrace_sdk.utils.xtrace_types.PaillierPublicKey)

Return type:

int

Not supported for Paillier.

static L(x, n)

Helper method for decryption

Parameters:
Return type:

int

static bitlen(x)

Helper method to get bit length of gmpy mpz integers

Parameters:

x (gmpy2.mpz)

Return type:

int

static crt_pair(a1, m1, a2, m2)

Helper method for Chinsese Remainder Theorem

Parameters:
  • a1 (gmpy2.mpz)

  • m1 (gmpy2.mpz)

  • a2 (gmpy2.mpz)

  • m2 (gmpy2.mpz)

Return type:

tuple[gmpy2.mpz, gmpy2.mpz]

static lift_to_p2_with_p_component(g_mod_p, p)

Multiply by (1+p) to inject an order-p component in Z_{p^2}*

Parameters:
  • g_mod_p (gmpy2.mpz)

  • p (gmpy2.mpz)

Return type:

gmpy2.mpz