| Title: | R Interface to the OpenFHE Fully Homomorphic Encryption Library |
|---|---|
| Description: | Provides an R interface to the OpenFHE C++ library for fully homomorphic encryption (FHE). Supports BFV, BGV, and CKKS schemes for computation on encrypted data, as well as FHEW/TFHE for Boolean circuit evaluation. |
| Authors: | Balasubramanian Narasimhan [aut, cre] (ORCID: <https://orcid.org/0000-0001-5852-7639>), Authors of the OpenFHE C++ library [ctb, cph] |
| Maintainer: | Balasubramanian Narasimhan <[email protected]> |
| License: | BSD_2_clause + file LICENSE |
| Version: | 1.5.1 |
| Built: | 2026-06-13 07:11:41 UTC |
| Source: | https://github.com/bnaras/openfhe |
Provides an R interface to the OpenFHE C++ library for fully homomorphic encryption (FHE). Supports BFV, BGV, and CKKS schemes for computation on encrypted data, as well as FHEW/TFHE for Boolean circuit evaluation.
Maintainer: Balasubramanian Narasimhan [email protected] (ORCID)
Authors:
Balasubramanian Narasimhan [email protected] (ORCID)
Useful links:
Report bugs at https://github.com/bnaras/fhe/issues
Constructor for the BFV scheme's CCParams surface. Every argument
maps 1:1 to an upstream CCParams<CryptoContextBFVRNS>::Set* method
whose override is not disabled in the BFV specialization. The 13
setters that BFV explicitly disables (SetScalingTechnique,
SetFirstModSize, SetPRENumHops, SetExecutionMode, …) are not
exposed here; see discovery D013.
BFVParams( plaintext_modulus = NULL, multiplicative_depth = NULL, scaling_mod_size = NULL, batch_size = NULL, security_level = NULL, secret_key_dist = NULL, key_switch_technique = NULL, ring_dim = NULL, digit_size = NULL, num_large_digits = NULL, standard_deviation = NULL, multiparty_mode = NULL, threshold_num_of_parties = NULL, multiplication_technique = NULL, max_relin_sk_deg = NULL, pre_mode = NULL, eval_add_count = NULL, key_switch_count = NULL, encryption_technique = NULL )BFVParams( plaintext_modulus = NULL, multiplicative_depth = NULL, scaling_mod_size = NULL, batch_size = NULL, security_level = NULL, secret_key_dist = NULL, key_switch_technique = NULL, ring_dim = NULL, digit_size = NULL, num_large_digits = NULL, standard_deviation = NULL, multiparty_mode = NULL, threshold_num_of_parties = NULL, multiplication_technique = NULL, max_relin_sk_deg = NULL, pre_mode = NULL, eval_add_count = NULL, key_switch_count = NULL, encryption_technique = NULL )
plaintext_modulus |
Integer modulus |
multiplicative_depth |
Integer depth of the multiplication
circuit the context must support. BFV and BGV grow ciphertext
noise with each multiplication, and the ring modulus |
scaling_mod_size |
Integer bit-size of each intermediate
scaling modulus in the RNS decomposition of |
batch_size |
Integer number of SIMD-batched plaintext slots.
Default is |
security_level |
One of |
secret_key_dist |
One of |
key_switch_technique |
One of |
ring_dim |
Integer power-of-two lattice ring dimension. Default
( |
digit_size |
Integer |
num_large_digits |
Integer number of digit groupings in
HYBRID key switching. Only meaningful when
|
standard_deviation |
Numeric standard deviation of the
Gaussian error distribution used during key generation and
encryption. Default ( |
multiparty_mode |
One of
|
threshold_num_of_parties |
Integer count of parties in an n-of-n threshold protocol. Ignored in non-threshold contexts. The cox-threshold vignette uses 2; the threshold-fhe-5p Python example uses 5. |
multiplication_technique |
One of
|
max_relin_sk_deg |
|
pre_mode |
|
eval_add_count |
|
key_switch_count |
|
encryption_technique |
|
A BFVParams S7 object.
Constructor for the BGV scheme's CCParams surface. Every argument
maps 1:1 to an enabled CCParams<CryptoContextBGVRNS>::Set* method.
The 10 BGV-disabled setters (SetEncryptionTechnique,
SetMultiplicationTechnique, SetExecutionMode, …) are not
exposed; see discovery D013.
BGVParams( plaintext_modulus = NULL, multiplicative_depth = NULL, scaling_mod_size = NULL, scaling_technique = NULL, batch_size = NULL, first_mod_size = NULL, security_level = NULL, secret_key_dist = NULL, key_switch_technique = NULL, ring_dim = NULL, digit_size = NULL, num_large_digits = NULL, standard_deviation = NULL, multiparty_mode = NULL, threshold_num_of_parties = NULL, max_relin_sk_deg = NULL, pre_mode = NULL, statistical_security = NULL, num_adversarial_queries = NULL, eval_add_count = NULL, key_switch_count = NULL, pre_num_hops = NULL )BGVParams( plaintext_modulus = NULL, multiplicative_depth = NULL, scaling_mod_size = NULL, scaling_technique = NULL, batch_size = NULL, first_mod_size = NULL, security_level = NULL, secret_key_dist = NULL, key_switch_technique = NULL, ring_dim = NULL, digit_size = NULL, num_large_digits = NULL, standard_deviation = NULL, multiparty_mode = NULL, threshold_num_of_parties = NULL, max_relin_sk_deg = NULL, pre_mode = NULL, statistical_security = NULL, num_adversarial_queries = NULL, eval_add_count = NULL, key_switch_count = NULL, pre_num_hops = NULL )
plaintext_modulus |
Integer modulus |
multiplicative_depth |
Integer multiplicative depth; sizes
the ring modulus |
scaling_mod_size |
Integer bit-size per scaling modulus in the modulus chain. |
scaling_technique |
One of |
batch_size |
Integer SIMD slot count; see the BFV entry. |
first_mod_size |
Integer bit size of the first (largest) prime in the modulus chain. Default leaves OpenFHE to pick. Override only when tuning the noise budget at the top of the chain. |
security_level |
See the BFV entry. |
secret_key_dist |
See the BFV entry. |
key_switch_technique |
See the BFV entry. BGV accepts both
|
ring_dim |
See the BFV entry. |
digit_size |
See the BFV entry. |
num_large_digits |
See the BFV entry. |
standard_deviation |
See the BFV entry. |
multiparty_mode |
See the BFV entry. |
threshold_num_of_parties |
See the BFV entry. |
max_relin_sk_deg |
|
pre_mode |
|
statistical_security |
|
num_adversarial_queries |
|
eval_add_count |
|
key_switch_count |
|
pre_num_hops |
|
A BGVParams S7 object.
Generate BinFHE bootstrapping keys
bin_bt_key_gen(ctx, sk, keygen_mode = KeygenMode$SYM_ENCRYPT)bin_bt_key_gen(ctx, sk, keygen_mode = KeygenMode$SYM_ENCRYPT)
ctx |
A BinFHE context |
sk |
An LWEPrivateKey |
keygen_mode |
Integer from KeygenMode; controls
whether the bootstrapping keys are generated under
symmetric-key encryption ( |
Decrypt a Binary FHE ciphertext
bin_decrypt(ctx, sk, ct, p = 4L)bin_decrypt(ctx, sk, ct, p = 4L)
ctx |
A BinFHE context |
sk |
An LWEPrivateKey |
ct |
An LWECiphertext |
p |
Plaintext modulus (default: 4) |
Integer value
Encrypt a value for Binary FHE
bin_encrypt(ctx, sk, message, output = 2L, p = 4L, mod = NULL)bin_encrypt(ctx, sk, message, output = 2L, p = 4L, mod = NULL)
ctx |
A BinFHE context |
sk |
An LWEPrivateKey |
message |
Integer (0 or 1 for Boolean; larger for integer FHE) |
output |
BINFHE_OUTPUT (default: 2 = BOOTSTRAPPED). Use
|
p |
Plaintext modulus (default: 4) |
mod |
Optional large ciphertext modulus Q for the LARGE_DIM path. NULL (default) selects the standard small-modulus encrypt. |
An LWECiphertext
Create a Binary FHE context
bin_fhe_context( paramset = BinFHEParamSet$STD128, method = BinFHEMethod$GINX, arb_func = FALSE, log_q = 11L, n = 0L, time_optimization = FALSE )bin_fhe_context( paramset = BinFHEParamSet$STD128, method = BinFHEMethod$GINX, arb_func = FALSE, log_q = 11L, n = 0L, time_optimization = FALSE )
paramset |
A BinFHEParamSet value (default: STD128) |
method |
A BinFHEMethod value (default: GINX) |
arb_func |
If TRUE, build a context that supports
arbitrary-function bootstrapping (EvalSign, EvalFunc). Selecting
any of |
log_q |
log2 of the large ciphertext modulus Q used by functional bootstrapping (default 11; use 17 for the eval-sign example). |
n |
Ring dimension override (0 lets OpenFHE pick). |
time_optimization |
Enable the GINX time-optimization variant. |
A BinFHEContext (stored as OpenFHEObject)
Generate BinFHE secret key
bin_key_gen(ctx)bin_key_gen(ctx)
ctx |
A BinFHE context |
An LWEPrivateKey
Binary FHE Methods Source: binfhe/binfhe-constants.h enum BINFHE_METHOD
BinFHEMethodBinFHEMethod
Binary FHE Output Types Source: binfhe/binfhe-constants.h enum BINFHE_OUTPUT
BinFHEOutputBinFHEOutput
Binary FHE Parameter Sets Source: binfhe/binfhe-constants.h enum BINFHE_PARAMSET (sequential from 0)
BinFHEParamSetBinFHEParamSet
Binary Gate Types Source: binfhe/binfhe-constants.h enum BINGATE (sequential from 0)
BinGateBinGate
Retrieve a parameter from a BFVParams, BGVParams, or
CKKSParams object. Each getter wraps the corresponding upstream
CCParams<T>::Get* method and returns its value unchanged.
get_ring_dim(params, ...) get_plaintext_modulus(params, ...) get_digit_size(params, ...) get_composite_degree(params, ...) get_scheme(params, ...) get_standard_deviation(params, ...) get_secret_key_dist(params, ...) get_max_relin_sk_deg(params, ...) get_pre_mode(params, ...) get_multiparty_mode(params, ...) get_execution_mode(params, ...) get_decryption_noise_mode(params, ...) get_noise_estimate(params, ...) get_desired_precision(params, ...) get_statistical_security(params, ...) get_num_adversarial_queries(params, ...) get_threshold_num_of_parties(params, ...) get_key_switch_technique(params, ...) get_scaling_technique(params, ...) get_batch_size(params, ...) get_first_mod_size(params, ...) get_num_large_digits(params, ...) get_multiplicative_depth(params, ...) get_scaling_mod_size(params, ...) get_security_level(params, ...) get_eval_add_count(params, ...) get_key_switch_count(params, ...) get_encryption_technique(params, ...) get_multiplication_technique(params, ...) get_pre_num_hops(params, ...) get_interactive_boot_compression_level(params, ...) get_register_word_size(params, ...) get_ckks_data_type(params, ...)get_ring_dim(params, ...) get_plaintext_modulus(params, ...) get_digit_size(params, ...) get_composite_degree(params, ...) get_scheme(params, ...) get_standard_deviation(params, ...) get_secret_key_dist(params, ...) get_max_relin_sk_deg(params, ...) get_pre_mode(params, ...) get_multiparty_mode(params, ...) get_execution_mode(params, ...) get_decryption_noise_mode(params, ...) get_noise_estimate(params, ...) get_desired_precision(params, ...) get_statistical_security(params, ...) get_num_adversarial_queries(params, ...) get_threshold_num_of_parties(params, ...) get_key_switch_technique(params, ...) get_scaling_technique(params, ...) get_batch_size(params, ...) get_first_mod_size(params, ...) get_num_large_digits(params, ...) get_multiplicative_depth(params, ...) get_scaling_mod_size(params, ...) get_security_level(params, ...) get_eval_add_count(params, ...) get_key_switch_count(params, ...) get_encryption_technique(params, ...) get_multiplication_technique(params, ...) get_pre_num_hops(params, ...) get_interactive_boot_compression_level(params, ...) get_register_word_size(params, ...) get_ckks_data_type(params, ...)
params |
A |
... |
Reserved for future method-specific arguments (currently
unused — all getters take only |
Per discovery D013, several parameters are "disabled" on specific
schemes (their setters throw at runtime). For a disabled
scheme/parameter combination the getter returns the default value
of the underlying field (typically 0L for uint32_t, 0 for
double, or the enum's zero sentinel) rather than throwing. This
is benign — the field was never set so its default is all the
information available — but it means e.g. calling
get_plaintext_modulus(params) on a CKKSParams object returns
0 rather than a meaningful modulus.
The underlying parameter value. Types vary per getter.
get_ring_dim: Ring dimension n of the lattice
the scheme operates over. For RLWE schemes this is the
cyclotomic ring's degree n = phi(m) (Euler's totient of the
cyclotomic order) and must be a power of two. The ring
dimension is the load-bearing cryptographic parameter —
security level and multiplicative depth together pin the
minimum n, and most runtime costs scale as O(n log n)
per homomorphic operation.
get_plaintext_modulus: Plaintext modulus t for the BFV
and BGV plaintext spaces. BFV/BGV plaintexts are elements of
Z_t[x]/Phi_m(x) and every homomorphic operation is performed
modulo t. On a CKKSParams object this returns the default
field value (0) because CKKS does not use a plaintext
modulus — see discovery D013.
get_digit_size: Digit size r for BV key-switching:
the base-2^r digit decomposition of the ciphertext during a
key-switch. Larger values decrease the number of digit
multiplications at the cost of larger per-digit noise.
get_composite_degree: Composite-scaling degree for the
CKKS COMPOSITESCALINGAUTO/COMPOSITESCALINGMANUAL scaling
techniques. Only meaningful when
scaling_technique = ScalingTechnique$COMPOSITESCALING*;
0 under the default FLEXIBLEAUTO path.
get_scheme: parity-deferred: integer scheme
identifier (see SchemeId for the enum values).
get_standard_deviation: parity-deferred: standard deviation
of the Gaussian error distribution.
get_secret_key_dist: parity-deferred: secret-key
distribution (see SecretKeyDist).
get_max_relin_sk_deg: parity-deferred: maximum
relinearization secret-key degree.
get_pre_mode: parity-deferred: proxy
re-encryption mode (see PREMode).
get_multiparty_mode: parity-deferred: multiparty mode
(see MultipartyMode).
get_execution_mode: parity-deferred: execution mode
(see ExecutionMode).
get_decryption_noise_mode: parity-deferred: decryption noise
mode (see DecryptionNoiseMode).
get_noise_estimate: parity-deferred: noise-flooding
noise estimate (double).
get_desired_precision: parity-deferred: noise-flooding
target precision (double, bits).
get_statistical_security: parity-deferred: statistical
security parameter. Return type is double per header
inconsistency; see the Return-type note.
get_num_adversarial_queries: parity-deferred: upper bound on
adversarial queries. Return type is double per header
inconsistency; see the Return-type note.
get_threshold_num_of_parties: parity-deferred: threshold-FHE
party count.
get_key_switch_technique: parity-deferred: key-switching
technique (see KeySwitchTechnique).
get_scaling_technique: parity-deferred: scaling technique
(see ScalingTechnique).
get_batch_size: parity-deferred: SIMD batch size.
get_first_mod_size: parity-deferred: bit size of the
first (largest) prime in the CKKS modulus chain.
get_num_large_digits: parity-deferred: number of large
digits for HYBRID key switching.
get_multiplicative_depth: parity-deferred: configured
multiplicative depth. Note: this is the depth the context was
constructed to support, not the current depth budget after
operations.
get_scaling_mod_size: parity-deferred: bit size of each
CKKS scaling modulus.
get_security_level: parity-deferred: target security
level (see SecurityLevel).
get_eval_add_count: parity-deferred: BFV/BGV
noise-flooding hint: maximum additions between multiplications.
get_key_switch_count: parity-deferred: BFV/BGV
noise-flooding hint: maximum key-switch count.
get_encryption_technique: parity-deferred: BFV encryption
technique (see EncryptionTechnique).
get_multiplication_technique: parity-deferred: BFV multiplication
technique (see MultiplicationTechnique).
get_pre_num_hops: parity-deferred: PRE hop count.
get_interactive_boot_compression_level: parity-deferred: CKKS interactive
bootstrap compression level (see CompressionLevel).
get_register_word_size: parity-deferred: register word size
for multi-precision arithmetic.
get_ckks_data_type: parity-deferred: CKKS data type
(see CKKSDataType).
get_statistical_security and get_num_adversarial_queries
return double rather than integer. This matches an
inconsistency in the upstream Params base class: the
corresponding setters take uint32_t but the getters return
double. The underlying field is a double — R binds per the
header, not per the setter signature.
get_plaintext_modulus returns an R integer on 32-bit-safe
values; for moduli that exceed the 32-bit signed integer range
the return value is a numeric (double) carrying a losslessly
rounded 53-bit integer, per the design.md §7 return-type
convention.
Wraps an encrypted OpenFHE ciphertext. Supports arithmetic operators
+, -, * which dispatch to homomorphic operations.
Ciphertext(ptr = NULL)Ciphertext(ptr = NULL)
ptr |
External pointer (internal use) |
Reads the real-valued scaling factor at level 0 from cc via
get_scaling_factor_real() and returns its log2 rounded to
the nearest integer. For a CKKS context constructed with
set_scaling_mod_size(50L) this returns 50L.
ckks_scaling_factor_bits(cc)ckks_scaling_factor_bits(cc)
cc |
A |
Used by the Stage 2 form of fhe_ckks_tolerance().
Integer.
CKKS Data Type Source: pke/constants-defs.h enum CKKSDataType
CKKSDataTypeCKKSDataType
Constructor for the CKKS scheme's CCParams surface. Every
argument maps 1:1 to an enabled
CCParams<CryptoContextCKKSRNS>::Set* method. The 8 CKKS-disabled
setters (SetPlaintextModulus, SetEvalAddCount,
SetKeySwitchCount, SetEncryptionTechnique,
SetMultiplicationTechnique, SetPRENumHops, SetMultipartyMode,
SetThresholdNumOfParties) are not exposed; see discovery D013.
CKKS is a fixed-point scheme over the complex numbers and has no
plaintext modulus; threshold_num_of_parties is currently
CKKS-disabled upstream even though the scheme supports threshold
variants via a separate code path.
CKKSParams( multiplicative_depth = NULL, scaling_mod_size = NULL, scaling_technique = NULL, batch_size = NULL, first_mod_size = NULL, security_level = NULL, secret_key_dist = NULL, key_switch_technique = NULL, ring_dim = NULL, digit_size = NULL, num_large_digits = NULL, interactive_boot_compression_level = NULL, standard_deviation = NULL, register_word_size = NULL, ckks_data_type = NULL, max_relin_sk_deg = NULL, pre_mode = NULL, execution_mode = NULL, decryption_noise_mode = NULL, noise_estimate = NULL, desired_precision = NULL, statistical_security = NULL, num_adversarial_queries = NULL, composite_degree = NULL )CKKSParams( multiplicative_depth = NULL, scaling_mod_size = NULL, scaling_technique = NULL, batch_size = NULL, first_mod_size = NULL, security_level = NULL, secret_key_dist = NULL, key_switch_technique = NULL, ring_dim = NULL, digit_size = NULL, num_large_digits = NULL, interactive_boot_compression_level = NULL, standard_deviation = NULL, register_word_size = NULL, ckks_data_type = NULL, max_relin_sk_deg = NULL, pre_mode = NULL, execution_mode = NULL, decryption_noise_mode = NULL, noise_estimate = NULL, desired_precision = NULL, statistical_security = NULL, num_adversarial_queries = NULL, composite_degree = NULL )
multiplicative_depth |
See the BFV entry. |
scaling_mod_size |
Integer bit-size of the CKKS rescaling
factor (typically 50 or 59 bits). Together with
|
scaling_technique |
See the BGV entry. CKKS additionally
supports |
batch_size |
See the BFV entry. |
first_mod_size |
See the BGV entry. |
security_level |
See the BFV entry. |
secret_key_dist |
See the BFV entry. |
key_switch_technique |
See the BFV entry. CKKS typically
benefits from |
ring_dim |
See the BFV entry. |
digit_size |
See the BFV entry. |
num_large_digits |
See the BFV entry. |
interactive_boot_compression_level |
One of
|
standard_deviation |
See the BFV entry. |
register_word_size |
Integer word size (in bits) for the register-based multi-precision arithmetic path. Default leaves it to upstream. Used by the simple-real-numbers-composite- scaling Python example. |
ckks_data_type |
One of |
max_relin_sk_deg |
|
pre_mode |
|
execution_mode |
|
decryption_noise_mode |
|
noise_estimate |
|
desired_precision |
|
statistical_security |
|
num_adversarial_queries |
|
composite_degree |
|
A CKKSParams S7 object.
Companion to clear_eval_mult_keys() for the
EvalAutomorphism key map (used by rotation and sum
operations). key_tag = NULL clears everything (same as
clear_fhe_state()'s "automorphism_keys" branch); a
character scalar clears only that tag's entries.
clear_eval_automorphism_keys(key_tag = NULL)clear_eval_automorphism_keys(key_tag = NULL)
key_tag |
|
NULL, invisibly.
clear_fhe_state(), clear_eval_mult_keys()
Clears the CryptoContextImpl internal EvalMult key map.
With key_tag = NULL (the default), clears the entire
cache — equivalent to the no-arg ClearEvalMultKeys() form
used by clear_fhe_state(). With a non-NULL key_tag,
clears only the entries registered under that tag,
preserving everything else. Useful in checkpoint workflows
where a single party's keys need to be evicted without
wiping the whole registry.
clear_eval_mult_keys(key_tag = NULL)clear_eval_mult_keys(key_tag = NULL)
key_tag |
|
NULL, invisibly.
clear_fhe_state(), clear_eval_automorphism_keys()
Clear cached evaluation keys and contexts
clear_fhe_state(what = c("mult_keys", "automorphism_keys", "contexts"))clear_fhe_state(what = c("mult_keys", "automorphism_keys", "contexts"))
what |
Character vector: subset of "mult_keys", "automorphism_keys", "contexts" |
Releases memory held in the upstream static eval-key maps and related global caches. Useful in long-running R sessions where repeated context construction accumulates static state. The call is idempotent; calling it when no static state is held is a no-op.
clear_static_maps_and_vectors()clear_static_maps_and_vectors()
invisible(NULL).
Truncates the ciphertext's RNS modulus representation to
towers_left towers and sets its noise-scale-degree to
noise_scale_deg. Used by the interactive multi-party
bootstrapping protocol to shrink a ciphertext before sending
it across the network (see notes/blocks/E-bindings-rewrite/ gap-matrix.md §21 for the bootstrap-side context).
compress(x, ...)compress(x, ...)
x |
A |
... |
Method-specific arguments: |
A compressed Ciphertext.
Compression Level (interactive multi-party bootstrap) Source: pke/constants-defs.h enum CompressionLevel NOTE: values start at 2, not 0. The header comment explains that compression levels 0 and 1 are not supported and the values are not renumbered.
CompressionLevelCompressionLevel
Crypto Context
CryptoContext(ptr = NULL)CryptoContext(ptr = NULL)
ptr |
External pointer (internal use) |
Wraps std::shared_ptr<CryptoParametersBase<DCRTPoly>> on the
C++ side. Returned by get_crypto_parameters(cc) and used as
an opaque token for RNS-level parameter accessors such as
get_scaling_factor_real, get_key_switch_technique, etc.
This class ships as scaffolding only: the S7 class definition
is in place so that the getter wiring can treat it as already
defined, but there is no constructor path from R.
CryptoParameters(ptr = NULL)CryptoParameters(ptr = NULL)
ptr |
External pointer (internal use) |
Decrypt a ciphertext
decrypt(ct, key, ...)decrypt(ct, key, ...)
ct |
A Ciphertext |
key |
A PrivateKey |
... |
Additional arguments (cc = CryptoContext) |
A Plaintext
Decryption Noise Mode Source: pke/constants-defs.h enum DecryptionNoiseMode
DecryptionNoiseModeDecryptionNoiseMode
Deserialize evaluation keys from file
deserialize_eval_keys( filename, type = c("mult", "automorphism", "sum"), format = "binary" )deserialize_eval_keys( filename, type = c("mult", "automorphism", "sum"), format = "binary" )
filename |
Path to serialized file |
type |
"mult", "automorphism", or "sum" |
format |
"binary" (default) or "json" |
TRUE on success (invisibly)
Distribution Type (lattice parameters) Source: core/lattice/stdlatticeparms.h enum DistributionType
DistributionTypeDistributionType
Wraps std::shared_ptr<typename DCRTPoly::Params> on the C++ side.
Used by the params argument of CKKS plaintext factories and
returned by get_element_params(). This class ships as
scaffolding only: no constructor surface other than
wrapping an existing external pointer.
ElementParams(ptr = NULL)ElementParams(ptr = NULL)
ptr |
External pointer (internal use) |
Accepts either a single PKESchemeFeature enum value or a
uint32_t bitwise-OR mask of PKESchemeFeature values (for
surface parity with the C++ Enable(uint32_t) overload). The two paths
dispatch on the value itself: a mask is detected by being
strictly larger than the largest single-feature value
(Feature$SCHEMESWITCH = 0x80 = 128) or by having more than one
bit set.
enable_feature(cc, ...)enable_feature(cc, ...)
cc |
A |
... |
|
cc invisibly.
Wraps std::shared_ptr<EncodingParamsImpl> on the C++ side.
Returned by get_encoding_params(cc) and by
Plaintext::GetEncodingParams() once the corresponding
Plaintext accessor lands. This class ships as scaffolding
only: the S7 class definition is in place so that the getter
wiring can treat it as already defined, but there is no
constructor path from R.
EncodingParams(ptr = NULL)EncodingParams(ptr = NULL)
ptr |
External pointer (internal use) |
encrypt dispatches on both the key type and the plaintext.
The (PublicKey, Plaintext) method performs public-key
encryption and is the canonical path used by every vignette.
The (PrivateKey, Plaintext) method
performs symmetric / secret-key encryption using the private
key directly; it is useful in protocols that want the secret
key to serve as both encryption and decryption key (e.g.
one-party tests, single-user benchmarks).
encrypt(key, pt, ...)encrypt(key, pt, ...)
key |
A |
pt |
A |
... |
Additional arguments ( |
A Ciphertext.
Encryption Technique Source: pke/constants-defs.h enum EncryptionTechnique
EncryptionTechniqueEncryptionTechnique
Homomorphic addition
eval_add(x, y, ...)eval_add(x, y, ...)
x, y
|
Ciphertext, Plaintext, or numeric values |
... |
Method-specific arguments |
A Ciphertext
Modifies the first argument in place to hold the result of adding the second argument. Avoids allocating a new Ciphertext, which matters in tight loops or when ciphertext memory footprint is a concern.
eval_add_in_place(x, ...)eval_add_in_place(x, ...)
x |
A |
... |
Method-specific arguments: |
x invisibly.
The Mutable* family exists so that operations that can safely mutate their inputs during evaluation (e.g. a temporary intermediate in a longer circuit) can do so without forcing a defensive copy. Semantically equivalent to the non-Mutable counterpart from the user's perspective; the difference is performance under specific workloads.
eval_add_mutable(x, ...)eval_add_mutable(x, ...)
x |
A |
... |
Method-specific arguments: |
A new Ciphertext holding x + y.
Standalone wrapper around the
CryptoContext::EvalAtIndexKeyGen(privateKey, indexList) C++
method. Functionally identical to eval_rotate_key_gen()
(the C++ EvalRotateKeyGen is a thin inline wrapper around
EvalAtIndexKeyGen) and provided for surface parity with the
C++ header and openfhe-python, both of which bind the two
names separately.
eval_at_index_key_gen(cc, sk, index_list)eval_at_index_key_gen(cc, sk, index_list)
cc |
A |
sk |
A |
index_list |
Integer vector of rotation indices. |
NULL, invisibly.
Evaluates the automorphism at the given index on ct
using the eval-key map returned by
eval_automorphism_key_gen(). The result is a new
ciphertext whose decrypted slot vector is a permutation
of ct's slot vector (the permutation determined by the
automorphism group element).
eval_automorphism(ct, index, eval_key_map)eval_automorphism(ct, index, eval_key_map)
ct |
A |
index |
Integer; the automorphism index (must match
one of the indices passed to
|
eval_key_map |
An |
A transformed Ciphertext.
eval_automorphism_key_gen(),
eval_rotate()
Generates the eval-key map needed to apply
eval_automorphism() at the given set of slot indices.
The generated keys are both inserted into the
CryptoContext's internal eval-automorphism-key registry
(keyed by sk's tag) and returned as an EvalKeyMap
handle that the caller can pass directly to
eval_automorphism().
eval_automorphism_key_gen(cc, sk, indices)eval_automorphism_key_gen(cc, sk, indices)
cc |
A |
sk |
A |
indices |
Integer vector of automorphism indices
(not slot indices — use |
On the C++ side this is equivalent to calling
EvalAutomorphismKeyGen(sk, indices) which internally
calls CryptoContextImpl::InsertEvalAutomorphismKey with
the generated map (cryptocontext.h line 2237). The dual
return / registry-insert pattern matches the openfhe-python
behavior at the equivalent entry point.
Companion to eval_rotate_key_gen() (reached via
key_gen()'s rotations argument): both populate the
same cc-internal storage. The automorphism form gives raw
access to the automorphism group element (bypassing the
rotate-to-automorphism slot mapping that
eval_rotate_key_gen performs internally).
An EvalKeyMap with one entry per input index.
eval_automorphism(),
find_automorphism_indices()
Evaluate a binary gate on encrypted values
eval_bin_gate(ctx, gate, ct1, ct2 = NULL)eval_bin_gate(ctx, gate, ct1, ct2 = NULL)
ctx |
A BinFHE context |
gate |
A BinGate value. Two-input gates: |
ct1 |
An |
ct2 |
An |
An LWECiphertext
Refreshes the ciphertext to allow further computation.
eval_bootstrap(ct, num_iterations = 1L, precision = 0L)eval_bootstrap(ct, num_iterations = 1L, precision = 0L)
ct |
A Ciphertext |
num_iterations |
Number of bootstrap iterations (default: 1) |
precision |
Target precision (default: 0 = automatic) |
A refreshed Ciphertext
Generate bootstrapping keys
eval_bootstrap_key_gen(cc, sk, slots)eval_bootstrap_key_gen(cc, sk, slots)
cc |
A CryptoContext |
sk |
A PrivateKey |
slots |
Number of slots |
Set up CKKS bootstrapping
eval_bootstrap_setup( cc, level_budget = c(5L, 4L), dim1 = c(0L, 0L), slots = 0L, correction_factor = 0L, precompute = TRUE, bt_slots_encoding = FALSE )eval_bootstrap_setup( cc, level_budget = c(5L, 4L), dim1 = c(0L, 0L), slots = 0L, correction_factor = 0L, precompute = TRUE, bt_slots_encoding = FALSE )
cc |
A CryptoContext |
level_budget |
Integer vector of length 2 (default: c(5, 4)) |
dim1 |
Integer vector of length 2 (default: c(0, 0)) |
slots |
Number of slots (default: 0 = automatic) |
correction_factor |
Correction factor (default: 0) |
precompute |
Precompute rotation keys (default: TRUE) |
bt_slots_encoding |
Logical; controls whether the
bootstrap precomputes with slot-count encoding (the
|
Uses OpenFHE's default algorithm selector, which routes to
eval_chebyshev_linear() for degree < 5 and
eval_chebyshev_ps() (Paterson-Stockmeyer) for higher
degrees. Call the variants directly to force one algorithm
or the other.
eval_chebyshev(ct, coefficients, a, b)eval_chebyshev(ct, coefficients, a, b)
ct |
A Ciphertext |
coefficients |
Numeric vector of Chebyshev coefficients |
a |
Lower bound of the approximation interval |
b |
Upper bound of the approximation interval |
A Ciphertext
eval_chebyshev_coefficients() and
eval_chebyshev_function() for constructing the coefficient
vector from a user-supplied function;
eval_chebyshev_linear() / eval_chebyshev_ps() for
forcing the algorithm.
Computes the Chebyshev (first-kind) coefficients that approximate
a univariate function func on the interval using the
discrete orthogonality formula at degree + 1 Chebyshev nodes.
This is a direct port of the upstream routine
EvalChebyshevCoefficients() in
core/lib/math/chebyshev.cpp of openfhe-development, and the
returned vector is in exactly the form that
eval_chebyshev() (and the upstream EvalChebyshevSeries)
expect — the zeroth coefficient is not halved.
eval_chebyshev_coefficients(func, a, b, degree)eval_chebyshev_coefficients(func, a, b, degree)
func |
An R function taking a single numeric argument and returning a numeric scalar. |
a |
Lower bound of the approximation interval. |
b |
Upper bound of the approximation interval. |
degree |
Chebyshev polynomial degree (must be >= 1). |
Numeric vector of length degree + 1.
eval_chebyshev(), eval_chebyshev_function().
Computes the Chebyshev coefficients for func on [a, b] via
eval_chebyshev_coefficients() and applies the resulting series
to ct via eval_chebyshev(). This mirrors the upstream
CryptoContext::EvalChebyshevFunction helper, which is a thin
wrapper around EvalChebyshevCoefficients followed by
EvalChebyshevSeries on the C++ side.
eval_chebyshev_function(ct, func, a, b, degree)eval_chebyshev_function(ct, func, a, b, degree)
ct |
A Ciphertext holding CKKS-encoded real values in
|
func |
An R function taking a single numeric argument and
returning a numeric scalar. It is evaluated on cleartext
Chebyshev nodes inside |
a |
Lower bound of the approximation interval. |
b |
Upper bound of the approximation interval. |
degree |
Chebyshev polynomial degree (must be >= 1). |
A Ciphertext holding the elementwise approximation of
func applied to the plaintext slots of ct.
eval_chebyshev(), eval_chebyshev_coefficients(),
eval_logistic(), eval_sin(), eval_cos(),
eval_divide().
Forces the "linear" Chebyshev evaluator regardless of degree. Shallower circuit depth than Paterson-Stockmeyer but uses more multiplications at high degree.
eval_chebyshev_linear(ct, coefficients, a, b)eval_chebyshev_linear(ct, coefficients, a, b)
ct |
A Ciphertext |
coefficients |
Numeric vector of Chebyshev coefficients |
a |
Lower bound of the approximation interval |
b |
Upper bound of the approximation interval |
A Ciphertext
eval_chebyshev(), eval_chebyshev_ps()
Forces the Paterson-Stockmeyer Chebyshev evaluator regardless of degree. Efficient for high-degree polynomials.
eval_chebyshev_ps(ct, coefficients, a, b)eval_chebyshev_ps(ct, coefficients, a, b)
ct |
A Ciphertext |
coefficients |
Numeric vector of Chebyshev coefficients |
a |
Lower bound of the approximation interval |
b |
Upper bound of the approximation interval |
A Ciphertext
eval_chebyshev(), eval_chebyshev_linear()
Evaluate cosine on a ciphertext
eval_cos(ct, a, b, degree)eval_cos(ct, a, b, degree)
ct |
A Ciphertext |
a |
Lower bound of the approximation interval |
b |
Upper bound of the approximation interval |
degree |
Chebyshev polynomial degree |
Evaluate division approximation on a ciphertext
eval_divide(ct, a, b, degree)eval_divide(ct, a, b, degree)
ct |
A Ciphertext |
a |
Lower bound of the approximation interval |
b |
Upper bound of the approximation interval |
degree |
Chebyshev polynomial degree |
Hoisted slot rotation using precomputed digits
eval_fast_rotation(ct, ...)eval_fast_rotation(ct, ...)
ct |
A Ciphertext |
... |
Method-specific arguments: |
A Ciphertext
Applies a rotation using precomputed digit decomposition
like eval_fast_rotation(), but with the extension that the
first digit of the decomposition can be folded into the
output before the rotation is applied (controlled by
add_first). Used inside the CKKS bootstrap fast-rotation
inner loop per openfhe-development's
scheme/base-scheme.cpp. The eval-key map is pulled from
the CryptoContext internal registry via the ciphertext's
key tag, so there is no EvalKeyMap argument at the R
boundary — the automorphism keys must already be resident
on the cc (call key_gen(cc, rotations = ...) to populate
them, then reuse the ct here).
eval_fast_rotation_ext(ct, ...)eval_fast_rotation_ext(ct, ...)
ct |
A |
... |
Method-specific arguments: |
A Ciphertext.
Computes the digit decomposition of a ciphertext once so that
multiple eval_fast_rotation() calls against the same ciphertext
avoid redoing it. The cyclotomic order m (typically 2 * N,
where N is the ring dimension) is required by eval_fast_rotation().
eval_fast_rotation_precompute(ct, ...)eval_fast_rotation_precompute(ct, ...)
ct |
A Ciphertext |
... |
Reserved for future method-specific arguments |
A FastRotationPrecomputation
Performs the LWE equivalent of floor(ct / 2^roundbits) via
functional bootstrapping. Used as a primitive in arbitrary-
function evaluation pipelines where the bit-level rounding
operation is needed separately from eval_func()'s LUT
path.
eval_floor(ctx, ct, roundbits)eval_floor(ctx, ct, roundbits)
ctx |
A BinFHEContext |
ct |
An LWECiphertext |
roundbits |
Integer; the number of low-order bits to round off. |
Binding-level note: the underlying
BinFHEContext__EvalFloor cpp11 binding has been present
since the earliest BinFHE work; the R wrapper was added
later to close the latent gap (cpp11-only entry with no R
path).
A new LWECiphertext holding the rounded value.
Functional bootstrapping with a precomputed lookup table. The
context must have been created with arb_func = TRUE.
eval_func(ctx, ct, lut)eval_func(ctx, ct, lut)
ctx |
A BinFHE context built with |
ct |
An LWECiphertext encrypted with |
lut |
A numeric vector of length |
An LWECiphertext encrypting lut[plaintext(ct) + 1]
Evaluate logistic function on a ciphertext
eval_logistic(ct, a, b, degree)eval_logistic(ct, a, b, degree)
ct |
A Ciphertext |
a |
Lower bound of the approximation interval |
b |
Upper bound of the approximation interval |
degree |
Chebyshev polynomial degree |
Homomorphic multiplication
eval_mult(x, y, ...)eval_mult(x, y, ...)
x, y
|
Ciphertext, Plaintext, or numeric values |
... |
Method-specific arguments |
A Ciphertext
Equivalent to relinearize(eval_mult_no_relin(x, y)) but
slightly more efficient in OpenFHE's implementation. Use this
at the end of a multiplication chain.
eval_mult_and_relinearize(x, ...)eval_mult_and_relinearize(x, ...)
x |
A |
... |
Method-specific arguments: |
A relinearized Ciphertext.
Modifies the first argument in place to hold the result of
multiplying by a numeric scalar. CryptoContextImpl only
declares EvalMultInPlace scalar overloads in the v1.5.1.0
header surface — the ct/ct and ct/pt variants that
upstream-defects P1 refers to live on SchemeBase and are not
exposed on CryptoContextImpl, so R's eval_mult_in_place
supports only the scalar case. The ct/ct multiplication
continues to work via the non-in-place eval_mult() generic.
eval_mult_in_place(x, ...)eval_mult_in_place(x, ...)
x |
A |
... |
Method-specific arguments: |
x invisibly.
Standalone wrapper around the
CryptoContext::EvalMultKeyGen(privateKey) C++ method.
Populates the CryptoContext's internal eval-mult registry
(keyed by the secret key's tag) so that ciphertext ×
ciphertext multiplication can be relinearized.
eval_mult_key_gen(cc, sk)eval_mult_key_gen(cc, sk)
cc |
A |
sk |
A |
key_gen() folds this into its eval_mult = TRUE branch as
a convenience for fresh keypairs. The standalone wrapper is
the right entry point when the secret key already exists —
for example in any threshold or multi-party flow that holds
a secret-key share but did not generate it through
key_gen().
NULL, invisibly.
Homomorphic multiply, mutable variant
eval_mult_mutable(x, ...)eval_mult_mutable(x, ...)
x |
A |
... |
Method-specific arguments: |
A new Ciphertext holding x * y.
Returns the raw product of two ciphertexts as a higher-degree
ciphertext (the result has n1 + n2 - 1 polynomial components
where the inputs had n1 and n2). The standard eval_mult()
automatically relinearizes the result back to 2 components;
this variant skips the relinearization step so that multiple
multiplications can be chained at higher polynomial degree
before a single relinearize() call at the end. Used by the
EvalMultAndRelinearize fused variant and by
EvalPolyWithPrecomp for noise-optimal polynomial evaluation.
eval_mult_no_relin(x, ...)eval_mult_no_relin(x, ...)
x |
A |
... |
Method-specific arguments: |
A Ciphertext at higher polynomial degree.
Homomorphic negation
eval_negate(x, ...)eval_negate(x, ...)
x |
A Ciphertext |
... |
Method-specific arguments |
A Ciphertext
Homomorphic negation in place
eval_negate_in_place(x, ...)eval_negate_in_place(x, ...)
x |
A |
... |
Reserved for future method-specific arguments. |
x invisibly.
Evaluate NOT on an encrypted value
eval_not(ctx, ct)eval_not(ctx, ct)
ctx |
A BinFHE context |
ct |
An LWECiphertext |
An LWECiphertext
Evaluates p(x) = c0 + c1x + c2x^2 + ... on encrypted x.
Uses OpenFHE's default algorithm selector, which routes to
eval_poly_linear() for degree < 5 and eval_poly_ps()
(Paterson-Stockmeyer) for higher degrees. Call the variants
directly to force one algorithm or the other — Linear is
shallower for low-degree polynomials; PS has fewer
multiplications for high-degree polynomials.
eval_poly(ct, coefficients)eval_poly(ct, coefficients)
ct |
A Ciphertext |
coefficients |
Numeric vector of polynomial coefficients |
A Ciphertext
eval_poly_linear(), eval_poly_ps()
Forces the "linear" Horner-style polynomial evaluator
regardless of degree. Shallower circuit depth than the
Paterson-Stockmeyer variant but uses more multiplications
at high degree. Cheaper for degree < 5; fall over to
eval_poly_ps() above that.
eval_poly_linear(ct, coefficients)eval_poly_linear(ct, coefficients)
ct |
A Ciphertext |
coefficients |
Numeric vector of polynomial coefficients |
A Ciphertext
Forces the Paterson-Stockmeyer polynomial evaluator
regardless of degree. Efficient for high-degree polynomials
(fewer multiplications at the cost of more additions and a
deeper circuit); for degree < 5 prefer eval_poly_linear().
eval_poly_ps(ct, coefficients)eval_poly_ps(ct, coefficients)
ct |
A Ciphertext |
coefficients |
Numeric vector of polynomial coefficients |
A Ciphertext
eval_poly(), eval_poly_linear()
Rotate ciphertext slots
eval_rotate(ct, ...)eval_rotate(ct, ...)
ct |
A Ciphertext |
... |
Method-specific arguments (index) |
A Ciphertext
Standalone wrapper around the
CryptoContext::EvalRotateKeyGen(privateKey, indexList) C++
method. Populates the CryptoContext's internal automorphism
key registry for the supplied rotation indices so that
eval_rotate() can consume them.
eval_rotate_key_gen(cc, sk, index_list)eval_rotate_key_gen(cc, sk, index_list)
cc |
A |
sk |
A |
index_list |
Integer vector of rotation indices. |
key_gen() folds this into its rotations = ... argument as
a convenience for fresh keypairs. The standalone wrapper is
the right entry point when the secret key already exists —
for example as the lead-party rotation-key generation step in
a multi-party rotation protocol, where subsequent parties
contribute via multi_eval_at_index_key_gen().
NULL, invisibly.
Extracts the most-significant bit of an LWE ciphertext encrypted
under the large modulus Q. The context must have been created with
arb_func = TRUE.
eval_sign(ctx, ct, scheme_switch = FALSE)eval_sign(ctx, ct, scheme_switch = FALSE)
ctx |
A BinFHE context built with |
ct |
An LWECiphertext encrypted via |
scheme_switch |
Logical; when |
An LWECiphertext encrypting 0 if the input was negative (i.e. lay in the upper half of [0, Q)), 1 otherwise
Evaluate sine on a ciphertext (Chebyshev approximation)
eval_sin(ct, a, b, degree)eval_sin(ct, a, b, degree)
ct |
A Ciphertext |
a |
Lower bound of the approximation interval |
b |
Upper bound of the approximation interval |
degree |
Chebyshev polynomial degree |
A Ciphertext
Homomorphic squaring
eval_square(x, ...)eval_square(x, ...)
x |
A Ciphertext |
... |
Method-specific arguments |
A Ciphertext
Homomorphic square, mutable variant
eval_square_mutable(x, ...)eval_square_mutable(x, ...)
x |
A |
... |
Reserved for future method-specific arguments. |
A new Ciphertext holding x * x.
Homomorphic subtraction
eval_sub(x, y, ...)eval_sub(x, y, ...)
x, y
|
Ciphertext, Plaintext, or numeric values |
... |
Method-specific arguments |
A Ciphertext
Modifies the first argument in place to hold the result of subtracting the second argument.
eval_sub_in_place(x, ...)eval_sub_in_place(x, ...)
x |
A |
... |
Method-specific arguments: |
x invisibly.
Homomorphic subtract, mutable variant
eval_sub_mutable(x, ...)eval_sub_mutable(x, ...)
x |
A |
... |
Method-specific arguments: |
A new Ciphertext holding x - y.
Sum all slots in a ciphertext
eval_sum(ct, ...)eval_sum(ct, ...)
ct |
A Ciphertext |
... |
Method-specific arguments (batch_size) |
A Ciphertext
Populates the CryptoContext's internal sum-key registry
(keyed by the secret key's tag) so that eval_sum() and the
multi-party sum-key protocol can consume the generated
entries. Closes a long-standing gap: the underlying
CryptoContext__EvalSumKeyGen cpp11 binding has been present
since the early phases but had no standalone R wrapper —
users had to go through key_gen()'s side-effects only.
The wrapper lands so that the multi-party sum-key flow
(which needs to call this on each party's secret share) has
a direct R-level entry point.
eval_sum_key_gen(cc, sk)eval_sum_key_gen(cc, sk)
cc |
A |
sk |
A |
NULL, invisibly.
EvalKey class for multi-party key operations
EvalKey(ptr = NULL)EvalKey(ptr = NULL)
ptr |
External pointer (internal use) |
Opaque S7 wrapper around a
shared_ptr<std::map<uint32_t, EvalKey<DCRTPoly>>>. Produced
by the multi_eval_*_key_gen() family and by
get_eval_sum_key_map() / get_eval_automorphism_key_map();
consumed by multi_add_eval_sum_keys(),
multi_add_eval_automorphism_keys(), insert_eval_sum_key(),
and insert_eval_automorphism_key(). The map is keyed by a
rotation/automorphism index and carries one EvalKey per
index.
EvalKeyMap(ptr = NULL)EvalKeyMap(ptr = NULL)
ptr |
External pointer (internal use). |
Users do not construct or index into an EvalKeyMap
directly — it is a transport format for the multi-party
eval-key protocols. In a single-user protocol the same data
is tracked inside the CryptoContext's internal key
registry (populated by EvalSumKeyGen() /
EvalRotateKeyGen()) and is only exposed as an EvalKeyMap
when the distributed-party flow needs to exchange it.
Execution Mode Source: pke/constants-defs.h enum ExecutionMode
ExecutionModeExecutionMode
Returned by eval_fast_rotation_precompute() and consumed by
eval_fast_rotation(). Hoisting amortizes the per-rotation
decomposition over many rotations of the same source ciphertext.
FastRotationPrecomputation(ptr = NULL)FastRotationPrecomputation(ptr = NULL)
ptr |
External pointer (internal use) |
PKE Scheme Features (bitmask) Source: pke/constants-defs.h enum PKESchemeFeature
FeatureFeature
Computes a tolerance value suitable for comparing the cleartext
result of a CKKS circuit against a decrypted ciphertext. The
value is a function of the scheme's scaling factor, the
circuit's multiplicative depth at the point of decryption, and
the ScalingTechnique-specific precision loss per level.
fhe_ckks_tolerance(x, ...)fhe_ckks_tolerance(x, ...)
x |
For the numeric method: integer multiplicative depth
at the point of decryption. For the Ciphertext method: a
|
... |
Method-specific arguments. The numeric method
accepts |
Two dispatch forms:
Stage 1 (numeric): pass parameters as direct arguments.
Useful when the ciphertext isn't yet constructed — e.g. in a
fixture setup block that has to produce a tolerance before
calling encrypt().
Stage 2 (Ciphertext): pass a Ciphertext directly. The
helper reads the associated CryptoContext via
get_crypto_context(), pulls the multiplicative depth (from
context) minus the ciphertext's current level, computes the
scaling factor bits via ckks_scaling_factor_bits(), and
looks up the scaling technique. This form is preferred at
test sites where a ciphertext exists.
Numeric scalar — the tolerance value to use as
tolerance in tinytest::expect_equal() or as atol in a
manual diff.
# Stage 1 — pass parameters directly: tol1 <- fhe_ckks_tolerance(4L, 50L, "FLEXIBLEAUTO") # Stage 2 — pass a ciphertext (requires a live CKKS context): # cc <- fhe_context("CKKS", multiplicative_depth = 4L, scaling_mod_size = 50L) # kp <- key_gen(cc, eval_mult = TRUE) # pt <- make_ckks_packed_plaintext(cc, c(0.1, 0.2, 0.3, 0.4)) # ct <- encrypt(kp@public, pt, cc) # tol2 <- fhe_ckks_tolerance(ct)# Stage 1 — pass parameters directly: tol1 <- fhe_ckks_tolerance(4L, 50L, "FLEXIBLEAUTO") # Stage 2 — pass a ciphertext (requires a live CKKS context): # cc <- fhe_context("CKKS", multiplicative_depth = 4L, scaling_mod_size = 50L) # kp <- key_gen(cc, eval_mult = TRUE) # pt <- make_ckks_packed_plaintext(cc, c(0.1, 0.2, 0.3, 0.4)) # ct <- encrypt(kp@public, pt, cc) # tol2 <- fhe_ckks_tolerance(ct)
High-level constructor that creates a CryptoContext with sensible
defaults. PKE, KEYSWITCH, and LEVELEDSHE features are enabled
automatically.
fhe_context(scheme = c("BFV", "BGV", "CKKS"), ..., features = NULL)fhe_context(scheme = c("BFV", "BGV", "CKKS"), ..., features = NULL)
scheme |
Character: "BFV", "BGV", or "CKKS". |
... |
Scheme-specific |
features |
Additional |
All scheme-specific CCParams setter arguments are accepted via
... and forwarded to the appropriate per-scheme constructor
(BFVParams(), BGVParams(), or CKKSParams()). See those
functions' argument lists for the valid per-scheme setter surface
— each scheme accepts only the setters that are not disabled in
its upstream CCParams<T> specialization (see discovery D013).
Passing an invalid scheme-specific argument produces an R-level
"unused argument" error at the underlying *Params() call site.
A CryptoContext object.
BFVParams(), BGVParams(), CKKSParams()
Deserialize an OpenFHE object from file
fhe_deserialize( filename, type = c("CryptoContext", "PublicKey", "PrivateKey", "Ciphertext"), format = "binary" )fhe_deserialize( filename, type = c("CryptoContext", "PublicKey", "PrivateKey", "Ciphertext"), format = "binary" )
filename |
Path to serialized file |
type |
One of "CryptoContext", "PublicKey", "PrivateKey", "Ciphertext" |
format |
"binary" (default) or "json" |
The deserialized object
Serialize an OpenFHE object to file
fhe_serialize(x, ...)fhe_serialize(x, ...)
x |
An OpenFHE object (CryptoContext, PublicKey, PrivateKey, Ciphertext) |
... |
Method-specific arguments (filename, format) |
TRUE on success (invisibly)
Maps a CKKS slot index to the corresponding automorphism
index in the cyclotomic ring Z[X]/(X^N + 1). The
automorphism group of the ring is isomorphic to the
multiplicative group (Z/2N)*; this function returns the
representative of that group that corresponds to rotating
the plaintext slots by the given amount.
find_automorphism_index(cc, index)find_automorphism_index(cc, index)
cc |
A |
index |
Integer; the slot index (positive = left rotation, negative = right rotation). |
Used as a primitive by find_automorphism_indices() and
by code that needs to address automorphism keys directly
(for example, selectively generating eval keys for a
sparse set of rotation amounts).
R-first binding:
openfhe-python does not bind FindAutomorphismIndex.
Logged in notes/upstream-defects.md under R-only
surface.
Integer; the automorphism group element corresponding to that rotation.
find_automorphism_indices() for the vector form.
Vector form of find_automorphism_index(). Takes a vector
of slot indices and returns the corresponding automorphism
indices in the same order. R-first binding —
openfhe-python does not bind FindAutomorphismIndices.
find_automorphism_indices(cc, indices)find_automorphism_indices(cc, indices)
cc |
A |
indices |
Integer vector of slot indices. |
Integer vector of automorphism indices.
Computes f(0:(p-1), p) and returns it as a numeric vector
suitable for eval_func(). This is the R-side analogue of
OpenFHE's GenerateLUTviaFunction — we don't bind the C++
helper because its signature takes a raw function pointer that
can't capture an R closure, and R is natively vectorised so a
pure-R helper is both simpler and faster than wiring an R
callback through cpp11.
generate_lut_via_function(f, p)generate_lut_via_function(f, p)
f |
A function |
p |
The plaintext modulus (typically |
A length-p numeric vector of LUT entries
Reads the entire CryptoContextImpl internal EvalAutomorphism
key map — a named R list keyed by secret-key tag, where each
element is an EvalKeyMap (the rotation/automorphism key map
for that party). Used for rotation and EvalAtIndex under the
EvalKeyMap wire format.
get_all_eval_automorphism_keys()get_all_eval_automorphism_keys()
A named list keyed by key-tag string. Each element
is an EvalKeyMap (opaque wrapper around
shared_ptr<map<uint32_t, EvalKey<DCRTPoly>>>).
get_eval_automorphism_key_map() for per-tag
lookup, insert_eval_automorphism_key() for the write
path.
Reads the entire CryptoContextImpl internal EvalMult key
map — a named R list keyed by secret-key tag, where each
element is itself a list of EvalKey objects (the vector
of multiplication-eval keys registered under that tag).
get_all_eval_mult_keys()get_all_eval_mult_keys()
The returned list is a snapshot: each EvalKey wraps
a fresh shared_ptr copy, so retained references survive
subsequent clear_eval_mult_keys() calls. The underlying
keys are still shared with the cc registry — modifications
through other paths remain visible.
Primary consumer: checkpoint/resume workflows that need to audit which parties have keys registered before serializing the cc.
A named list keyed by key-tag string. Each element
is a list of EvalKey objects.
get_eval_mult_key_vector() for per-tag lookup,
insert_eval_mult_key() for the write path.
Reads the entire CryptoContextImpl internal EvalSum key
map. Structurally identical to
get_all_eval_automorphism_keys(): both share backing
storage on the C++ side, but the
two accessors are exposed separately so that fixture
authors can match whichever OpenFHE doc they are reading.
get_all_eval_sum_keys()get_all_eval_sum_keys()
A named list keyed by key-tag string. Each element
is an EvalKeyMap.
get_eval_sum_key_map(), insert_eval_sum_key()
Get the required multiplicative depth for CKKS bootstrapping
get_bootstrap_depth(level_budget, secret_key_dist = 1L)get_bootstrap_depth(level_budget, secret_key_dist = 1L)
level_budget |
Integer vector of length 2 |
secret_key_dist |
Secret key distribution (default: UNIFORM_TERNARY = 1) |
Integer: required depth
Reads the current correction factor the scheme uses during
the bootstrap EvalModReduceInternal step. Companion of
set_ckks_boot_correction_factor(). Changes here affect
all subsequent bootstrap operations on this CryptoContext
until another call to set_ckks_boot_correction_factor().
get_ckks_boot_correction_factor(cc)get_ckks_boot_correction_factor(cc)
cc |
A |
Integer; the current correction factor.
set_ckks_boot_correction_factor(), eval_bootstrap_setup()
Reads the CKKS plaintext's internal slot vector as complex
numbers. Every CKKS plaintext slot carries a
std::complex<double> internally; when a plaintext was
constructed from a real-valued vector via
make_ckks_packed_plaintext(), the imaginary parts are
all zero (up to CKKS encoding noise). When a plaintext
was constructed from a complex vector (the is-complex
dispatch path), both real and imaginary parts carry
information.
get_complex_packed_value(pt)get_complex_packed_value(pt)
pt |
A |
A native R complex vector.
get_real_packed_value() for the real-only view,
make_ckks_packed_plaintext() for the matching
constructor.
Returns the CryptoContext that was used to construct ct.
OpenFHE ciphertexts carry a back-pointer to their context so
that homomorphic operations can dispatch to the correct scheme
implementation without requiring the user to pass the context
explicitly.
get_crypto_context(ct, ...)get_crypto_context(ct, ...)
ct |
A |
... |
Reserved for future method-specific arguments. |
Naming note: get_crypto_context is distinct from
get_crypto_parameters. The former returns the
high-level CryptoContext S7 wrapper; the latter returns the
opaque CryptoParameters S7 wrapper.
A CryptoContext S7 object.
Returns the CryptoParameters S7 object carrying the opaque
std::shared_ptr<CryptoParametersBase<DCRTPoly>> at the C++
level. Useful for introspection; most R users will prefer to
call the individual lambda-routed getters (e.g.
get_scaling_technique(cc), get_batch_size(cc)) directly
instead of going through the CryptoParameters object.
get_crypto_parameters(cc, ...)get_crypto_parameters(cc, ...)
cc |
A |
... |
Reserved for future method-specific arguments. |
A CryptoParameters S7 object.
Integer m such that the underlying polynomial ring is
Z[x]/(x^n + 1) with n = m/2 (the ring dimension). Always
2 * ring_dimension(cc) for power-of-two cyclotomics.
get_cyclotomic_order(cc, ...)get_cyclotomic_order(cc, ...)
cc |
A |
... |
Reserved for future method-specific arguments. |
Integer.
Returns the ElementParams S7 object wrapping
std::shared_ptr<typename DCRTPoly::Params>. This is the
object that can be passed as the params argument to
make_ckks_packed_plaintext() to build a plaintext against a
specific parameter set rather than the context default.
get_element_params(cc, ...)get_element_params(cc, ...)
cc |
A |
... |
Reserved for future method-specific arguments. |
This is the first R-side way to obtain a non-default
ElementParams (the class itself has existed as a scaffold
but had no constructor path until now).
An ElementParams S7 object.
Returns the EncodingParams S7 object wrapping
std::shared_ptr<EncodingParamsImpl>. Holds the plaintext
modulus, batch size, and other encoding-level parameters.
get_encoding_params(cc, ...)get_encoding_params(cc, ...)
cc |
A |
... |
Reserved for future method-specific arguments. |
An EncodingParams S7 object.
Accessor for the cc-internal static automorphism-key map. The
underlying C++ call returns a shared_ptr directly (no copy),
so the returned EvalKeyMap is a live view of the cc
registry.
get_eval_automorphism_key_map(key_tag)get_eval_automorphism_key_map(key_tag)
key_tag |
Character; the key tag used when the map was originally generated. |
An EvalKeyMap.
Reads the vector of EvalMult keys registered under
key_tag. Errors (via catch_openfhe) if the tag is not
present in the registry.
get_eval_mult_key_vector(key_tag)get_eval_mult_key_vector(key_tag)
key_tag |
Character; the tag to look up (typically
|
A list of EvalKey objects.
get_all_eval_mult_keys(), insert_eval_mult_key()
Accessor for the cc-internal static map populated by
eval_sum_key_gen(). Used by the multi-party sum protocol to
pull the lead party's initial eval-sum map so other parties
can produce their shares.
get_eval_sum_key_map(key_tag)get_eval_sum_key_map(key_tag)
key_tag |
Character; the key tag used when the map was
originally generated. Typically the |
The underlying C++ call returns a const std::map&; the R
wrapper copies the map into a fresh shared_ptr to give the
returned EvalKeyMap owning semantics. The returned map is a
snapshot: subsequent modifications to the cc registry are not
reflected.
An EvalKeyMap.
Integer level at which subsequent key_gen() calls will
generate keys. Defaults to 0L. Useful when generating keys
at a non-fresh level for deep circuit protocols.
get_key_gen_level(cc, ...)get_key_gen_level(cc, ...)
cc |
A |
... |
Reserved for future method-specific arguments. |
Integer.
Maximum supported plaintext space for functional bootstrapping
get_max_plaintext_space(ctx)get_max_plaintext_space(ctx)
ctx |
A BinFHE context built with |
A numeric scalar (q / (2 * beta))
Returns 64 or 128 depending on how OpenFHE was compiled.
get_native_int()get_native_int()
integer
Get packed integer values from a plaintext
get_packed_value(pt)get_packed_value(pt)
pt |
A Plaintext |
Integer vector
Get real values from a CKKS plaintext
get_real_packed_value(pt)get_real_packed_value(pt)
pt |
A Plaintext |
Numeric vector
get_complex_packed_value() for the complex-view
accessor on the same underlying plaintext (each slot
internally carries a complex pair — this function
returns only the real parts).
Returns cryptoParams->GetScalingFactorReal(level) — the
double-valued scaling factor at the given level of the CKKS
modulus chain. Meaningful only for CKKS contexts; BFV/BGV
contexts return the default field value (effectively 1.0).
get_scaling_factor_real(cc, ...)get_scaling_factor_real(cc, ...)
cc |
A |
... |
Method-specific arguments. The CryptoContext method
accepts |
Used by ckks_scaling_factor_bits() (which takes log2 of the
level-0 value to recover the bit size originally set via
set_scaling_mod_size()) and by the Stage 2 form of
fhe_ckks_tolerance().
Numeric scalar.
After combining multi-party automorphism-key shares via
multi_add_eval_automorphism_keys(), insert the joined map
into the cc-internal registry so that
eval_rotate() / eval_fast_rotation() can consume it.
insert_eval_automorphism_key(eval_key_map, key_tag = "")insert_eval_automorphism_key(eval_key_map, key_tag = "")
eval_key_map |
An |
key_tag |
Character; default |
NULL, invisibly.
Adds a vector of EvalKey objects to the CryptoContext's
internal EvalMult-key map under key_tag. Silently replaces
any existing matching keys. If key_tag is the empty string
("", the default), the tag is retrieved from the eval-key
vector itself (each EvalKey carries its own tag).
insert_eval_mult_key(eval_keys, key_tag = "")insert_eval_mult_key(eval_keys, key_tag = "")
eval_keys |
A list of |
key_tag |
Character; the tag to register the vector
under. Default |
Used in checkpoint/resume workflows: after
fhe_deserialize_eval_keys() or multi_add_eval_mult_keys()
produces a combined eval-mult key vector, this function
registers it into the cc's internal storage so that
subsequent eval_mult() calls on ciphertexts encrypted
under the associated party's key can consume it.
NULL, invisibly.
insert_eval_sum_key(), insert_eval_automorphism_key()
After combining multi-party shares via
multi_add_eval_sum_keys(), the joined map has to be
inserted back into the cc's internal static registry before
eval_sum() can consume it. insert_eval_sum_key() routes
the map through CryptoContextImpl::InsertEvalSumKey (which
delegates internally to InsertEvalAutomorphismKey — the
same static storage is shared between the two surfaces).
insert_eval_sum_key(eval_key_map, key_tag = "")insert_eval_sum_key(eval_key_map, key_tag = "")
eval_key_map |
An |
key_tag |
Character; the tag to register the map under.
Default |
NULL, invisibly.
Final step of the two-party interactive bootstrap protocol. Adds the server's masked decryption to the client's re-encryption to produce the refreshed ciphertext.
int_boot_add(ct1, ct2)int_boot_add(ct1, ct2)
ct1, ct2
|
|
A refreshed Ciphertext.
Adjusts a ciphertext's scale to meet the scheme's
requirements before entering the interactive bootstrap
protocol. Typically called before int_boot_decrypt().
int_boot_adjust_scale(ct)int_boot_adjust_scale(ct)
ct |
A |
A Ciphertext ready for int_boot_decrypt().
First step of the single-party interactive bootstrap
protocol. The server applies its secret key share to produce
a "masked" partial decryption that the client can finish
off-line. Pairs with int_boot_encrypt() /
int_boot_add() / int_boot_adjust_scale() to complete the
refresh.
int_boot_decrypt(sk, ct)int_boot_decrypt(sk, ct)
sk |
A |
ct |
A |
A Ciphertext holding the masked decryption.
int_boot_encrypt(), int_boot_add(),
int_boot_adjust_scale()
Encrypts the client's masked decryption result under the public key, raising the ciphertext modulus back to a fresh level.
int_boot_encrypt(pk, ct)int_boot_encrypt(pk, ct)
pk |
A |
ct |
A |
A refreshed Ciphertext.
Combines the shares-pair lists produced by each party's
call to int_mp_boot_decrypt() into a single aggregated
shares pair for use in int_mp_boot_encrypt(). The input
is a list of per-party shares-pair lists (a list of lists
of Ciphertext).
int_mp_boot_add(cc, shares_pair_list)int_mp_boot_add(cc, shares_pair_list)
cc |
A |
shares_pair_list |
A list where each element is a
list of |
A list of Ciphertext objects — the aggregated
shares pair.
Multi-party analogue of int_boot_adjust_scale(). Adjusts
the ciphertext's scale before entering the distributed
bootstrap protocol.
int_mp_boot_adjust_scale(ct)int_mp_boot_adjust_scale(ct)
ct |
A |
A Ciphertext ready for the multi-party bootstrap
protocol.
Each party calls this with their own secret share, the
ciphertext being refreshed, and the common random element
from int_mp_boot_random_element_gen(). Returns a list of
two Ciphertext objects — the party's masked-decryption
"shares pair". Each party's shares pair gets collected and
fed into int_mp_boot_add().
int_mp_boot_decrypt(sk, ct, a)int_mp_boot_decrypt(sk, ct, a)
sk |
A |
ct |
A |
a |
A |
A list of two Ciphertext objects (the party's
shares pair).
Lead party's final step in the multi-party interactive
bootstrap. Takes the aggregated shares pair from
int_mp_boot_add() plus the common random element and the
original ciphertext, produces the refreshed ciphertext at a
fresh modulus level.
int_mp_boot_encrypt(pk, shares_pair, a, ct)int_mp_boot_encrypt(pk, shares_pair, a, ct)
pk |
The lead party's |
shares_pair |
A list of |
a |
The common random element |
ct |
The original |
A refreshed Ciphertext.
Generates a common random polynomial used by all parties in a multi-party interactive bootstrap round. Two overloads:
int_mp_boot_random_element_gen(cc, source)int_mp_boot_random_element_gen(cc, source)
cc |
A |
source |
Either a |
When source is a PublicKey (the lead party's public
key), routes to the (publicKey) C++ overload.
When source is a Ciphertext, routes to the
(ciphertext) overload which derives the cc and
parameters from the ciphertext directly — convenient when
a ciphertext is already in scope.
A Ciphertext holding the common random element.
Returns TRUE when both the public and secret keys of a
KeyPair are non-null external pointers. The C++
KeyPair::good() predicate performs the same check on the
C++ side; because R's KeyPair is a pure-R aggregate that
wraps an already-constructed PublicKey and PrivateKey,
the R-level check is equivalent.
is_good(kp, ...)is_good(kp, ...)
kp |
A |
... |
Reserved for future method-specific arguments (currently unused). |
TRUE or FALSE.
Generate key pair
key_gen(cc, ...)key_gen(cc, ...)
cc |
A CryptoContext |
... |
Method-specific arguments (eval_mult, rotations) |
A KeyPair
Brings a ciphertext that lives in the extended PQ basis
(for example, the output of eval_fast_rotation_ext() with
hybrid key switching) back to the standard Q basis. Only
supported when the scheme is configured with hybrid key
switching — other key-switching techniques have no
round-trip to extended PQ and therefore nothing to scale
back from.
key_switch_down(ct)key_switch_down(ct)
ct |
A |
R-first binding: openfhe-python v1.5.1.0 does not expose
KeySwitchDown at all. See notes/upstream-defects.md for
the R-only surface tracking.
A Ciphertext in the Q basis.
Every PublicKey / PrivateKey carries a string "key tag"
identifying which key pair it belongs to. The tag is set at
key-generation time by OpenFHE and can be inspected or
overwritten via these accessors. In threshold / multiparty
protocols the tag is used to associate a key with the party
that owns it; in single-user protocols it is typically left
at its default.
get_key_tag(key, ...) set_key_tag(key, ...)get_key_tag(key, ...) set_key_tag(key, ...)
key |
A |
... |
Reserved for future method-specific arguments.
|
get_key_tag: character scalar. set_key_tag: the
key invisibly.
Key Generation Mode Source: binfhe/binfhe-constants.h enum KEYGEN_MODE
KeygenModeKeygenMode
Contains a public key and a secret (private) key.
KeyPair(public = NULL, secret = NULL)KeyPair(public = NULL, secret = NULL)
public |
A PublicKey |
secret |
A PrivateKey |
Key Switching Techniques Source: pke/constants-defs.h enum KeySwitchTechnique
KeySwitchTechniqueKeySwitchTechnique
Drops levels levels from x's modulus chain in a single
operation. Useful when x is at a deeper level than the
ciphertext it will interact with next; level-reducing brings
them onto the same rung of the chain.
level_reduce(x, ...)level_reduce(x, ...)
x |
A |
... |
Method-specific arguments: |
An evaluation key is required — supply it from
key_gen(cc, eval_mult = TRUE).
A Ciphertext at x$level + levels.
Reduce the modulus chain by multiple levels, in place
level_reduce_in_place(x, ...)level_reduce_in_place(x, ...)
x |
A |
... |
Method-specific arguments: |
x invisibly.
LWE Ciphertext (Binary FHE)
LWECiphertext(ptr = NULL)LWECiphertext(ptr = NULL)
ptr |
External pointer (internal use) |
LWE Private Key (Binary FHE)
LWEPrivateKey(ptr = NULL)LWEPrivateKey(ptr = NULL)
ptr |
External pointer (internal use) |
Encode a real-valued numeric vector as a CKKS packed plaintext.
The result is an unencrypted Plaintext object that can then
be passed to encrypt().
make_ckks_packed_plaintext( cc, values, noise_scale_deg = 1L, level = 0L, params = NULL, slots = 0L )make_ckks_packed_plaintext( cc, values, noise_scale_deg = 1L, level = 0L, params = NULL, slots = 0L )
cc |
A |
values |
A numeric vector to pack. Length must not exceed
|
noise_scale_deg |
Integer degree of the initial scaling
factor applied to the encoded plaintext, expressed as a power
of the scheme's scaling factor. Defaults to |
level |
Integer target encryption level of the encoded
plaintext. Defaults to |
params |
Advanced. An |
slots |
Integer number of CKKS slots to pack into.
Defaults to |
A Plaintext.
Encode an integer vector as a coefficient-packed plaintext.
Coefficient packing places each input value in a separate
polynomial coefficient and is the alternative to the SIMD
batched packing produced by make_packed_plaintext(). Used by
the integer-modulus Ring-LWE vignettes where per-coefficient
access is needed.
make_coef_packed_plaintext(cc, values, noise_scale_deg = 1L, level = 0L)make_coef_packed_plaintext(cc, values, noise_scale_deg = 1L, level = 0L)
cc |
A |
values |
An integer vector whose length must not exceed
the ring dimension of |
noise_scale_deg |
See the |
level |
See the |
A Plaintext.
Encode an integer vector as a BFV / BGV packed plaintext. The
result is an unencrypted Plaintext object that can then be
passed to encrypt().
make_packed_plaintext(cc, values, noise_scale_deg = 1L, level = 0L)make_packed_plaintext(cc, values, noise_scale_deg = 1L, level = 0L)
cc |
A |
values |
An integer vector to pack. Length must not exceed
|
noise_scale_deg |
Integer degree of the initial scaling
factor applied to the encoded plaintext. Defaults to |
level |
Integer target level in the RNS modulus chain.
Defaults to |
A Plaintext.
Synonym for rescale(). Both names dispatch to the same C++
operation (CryptoContextImpl::Rescale delegates to
ModReduce internally); the R binding keeps both so fixture
and vignette authors can use whichever name matches the
OpenFHE documentation they're following.
mod_reduce(x, ...)mod_reduce(x, ...)
x |
A |
... |
Reserved for future method-specific arguments. |
A Ciphertext at one lower level.
rescale(), mod_reduce_in_place()
Reduce the modulus chain by one level, in place
mod_reduce_in_place(x, ...)mod_reduce_in_place(x, ...)
x |
A |
... |
Reserved for future method-specific arguments. |
x invisibly.
Combine two automorphism-key map shares
multi_add_eval_automorphism_keys( cc, eval_key_map1, eval_key_map2, key_tag = "" )multi_add_eval_automorphism_keys( cc, eval_key_map1, eval_key_map2, key_tag = "" )
cc |
A |
eval_key_map1, eval_key_map2
|
|
key_tag |
Character; default |
A combined EvalKeyMap suitable for insertion into
the cc registry via insert_eval_automorphism_key().
Combines two partial key-switching eval keys into a joint
eval key. See multi_add_eval_mult_keys() for the eval-mult
variant — the two functions consume keys produced by different
generators and are not interchangeable.
multi_add_eval_keys(cc, ek1, ek2, key_tag = "")multi_add_eval_keys(cc, ek1, ek2, key_tag = "")
cc |
A CryptoContext |
ek1, ek2
|
EvalKey objects to combine |
key_tag |
Character; optional tag to associate with the
combined key. Default |
A combined EvalKey
The eval-mult flavor of multi_add_eval_keys(). Consumes
keys produced by a multi-party eval-mult key generator rather
than by multi_key_switch_gen(). Where the R generator is
not yet exposed, the wrapper still lets downstream code
exercise the add-keys flow against keys constructed through
the underlying cpp11 binding.
multi_add_eval_mult_keys(cc, ek1, ek2, key_tag = "")multi_add_eval_mult_keys(cc, ek1, ek2, key_tag = "")
cc |
A CryptoContext |
ek1, ek2
|
EvalKey objects (eval-mult partials) to combine |
key_tag |
Character; optional tag to associate with the
combined key. Default |
A combined EvalKey
Combine two sum-key map shares into a joint sum-key map
multi_add_eval_sum_keys(cc, eval_key_map1, eval_key_map2, key_tag = "")multi_add_eval_sum_keys(cc, eval_key_map1, eval_key_map2, key_tag = "")
cc |
A |
eval_key_map1, eval_key_map2
|
|
key_tag |
Character; default |
A combined EvalKeyMap suitable for insertion into
the cc registry via insert_eval_sum_key().
Combine public keys from multiple parties
multi_add_pub_keys(cc, pk1, pk2, key_tag = "")multi_add_pub_keys(cc, pk1, pk2, key_tag = "")
cc |
A CryptoContext |
pk1, pk2
|
PublicKey objects to combine |
key_tag |
Character; optional tag to associate with the
combined key. Default |
A combined PublicKey
The EvalAtIndex flavor of multi_eval_automorphism_key_gen();
takes signed rotation indices rather than automorphism indices.
Semantically equivalent but lives on a distinct C++ entry
point, matching the openfhe-python surface.
multi_eval_at_index_key_gen(cc, sk, eval_key_map, index_list, key_tag = "")multi_eval_at_index_key_gen(cc, sk, eval_key_map, index_list, key_tag = "")
cc |
A |
sk |
This party's |
eval_key_map |
An existing |
index_list |
Integer vector of signed rotation indices. |
key_tag |
Character; default |
An EvalKeyMap.
Produces this party's share of the joined automorphism eval
key map for the supplied index_list. Each other party calls
the same method with their own secret share, and the shares
are combined via multi_add_eval_automorphism_keys() to
produce the final joined map.
multi_eval_automorphism_key_gen(cc, sk, eval_key_map, index_list, key_tag = "")multi_eval_automorphism_key_gen(cc, sk, eval_key_map, index_list, key_tag = "")
cc |
A |
sk |
This party's |
eval_key_map |
An existing |
index_list |
Integer vector of rotation indices. |
key_tag |
Character; optional tag to associate with the
produced map. Default |
An EvalKeyMap holding this party's joint share.
Generate a joint sum-key share for multi-party EvalSum
multi_eval_sum_key_gen(cc, sk, eval_key_map, key_tag = "")multi_eval_sum_key_gen(cc, sk, eval_key_map, key_tag = "")
cc |
A |
sk |
This party's |
eval_key_map |
An existing |
key_tag |
Character; default |
An EvalKeyMap.
Generates an eval key that switches ciphertexts encrypted
under sk_orig into a form decryptable by sk_new, starting
from an existing eval key that carries the key-switch
auxiliary information. Used by threshold protocols to route
partial decryptions across a re-keyed party set.
multi_key_switch_gen(cc, sk_orig, sk_new, eval_key)multi_key_switch_gen(cc, sk_orig, sk_new, eval_key)
cc |
A CryptoContext |
sk_orig |
The original party's PrivateKey |
sk_new |
The new party's PrivateKey |
eval_key |
An EvalKey carrying key-switch auxiliary data |
An EvalKey suitable for routing through
multi_add_eval_keys() to combine with other parties'
key-switch shares
Combines partial decryptions from any number of parties (n >= 2).
The lead party's partial decryption (from
multiparty_decrypt_lead()) must be supplied first; subsequent
partials (from multiparty_decrypt_main()) follow in any order.
multiparty_decrypt_fusion(cc, ...)multiparty_decrypt_fusion(cc, ...)
cc |
A CryptoContext |
... |
Two or more partially decrypted Ciphertext objects. The first must be from the lead party. |
A Plaintext with the final decrypted result
In threshold decryption, the lead party calls this first.
Accepts either a single Ciphertext or a list of
Ciphertext objects:
multiparty_decrypt_lead(cc, sk, ct)multiparty_decrypt_lead(cc, sk, ct)
cc |
A CryptoContext |
sk |
This party's PrivateKey |
ct |
A Ciphertext or a list of Ciphertexts |
single Ciphertext: returns a single partially decrypted
Ciphertext, matching the original single-ciphertext signature.
list of Ciphertext: returns a list of partially decrypted
Ciphertext objects of the same length, routed through the
C++ MultipartyDecryptLead(vector<Ciphertext>, PrivateKey)
overload (cryptocontext.h line 3115). Useful when a protocol
round needs to partially decrypt a batch in one trip.
A partially decrypted Ciphertext or list of Ciphertexts, mirroring the input shape.
Other parties call this after the lead. Accepts either a
single Ciphertext or a list of Ciphertext objects with the
same semantics as multiparty_decrypt_lead().
multiparty_decrypt_main(cc, sk, ct)multiparty_decrypt_main(cc, sk, ct)
cc |
A CryptoContext |
sk |
This party's PrivateKey |
ct |
A Ciphertext or a list of Ciphertexts |
A partially decrypted Ciphertext or list of Ciphertexts, mirroring the input shape.
The lead party uses key_gen() to generate the initial keypair.
Subsequent parties call this with the lead's public key.
multiparty_key_gen(cc, lead_pk, make_sparse = FALSE, fresh = FALSE)multiparty_key_gen(cc, lead_pk, make_sparse = FALSE, fresh = FALSE)
cc |
A CryptoContext (must have MULTIPARTY feature enabled) |
lead_pk |
The lead party's PublicKey |
make_sparse |
Logical; if |
fresh |
Logical; if |
A KeyPair for this party
Multiparty Mode Source: pke/constants-defs.h enum MultipartyMode
MultipartyModeMultipartyMode
Multiplication Technique (BFV) Source: pke/constants-defs.h enum MultiplicationTechnique
MultiplicationTechniqueMultiplicationTechnique
All OpenFHE objects (CryptoContext, Ciphertext, Plaintext, Keys, etc.) inherit from this class. It holds an external pointer to a C++ shared_ptr.
OpenFHEObject(ptr = NULL)OpenFHEObject(ptr = NULL)
ptr |
External pointer to C++ object (internal use) |
Plaintext
Plaintext(ptr = NULL)Plaintext(ptr = NULL)
ptr |
External pointer (internal use) |
Retrieve or set fields on a Plaintext object. Each accessor
wraps the corresponding upstream PlaintextImpl::Get*/Set*
method and returns its value unchanged.
get_noise_scale_deg(x, ...) get_length(x, ...) get_level(x, ...) get_scaling_factor(x, ...) get_log_precision(x, ...) get_formatted_values(x, ...) set_ckks_data_type(x, ...) get_encoding_type(x, ...) get_scaling_factor_int(x, ...) get_scheme_id(x, ...) is_encoded(x, ...) low_bound(x, ...) high_bound(x, ...) get_slots(x, ...) get_log_error(x, ...) get_coef_packed_value(x, ...) get_string_value(x, ...) get_element_ring_dimension(x, ...) set_scaling_factor(x, ...) set_scaling_factor_int(x, ...) set_noise_scale_deg(x, ...) set_level(x, ...) set_slots(x, ...) set_string_value(x, ...) set_int_vector_value(x, ...)get_noise_scale_deg(x, ...) get_length(x, ...) get_level(x, ...) get_scaling_factor(x, ...) get_log_precision(x, ...) get_formatted_values(x, ...) set_ckks_data_type(x, ...) get_encoding_type(x, ...) get_scaling_factor_int(x, ...) get_scheme_id(x, ...) is_encoded(x, ...) low_bound(x, ...) high_bound(x, ...) get_slots(x, ...) get_log_error(x, ...) get_coef_packed_value(x, ...) get_string_value(x, ...) get_element_ring_dimension(x, ...) set_scaling_factor(x, ...) set_scaling_factor_int(x, ...) set_noise_scale_deg(x, ...) set_level(x, ...) set_slots(x, ...) set_string_value(x, ...) set_int_vector_value(x, ...)
x |
A |
... |
Reserved for future method-specific arguments.
Setters accept a |
Several base-class accessors are declared virtual and throw
OPENFHE_THROW in the base implementation (e.g. get_string_value
on a non-string plaintext, get_log_precision on a non-CKKS
plaintext). Calling an accessor on the wrong kind of plaintext
therefore raises an R error via cli::cli_abort, not a silent
wrong value.
The underlying field value. Types vary per accessor.
get_noise_scale_deg: Integer noise-scale-degree of a
CKKS plaintext. After construction the degree is the value
passed to make_ckks_packed_plaintext(..., noise_scale_deg)
under FIXEDMANUAL scaling; under FLEXIBLEAUTO the scheme
overrides the user-supplied value at context-generation time
(see discovery D011). Incremented by each multiplication
before a rescale. The harness Signal 2 differential fixture
for MakeCKKSPackedPlaintext reads this value to verify the
noise_scale_deg argument reached the C++ call site.
get_length: Integer effective length of a
packed plaintext — the number of slots that hold user-supplied
values. Defaults to the full batch size at construction;
set_length() can shorten it for display or decryption
purposes.
get_level: Integer level of the plaintext
in the RNS modulus chain. 0 for a fresh plaintext;
incremented by each rescale() the plaintext survives. For
CKKS-packed plaintexts the level must match the ciphertext
level at every homomorphic operation, or the evaluator rejects
the pair. The harness Signal 2 fixture reads this value to
verify the level argument reached the C++ call site.
get_scaling_factor: Numeric scaling factor for
CKKS-based plaintexts — the multiplier the real vector is
scaled by before encoding. Equals 2^scaling_mod_size for a
freshly-encoded plaintext under FLEXIBLEAUTO; halves after
each rescale. For BFV/BGV plaintexts this is returned as a
default value (no rescaling applies).
get_log_precision: Numeric log2 of the precision
lost during CKKS encoding. Only meaningful for CKKS plaintexts;
throws via OPENFHE_THROW for BFV/BGV and is surfaced as an
R error by cli::cli_abort.
get_formatted_values: String-format the plaintext's
encoded values with precision decimal digits. Implemented
on the concrete plaintext subclass (packed, CKKS, string,
coefficient); throws on plaintexts whose subclass does not
override.
set_ckks_data_type: Set the CKKS data type to
CKKSDataType$REAL or CKKSDataType$COMPLEX. Only meaningful
for CKKS plaintexts. Most R vignettes use the default REAL
type; set to COMPLEX only when you are constructing a CKKS
plaintext from a complex vector.
get_encoding_type: parity-deferred: integer
encoding type (see PlaintextEncodings for the enum values).
get_scaling_factor_int: parity-deferred: BGV integer
scaling factor. Returned as a double carrying a losslessly
rounded 53-bit integer per design.md §7.
get_scheme_id: parity-deferred: scheme
identifier (see SchemeId enum).
is_encoded: parity-deferred: logical
"has the plaintext been encoded yet?" The factory methods
typically encode plaintexts eagerly, so this is TRUE for
fresh plaintexts. Returns FALSE only for plaintexts
constructed in a two-step uninitialised form.
low_bound: parity-deferred: integer
lower bound that can be encoded with the current plaintext
modulus: -floor(t / 2).
high_bound: parity-deferred: integer
upper bound that can be encoded with the current plaintext
modulus: floor(t / 2).
get_slots: parity-deferred: integer CKKS
slot count. For Plaintext dispatch this is the GetSlots()
value set at construction. The harness Signal 2 fixture reads
this value to verify the slots argument reached the C++
call site.
get_log_error: parity-deferred: numeric
log2 of the error estimate. Only meaningful for CKKS
plaintexts; throws for BFV/BGV.
get_coef_packed_value: parity-deferred: integer
vector of the underlying coef-packed encoding. Throws for
plaintexts whose subclass is not coef-packed.
get_string_value: parity-deferred: string value
of a string-encoded plaintext. Throws for plaintexts whose
subclass is not string-encoded.
get_element_ring_dimension: parity-deferred: integer ring
dimension of the underlying Element. This is the plaintext's
view of the lattice ring dimension; typically matches the
crypto context's ring dimension.
set_scaling_factor: parity-deferred: set the CKKS
plaintext scaling factor.
set_scaling_factor_int: parity-deferred: set the BGV
plaintext integer scaling factor.
set_noise_scale_deg: parity-deferred: set the
plaintext noise scale degree. Most users should not call this
directly — the factory methods and the evaluator manage
noise_scale_deg automatically.
set_level: parity-deferred: set the
plaintext level. As with set_noise_scale_deg, most users
should not call this directly.
set_slots: parity-deferred: set the CKKS
slot count. As with set_length, this is typically managed
by the factory methods.
set_string_value: parity-deferred: set the
string value of a string-encoded plaintext. Throws for
plaintexts whose subclass is not string-encoded.
set_int_vector_value: parity-deferred: set the
integer-vector value of an integer-encoded plaintext. Throws
for plaintexts whose subclass does not support an integer
vector.
Combines the plaintext's encoding type, scaling factor, noise scale degree, level, and slot count into a deterministic string representation. Two plaintexts with identical parameters produce identical strings; any parameter change produces a different string.
plaintext_params_hash(x)plaintext_params_hash(x)
x |
A |
Named plaintext_params_hash in design.md §10 as
the fourth "harness unblocker" for the Signal 2 differential
fixture for make_ckks_packed_plaintext. The fixture calls
plaintext_params_hash() on a default and a perturbed plaintext
and expects different strings when the perturbation reaches the
C++ call site.
Not a cryptographic hash — equality comparison is the only guarantee. The returned string's format is implementation detail and may change without notice.
Character scalar.
Plaintext Encoding Types Source: pke/constants-defs.h enum PlaintextEncodings
PlaintextEncodingsPlaintextEncodings
PREMode matches the design.md §8 shortening convention
(same pattern as Feature for PKESchemeFeature).Proxy Re-encryption Mode
Source: pke/constants-defs.h enum ProxyReEncryptionMode
R-side name PREMode matches the design.md §8 shortening convention
(same pattern as Feature for PKESchemeFeature).
PREModePREMode
Private Key
PrivateKey(ptr = NULL)PrivateKey(ptr = NULL)
ptr |
External pointer (internal use) |
Public Key
PublicKey(ptr = NULL)PublicKey(ptr = NULL)
ptr |
External pointer (internal use) |
Reduces a ciphertext to 2 polynomial components. Needed after a
sequence of eval_mult_no_relin() calls to restore a
decryptable form. A relinearization key must have been
generated via key_gen(cc, eval_mult = TRUE) before calling
this.
relinearize(x, ...)relinearize(x, ...)
x |
A |
... |
Reserved for future method-specific arguments. |
A Ciphertext with exactly 2 components.
Reduces the modulus chain by one level. Required after eval_mult
under FIXEDMANUAL scaling; automatic under FIXEDAUTO /
FLEXIBLEAUTO.
rescale(ct, ...)rescale(ct, ...)
ct |
A Ciphertext |
... |
Reserved for future method-specific arguments |
A Ciphertext at one lower level
Returns N, the cyclotomic ring dimension. The cyclotomic order
M used by eval_fast_rotation() is 2 * N.
ring_dimension(cc, ...)ring_dimension(cc, ...)
cc |
A CryptoContext |
... |
Reserved for future method-specific arguments |
Integer ring dimension
Scaling Techniques (CKKS) Source: pke/constants-defs.h enum ScalingTechnique
ScalingTechniqueScalingTechnique
Returned by get_scheme() on any CCParams object. R-side name
SchemeId matches the upstream pke/scheme/scheme-id.h header
filename and avoids colliding with a future Scheme S7 class
(design.md §6 mentions a potential wrapper around
std::shared_ptr<SchemeBase<DCRTPoly>> with that name).
SchemeIdSchemeId
Source: pke/scheme/scheme-id.h enum SCHEME
Secret Key Distribution Source: core/lattice/constants-lattice.h enum SecretKeyDist
SecretKeyDistSecretKeyDist
Security Levels Source: core/lattice/stdlatticeparms.h enum SecurityLevel
SecurityLevelSecurityLevel
Serialize evaluation keys to file
serialize_eval_keys( filename, type = c("mult", "automorphism", "sum"), format = "binary", key_tag = "" )serialize_eval_keys( filename, type = c("mult", "automorphism", "sum"), format = "binary", key_tag = "" )
filename |
Path to output file |
type |
"mult" or "automorphism" |
format |
"binary" (default) or "json" |
key_tag |
Key tag (default: "") |
TRUE on success (invisibly)
Sets the scheme-level correction factor used by subsequent
bootstraps. Normally this is set via the correction_factor
argument to eval_bootstrap_setup() at bootstrap setup
time; this pair exists for post-setup programmatic control.
set_ckks_boot_correction_factor(cc, cf)set_ckks_boot_correction_factor(cc, cf)
cc |
A |
cf |
Integer; the new correction factor. |
The cc, invisibly.
get_ckks_boot_correction_factor()
Set the key-generation level of a CryptoContext
set_key_gen_level(cc, ...)set_key_gen_level(cc, ...)
cc |
A |
... |
Method-specific arguments; the |
cc invisibly.
Set the effective length of a plaintext
set_length(pt, len)set_length(pt, len)
pt |
A Plaintext |
len |
Integer length |
Performs a full n-of-n threshold decryption of ct given the
ordered list of party secret keys. The first key in sks is used
for multiparty_decrypt_lead(); the remaining keys for
multiparty_decrypt_main(); the resulting partials are then
fused with multiparty_decrypt_fusion().
threshold_decrypt(cc, sks, ct)threshold_decrypt(cc, sks, ct)
cc |
A CryptoContext |
sks |
A list of PrivateKey objects, lead first |
ct |
The Ciphertext to decrypt |
Use this when you have all secret keys in one place (testing, simulation, single-process demos). In a real distributed deployment each site holds only its own secret key and the partials travel over the network — that flow uses the lead / main / fusion functions directly.
A Plaintext
Clears eval keys and releases contexts on exit (even on error).
with_fhe_context(expr)with_fhe_context(expr)
expr |
Expression to evaluate |
Result of expr