| Title: | R Interface to the 'OpenFHE' Fully Homomorphic Encryption Library |
|---|---|
| Description: | Provides an R interface to 'OpenFHE', the open-source C++ library for fully homomorphic encryption (Al Badawi and others, 2022) <https://eprint.iacr.org/2022/915>, which allows computation directly on encrypted data without access to the secret key. Supports the Brakerski-Fan-Vercauteren (BFV, 2012) <https://eprint.iacr.org/2012/144>, Brakerski-Gentry-Vaikuntanathan (BGV, 2014) <doi:10.1145/2633600>, and Cheon-Kim-Kim-Song (CKKS, 2017) <https://eprint.iacr.org/2016/421> schemes for arithmetic on encrypted numbers, together with the Ducas-Micciancio (FHEW, 2015) <https://eprint.iacr.org/2014/816> and Chillotti-Gama-Georgieva-Izabachene (TFHE, 2020) <https://eprint.iacr.org/2018/421> schemes for evaluating arbitrary functions on encrypted bits. |
| Authors: | Balasubramanian Narasimhan [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-5852-7639>), New Jersey Institute of Technology [cph] (OpenFHE C++ library, inst/openfhe/src), Duality Technologies, Inc. [ctb, cph] (OpenFHE C++ library, inst/openfhe/src), Samuel Neves [ctb, cph] (BLAKE2 reference implementation, inst/openfhe/src/core), Jean-Philippe Aumasson [ctb, cph] (BLAKE2X reference implementation, inst/openfhe/src/core), Randolph Voorhies [ctb, cph] (cereal serialization library, inst/openfhe/cereal), Shane Grant [ctb, cph] (cereal serialization library, inst/openfhe/cereal), Juan Pedro Bolivar Puente [ctb, cph] (cereal std::optional and std::variant support), THL A29 Limited, a Tencent company [cph] (RapidJSON, bundled in inst/openfhe/cereal), Milo Yip [ctb, cph] (RapidJSON, bundled in inst/openfhe/cereal), Alexander Chemeris [ctb, cph] (msinttypes, bundled in inst/openfhe/cereal), Marcin Kalicinski [ctb, cph] (RapidXml, bundled in inst/openfhe/cereal), Rene Nyffenegger [ctb, cph] (base64 encoder/decoder, bundled in inst/openfhe/cereal) |
| Maintainer: | Balasubramanian Narasimhan <[email protected]> |
| License: | BSD_2_clause + file LICENSE |
| Version: | 1.5.1.2 |
| Built: | 2026-10-09 13:28:22 UTC |
| Source: | https://github.com/openfheorg/openfhe.r |
Provides an R interface to 'OpenFHE', the open-source C++ library for fully homomorphic encryption (Al Badawi and others, 2022) https://eprint.iacr.org/2022/915, which allows computation directly on encrypted data without access to the secret key. Supports the Brakerski-Fan-Vercauteren (BFV, 2012) https://eprint.iacr.org/2012/144, Brakerski-Gentry-Vaikuntanathan (BGV, 2014) doi:10.1145/2633600, and Cheon-Kim-Kim-Song (CKKS, 2017) https://eprint.iacr.org/2016/421 schemes for arithmetic on encrypted numbers, together with the Ducas-Micciancio (FHEW, 2015) https://eprint.iacr.org/2014/816 and Chillotti-Gama-Georgieva-Izabachene (TFHE, 2020) https://eprint.iacr.org/2018/421 schemes for evaluating arbitrary functions on encrypted bits.
Maintainer: Balasubramanian Narasimhan [email protected] (ORCID) [copyright holder]
Authors:
Balasubramanian Narasimhan [email protected] (ORCID) [copyright holder]
Other contributors:
New Jersey Institute of Technology (OpenFHE C++ library, inst/openfhe/src) [copyright holder]
Duality Technologies, Inc. (OpenFHE C++ library, inst/openfhe/src) [contributor, copyright holder]
Samuel Neves (BLAKE2 reference implementation, inst/openfhe/src/core) [contributor, copyright holder]
Jean-Philippe Aumasson (BLAKE2X reference implementation, inst/openfhe/src/core) [contributor, copyright holder]
Randolph Voorhies (cereal serialization library, inst/openfhe/cereal) [contributor, copyright holder]
Shane Grant (cereal serialization library, inst/openfhe/cereal) [contributor, copyright holder]
Juan Pedro Bolivar Puente (cereal std::optional and std::variant support) [contributor, copyright holder]
THL A29 Limited, a Tencent company (RapidJSON, bundled in inst/openfhe/cereal) [copyright holder]
Milo Yip (RapidJSON, bundled in inst/openfhe/cereal) [contributor, copyright holder]
Alexander Chemeris (msinttypes, bundled in inst/openfhe/cereal) [contributor, copyright holder]
Marcin Kalicinski (RapidXml, bundled in inst/openfhe/cereal) [contributor, copyright holder]
Rene Nyffenegger (base64 encoder/decoder, bundled in inst/openfhe/cereal) [contributor, copyright holder]
Useful links:
Report bugs at https://github.com/openfheorg/openfhe.R/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.
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 |
maximum degree of the secret key that can be relinearized. Upstream default is 2. No current vignette or Python example exercises this; the cpp11 binding is in place so a later release can promote it without a recompile. |
pre_mode |
proxy re-encryption mode
( |
eval_add_count |
upstream noise-budget hint: maximum additions between multiplications. Used only by the noise-flooding path. Default 0. |
key_switch_count |
upstream noise-budget hint: maximum key-switch count. Default 0. |
encryption_technique |
BFV-specific
encryption variant ( |
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.
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 |
see the BFV entry. |
pre_mode |
see the BFV entry. |
statistical_security |
statistical security parameter (bits), used by the noise-flooding decryption path. |
num_adversarial_queries |
upper bound on the number of adversarial queries the noise-flooding path must survive. |
eval_add_count |
see the BFV entry. |
key_switch_count |
see the BFV entry. |
pre_num_hops |
maximum number of hops for proxy re-encryption in BGV. Only meaningful if the PRE feature is enabled. |
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 ( |
Invisibly, the ctx BinFHE context that was passed in. Called for
its side effect: the bootstrapping and key-switching keys are
generated and stored inside the C++ context, after which
eval_bin_gate() and the other gate evaluations can be used.
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 object.
Generate BinFHE secret key
bin_key_gen(ctx)bin_key_gen(ctx)
ctx |
A BinFHE context |
An LWEPrivateKey
BinFHE context (Binary FHE)
BinFHEContext(ptr = NULL)BinFHEContext(ptr = NULL)
ptr |
External pointer (internal use) |
An S7 object of class BinFHEContext, inheriting from
OpenFHEObject, whose ptr property holds an external pointer to
the C++ boolean-circuit context. It is the BinFHE counterpart of
CryptoContext and is deliberately a different class, so a
CryptoContext cannot be passed where a BinFHE context belongs or
the other way round. Obtain one from bin_fhe_context() rather
than by calling this constructor directly.
Mirrors the C++ enum BINFHE_METHOD in binfhe/binfhe-constants.h.
BinFHEMethodBinFHEMethod
A named list of 4 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, selecting the
bootstrapping method a boolean-circuit context uses: AP
(Alperin-Sheriff-Peikert), GINX (Gama-Izabachene-Nguyen-Xie, the
default) or LMKCDEY. INVALID_METHOD marks an unset value. Pass
an element as the method argument of bin_fhe_context().
Mirrors the C++ enum BINFHE_OUTPUT in binfhe/binfhe-constants.h.
BinFHEOutputBinFHEOutput
A named list of 5 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, describing the form the
ciphertext produced by a BinFHE operation should take: FRESH
(noise reset to the level of a fresh encryption), BOOTSTRAPPED,
LARGE_DIM and SMALL_DIM (the LWE dimension the result is
expressed in). INVALID_OUTPUT marks an unset value. Pass an
element as the output argument of bin_encrypt().
Mirrors the C++ enum BINFHE_PARAMSET in binfhe/binfhe-constants.h,
whose enumerators are numbered sequentially from 0.
BinFHEParamSetBinFHEParamSet
A named list of 44 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name. An element names a
pre-tabulated set of lattice parameters for the boolean-circuit
(BinFHE) schemes: TOY and MEDIUM are insecure sizes for
experimentation, and the STD128, STD192 and STD256 families
give the corresponding bits of security, with the Q suffix
denoting a larger ciphertext modulus, the _3 and _4 suffixes
3- and 4-input gates, LMKCDEY the Lee-Micciancio-Kim-Choi-Deryabin-Eom-Yoo
bootstrapping method and LPF a low-probability-of-failure
variant. Pass an element as the paramset argument of
bin_fhe_context().
Mirrors the C++ enum BINGATE in binfhe/binfhe-constants.h, whose
enumerators are numbered sequentially from 0.
BinGateBinGate
A named list of 14 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, naming the boolean gate to
evaluate on encrypted bits: the two-input gates OR, AND, NOR,
NAND, XOR, XNOR and the faster XOR_FAST, XNOR_FAST; the
three- and four-input AND3, OR3, AND4, OR4; and MAJORITY
and CMUX. Pass an element as the gate argument of
eval_bin_gate().
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 |
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.
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: integer scheme
identifier (see SchemeId for the enum values).
get_standard_deviation: standard deviation
of the Gaussian error distribution.
get_secret_key_dist: secret-key
distribution (see SecretKeyDist).
get_max_relin_sk_deg: maximum
relinearization secret-key degree.
get_pre_mode: proxy
re-encryption mode (see PREMode).
get_multiparty_mode: multiparty mode
(see MultipartyMode).
get_execution_mode: execution mode
(see ExecutionMode).
get_decryption_noise_mode: decryption noise
mode (see DecryptionNoiseMode).
get_noise_estimate: noise-flooding
noise estimate (double).
get_desired_precision: noise-flooding
target precision (double, bits).
get_statistical_security: statistical
security parameter. Return type is double per header
inconsistency; see the Return-type note.
get_num_adversarial_queries: upper bound on
adversarial queries. Return type is double per header
inconsistency; see the Return-type note.
get_threshold_num_of_parties: threshold-FHE
party count.
get_key_switch_technique: key-switching
technique (see KeySwitchTechnique).
get_scaling_technique: scaling technique
(see ScalingTechnique).
get_batch_size: SIMD batch size.
get_first_mod_size: bit size of the
first (largest) prime in the CKKS modulus chain.
get_num_large_digits: number of large
digits for HYBRID key switching.
get_multiplicative_depth: 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: bit size of each
CKKS scaling modulus.
get_security_level: target security
level (see SecurityLevel).
get_eval_add_count: BFV/BGV
noise-flooding hint: maximum additions between multiplications.
get_key_switch_count: BFV/BGV
noise-flooding hint: maximum key-switch count.
get_encryption_technique: BFV encryption
technique (see EncryptionTechnique).
get_multiplication_technique: BFV multiplication
technique (see MultiplicationTechnique).
get_pre_num_hops: PRE hop count.
get_interactive_boot_compression_level: CKKS interactive
bootstrap compression level (see CompressionLevel).
get_register_word_size: register word size
for multi-precision arithmetic.
get_ckks_data_type: 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.
Wraps an encrypted OpenFHE ciphertext. Supports arithmetic operators
+, -, * which dispatch to homomorphic operations.
Ciphertext(ptr = NULL)Ciphertext(ptr = NULL)
ptr |
External pointer (internal use) |
An S7 object of class Ciphertext, inheriting from OpenFHEObject,
whose ptr property holds an external pointer to the C++
ciphertext. Ciphertexts are produced by encrypt() and by the
eval_*() family rather than by calling this constructor directly,
and they carry the encrypted vector together with the level and
scaling-factor bookkeeping the scheme needs.
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.
Mirrors the C++ enum CKKSDataType in pke/constants-defs.h.
CKKSDataTypeCKKSDataType
A named list of 2 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, declaring whether the
slots of a CKKS ciphertext hold REAL or COMPLEX numbers.
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.
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 |
see the BFV entry. |
pre_mode |
see the BFV entry. |
execution_mode |
one of
|
decryption_noise_mode |
one of
|
noise_estimate |
numeric noise estimate
used by the noise-flooding path. Paired with |
desired_precision |
numeric target precision (in bits) for the noise-flooding path. |
statistical_security |
see the BGV entry. |
num_adversarial_queries |
see the BGV entry. |
composite_degree |
composite scaling
degree for the |
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" |
No return value, called for side effects. Depending on what, it
drops the process-wide caches of relinearization keys and of
automorphism (rotation) keys, and releases the registry of crypto
contexts, freeing the memory they hold.
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.
compress(x, ...)compress(x, ...)
x |
A |
... |
Method-specific arguments: |
A compressed Ciphertext.
Mirrors the C++ enum CompressionLevel in pke/constants-defs.h.
Note that the values start at 2, not 0: the header explains that
compression levels 0 and 1 are not supported and that the remaining
values are deliberately not renumbered.
CompressionLevelCompressionLevel
A named list of 2 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, naming how far a
ciphertext is compressed before the interactive bootstrapping
round-trip: COMPACT (2) sends the least data but is only safe
when the result is decrypted immediately, while SLACK (3) leaves
room for further computation on the result. Pass an element as the
interactive_boot_compression_level argument of CKKSParams() or
fhe_context().
Crypto Context
CryptoContext(ptr = NULL)CryptoContext(ptr = NULL)
ptr |
External pointer (internal use) |
An S7 object of class CryptoContext, inheriting from
OpenFHEObject, whose ptr property holds an external pointer to
the C++ crypto context. The context owns the scheme parameters and
the registry of evaluation keys, and is the first argument to most
operations. Obtain one from fhe_context() rather than by calling
this constructor directly.
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) |
An S7 object of class CryptoParameters, inheriting from
OpenFHEObject, whose ptr property holds an external pointer to
the C++ CryptoParametersBase<DCRTPoly>. It is an opaque token: its
contents are read with the RNS-level accessors rather than from R,
and it is obtained from get_crypto_parameters() rather than by
calling this constructor directly.
decrypt dispatches on both arguments and accepts them in either
order, as the C++ header does: Decrypt(ciphertext, privateKey) is
the primary form and Decrypt(privateKey, ciphertext) forwards to
it (cryptocontext.h, both overloads). The key-first order lets
code that is written around the holder of the key, such as a party
object in a protocol, put that holder first, the same way
encrypt() puts the key first.
decrypt(ct, key, ...)decrypt(ct, key, ...)
ct |
A |
key |
A |
... |
Additional arguments (cc = CryptoContext) |
A Plaintext
cc <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) kp <- key_gen(cc, eval_mult = TRUE) pt <- make_ckks_packed_plaintext(cc, c(0.25, 0.5, 0.75, 1)) ct <- encrypt(kp@public, pt, cc = cc) ## Add the encrypted vector to itself, then decrypt. Decryption ## returns a Plaintext padded out to the full slot count, so trim it ## back to the length that was encoded. out <- decrypt(eval_add(ct, ct), kp@secret, cc = cc) out <- set_length(out, 4L) get_real_packed_value(out) ## The same call with the key first: out2 <- decrypt(kp@secret, eval_add(ct, ct), cc = cc) get_real_packed_value(set_length(out2, 4L))cc <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) kp <- key_gen(cc, eval_mult = TRUE) pt <- make_ckks_packed_plaintext(cc, c(0.25, 0.5, 0.75, 1)) ct <- encrypt(kp@public, pt, cc = cc) ## Add the encrypted vector to itself, then decrypt. Decryption ## returns a Plaintext padded out to the full slot count, so trim it ## back to the length that was encoded. out <- decrypt(eval_add(ct, ct), kp@secret, cc = cc) out <- set_length(out, 4L) get_real_packed_value(out) ## The same call with the key first: out2 <- decrypt(kp@secret, eval_add(ct, ct), cc = cc) get_real_packed_value(set_length(out2, 4L))
Mirrors the C++ enum DecryptionNoiseMode in
pke/constants-defs.h.
DecryptionNoiseModeDecryptionNoiseMode
A named list of 2 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name: FIXED_NOISE_DECRYPT
decrypts with a fixed noise estimate, while
NOISE_FLOODING_DECRYPT floods the result with extra noise so that
the decryption itself leaks nothing about the circuit. Pass an
element as the decryption_noise_mode argument of CKKSParams()
or fhe_context().
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)
Mirrors the C++ enum DistributionType in
core/lattice/stdlatticeparms.h.
DistributionTypeDistributionType
A named list of 3 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, naming the secret
distribution a row of the HomomorphicEncryption.org standard
parameter tables applies to: HEStd_uniform, HEStd_error or
HEStd_ternary.
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) |
An S7 object of class ElementParams, inheriting from
OpenFHEObject, whose ptr property holds an external pointer to
the C++ DCRTPoly::Params. It is an opaque token describing the
ring the polynomials live in, obtained from get_element_params()
and passed on to the CKKS plaintext factories.
Accepts either a single PKESchemeFeature enum value or a
uint32_t bitwise-OR mask of PKESchemeFeature values (for
matching 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) |
An S7 object of class EncodingParams, inheriting from
OpenFHEObject, whose ptr property holds an external pointer to
the C++ EncodingParamsImpl. It is an opaque token describing how
values are packed into a plaintext, obtained from
get_encoding_params() rather than by calling this constructor
directly.
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.
cc <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) kp <- key_gen(cc, eval_mult = TRUE) pt <- make_ckks_packed_plaintext(cc, c(0.5, 1.5, 2.5, 3.5)) ## Public-key encryption -- the usual path, and the one that lets a ## party encrypt without holding the secret key: ct <- encrypt(kp@public, pt, cc = cc) ct ## Symmetric encryption with the secret key, for protocols where the ## same party encrypts and decrypts: ct2 <- encrypt(kp@secret, pt, cc = cc) ct2cc <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) kp <- key_gen(cc, eval_mult = TRUE) pt <- make_ckks_packed_plaintext(cc, c(0.5, 1.5, 2.5, 3.5)) ## Public-key encryption -- the usual path, and the one that lets a ## party encrypt without holding the secret key: ct <- encrypt(kp@public, pt, cc = cc) ct ## Symmetric encryption with the secret key, for protocols where the ## same party encrypts and decrypts: ct2 <- encrypt(kp@secret, pt, cc = cc) ct2
Mirrors the C++ enum EncryptionTechnique in
pke/constants-defs.h.
EncryptionTechniqueEncryptionTechnique
A named list of 2 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name: STANDARD encrypts in the
ciphertext modulus, while EXTENDED encrypts in an enlarged
modulus, which lowers the noise BFV multiplication starts from.
Pass an element as the encryption_technique argument of
BFVParams() or fhe_context().
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 both names are provided to mirror the
C++ API.
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 mirrors the equivalent C++
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 |
Invisibly, the cc crypto context that was passed in. Called for
its side effect: the rotation and evaluation keys bootstrapping
needs are generated from sk and stored inside the C++ context,
after which eval_bootstrap() can be called.
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
|
Invisibly, the cc crypto context that was passed in. Called for
its side effect: the linear transforms bootstrapping needs are
precomputed and cached inside the C++ context. Call it before
eval_bootstrap_key_gen().
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 |
A Ciphertext holding the encrypted, slot-wise cosine of ct,
approximated by a Chebyshev polynomial of the given degree on the
interval [a, b]. Accuracy degrades outside that interval, and the
result sits ceiling(log2(degree)) + 1 levels below ct.
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 |
A Ciphertext holding the encrypted, slot-wise reciprocal of ct,
approximated by a Chebyshev polynomial of the given degree on the
interval [a, b]. The interval must exclude zero, accuracy degrades
outside it, and the result sits ceiling(log2(degree)) + 1 levels
below ct.
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 |
A Ciphertext holding the encrypted, slot-wise logistic function 1 / (1 + exp(-x)) of ct, approximated by a Chebyshev polynomial of
the given degree on the interval [a, b]. Accuracy degrades
outside that interval, and the result sits ceiling(log2(degree)) + 1 levels below ct.
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) |
An S7 object of class EvalKey, inheriting from OpenFHEObject,
whose ptr property holds an external pointer to the C++
EvalKey<DCRTPoly>. An evaluation key is the public material that
lets the computing party carry out one operation — a
relinearization, a rotation, or a re-encryption — without the secret
key. Obtain one from multi_key_switch_gen() or the rest of the
multi_*() family rather than by calling this constructor directly.
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.
An S7 object of class EvalKeyMap, inheriting from OpenFHEObject,
whose ptr property holds an external pointer to the C++
std::map<uint32_t, EvalKey<DCRTPoly>>. It carries one evaluation
key per rotation or automorphism index and acts as the transport
format for the multi-party key protocols; it is produced by the
multi_eval_*_key_gen() family rather than by calling this
constructor directly.
Mirrors the C++ enum ExecutionMode in pke/constants-defs.h.
ExecutionModeExecutionMode
A named list of 2 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name: EXEC_EVALUATION runs the
computation normally, while EXEC_NOISE_ESTIMATION runs it only to
measure the noise growth, which is the first of the two passes
needed when decryption uses noise flooding. Pass an element as the
execution_mode argument of CKKSParams() or fhe_context().
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) |
An S7 object of class FastRotationPrecomputation, inheriting from
OpenFHEObject, whose ptr property holds an external pointer to
the C++ digit decomposition. It caches the work that is common to
every rotation of one source ciphertext; obtain one from
eval_fast_rotation_precompute() and pass it to
eval_fast_rotation() rather than calling this constructor
directly.
Mirrors the C++ enum PKESchemeFeature in pke/constants-defs.h.
The values are bit flags, so several may be combined with
bitwOr() to describe a set of capabilities.
FeatureFeature
A named list of 8 integer scalars. Each element carries the
integer value the OpenFHE C++ enumerator of the same name has, and
names a capability of a crypto context: PKE (encryption and
decryption), KEYSWITCH, PRE (proxy re-encryption),
LEVELEDSHE (leveled homomorphic arithmetic), ADVANCEDSHE,
MULTIPARTY, FHE (bootstrapping) and SCHEMESWITCH. Pass an
element to enable_feature() to turn that capability on for a
context.
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. when
you need 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 the parameters directly: fhe_ckks_tolerance(4L, 50L, "FLEXIBLEAUTO") ## Stage 2 -- pass a ciphertext and let it read the parameters ## off the associated context: cc <- fhe_context("CKKS", multiplicative_depth = 4L, scaling_mod_size = 50L, batch_size = 8L) 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 = cc) fhe_ckks_tolerance(ct)## Stage 1 -- pass the parameters directly: fhe_ckks_tolerance(4L, 50L, "FLEXIBLEAUTO") ## Stage 2 -- pass a ciphertext and let it read the parameters ## off the associated context: cc <- fhe_context("CKKS", multiplicative_depth = 4L, scaling_mod_size = 50L, batch_size = 8L) 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 = cc) 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.
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()
## An exact context over the integers modulo 65537 (BFV). The ring ## dimension is chosen for you from the security level. bfv <- fhe_context("BFV", plaintext_modulus = 65537L, multiplicative_depth = 2L) ring_dimension(bfv) ## An approximate context over the reals (CKKS), which is what the ## statistical applications use. ckks <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) ring_dimension(ckks)## An exact context over the integers modulo 65537 (BFV). The ring ## dimension is chosen for you from the security level. bfv <- fhe_context("BFV", plaintext_modulus = 65537L, multiplicative_depth = 2L) ring_dimension(bfv) ## An approximate context over the reals (CKKS), which is what the ## statistical applications use. ckks <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) ring_dimension(ckks)
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).
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.
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 callers 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
Returns the cap OpenFHE currently applies to its parallel regions: the
number of hardware threads at load, or the value most recently passed
to set_num_threads(). Returns 1 when the package was built without
OpenMP.
get_num_threads()get_num_threads()
integer; the current thread cap.
get_num_threads()get_num_threads()
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
cc <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) ## Encryption keys only: kp <- key_gen(cc) kp ## Also generate the relinearization key homomorphic multiplication ## needs and the rotation keys for shifts by one slot either way. ## These are stored inside the context, not in the returned pair. kp <- key_gen(cc, eval_mult = TRUE, rotations = c(1L, -1L)) kp@public kp@secretcc <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) ## Encryption keys only: kp <- key_gen(cc) kp ## Also generate the relinearization key homomorphic multiplication ## needs and the rotation keys for shifts by one slot either way. ## These are stored inside the context, not in the returned pair. kp <- key_gen(cc, eval_mult = TRUE, rotations = c(1L, -1L)) kp@public kp@secret
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 |
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.
Mirrors the C++ enum KEYGEN_MODE in binfhe/binfhe-constants.h.
KeygenModeKeygenMode
A named list of 2 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name: SYM_ENCRYPT generates
only the material needed for symmetric-key encryption, while
PUB_ENCRYPT additionally generates a public key. Pass an element
as the keygen_mode argument of bin_bt_key_gen().
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 |
An S7 object of class KeyPair with two properties, public (a
PublicKey) and secret (a PrivateKey), which are the two halves
of one freshly generated key. Obtain one from key_gen() rather
than by calling this constructor directly.
Mirrors the C++ enum KeySwitchTechnique in pke/constants-defs.h.
KeySwitchTechniqueKeySwitchTechnique
A named list of 3 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name. BV selects the
Brakerski-Vaikuntanathan digit-decomposition key switch and
HYBRID the hybrid variant, which is the usual choice;
INVALID_KS_TECH marks an unset value. Pass an element as the
key_switch_technique argument of CKKSParams(), BFVParams(),
BGVParams() or fhe_context().
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) |
An S7 object of class LWECiphertext, inheriting from
OpenFHEObject, whose ptr property holds an external pointer to
the C++ LWE ciphertext. This is the encrypted-bit type the boolean-
circuit (BinFHE) schemes operate on; obtain one from bin_encrypt()
or from a gate evaluation rather than by calling this constructor
directly.
LWE Private Key (Binary FHE)
LWEPrivateKey(ptr = NULL)LWEPrivateKey(ptr = NULL)
ptr |
External pointer (internal use) |
An S7 object of class LWEPrivateKey, inheriting from
OpenFHEObject, whose ptr property holds an external pointer to
the C++ LWE secret key. It both encrypts and decrypts in the
boolean-circuit (BinFHE) schemes; obtain one from bin_key_gen()
rather than by calling this constructor directly.
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.
cc <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) ## Encode four reals into the CKKS slots. The remaining slots are ## zero-padded out to `batch_size`. pt <- make_ckks_packed_plaintext(cc, c(0.25, 0.5, 0.75, 1)) pt get_real_packed_value(set_length(pt, 4L))cc <- fhe_context("CKKS", multiplicative_depth = 2L, scaling_mod_size = 50L, batch_size = 8L) ## Encode four reals into the CKKS slots. The remaining slots are ## zero-padded out to `batch_size`. pt <- make_ckks_packed_plaintext(cc, c(0.25, 0.5, 0.75, 1)) pt get_real_packed_value(set_length(pt, 4L))
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 callers
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.
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
Mirrors the C++ enum MultipartyMode in pke/constants-defs.h.
MultipartyModeMultipartyMode
A named list of 3 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, selecting how a threshold
context masks the secret shares: FIXED_NOISE_MULTIPARTY adds a
fixed amount of noise, while NOISE_FLOODING_MULTIPARTY adds
enough to give provable circuit privacy at a higher cost.
INVALID_MULTIPARTY_MODE marks an unset value. Pass an element as the
multiparty_mode argument of BFVParams(), BGVParams() or
fhe_context().
Mirrors the C++ enum MultiplicationTechnique in
pke/constants-defs.h.
MultiplicationTechniqueMultiplicationTechnique
A named list of 4 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, selecting the algorithm
BFV uses for homomorphic multiplication: BEHZ
(Bajard-Eynard-Hasan-Zucca) or the Halevi-Polyakov-Shoup variants
HPS, HPSPOVERQ and HPSPOVERQLEVELED. Pass an element as the
multiplication_technique argument of BFVParams() or
fhe_context().
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) |
An S7 object of class OpenFHEObject, the base class every object
in this package inherits from. It has a single property, ptr,
holding an external pointer to the underlying C++ shared_ptr.
Constructing one directly is of no use; the class exists so that
methods can dispatch on the common parent and so that the pointer is
managed in one place.
Plaintext
Plaintext(ptr = NULL)Plaintext(ptr = NULL)
ptr |
External pointer (internal use) |
An S7 object of class Plaintext, inheriting from OpenFHEObject,
whose ptr property holds an external pointer to the C++ plaintext.
A plaintext holds an encoded but unencrypted vector together with
its encoding type; obtain one from a make_*_plaintext() factory or
from decrypt() rather than by calling this constructor directly,
and read its contents with get_packed_value(), get_real_value()
and the other accessors.
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. Incremented by each multiplication before a rescale.
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.
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: integer
encoding type (see PlaintextEncodings for the enum values).
get_scaling_factor_int: BGV integer
scaling factor. Returned as a double carrying a losslessly
rounded 53-bit integer.
get_scheme_id: scheme
identifier (see SchemeId enum).
is_encoded: 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 uninitialized form.
low_bound: integer
lower bound that can be encoded with the current plaintext
modulus: -floor(t / 2).
high_bound: integer
upper bound that can be encoded with the current plaintext
modulus: floor(t / 2).
get_slots: integer CKKS
slot count. For Plaintext dispatch this is the GetSlots()
value set at construction.
get_log_error: numeric
log2 of the error estimate. Only meaningful for CKKS
plaintexts; throws for BFV/BGV.
get_coef_packed_value: integer
vector of the underlying coef-packed encoding. Throws for
plaintexts whose subclass is not coef-packed.
get_string_value: string value
of a string-encoded plaintext. Throws for plaintexts whose
subclass is not string-encoded.
get_element_ring_dimension: 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: set the CKKS
plaintext scaling factor.
set_scaling_factor_int: set the BGV
plaintext integer scaling factor.
set_noise_scale_deg: 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: set the
plaintext level. As with set_noise_scale_deg, most users
should not call this directly.
set_slots: set the CKKS
slot count. As with set_length, this is typically managed
by the factory methods.
set_string_value: set the
string value of a string-encoded plaintext. Throws for
plaintexts whose subclass is not string-encoded.
set_int_vector_value: 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 |
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.
Mirrors the C++ enum PlaintextEncodings in
pke/constants-defs.h.
PlaintextEncodingsPlaintextEncodings
A named list of 5 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, naming how values are laid
out inside a plaintext polynomial: COEF_PACKED_ENCODING,
PACKED_ENCODING (integer SIMD slots), STRING_ENCODING and
CKKS_PACKED_ENCODING (approximate real or complex slots).
INVALID_ENCODING marks an unset value. This is the value reported
by get_encoding_type() on a Plaintext.
Mirrors the C++ enum ProxyReEncryptionMode in
pke/constants-defs.h. The R-side name PREMode is a shortened
form, the same pattern as Feature for PKESchemeFeature.
PREModePREMode
A named list of 4 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, naming the security notion
the re-encryption key should satisfy: INDCPA,
FIXED_NOISE_HRA or NOISE_FLOODING_HRA, the last two being
honest-re-encryption-attack secure. NOT_SET disables proxy
re-encryption. Pass an element as the pre_mode argument of
CKKSParams(), BFVParams(), BGVParams() or fhe_context().
Private Key
PrivateKey(ptr = NULL)PrivateKey(ptr = NULL)
ptr |
External pointer (internal use) |
An S7 object of class PrivateKey, inheriting from OpenFHEObject,
whose ptr property holds an external pointer to the C++ secret
key. This is the key decrypt() takes; obtain one as the secret
element of the KeyPair returned by key_gen() rather than by
calling this constructor directly.
Public Key
PublicKey(ptr = NULL)PublicKey(ptr = NULL)
ptr |
External pointer (internal use) |
An S7 object of class PublicKey, inheriting from OpenFHEObject,
whose ptr property holds an external pointer to the C++ public
key. This is the key encrypt() takes; obtain one as the public
element of the KeyPair returned by key_gen() rather than by
calling this constructor directly.
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
Mirrors the C++ enum ScalingTechnique in pke/constants-defs.h.
ScalingTechniqueScalingTechnique
A named list of 8 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name. The element chosen tells a
CKKS context how to manage the scaling factor between
multiplications: FIXEDMANUAL leaves rescaling to the caller,
FIXEDAUTO and the FLEXIBLE* variants rescale automatically with
increasing precision, the COMPOSITESCALING* variants split the
scaling factor across several moduli, and NORESCALE disables
rescaling. INVALID_RS_TECHNIQUE marks an unset value. Pass an
element as the scaling_technique argument of CKKSParams(),
BGVParams() or fhe_context().
Mirrors the C++ enum SCHEME in pke/scheme/scheme-id.h. The R-side
name SchemeId matches the upstream header filename and avoids
colliding with a potential future Scheme S7 class.
SchemeIdSchemeId
A named list of 4 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, identifying the encryption
scheme a context implements: CKKSRNS_SCHEME, BFVRNS_SCHEME or
BGVRNS_SCHEME, with INVALID_SCHEME for an unset value. This is
the value reported by get_scheme() on any CCParams object.
Mirrors the C++ enum SecretKeyDist in
core/lattice/constants-lattice.h.
SecretKeyDistSecretKeyDist
A named list of 4 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name, naming the distribution
the secret key polynomial is drawn from: GAUSSIAN,
UNIFORM_TERNARY (the default, coefficients uniform on
-1, 0, 1), SPARSE_TERNARY (ternary with a fixed small Hamming
weight) and SPARSE_ENCAPSULATED. Pass an element as the
secret_key_dist argument of CKKSParams(), BFVParams(),
BGVParams() or fhe_context().
Mirrors the C++ enum SecurityLevel in
core/lattice/stdlatticeparms.h.
SecurityLevelSecurityLevel
A named list of 7 integer scalars, each the value of the
OpenFHE C++ enumerator of the same name. An element names the
number of bits of security the ring dimension is chosen to provide
against a classical (HEStd_*_classic) or quantum
(HEStd_*_quantum) adversary, following the HomomorphicEncryption.org
standard tables. HEStd_NotSet skips the table lookup, in which
case the ring dimension must be set explicitly. Pass an element as the
security_level argument of CKKSParams(), BFVParams(),
BGVParams() or fhe_context().
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 |
Invisibly, the pt plaintext that was passed in. Called for its
side effect: the plaintext is truncated in place so that the
accessors report only the first len slots, which is how the
padding introduced by encoding is trimmed after decryption.
OpenFHE parallelizes its core arithmetic with OpenMP and, by default,
uses every hardware thread the machine reports. set_num_threads()
sets the cap through OpenFHE's own thread controls, which every
parallel region in the library consults when it starts, so the change
takes effect immediately, on every platform, and regardless of which
thread the work runs on. It is a no-op when the package was built
without OpenMP.
set_num_threads(n)set_num_threads(n)
n |
integer; the requested maximum number of threads (at least 1). |
Requests above the number of threads available when the library was
loaded (the hardware count, or OMP_NUM_THREADS if that was set
before R started) are reduced to that number. The value in effect is
returned, so a reduced request is visible to the caller;
get_num_threads() reports the same value later.
The package default is uncapped, so interactive users get full
parallelism. Under R CMD check, which sets _R_CHECK_LIMIT_CORES_,
the package caps itself at two threads when it is loaded, in line with
CRAN's two-thread policy. This also covers packages that depend on
'openfhe.R', which therefore need no thread handling of their own.
integer; the cap now in effect, invisibly.
old <- get_num_threads() set_num_threads(2L) set_num_threads(old)old <- get_num_threads() set_num_threads(2L) set_num_threads(old)
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