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

public class alice extends socialist_millionaires implements alice_interface
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

  • Constructor Details

    • alice

      public alice()
      Default constructor for the alice class. Initializes the isDGK flag to false.
    • alice

      public alice(Socket clientSocket) throws IOException
      Constructor for the alice class 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 provided clientSocket is null.
  • Method Details

    • set_socket

      public void set_socket(Socket socket) throws IOException
      Sets up the socket for communication with Bob using a standard Socket.
      Specified by:
      set_socket in interface alice_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 values a and b. Implements "Protocol 1 EQT-1" from the paper "Secure Equality Testing Protocols in the Two-Party Setting".
      Specified by:
      encrypted_equals in interface alice_interface
      Parameters:
      a - the first encrypted value.
      b - the second encrypted value.
      Returns:
      true if the two values are equal, false otherwise.
      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:
      true if the two values are equal, false otherwise.
      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

      Executes Protocol 1 to securely compute whether x <= y in a two-party setting. This protocol uses homomorphic encryption to ensure privacy during the comparison.
      Specified by:
      Protocol1 in interface alice_interface
      Parameters:
      x - the plaintext value to compare.
      Returns:
      true if x <= y, false otherwise.
      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

      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:
      Protocol2 in interface alice_interface
      Parameters:
      x - the encrypted value of X (Paillier or DGK encrypted).
      y - the encrypted value of Y (Paillier or DGK encrypted).
      Returns:
      true if x >= y, false otherwise.
      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

      Please review Protocol 2 in the "Encrypted Integer Division" paper by Thjis Veugen
      Specified by:
      division in interface alice_interface
      Parameters:
      x - - Encrypted Paillier value or Encrypted DGK value
      d - - plaintext divisor
      Returns:
      the result of the division as an encrypted integer.
      Throws:
      IOException - - Any socket errors
      HomomorphicException - if the constraints 0 <= x <= N * 2^(-sigma) or 0 <= d < N are violated.
      ClassNotFoundException - if the class of a serialized object cannot be found.
    • multiplication

      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:
      multiplication in interface alice_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

      public void set_dgk_private_key(DGKPrivateKey dgk_private)
      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

      public void receivePublicKeys() throws IOException, ClassNotFoundException
      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:
      receivePublicKeys in interface alice_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:
      getKValues in interface alice_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:
      getKValues in interface alice_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 of x.
      Returns:
      an array of encrypted XOR results.
      Throws:
      HomomorphicException - if an error occurs during homomorphic operations.