Code base obscuration (for images) 1.0
It implements different obscuration methods on portable images (.pgm and .ppm)
Loading...
Searching...
No Matches
Paillier< T_in, T_out > Class Template Reference

This class implements the Paillier cryptosystem. More...

#include <Paillier.hpp>

Public Member Functions

 Paillier ()
 Construct a new Paillier object.
 
 ~Paillier ()
 Destroy the Paillier object.
 
uint64_t random64 (uint64_t min, uint64_t max)
 Generate a random 64-bit unsigned integer.
 
uint64_t fastMod_64t (uint64_t x, uint64_t e, uint64_t n)
 Calculate the modular exponentiation of a base raised to a power modulo a modulus.
 
uint64_t gcd_64t (uint64_t a, uint64_t b)
 Calculate the greatest common divisor (GCD) of two 64-bit unsigned integers.
 
std::vector< uint64_t > calc_set_same_remainder_divide_euclide_64t (uint64_t n)
 Calculate the set of elements in (Z/n²Z)*.
 
std::vector< uint64_t > calc_set_same_remainder_divide_euclide_64t_v2 (uint64_t n, const uint64_t &lambda)
 Calculate the set of elements in (Z/n²Z)* that satisfy the condition L(x) = (x-1)/n where x is a positive integer and mu exists.
 
uint64_t choose_g_in_vec_64t (std::vector< uint64_t > &set, const uint64_t &n, const uint64_t &lambda)
 Choose g from the set of elements in (Z/n²Z)* that satisfy the condition L(x) = (x-1)/n where x is a positive integer and mu exists.
 
uint64_t choose_g_in_vec_64t_v2 (std::vector< uint64_t > &set)
 Choose g from the set of elements in (Z/n²Z)*.
 
uint64_t L_64t (uint64_t x, uint64_t n)
 Calculate L(x).
 
uint64_t lcm_64t (uint64_t a, uint64_t b)
 Calculate the least common multiple (LCM) of two 64-bit unsigned integers.
 
uint64_t modInverse_64t (uint64_t a, uint64_t n)
 Calculate the modular inverse of a 64-bit unsigned integer modulo a modulus.
 
uint64_t pow_uint64_t (uint64_t x, uint64_t n)
 Calculate the power of a 64-bit unsigned integer.
 
uint64_t randomZNStar (uint64_t n)
 Choose a random element from the set Z/nZ*.
 
std::vector< uint64_t > get_set_ZNZStar (uint64_t n)
 Return the set Z/nZ* as a vector.
 
std::vector< uint64_t > get_set_ZN2ZStar (uint64_t n, uint64_t lambda)
 Return the set Z/n²Z* that satisfy the condition gcd(L(g^lambda mod n²), n) = 1 as a vector.
 
uint64_t generate_g_64t (uint64_t n, uint64_t lambda)
 Generate g for Paillier cryptosystem.
 
void generateMu_64t (uint64_t &mu, const uint64_t &g, const uint64_t &lambda, const uint64_t &n)
 Generate Mu for Paillier cryptosystem.
 
void generatePrivateKey_64t (uint64_t &lambda, uint64_t &mu, const uint64_t &p, const uint64_t &q, const uint64_t &n, const uint64_t &g)
 Generate private key for Paillier cryptosystem.
 
T_out paillierEncryption (uint64_t n, uint64_t g, T_in m)
 Encrypt a message using Paillier cryptosystem.
 
T_out paillierEncryption (uint64_t n, uint64_t g, T_in m, uint64_t r)
 Encrypt a message using Paillier cryptosystem with a given random value.
 
T_in paillierDecryption (uint64_t n, uint64_t lambda, uint64_t mu, T_out c)
 Decrypt a ciphertext using Paillier cryptosystem.
 

Detailed Description

template<typename T_in, typename T_out>
class Paillier< T_in, T_out >

This class implements the Paillier cryptosystem.

Template Parameters
T_inThe input data type.
T_outThe output data type.
Author
Katia Auxilien
Date
April 2024 - May 2024

Constructor & Destructor Documentation

◆ Paillier()

template<typename T_in , typename T_out >
Paillier< T_in, T_out >::Paillier ( )
inline

Construct a new Paillier object.

Author
Katia Auxilien
Date
April 2024 - May 2024

◆ ~Paillier()

template<typename T_in , typename T_out >
Paillier< T_in, T_out >::~Paillier ( )
inline

Destroy the Paillier object.

Author
Katia Auxilien
Date
April 2024 - May 2024

Member Function Documentation

◆ calc_set_same_remainder_divide_euclide_64t()

template<typename T_in , typename T_out >
std::vector< uint64_t > Paillier< T_in, T_out >::calc_set_same_remainder_divide_euclide_64t ( uint64_t n)
inline

Calculate the set of elements in (Z/n²Z)*.

Deprecated
This function is not sufficient for Paillier cryptosystem.

This function calculates the set of elements in (Z/n²Z)* that are coprime to n.

Parameters
uint64_tn - The n parameter of public key.
Returns
std::vector<uint64_t> - The set of elements in (Z/n²Z)* that are coprime to n.
Authors
Katia Auxilien
Date
30 April 2024 15:51:00

◆ calc_set_same_remainder_divide_euclide_64t_v2()

template<typename T_in , typename T_out >
std::vector< uint64_t > Paillier< T_in, T_out >::calc_set_same_remainder_divide_euclide_64t_v2 ( uint64_t n,
const uint64_t & lambda )
inline

Calculate the set of elements in (Z/n²Z)* that satisfy the condition L(x) = (x-1)/n where x is a positive integer and mu exists.

Deprecated
This function is not sufficient for Paillier cryptosystem.

This function calculates the set of elements in (Z/n²Z)* that satisfy the condition L(x) = (x-1)/n where x is a positive integer and mu exists.

Parameters
uint64_tn - The n parameter of public key.
constuint64_t &lambda - The lambda parameter of private key.
Returns
std::vector<uint64_t> - The set of elements in (Z/n²Z)* that satisfy the condition L(x) = (x-1)/n where x is a positive integer and mu exists.
Authors
Katia Auxilien
Date
22 May 2024 14:45:00

◆ choose_g_in_vec_64t()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::choose_g_in_vec_64t ( std::vector< uint64_t > & set,
const uint64_t & n,
const uint64_t & lambda )
inline

Choose g from the set of elements in (Z/n²Z)* that satisfy the condition L(x) = (x-1)/n where x is a positive integer and mu exists.

Deprecated
This function is not sufficient for Paillier cryptosystem.

This function chooses g from the set of elements in (Z/n²Z)* that satisfy the condition L(x) = (x-1)/n where x is a positive integer and mu exists.

Parameters
std::vector<uint64_t>&set - The set of elements in (Z/n²Z)* that satisfy the condition L(x) = (x-1)/n where x is a positive integer and mu exists.
constuint64_t &n - The n parameter of public key.
constuint64_t &lambda - The lambda parameter of private key.
Returns
uint64_t - The chosen value of g.
Authors
Katia Auxilien
Date
02 May 2024

◆ choose_g_in_vec_64t_v2()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::choose_g_in_vec_64t_v2 ( std::vector< uint64_t > & set)
inline

Choose g from the set of elements in (Z/n²Z)*.

Deprecated
This function is not sufficient for Paillier cryptosystem.

This function chooses g from the set of elements in (Z/n²Z)*.

Parameters
std::vector<uint64_t>&set - The set of elements in (Z/n²Z)*.
Returns
uint64_t - The chosen value of g.
Authors
Katia Auxilien
Date
22 May 2024 14:45:00

◆ fastMod_64t()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::fastMod_64t ( uint64_t x,
uint64_t e,
uint64_t n )
inline

Calculate the modular exponentiation of a base raised to a power modulo a modulus.

This function calculates the modular exponentiation of a base raised to a power modulo a modulus using the square-and-multiply algorithm.

Parameters
uint64_tx - The base value.
uint64_te - The exponent value.
uint64_tn - The n parameter of public key.
Returns
uint64_t - The result of the modular exponentiation.
Author
Bianca Jansen Van Rensburg
Date
30 April 2024

◆ gcd_64t()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::gcd_64t ( uint64_t a,
uint64_t b )
inline

Calculate the greatest common divisor (GCD) of two 64-bit unsigned integers.

This function calculates the greatest common divisor (GCD) of two 64-bit unsigned integers using the Euclidean algorithm.

Parameters
uint64_ta - The first integer.
uint64_tb - The second integer.
Returns
uint64_t - The greatest common divisor of a and b.
Authors
Bianca Jansen Van Rensburg
Date
30 April 2024

◆ generate_g_64t()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::generate_g_64t ( uint64_t n,
uint64_t lambda )
inline

Generate g for Paillier cryptosystem.

This function generates g for Paillier cryptosystem such that gcd(L(g^lambda mod n²), n) = 1 where L(u) = (u-1)/n. From program Paillier.java (https://perso.liris.cnrs.fr/omar.hasan/pprs/paillierdemo/) developped by Omar Hasan.

Parameters
uint64_tn - The n parameter of public key.
uint64_tlambda - The lambda parameter of private key.
Returns
uint64_t - The generated value of g.
Authors
Katia Auxilien
Date
23 May 2024 15:00:00

◆ generateMu_64t()

template<typename T_in , typename T_out >
void Paillier< T_in, T_out >::generateMu_64t ( uint64_t & mu,
const uint64_t & g,
const uint64_t & lambda,
const uint64_t & n )
inline

Generate Mu for Paillier cryptosystem.

This function generates Mu for Paillier cryptosystem which is used in the decryption process.

Parameters
uint64_t&mu - The generated value of Mu.
constuint64_t &g - The generator value.
constuint64_t &lambda - The Carmichael function of n.
constuint64_t &n - The modulus value.
Author
Bianca Jansen Van Rensburg
Date
?

◆ generatePrivateKey_64t()

template<typename T_in , typename T_out >
void Paillier< T_in, T_out >::generatePrivateKey_64t ( uint64_t & lambda,
uint64_t & mu,
const uint64_t & p,
const uint64_t & q,
const uint64_t & n,
const uint64_t & g )
inline

Generate private key for Paillier cryptosystem.

This function generates the private key for Paillier cryptosystem which consists of lambda and Mu values.

Parameters
uint64_t&lambda - The generated value of lambda.
uint64_t&mu - The generated value of Mu.
constuint64_t &p - The first prime factor of n.
constuint64_t &q - The second prime factor of n.
constuint64_t &n - The n parameter of public key.
constuint64_t &g - The generator value.
Author
Bianca Jansen Van Rensburg

◆ get_set_ZN2ZStar()

template<typename T_in , typename T_out >
std::vector< uint64_t > Paillier< T_in, T_out >::get_set_ZN2ZStar ( uint64_t n,
uint64_t lambda )
inline

Return the set Z/n²Z* that satisfy the condition gcd(L(g^lambda mod n²), n) = 1 as a vector.

This function returns the set Z/n²Z* that satisfy the condition gcd(L(g^lambda mod n²), n) = 1 as a vector.

Parameters
uint64_tn - The n parameter of public key.
uint64_tlambda - The lambda parameter of private key.
Returns
std::vector<uint64_t> - The set Z/n²Z* that satisfy the condition gcd(L(g^lambda mod n²), n) = 1 as a vector.
Author
Katia Auxilien
Date
27 May 2024 15:00:00

◆ get_set_ZNZStar()

template<typename T_in , typename T_out >
std::vector< uint64_t > Paillier< T_in, T_out >::get_set_ZNZStar ( uint64_t n)
inline

Return the set Z/nZ* as a vector.

This function returns the set Z/nZ* as a vector.

Parameters
uint64_tn - The n parameter of public key.
Returns
std::vector<uint64_t> - The set Z/nZ* as a vector.
Author
Katia Auxilien
Date
23 May 2024 9:18:00

◆ L_64t()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::L_64t ( uint64_t x,
uint64_t n )
inline

Calculate L(x).

This function calculates L(x) which is used in the generation of Mu and the decryption by Paillier.

Parameters
uint64_tx - The value of x.
uint64_tn - The n parameter of public key.
Returns
uint64_t - The value of L(x).
Author
Bianca Jansen Van Rensburg

◆ lcm_64t()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::lcm_64t ( uint64_t a,
uint64_t b )
inline

Calculate the least common multiple (LCM) of two 64-bit unsigned integers.

This function calculates the least common multiple (LCM) of two 64-bit unsigned integers using the GCD function.

Parameters
uint64_ta - The first integer.
uint64_tb - The second integer.
Returns
uint64_t - The least common multiple of a and b.
Author
Bianca Jansen Van Rensburg

◆ modInverse_64t()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::modInverse_64t ( uint64_t a,
uint64_t n )
inline

Calculate the modular inverse of a 64-bit unsigned integer modulo a modulus.

This function calculates the modular inverse of a 64-bit unsigned integer modulo a modulus using the extended Euclidean algorithm.

Parameters
uint64_ta - The integer to calculate the modular inverse of.
uint64_tn - The n parameter of public key.
Returns
uint64_t - The modular inverse of a modulo n.
Author
Bianca Jansen Van Rensburg

◆ paillierDecryption()

template<typename T_in , typename T_out >
T_in Paillier< T_in, T_out >::paillierDecryption ( uint64_t n,
uint64_t lambda,
uint64_t mu,
T_out c )
inline

Decrypt a ciphertext using Paillier cryptosystem.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function decrypts a ciphertext using Paillier cryptosystem.

Parameters
uint64_tn - The modulus value.
uint64_tlambda - The Carmichael function of n.
uint64_tmu - The Mu value.
T_outc - The ciphertext to be decrypted.
Returns
T_in - The decrypted message.
Authors
Bianca Jansen Van Rensburg, Katia Auxilien
Date
13 May 2024

◆ paillierEncryption() [1/2]

template<typename T_in , typename T_out >
T_out Paillier< T_in, T_out >::paillierEncryption ( uint64_t n,
uint64_t g,
T_in m )
inline

Encrypt a message using Paillier cryptosystem.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function encrypts a message using Paillier cryptosystem.

Parameters
uint64_tn - The modulus value.
uint64_tg - The generator value.
T_inm - The message to be encrypted.
Returns
T_out - The encrypted message.
Authors
Bianca Jansen Van Rensburg, Katia Auxilien
Date
13 May 2024

◆ paillierEncryption() [2/2]

template<typename T_in , typename T_out >
T_out Paillier< T_in, T_out >::paillierEncryption ( uint64_t n,
uint64_t g,
T_in m,
uint64_t r )
inline

Encrypt a message using Paillier cryptosystem with a given random value.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function encrypts a message using Paillier cryptosystem with a given random value.

Parameters
uint64_tn - The modulus value.
uint64_tg - The generator value.
T_inm - The message to be encrypted.
uint64_tr - The random value.
Returns
T_out - The encrypted message.
Authors
Bianca Jansen Van Rensburg, Katia Auxilien
Date
13 May 2024

◆ pow_uint64_t()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::pow_uint64_t ( uint64_t x,
uint64_t n )
inline

Calculate the power of a 64-bit unsigned integer.

This function calculates the power of a 64-bit unsigned integer using recursion.

Parameters
uint64_tx - The base value.
uint64_tn - The exponent value.
Returns
uint64_t - The result of the power calculation.
Author
Katia Auxilien
Date
30 April 2024

◆ random64()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::random64 ( uint64_t min,
uint64_t max )
inline

Generate a random 64-bit unsigned integer.

This function generates a random 64-bit unsigned integer between a given range using the Mersenne Twister algorithm.

Parameters
uint64_tmin - The minimum value of the range.
uint64_tmax - The maximum value of the range.
Returns
uint64_t - A random 64-bit unsigned integer between min and max.
Author
Katia Auxilien
Date
23 May 2024

◆ randomZNStar()

template<typename T_in , typename T_out >
uint64_t Paillier< T_in, T_out >::randomZNStar ( uint64_t n)
inline

Choose a random element from the set Z/nZ*.

This function chooses a random element from the set Z/nZ*. From program Paillier.java (https://perso.liris.cnrs.fr/omar.hasan/pprs/paillierdemo/) developped by Omar Hasan.

Parameters
uint64_tn - The n parameter of public key.
Returns
uint64_t - The chosen random element from the set Z/nZ*.
Parameters

author Katia Auxilien

Date
23 May 2024 15:00:00