| Type: | Package |
| Title: | Homomorphic Computations in R |
| Version: | 0.3 |
| Date: | 2025-04-08 |
| VignetteBuilder: | knitr |
| URL: | https://github.com/bnaras/homomorpheR |
| BugReports: | https://github.com/bnaras/homomorpheR/issues |
| Suggests: | knitr, rmarkdown, survival, dplyr, magrittr, digest |
| Imports: | R6, gmp, sodium |
| Description: | Homomorphic computations in R for privacy-preserving applications. Currently only the Paillier Scheme is implemented. |
| License: | MIT + file LICENSE |
| RoxygenNote: | 7.3.2 |
| Encoding: | UTF-8 |
| NeedsCompilation: | no |
| Packaged: | 2025-04-08 20:30:33 UTC; naras |
| Author: | Balasubramanian Narasimhan [aut, cre] |
| Maintainer: | Balasubramanian Narasimhan <naras@stat.Stanford.EDU> |
| Repository: | CRAN |
| Date/Publication: | 2025-04-09 22:30:12 UTC |
homomorpheR: Homomorphic computations in R
Description
homomorpheR is a start at a rudimentary package for
homomorphic computations in R. The goal is to collect homomorphic
encryption schemes in this package for privacy-preserving
distributed computations; for example, applications of the sort
immplemented in package distcomp.
Details
At the moment, only one scheme is implemented, the Paillier scheme. The current implementation makes no pretense at efficiency and also uses direct translations of other implementations, particularly the one in Javascript.
For a quick overview of the features, refer to the vignettes in this package.
Author(s)
Maintainer: Balasubramanian Narasimhan naras@stat.Stanford.EDU
References
See Also
Useful links:
Examples
keys <- PaillierKeyPair$new(1024) # Generate new key pair
encryptAndDecrypt <- function(x) keys$getPrivateKey()$decrypt(keys$pubkey$encrypt(x))
a <- gmp::as.bigz(1273849)
identical(a + 10L, encryptAndDecrypt(a+10L))
x <- lapply(1:100, function(x) random.bigz(nBits = 512))
edx <- lapply(x, encryptAndDecrypt)
identical(x, edx)
Construct a Paillier public and private key pair given a fixed number of bits
Description
Construct a Paillier public and private key pair given a fixed number of bits
Construct a Paillier public and private key pair given a fixed number of bits
Format
An R6::R6Class() generator object
Methods
PaillierKeyPair$getPrivateKey()Return the private key
Public fields
pubkeythe public key
Methods
Public methods
Method new()
Create a new public private key pair with specified number of modulus bits
Usage
PaillierKeyPair$new(modulusBits)
Arguments
modulusBitsthe number of bits to use
Returns
a PaillierKeyPair object
Method getPrivateKey()
Return the private key
Usage
PaillierKeyPair$getPrivateKey()
Returns
the private key
Method clone()
The objects of this class are cloneable with this method.
Usage
PaillierKeyPair$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
PaillierPublicKey() and PaillierPrivateKey()
Examples
keys <- PaillierKeyPair$new(1024)
keys$pubkey
keys$getPrivateKey()
Construct a Paillier private key with the given secret and a public key
Description
Construct a Paillier private key with the given secret and a public key
Construct a Paillier private key with the given secret and a public key
Format
An R6::R6Class() generator object
Public fields
pubkeythe public key
Methods
Public methods
Method new()
Create a new private key with given secret lambda and the public key
Usage
PaillierPrivateKey$new(lambda, pubkey)
Arguments
lambdathe secret
pubkeythe public key
Method getLambda()
Return the secret lambda
Usage
PaillierPrivateKey$getLambda()
Returns
lambda
Method decrypt()
Decrypt a message
Usage
PaillierPrivateKey$decrypt(c)
Arguments
cthe message
Returns
the decrypted message
Method clone()
The objects of this class are cloneable with this method.
Usage
PaillierPrivateKey$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
PaillierPublicKey() which goes hand-in-hand with this object
Construct a Paillier public key with the given modulus.
Description
Construct a Paillier public key with the given modulus.
Construct a Paillier public key with the given modulus.
Value
An R6::R6Class() generator object
Public fields
bitsthe number of bits in the modulus
nthe modulus
nSquaredthe square of the modulus
nPlusOneone more than the modulus
Methods
Public methods
Method new()
Create a new public key and precompute some internal values for efficiency
Usage
PaillierPublicKey$new(bits, n)
Arguments
bitsnumber of bits to use
nthe modulus to use
Returns
a new PaillierPublicKey object
Method encrypt()
Encrypt a message
Usage
PaillierPublicKey$encrypt(m)
Arguments
mthe message
Returns
the encrypted message
Method add()
Add two encrypted messages
Usage
PaillierPublicKey$add(a, b)
Arguments
aa message
banother message
Returns
the sum of a and b
Method sub()
Subtract one encrypted message from another
Usage
PaillierPublicKey$sub(a, b)
Arguments
aa message
banother message
Returns
the difference a - b
Method add_real()
Return the sum a + b
of an encrypted real message a,
a list consisting of a encrypted
integer part (named int) and an
encrypted fractional part (named frac),
and a real number a using
den as denominator in the rational
approximation.
Usage
PaillierPublicKey$add_real(den, a, b)
Arguments
denthe denominator to use for rational approximations
athe real message, a list consisting of the integer and fractional parts named
intandfracrespectivelyba simple real number
Method sub_real()
Return the difference a - b
of an encrypted real message a,
a list consisting of a encrypted
integer part (named int) and an
encrypted fractional part (named frac),
and a real number b using
den as denominator in the rational
approximation.
Usage
PaillierPublicKey$sub_real(den, a, b)
Arguments
denthe denominator to use for rational approximations
athe real message, a list consisting of the integer and fractional parts named
intandfracrespectivelyba simple real number
Method mult()
Return the product of two encrypted
messages a and b
Usage
PaillierPublicKey$mult(a, b)
Arguments
aa message
banother message
Returns
the product of a and b
Method clone()
The objects of this class are cloneable with this method.
Usage
PaillierPublicKey$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
PaillierPrivateKey() which goes hand-in-hand with this object
Return a random big number using the cryptographically secure random number generator
from in the sodium package.
Description
Return a random big number using the cryptographically secure random number generator
from in the sodium package.
Usage
random.bigz(nBits)
Arguments
nBits |
the number of bits, which must be a multiple of 8, is not checked for efficiency. |