Class DGKOperations
java.lang.Object
edu.fiu.adwise.homomorphic_encryption.dgk.DGKOperations
- All Implemented Interfaces:
CipherConstants
DGKOperations is responsible for all the basic DGK functions.
Note, we denote x, y as plaintext values and [x] and [y] as the encrypted version of x and y.
The functions are:
- Encrypt x -> [x]
- Decrypt [x] -> x
- Add two ciphertexts [x] + [y] -> [x + y]
- Add a ciphertext and plaintext [x] + y -> [x + y]
- Subtract two ciphertexts [x] - [y] -> [x - y]
- Subtract a ciphertext and plaintext [x] - y -> [x - y]
- Subtract a plaintext and ciphertext y - [x] -> [y - x]
- Multiply a ciphertext and plaintext [x] * y -> [x * y]
- Divide a ciphertext by plaintext [x] / y -> [x / y] THIS ONLY WORKS IF YOU KNOW YOU HAVE A PERFECT DIVISOR
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic BigIntegeradd(BigInteger ciphertext1, BigInteger ciphertext2, DGKPublicKey public_key) returns the sum of the two DGK encrypted values Note: The result is still encrypted Warning: If the sum exceeds N, it is subject to Nstatic BigIntegeradd_plaintext(BigInteger ciphertext, long plaintext, DGKPublicKey public_key) returns the sum of the DGK encrypted value and plaintext value Warning: If the sum exceeds u, it is subject to mod ustatic BigIntegeradd_plaintext(BigInteger ciphertext, BigInteger plaintext, DGKPublicKey public_key) returns the sum of the DGK encrypted value and plaintext value Warning: If the sum exceeds u, it is subject to mod ustatic longdecrypt(BigInteger ciphertext, DGKPrivateKey private_key) Compute DGK decryption c = g^m * h^r (mod n) c^vp (mod p) = g^{vp*m} (mod p), Because h^{vp} (mod p) = 1 Use the pre-computed hashmap to retrieve m.static BigIntegerdivide(BigInteger ciphertext, BigInteger plaintext, DGKPublicKey public_key) Compute the division of the DGK cipher-text and a plaintext.static BigIntegerencrypt(long plaintext, DGKPublicKey public_key) Encrypt plaintext with DGK Public Key Compute ciphertext = g^{m}h^{r} (mod n)static BigIntegerencrypt(BigInteger plaintext, DGKPublicKey public_key) Encrypt plaintext with DGK Public Key Compute ciphertext = g^{m}h^{r} (mod n)static BigIntegermultiply(BigInteger ciphertext, long plaintext, DGKPublicKey public_key) Compute the DGK encrypted value of ciphertext multiplied by the plaintext.static BigIntegermultiply(BigInteger ciphertext, BigInteger plaintext, DGKPublicKey public_key) Compute the DGK encrypted value of ciphertext multiplied by the plaintext.static BigIntegersubtract(BigInteger ciphertext1, BigInteger ciphertext2, DGKPublicKey public_key) Subtract ciphertext1 and ciphertext 2static BigIntegersubtract_ciphertext(BigInteger plaintext, BigInteger ciphertext, DGKPublicKey public_key) y - [x] = y + [-x] = [-x] + y Computes encrypted DGK value of the cipher-text subtracted by the plaintextstatic BigIntegersubtract_plaintext(BigInteger ciphertext, BigInteger plaintext, DGKPublicKey public_key) Computes encrypted DGK value of the cipher-text subtracted by the plaintext Warning: If the difference goes negative, add u.static BigIntegersum(BigInteger[] parts, DGKPublicKey public_key) Compute the sum of the encrypted DGK valuesstatic BigIntegersum(BigInteger[] values, DGKPublicKey public_key, int limit) Compute the sum of the encrypted DGK valuesstatic BigIntegersum(List<BigInteger> values, DGKPublicKey public_key) Compute the sum of the encrypted DGK valuesstatic BigIntegersum(List<BigInteger> values, DGKPublicKey public_key, int limit) Compute the sum of the encrypted DGK valuesstatic BigIntegersum_product(BigInteger[] ciphertext, Long[] plaintext, DGKPublicKey public_key) Compute the sum-product.static BigIntegersum_product(List<BigInteger> ciphertext, List<Long> plaintext, DGKPublicKey public_key) Compute the sum-product.
-
Constructor Details
-
DGKOperations
public DGKOperations()
-
-
Method Details
-
encrypt
public static BigInteger encrypt(long plaintext, DGKPublicKey public_key) throws HomomorphicException Encrypt plaintext with DGK Public Key Compute ciphertext = g^{m}h^{r} (mod n)- Parameters:
plaintext- - plaintext value to be encryptedpublic_key- - use this to encrypt plaintext- Returns:
- - DGK ciphertext of the plaintext
- Throws:
HomomorphicException- - If the plaintext is larger than the plaintext supported by DGK Public Key an exception will be thrown
-
encrypt
public static BigInteger encrypt(BigInteger plaintext, DGKPublicKey public_key) throws HomomorphicException Encrypt plaintext with DGK Public Key Compute ciphertext = g^{m}h^{r} (mod n)- Parameters:
plaintext- - plaintext value to be encryptedpublic_key- - use this to encrypt plaintext- Returns:
- - DGK ciphertext of the plaintext
- Throws:
HomomorphicException- - If the plaintext is larger than the plaintext supported by DGK Public Key an exception will be thrown
-
decrypt
public static long decrypt(BigInteger ciphertext, DGKPrivateKey private_key) throws HomomorphicException Compute DGK decryption c = g^m * h^r (mod n) c^vp (mod p) = g^{vp*m} (mod p), Because h^{vp} (mod p) = 1 Use the pre-computed hashmap to retrieve m.- Parameters:
ciphertext- - DGK ciphertextprivate_key- - used to decrypt ciphertext- Returns:
- plaintext
- Throws:
HomomorphicException- - If the ciphertext is larger than the ciphertext supported by DGK Public Key an exception will be thrown
-
add
public static BigInteger add(BigInteger ciphertext1, BigInteger ciphertext2, DGKPublicKey public_key) throws HomomorphicException returns the sum of the two DGK encrypted values Note: The result is still encrypted Warning: If the sum exceeds N, it is subject to N- Parameters:
ciphertext1- - Encrypted DGK valueciphertext2- - Encrypted DGK valuepublic_key- - used to encrypt both ciphertexts- Returns:
- the encrypted sum of both DGK encrypted values
- Throws:
HomomorphicException- - If either ciphertext is greater than N or negative, throw an exception
-
add_plaintext
public static BigInteger add_plaintext(BigInteger ciphertext, BigInteger plaintext, DGKPublicKey public_key) throws HomomorphicException returns the sum of the DGK encrypted value and plaintext value Warning: If the sum exceeds u, it is subject to mod u- Parameters:
ciphertext- - DGK encrypted valueplaintext- - plaintext valuepublic_key- - was used to encrypt ciphertext- Returns:
- Encrypted sum of ciphertext and plaintext
- Throws:
HomomorphicException- - If a ciphertext is negative or exceeds N, or plaintext is negative or exceeds u
-
add_plaintext
public static BigInteger add_plaintext(BigInteger ciphertext, long plaintext, DGKPublicKey public_key) throws HomomorphicException returns the sum of the DGK encrypted value and plaintext value Warning: If the sum exceeds u, it is subject to mod u- Parameters:
ciphertext- - DGK encrypted valueplaintext- - plaintext valuepublic_key- - was used to encrypt ciphertext- Returns:
- Encrypted sum of ciphertext and plaintext
- Throws:
HomomorphicException- - If a ciphertext is negative or exceeds N, or plaintext is negative or exceeds u
-
subtract
public static BigInteger subtract(BigInteger ciphertext1, BigInteger ciphertext2, DGKPublicKey public_key) throws HomomorphicException Subtract ciphertext1 and ciphertext 2- Parameters:
ciphertext1- - Encrypted DGK valueciphertext2- - Encrypted DGK valuepublic_key- - used to encrypt both ciphertexts- Returns:
- DGK encrypted ciphertext with ciphertext1 - ciphertext2
- Throws:
HomomorphicException- - If an invalid input was found
-
subtract_plaintext
public static BigInteger subtract_plaintext(BigInteger ciphertext, BigInteger plaintext, DGKPublicKey public_key) throws HomomorphicException Computes encrypted DGK value of the cipher-text subtracted by the plaintext Warning: If the difference goes negative, add u.- Parameters:
ciphertext- - Encrypted DGK valueplaintext- - plaintext valuepublic_key- - used to encrypt ciphertext- Returns:
- DGK encrypted ciphertext with ciphertext1 - ciphertext2
- Throws:
HomomorphicException- - If an invalid input was found
-
subtract_ciphertext
public static BigInteger subtract_ciphertext(BigInteger plaintext, BigInteger ciphertext, DGKPublicKey public_key) throws HomomorphicException y - [x] = y + [-x] = [-x] + y Computes encrypted DGK value of the cipher-text subtracted by the plaintext- Parameters:
plaintext- - plaintext valueciphertext- - Encrypted DGK valuepublic_key- - used to encrypt ciphertext- Returns:
- DGK encrypted ciphertext with plaintext - ciphertext
- Throws:
HomomorphicException- - If an invalid input was found
-
multiply
public static BigInteger multiply(BigInteger ciphertext, BigInteger plaintext, DGKPublicKey public_key) throws HomomorphicException Compute the DGK encrypted value of ciphertext multiplied by the plaintext.- Parameters:
ciphertext- - DGK encrypted valueplaintext- - plaintext valuepublic_key- - DGK Public key the encrypted ciphertext- Returns:
- product - the encrypted product of the ciphertext and the plaintext
- Throws:
HomomorphicException- - If ciphertext is negative or exceeds N or plaintext exceeds u
-
multiply
public static BigInteger multiply(BigInteger ciphertext, long plaintext, DGKPublicKey public_key) throws HomomorphicException Compute the DGK encrypted value of ciphertext multiplied by the plaintext.- Parameters:
ciphertext- - DGK encrypted valueplaintext- - plaintext valuepublic_key- - DGK Public key the encrypted ciphertext- Returns:
- product - the encrypted product of ciphertext and the plaintext value
- Throws:
HomomorphicException- - If ciphertext is negative or exceeds N or plaintext exceeds u
-
divide
public static BigInteger divide(BigInteger ciphertext, BigInteger plaintext, DGKPublicKey public_key) throws HomomorphicException Compute the division of the DGK cipher-text and a plaintext. Warning: Divide will only work correctly on perfect divisor like 2|20, it will work. If you try 3|20, it will NOT work, and you will get a wrong answer! If you want to do 3|20, you MUST use a division protocol from Veugen paper- Parameters:
ciphertext- - DGK ciphertextplaintext- -plaintext valuepublic_key- - was used to encrypt ciphertext- Returns:
- Encrypted DGK value equal to ciphertext/plaintext
- Throws:
HomomorphicException- - If an invalid input was found
-
sum
public static BigInteger sum(BigInteger[] parts, DGKPublicKey public_key) throws HomomorphicException Compute the sum of the encrypted DGK values- Parameters:
parts- - Array of Encrypted DGK valuespublic_key- - DGKPublicKey used to encrypt all the values- Returns:
- sum - the encrypted sum of all encrypted values in the array
- Throws:
HomomorphicException- - If an invalid input was found
-
sum
public static BigInteger sum(BigInteger[] values, DGKPublicKey public_key, int limit) throws HomomorphicException Compute the sum of the encrypted DGK values- Parameters:
values- - Array of Encrypted DGK valuespublic_key- - DGKPublicKey used to encrypt the valueslimit- - Sum values up to this index value in the list- Returns:
- sum - the encrypted sum of all values in the array
- Throws:
HomomorphicException- - If an invalid input was found
-
sum
public static BigInteger sum(List<BigInteger> values, DGKPublicKey public_key) throws HomomorphicException Compute the sum of the encrypted DGK values- Parameters:
values- - List of Encrypted DGK valuespublic_key- - DGKPublicKey used to encrypt the values- Returns:
- sum - the encrypted sum of all values in the list
- Throws:
HomomorphicException- - If an invalid input was found
-
sum
public static BigInteger sum(List<BigInteger> values, DGKPublicKey public_key, int limit) throws HomomorphicException Compute the sum of the encrypted DGK values- Parameters:
values- - List of Encrypted DGK valuespublic_key- - DGKPublicKey used to encrypt the valueslimit- - Sum values up to this index value in the list- Returns:
- sum - the encrypted sum of all values in the list
- Throws:
HomomorphicException- - If an invalid input was found
-
sum_product
public static BigInteger sum_product(List<BigInteger> ciphertext, List<Long> plaintext, DGKPublicKey public_key) throws HomomorphicException Compute the sum-product. It computes the scalar multiplication between the array of Encrypted and plaintext values. Then it computes the encrypted sum.- Parameters:
ciphertext- - List of Encrypted DGK valuesplaintext- - List of Encrypted DGK valuespublic_key- - DGK Public Key used to encrypt list of ciphertext- Returns:
- DGK Encrypted sum product
- Throws:
HomomorphicException- - If an invalid input was found
-
sum_product
public static BigInteger sum_product(BigInteger[] ciphertext, Long[] plaintext, DGKPublicKey public_key) throws HomomorphicException Compute the sum-product. It computes the scalar multiplication between the array of Encrypted and plaintext values. Then it computes the encrypted sum.- Parameters:
ciphertext- - Array of Encrypted DGK valuesplaintext- - Array of Plaintext valuespublic_key- - DGK Public Key used to encrypt values in a ciphertext list- Returns:
- DGK Encrypted sum-product
- Throws:
HomomorphicException- - If the size of plaintext array and ciphertext array isn't equal
-