Learn R Programming

openfhe.R

This is an interface to the Fully Homomorphic Encryption library developed by OpenFHE.

The companion package homomorpheR (version >= 1.0) imports this package and includes a number of illustrative vignettes. Specifically, the examples demonstrate how to use existing R functions and optimizers to implement a homomorphic-encryption protocol across multiple sites.

Citing

Both packages are described in

Narasimhan, B. (2026). Fully Homomorphic Encryption for Statistical Modeling. arXiv:2610.04163 [stat.CO]. https://arxiv.org/abs/2610.04163

citation("openfhe.R") gives the BibTeX entries for the paper, the package, and the underlying OpenFHE library.

Schemes

  • BFV / BGV: exact integer arithmetic
  • CKKS: approximate real-number arithmetic (with sin, cos, logistic, bootstrapping)
  • FHEW / TFHE (BinFHE): Boolean circuit evaluation

All four FHE subsystems (BFV, BGV, CKKS, BinFHE) are exposed. In addition, we provide facilities for serialization, threshold FHE, CKKS bootstrapping, transcendental function evaluation, and CKKS hoisted (fast) rotations.

Quick Start

library(openfhe.R)

# BFV: exact integer arithmetic
cc <- fhe_context("BFV", plaintext_modulus = 65537, multiplicative_depth = 2)
keys <- key_gen(cc, eval_mult = TRUE)

ct1 <- encrypt(keys@public, make_packed_plaintext(cc, 1:8), cc = cc)
ct2 <- encrypt(keys@public, make_packed_plaintext(cc, 10:17), cc = cc)

# Compute on encrypted data
result <- decrypt(ct1 + ct2, keys@secret, cc = cc)
get_packed_value(result)[1:8]
#> [1] 11 13 15 17 19 21 23 25

Copy Link

Version

Install

install.packages('openfhe.R')

Monthly Downloads

444

Version

1.6.1

License

BSD_2_clause + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Balasubramanian Narasimhan

Last Published

November 13th, 2026

Functions in openfhe.R (1.6.1)

LWEKeyPair

LWE key pair (Binary FHE)
LWECiphertext

LWE Ciphertext (Binary FHE)
ElementParams

Element Parameters (opaque)
EncodingParams

Encoding Parameters (opaque)
MultiplicationTechnique

Multiplication Technique (BFV)
FastRotationPrecomputation

Precomputed digit decomposition for hoisted rotations
Feature

PKE Scheme Features (bitmask)
KeyPair

Key Pair
Format

Polynomial representation
LWEPrivateKey

LWE Private Key (Binary FHE)
OpenFHEObject

Base class for OpenFHE objects
LWEPublicKey

LWE public key (Binary FHE)
KeySwitchTechnique

Key Switching Techniques
KeygenMode

Key Generation Mode
EvalKeyMap

Map of homomorphic evaluation keys
Plaintext

Plaintext
SchemeId

Scheme Identifier
PREMode

Proxy Re-encryption Mode
SchemeBase

The scheme object of a CryptoContext
SchSwchParams

Parameters of scheme switching
RingGSWBTKey

Bootstrapping key (Binary FHE)
SecretShareMap

Map of secret-key shares for threshold-FHE abort recovery
SecretKeyDist

Secret Key Distribution
bin_fhe_context

Create a Binary FHE context
bin_key_gen

Generate BinFHE secret key
bin_key_gen_pair

Keys of the LWE scheme of a BinFHE context
ccparams_getters

CCParams getters (all schemes)
ExecutionMode

Execution Mode
PlaintextEncodings

Plaintext Encoding Types
ScalingTechnique

Scaling Techniques (CKKS)
bin_bootstrap

Bootstrap an LWE ciphertext
bin_decrypt

Decrypt a Binary FHE ciphertext
bin_encrypt

Encrypt a value for Binary FHE
PolyVector

An RLWE ciphertext
SchemeSwitchingDataSerializer

Write and read the data of a scheme-switching computation
composed_eval_mult

Multiply two ciphertexts and reduce the modulus
clear_all_ckks_caches

Release the precomputations a CKKS context has cached
clear_eval_mult_keys

Clear the EvalMult key cache
bin_bt_key_gen

Generate BinFHE bootstrapping keys
clone

Copy a ciphertext
clear_eval_sum_keys

Remove summation keys from the registry
LWESwitchingKey

LWE switching key (Binary FHE)
PublicKey

Public Key
PrivateKey

Private Key
SecurityLevel

Security Levels
MultipartyMode

Multiparty Mode
eval_add_in_place

Homomorphic addition in place
eval_add

Homomorphic addition
clear_eval_automorphism_keys

Clear the EvalAutomorphism key cache
encode

Encode or decode a plaintext
enable_feature

Enable a feature on a CryptoContext
clear_fhe_state

Clear cached evaluation keys and contexts
clear_static_maps_and_vectors

Clear OpenFHE static maps and vectors
deserialize_eval_keys

Deserialize evaluation keys from file
eval_at_index

Rotate the slots of a ciphertext by an index
deserialize_eval_keys_string

Deserialize evaluation keys held in memory
eval_at_index_key_gen

Generate at-index (rotation) keys for a secret key
eval_bootstrap

Perform CKKS bootstrapping
eval_bin_gate

Evaluate a binary gate on encrypted values
enable_precompute_crt_tables_after_deserializaton

Precompute CRT tables when a context is deserialized
eval_bootstrap_setup

Set up CKKS bootstrapping
eval_bootstrap_stc_first

CKKS bootstrapping with slots-to-coefficients first
ckks_scaling_factor_bits

CKKS scaling-mod-size in bits
decrypt

Decrypt a ciphertext
SeriesPowers

Precomputed powers of a ciphertext
ccparams_setters

Set a parameter on a parameter object
compress

Compress a ciphertext to fewer towers
eval_add_many

Add or multiply a list of ciphertexts
eval_chebyshev_linear

Evaluate a Chebyshev series via the linear evaluator
eval_chebyshev_ps

Evaluate a Chebyshev series via the Paterson-Stockmeyer method
eval_chebyshev

Evaluate a Chebyshev series on a ciphertext
eval_chebyshev_coefficients

Chebyshev coefficients for a real-valued function
eval_fast_rotation_precompute

Precompute digit decomposition for hoisted fast rotations
eval_add_mutable

Homomorphic add, mutable variant
eval_chebyshev_function_ptxt

Chebyshev approximation of a function, in the clear
eval_cos

Evaluate cosine on a ciphertext
eval_add_mutable_in_place

Mutable arithmetic on two ciphertexts, in place
eval_chebyshev_function

Evaluate a user-supplied function on a CKKS ciphertext via Chebyshev approximation
eval_add_in_place_no_check

Arithmetic without the library's operand checks
encrypt

Encrypt a plaintext
eval_automorphism

Apply an automorphism to a ciphertext
eval_automorphism_key_gen

Generate automorphism evaluation keys for a set of indices
eval_fast_rotation_ext

Extended hoisted slot rotation
eval_divide

Evaluate division approximation on a ciphertext
eval_ckks_to_fhew_setup

Switch a CKKS ciphertext to FHEW ciphertexts
eval_bootstrap_key_gen

Generate bootstrapping keys
eval_bootstrap_precompute

Precompute the plaintexts of CKKS bootstrapping
eval_fbt_setup

CKKS functional bootstrapping of a look-up table
eval_fe_func_bootstrap_setup

CKKS functional bootstrapping of a Fourier series
eval_fast_rotation

Hoisted slot rotation using precomputed digits
eval_logistic

Evaluate logistic function on a ciphertext
eval_constant

A constant as an LWE ciphertext
eval_func

Evaluate an arbitrary function on an encrypted value
eval_hermite_trig_series

Evaluate a trigonometric Hermite series on a ciphertext
eval_merge

Merge the first slots of several ciphertexts into one
eval_negate

Homomorphic negation
eval_mult_in_place

Homomorphic multiplication by a number, in place
eval_negate_in_place

Homomorphic negation in place
eval_mult_no_relin

Homomorphic multiplication without relinearization
eval_decomp

Decompose a large-precision ciphertext into digits
eval_fhew_to_ckks_setup

Switch FHEW ciphertexts to a CKKS ciphertext
eval_floor

Evaluate a floor (rounding) function on an LWE ciphertext
eval_mvb_precompute

Several look-up tables on one input (multi-value bootstrapping)
eval_linear_wsum

Weighted sum of ciphertexts (CKKS)
eval_inner_product

Inner product of two encrypted vectors
eval_mult_key_gen

Generate relinearization (eval-mult) keys for a secret key
eval_mult

Homomorphic multiplication
eval_mult_and_relinearize

Fused multiply-and-relinearize
eval_not

Evaluate NOT on an encrypted value
eval_scheme_switching_setup

Comparison, minimum and maximum through scheme switching
eval_rotate_key_gen

Generate rotation keys for a secret key
eval_mult_keys_gen

Generate relinearization keys for higher powers of the secret key
eval_mult_mutable

Homomorphic multiply, mutable variant
eval_square_in_place

Square, rescale or relinearize a ciphertext in place
eval_square

Homomorphic squaring
eval_sum_key_gen

Generate sum keys for a secret key
eval_sum

Sum all slots in a ciphertext
eval_sign

Evaluate sign on an encrypted value (functional bootstrapping)
eval_sin

Evaluate sine on a ciphertext (Chebyshev approximation)
eval_poly_ps

Evaluate a polynomial via the Paterson-Stockmeyer method
eval_poly_linear

Evaluate a polynomial via the linear evaluator
eval_poly

Evaluate a polynomial on a ciphertext
eval_rotate

Rotate ciphertext slots
eval_sum_rows

Sum the rows or the columns of an encrypted matrix
eval_powers

Evaluate several series on one ciphertext
eval_sub_in_place

Homomorphic subtraction in place
eval_sub_mutable

Homomorphic subtract, mutable variant
fhe_deserialize

Deserialize an OpenFHE object from file
fhe_context

Create a fully homomorphic encryption context
fhe_ckks_tolerance

Per-test CKKS precision tolerance
generate_lut_via_function

Generate a lookup table for an arbitrary plaintext function
gen_crypto_context

Generate a CryptoContext from a parameter object
find_automorphism_index

Compute the automorphism index for a single slot index
find_automorphism_indices

Compute the automorphism indices for a list of slot indices
get_crypto_parameters

Crypto parameters of a CryptoContext
get_cyclotomic_order

Cyclotomic order of a CryptoContext
eval_sub

Homomorphic subtraction
get_bt_key

The bootstrapping keys of a BinFHE context
get_ckks_boot_correction_factor

Get the CKKS bootstrap correction factor
eval_square_mutable

Homomorphic square, mutable variant
get_bootstrap_depth

Get the required multiplicative depth for CKKS bootstrapping
get_bin_cc_for_scheme_switch

The FHEW side of a scheme-switching context
fhe_serialize

Serialize an OpenFHE object
fhe_deserialize_string

Deserialize an OpenFHE object held in memory
get_all_eval_automorphism_keys

Retrieve all registered EvalAutomorphism key maps
get_complex_packed_value

Get complex values from a CKKS plaintext
get_all_contexts

All contexts the library currently holds
get_eval_mult_key_vector

Retrieve the EvalMult key vector for a given key tag
get_eval_sum_key_map

Retrieve the sum-key map for a given key tag
get_all_eval_mult_keys

Retrieve all registered EvalMult key vectors
get_element_modulus

Modulus and representation of a plaintext's element
get_element_params

Element parameters of a CryptoContext
get_all_eval_sum_keys

Retrieve all registered EvalSum key maps
get_fbt_depth

Multiplicative depth of functional bootstrapping
get_existing_eval_automorphism_key_indices

Which automorphism keys exist
get_max_plaintext_space

Maximum supported plaintext space for functional bootstrapping
get_crypto_context

Associated CryptoContext of a Ciphertext
get_hermite_trig_coefficients

Trigonometric Hermite interpolation of a look-up table
get_plaintext_for_decrypt

An empty plaintext of the type a decryption will fill
get_hop_level

Hop level and encoding type of a ciphertext
get_packed_value

Get packed integer values from a plaintext
get_key_gen_level

Key-generation level of a CryptoContext
get_multiplicative_depth_by_coeff_vector

Multiplicative depth of a polynomial evaluation
get_eval_automorphism_key_map

Retrieve the automorphism-key map for a given key tag
get_plaintext_generator

The plaintext generator of an encoding
get_encoding_params

Encoding parameters of a CryptoContext
get_real_packed_value

Get real values from a CKKS plaintext
get_n

Parameters of a BinFHE context
int_boot_adjust_scale

Prepare a ciphertext for interactive bootstrap
get_native_int

Get the native integer size of the OpenFHE build
get_num_threads

Report the number of OpenMP threads available to OpenFHE
get_ptr

Extract pointer with validation
get_pt_modulus

Moduli of an LWE ciphertext
int_mp_boot_encrypt

Final re-encryption for multi-party interactive bootstrap
int_boot_decrypt

Server-side masked decryption for interactive bootstrap
get_public_key

The public key an object holds
insert_eval_automorphism_key

Insert a joined automorphism-key map into the cc registry
insert_eval_mult_key

Insert an EvalMult key vector into the cc registry
key_switch_ext

Steps of hybrid key switching
key_switch_down

Scale a ciphertext down from extended CRT basis to Q
get_scaling_factor_real

Real-valued CKKS scaling factor at a modulus-chain level
is_good

Is a KeyPair valid?
key_gen

Generate key pair
mod_reduce

Reduce the modulus chain by one level
make_packed_plaintext

Make a packed integer plaintext
int_mp_boot_random_element_gen

Generate a common random element for multi-party bootstrap
make_ckks_packed_plaintext

Make a CKKS packed plaintext from real numbers
get_modulus

The ciphertext modulus
make_coef_packed_plaintext

Make a coefficient-packed integer plaintext
mod_reduce_in_place

Reduce the modulus chain by one level, in place
int_mp_boot_adjust_scale

Prepare a ciphertext for multi-party interactive bootstrap
get_modulus_ckks

Moduli and root of unity of a CryptoContext
int_boot_add

Combine encrypted and unencrypted masked decryptions
insert_eval_sum_key

Insert a joined sum-key map into the cc registry
int_mp_boot_add

Aggregate multi-party shares pairs
int_boot_encrypt

Client-side re-encryption for interactive bootstrap
make_string_plaintext

Encode a character string as a plaintext
int_mp_boot_decrypt

Multi-party masked decryption for interactive bootstrap
level_reduce

Reduce the modulus chain by multiple levels
key_tag

Key tag accessors
key_switch_gen

Switch a ciphertext from one secret key to another
level_reduce_in_place

Reduce the modulus chain by multiple levels, in place
multi_mult_eval_key

A party's share of the joint multiplication key (threshold FHE)
multi_key_switch_gen

Multi-party key-switch eval-key generation
multi_eval_automorphism_key_gen

Generate a joint automorphism-key share for multi-party rotation
multi_eval_at_index_key_gen

Generate a joint rotation-at-index key share
multi_add_pub_keys

Combine public keys from multiple parties
multi_add_eval_mult_keys

Combine partial eval-mult keys from multiple parties
multi_add_eval_automorphism_keys

Combine two automorphism-key map shares
multi_add_eval_sum_keys

Combine two sum-key map shares into a joint sum-key map
ptr_is_valid

Check if an external pointer is valid (non-NULL)
multi_add_eval_keys

Combine evaluation keys from multiple parties
re_key_gen

Proxy re-encryption
multiparty_decrypt_fusion

Fuse partial decryptions into final plaintext
multiparty_decrypt_lead

Lead party's partial decryption
openfhe.R-package

openfhe.R: R Interface to the 'OpenFHE' Fully Homomorphic Encryption Library
number_ciphertext_elements

The ring elements of a ciphertext
multiparty_key_gen

Generate a key pair for a secondary party in threshold FHE
ring_dimension

Ring dimension of a CryptoContext
rescale

Rescale a CKKS ciphertext (alias for ModReduce)
schemelet_convert_rlwe_to_ckks

Convert between RLWE and CKKS ciphertexts
multi_eval_sum_key_gen

Generate a joint sum-key share for multi-party EvalSum
multiparty_decrypt_main

Non-lead party's partial decryption
plaintext_params_hash

Deterministic hash of a plaintext's identifying parameters
set_ckks_boot_correction_factor

Set the CKKS bootstrap correction factor
plaintext_accessors

Plaintext accessors
serialized_object_name

Name and version of a serialized object
recover_shared_key

Recover a secret key from distributed shares
serialize_eval_keys

Serialize evaluation keys from the key registry
serialize_eval_bootstrap_key

Serialize the keys CKKS bootstrapping uses
schemelet_get_element_params

RLWE encryption under a CKKS secret key
relinearize

Relinearize a higher-degree ciphertext
set_num_threads

Set the number of OpenMP threads OpenFHE may use
set_scheme_id

Set the scheme identifier of a CryptoContext
with_fhe_context

Execute code with automatic cleanup of FHE state
set_length

Set the effective length of a plaintext
sparse_key_gen

Generate a sparse key pair
set_params_from_ckks_cryptocontext

Fill scheme-switching parameters from a CKKS context
switch_ct_to_qn

Switch a public-key ciphertext to the small modulus and dimension
threshold_decrypt

Threshold decryption convenience: lead + main + fusion in one call
share_keys

Distribute a secret key into shares
set_key_gen_level

Set the key-generation level of a CryptoContext
BinGate

Binary Gate Types
CKKSDataType

CKKS Data Type
BinFHEMethod

Binary FHE Methods
BinFHEOutput

Binary FHE Output Types
Ciphertext

Ciphertext class
BGVParams

BGV Parameters
BFVParams

BFV Parameters
CKKSParams

CKKS Parameters
BinFHEContext

BinFHE context (Binary FHE)
BinFHEParamSet

Binary FHE Parameter Sets
DistributionType

Distribution Type (lattice parameters)
DecryptionNoiseMode

Decryption Noise Mode
CryptoContext

Crypto Context
CompressionLevel

Compression Level (interactive multi-party bootstrap)
CryptoParameters

Crypto Parameters (opaque)
DCRTPoly

A ring element of a ciphertext
EncryptionTechnique

Encryption Technique
EvalKey

EvalKey class for multi-party key operations