Class alice
java.lang.Object
edu.fiu.adwise.homomorphic_encryption.socialistmillionaire.socialist_millionaires
edu.fiu.adwise.homomorphic_encryption.socialistmillionaire.alice
- All Implemented Interfaces:
CipherConstants,alice_interface
- Direct Known Subclasses:
alice_joye,alice_veugen
The
alice class represents Alice in the Socialist Millionaire's Problem.
It implements the alice_interface and extends socialist_millionaires.
This class provides methods for secure equality testing and other cryptographic operations
using homomorphic encryption techniques.
This specific class implements the first generation of encrypted comparison protocols
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondivision(BigInteger x, long d) Please review Protocol 2 in the "Encrypted Integer Division" paper by Thjis VeugenbooleanPerforms encrypted equality testing between two encrypted valuesaandb.encrypted_xor(BigInteger x, BigInteger[] Encrypted_Y) Computes the XOR operation between the bits of a plaintext value and an array of encrypted bits.getKValues(BigInteger[] input, int k, boolean smallest_first) Retrieves the k largest or smallest values from the input array using a bubble sort algorithm.getKValues(List<BigInteger> input, int k, boolean smallest_first) Retrieves the k largest or smallest values from the input list using a bubble sort algorithm.See the paper "Correction of a Secure Comparison Protocol for Encrypted Integers in IEEE WIFS 2012 (Short Paper)" Performs secure multiplication of two encrypted values using homomorphic encryption.booleanPerforms an equality check as part of the encrypted equality testing protocol.booleanExecutes Protocol 1 to securely compute whetherx <= yin a two-party setting.booleanProtocol2(BigInteger x, BigInteger y) Executes Protocol 2 to securely compute whether X >= Y in a two-party setting.voidReceives public keys from Bob and sets them for Alice.voidset_dgk_private_key(DGKPrivateKey dgk_private) Sets the DGK private key for Alice.voidset_socket(Socket socket) Sets up the socket for communication with Bob using a standardSocket.Methods inherited from class edu.fiu.adwise.homomorphic_encryption.socialistmillionaire.socialist_millionaires
get_bytes_sent, getDGKPublicKey, getElGamalPublicKey, getPaillierPublicKey, isDGK, readBoolean, readInt, readObject, setDGKMode, setDGKPublicKey, setElGamalPublicKey, setPaillierPublicKey, writeBoolean, writeInt, writeObject
-
Constructor Details
-
alice
public alice()Default constructor for thealiceclass. Initializes theisDGKflag tofalse. -
alice
Constructor for thealiceclass that accepts a client socket.- Parameters:
clientSocket- the client socket to communicate with Bob.- Throws:
IOException- if an I/O error occurs when setting up the socket.NullPointerException- if the providedclientSocketisnull.
-
-
Method Details
-
set_socket
Sets up the socket for communication with Bob using a standardSocket.- Specified by:
set_socketin interfacealice_interface- Parameters:
socket- the socket to communicate with Bob.- Throws:
IOException- if an I/O error occurs when setting up the socket.
-
encrypted_equals
public boolean encrypted_equals(BigInteger a, BigInteger b) throws HomomorphicException, IOException, ClassNotFoundException Performs encrypted equality testing between two encrypted valuesaandb. Implements "Protocol 1 EQT-1" from the paper "Secure Equality Testing Protocols in the Two-Party Setting".- Specified by:
encrypted_equalsin interfacealice_interface- Parameters:
a- the first encrypted value.b- the second encrypted value.- Returns:
trueif the two values are equal,falseotherwise.- Throws:
HomomorphicException- if a homomorphic encryption error occurs.IOException- if an I/O error occurs during communication.ClassNotFoundException- if a class cannot be found during deserialization.
-
private_equals
public boolean private_equals(BigInteger r) throws HomomorphicException, IOException, ClassNotFoundException Performs an equality check as part of the encrypted equality testing protocol. This function is 'protected' as it is used by the public 'encrypted_equals' function- Parameters:
r- the random value used in the protocol.- Returns:
trueif the two values are equal,falseotherwise.- Throws:
HomomorphicException- if a homomorphic encryption error occurs.IOException- if an I/O error occurs during communication.ClassNotFoundException- if a class cannot be found during deserialization.
-
Protocol1
public boolean Protocol1(BigInteger x) throws IOException, IllegalArgumentException, HomomorphicException, ClassNotFoundException Executes Protocol 1 to securely compute whetherx <= yin a two-party setting. This protocol uses homomorphic encryption to ensure privacy during the comparison.- Specified by:
Protocol1in interfacealice_interface- Parameters:
x- the plaintext value to compare.- Returns:
trueifx <= y,falseotherwise.- Throws:
IOException- if an I/O error occurs during communication.ClassNotFoundException- if a class cannot be found during deserialization.IllegalArgumentException- if the bit length of X exceeds the limit defined by the DGK public key.HomomorphicException- if an error occurs during homomorphic operations.
-
Protocol2
public boolean Protocol2(BigInteger x, BigInteger y) throws IOException, ClassNotFoundException, HomomorphicException Executes Protocol 2 to securely compute whether X >= Y in a two-party setting. This protocol uses homomorphic encryption to ensure privacy during the comparison.- Specified by:
Protocol2in interfacealice_interface- Parameters:
x- the encrypted value of X (Paillier or DGK encrypted).y- the encrypted value of Y (Paillier or DGK encrypted).- Returns:
trueifx >= y,falseotherwise.- Throws:
IOException- if an I/O error occurs during communication.ClassNotFoundException- if a class cannot be found during deserialization.HomomorphicException- if an error occurs during homomorphic operations.IllegalArgumentException- if the protocol is used with unsupported encryption schemes or invalid parameters.
-
division
public BigInteger division(BigInteger x, long d) throws IOException, ClassNotFoundException, HomomorphicException Please review Protocol 2 in the "Encrypted Integer Division" paper by Thjis Veugen- Specified by:
divisionin interfacealice_interface- Parameters:
x- - Encrypted Paillier value or Encrypted DGK valued- - plaintext divisor- Returns:
- the result of the division as an encrypted integer.
- Throws:
IOException- - Any socket errorsHomomorphicException- if the constraints0 <= x <= N * 2^(-sigma)or0 <= d < Nare violated.ClassNotFoundException- if the class of a serialized object cannot be found.
-
multiplication
public BigInteger multiplication(BigInteger x, BigInteger y) throws IOException, ClassNotFoundException, IllegalArgumentException, HomomorphicException See the paper "Correction of a Secure Comparison Protocol for Encrypted Integers in IEEE WIFS 2012 (Short Paper)" Performs secure multiplication of two encrypted values using homomorphic encryption. This method ensures privacy by adding random blinding factors to the inputs before computation. The protocol involves communication with Bob to compute the product securely. by Mau et al.- Specified by:
multiplicationin interfacealice_interface- Parameters:
x- the first encrypted value.y- the second encrypted value.- Returns:
- the encrypted result of the multiplication \( x \times y \).
- Throws:
IOException- if an I/O error occurs during communication.ClassNotFoundException- if a class cannot be found during deserialization.IllegalArgumentException- if the received object is not of the expected type.HomomorphicException- if an error occurs during homomorphic operations.
-
set_dgk_private_key
Sets the DGK private key for Alice. This key is used for decryption and other operations in the DGK cryptosystem. You should NOT be using this function! This is only here to help with testing! Alice should never be getting Bob's private key!!!!- Parameters:
dgk_private- the DGK private key to be set.
-
receivePublicKeys
Receives public keys from Bob and sets them for Alice. This method handles DGK, Paillier, and ElGamal public keys. If a specific key is not received, the corresponding field is set to null.- Specified by:
receivePublicKeysin interfacealice_interface- Throws:
IOException- if an I/O error occurs during communication.ClassNotFoundException- if a class cannot be found during deserialization.
-
getKValues
public BigInteger[] getKValues(BigInteger[] input, int k, boolean smallest_first) throws ClassNotFoundException, IOException, IllegalArgumentException, HomomorphicException Retrieves the k largest or smallest values from the input array using a bubble sort algorithm. The method can sort the entire array or only extract the k largest/smallest values.- Specified by:
getKValuesin interfacealice_interface- Parameters:
input- the array of BigInteger values to process.k- the number of values to retrieve.smallest_first- if true, retrieves the k smallest values; otherwise, retrieves the k largest values.- Returns:
- an array containing the k largest or smallest values.
- Throws:
ClassNotFoundException- if a class cannot be found during deserialization.IOException- if an I/O error occurs during communication.IllegalArgumentException- if k is invalid or out of bounds.HomomorphicException- if an error occurs during homomorphic operations.
-
getKValues
public BigInteger[] getKValues(List<BigInteger> input, int k, boolean smallest_first) throws ClassNotFoundException, IOException, IllegalArgumentException, HomomorphicException Retrieves the k largest or smallest values from the input list using a bubble sort algorithm. The method can sort the entire list or only extract the k largest/smallest values. This operation involves secure comparisons using homomorphic encryption.- Specified by:
getKValuesin interfacealice_interface- Parameters:
input- the list of BigInteger values to process.k- the number of values to retrieve.smallest_first- if true, retrieves the k smallest values; otherwise, retrieves the k largest values.- Returns:
- an array containing the k largest or smallest values.
- Throws:
ClassNotFoundException- if a class cannot be found during deserialization.IOException- if an I/O error occurs during communication.IllegalArgumentException- if k is invalid or out of bounds.HomomorphicException- if an error occurs during homomorphic operations.
-
encrypted_xor
public BigInteger[] encrypted_xor(BigInteger x, BigInteger[] Encrypted_Y) throws HomomorphicException Computes the XOR operation between the bits of a plaintext value and an array of encrypted bits. The XOR operation is performed bit by bit, ensuring compatibility with homomorphic encryption. If the encrypted array is shorter than the plaintext value, missing bits are treated as zeros.This is a function used for all versions of Alice
- Parameters:
x- the plaintext value whose bits are XORed.Encrypted_Y- the array of encrypted bits to XOR with the bits ofx.- Returns:
- an array of encrypted XOR results.
- Throws:
HomomorphicException- if an error occurs during homomorphic operations.
-