API reference
SecureArithmetic.OpenFHEBackend
— TypeOpenFHEBackend
Cryptography backend for use with the homomorphic encryption library OpenFHE (https://github.com/openfheorg/openfhe-development).
See also: SecureContext
, Unencrypted
SecureArithmetic.PlainArray
— TypePlainArray{Backend, N, DataT}
Holds an encoded - but not encrypted - N
-dimensional array for arithmetic operations. Can be converted to a SecureArray
using encrypt
.
See also: SecureArray
, encrypt
SecureArithmetic.PlainArray
— MethodPlainArray(data::Array{<:Real}, context::SecureContext{<:OpenFHEBackend})
Constructor for data type PlainArray
takes an unencrypted data
array and a context
object of type SecureContext{<:OpenFHEBackend}
. Return PlainArray
with encoded but not encrypted data. The context
can be utilized later for encryption using encrypt
, resulting in SecureArray
.
See also: PlainArray
, SecureArray
, encrypt
, decrypt
OpenFHEBackend
SecureArithmetic.PlainArray
— MethodPlainArray(data::Array{<:Real}, context::SecureContext{<:Unencrypted})
Constructor for data type PlainArray
takes an unencrypted data
array and a context
object of type SecureContext{<:Unencrypted}
. Returns PlainArray
with not encoded and not encrypted data. The context can be utilized later for encryption using encrypt
, resulting in SecureArray
.
See also: PlainArray
, SecureArray
, encrypt
, decrypt
SecureArithmetic.PlainMatrix
— TypePlainMatrix{Backend, DataT}
Alias for PlainArray{Backend, 2, DataT}. Holds encoded - but not encrypted - matrix data for arithmetic operations. Can be converted to a SecureMatrix
using encrypt
.
See also: SecureMatrix
, PlainArray
, encrypt
SecureArithmetic.PlainMatrix
— MethodPlainMatrix(data::Matrix{<:Real}, context::SecureContext{<:OpenFHEBackend})
Constructor for data type PlainMatrix
takes an unencrypted data
matrix and a context
object of type SecureContext{<:OpenFHEBackend}
. Return PlainMatrix
with encoded but not encrypted data. The context
can be utilized later for encryption using encrypt
, resulting in SecureMatrix
.
See also: PlainMatrix
, SecureMatrix
, encrypt
, decrypt
OpenFHEBackend
SecureArithmetic.PlainMatrix
— MethodPlainMatrix(data::Matrix{<:Real}, context::SecureContext{<:Unencrypted})
Constructor for data type PlainMatrix
takes an unencrypted data
matrix and a context
object of type SecureContext{<:Unencrypted}
. Returns PlainMatrix
with not encoded and not encrypted data. The context can be utilized later for encryption using encrypt
, resulting in SecureMatrix
.
See also: PlainMatrix
, SecureMatrix
, encrypt
, decrypt
SecureArithmetic.PlainVector
— TypePlainVector{Backend, DataT}
Alias for PlainArray{Backend, 1, DataT}. Holds encoded - but not encrypted - vector data for arithmetic operations. Can be converted to a SecureVector
using encrypt
.
See also: SecureVector
, PlainArray
, encrypt
SecureArithmetic.PlainVector
— MethodPlainVector(data::Vector{<:Real}, context::SecureContext{<:OpenFHEBackend})
Constructor for data type PlainVector
takes an unencrypted data
vector and a context
object of type SecureContext{<:OpenFHEBackend}
. Return PlainVector
with encoded but not encrypted data. The context
can be utilized later for encryption using encrypt
, resulting in SecureVector
.
See also: PlainVector
, SecureVector
, encrypt
, decrypt
OpenFHEBackend
SecureArithmetic.PlainVector
— MethodPlainVector(data::Vector{<:Real}, context::SecureContext{<:Unencrypted})
Constructor for data type PlainVector
takes an unencrypted data
vector and a context
object of type SecureContext{<:Unencrypted}
. Returns PlainVector
with not encoded and not encrypted data. The context can be utilized later for encryption using encrypt
, resulting in SecureVector
.
See also: PlainVector
, SecureVector
, encrypt
, decrypt
SecureArithmetic.PrivateKey
— TypePrivateKey
Holds a private key that is used for decryption in decrypt
.
See also: PlainVector
, SecureVector
, decrypt
SecureArithmetic.PublicKey
— TypePublicKey
Holds a public key that is used for encryption in encrypt
.
See also: PlainVector
, SecureVector
, encrypt
SecureArithmetic.SecureArray
— TypeSecureArray{Backend, N, DataT}
Holds an encrypted N
-dimensional array for arithmetic operations. Can be converted to a PlainArray
using decrypt
.
See also: PlainArray
, decrypt
SecureArithmetic.SecureContext
— TypeSecureContext
A structure used to generalize CryptoContext
defined in OpenFHE.jl for unencrypted data, to maximize utilization of the same code for both plaintext and ciphertext.
See also: OpenFHEBackend
, Unencrypted
SecureArithmetic.SecureMatrix
— TypeSecureMatrix{Backend, DataT}
Alias for SecureArray{Backend, 2, DataT}. Holds encrypted matrix data for arithmetic operations. Can be converted to a PlainMatrix
using decrypt
.
See also: PlainMatrix
, SecureArray
, decrypt
SecureArithmetic.SecureVector
— TypeSecureVector{Backend, DataT}
Alias for SecureArray{Backend, 1, DataT}. Holds encrypted vector data for arithmetic operations. Can be converted to a PlainVector
using decrypt
.
See also: PlainVector
, SecureArray
, decrypt
SecureArithmetic.Unencrypted
— TypeUnencrypted
An alternative backend to use instead of OpenFHEBackend
to experiment with algorithms on unencrypted data.
See also: SecureContext
, OpenFHEBackend
Base.circshift
— Methodcircshift(sa::SecureArray, shifts)
Circularly shift, i.e., rotate the data in sa
by shifts
positions, similarly to Julia's circshift
for regular arrays.
Note: If N
is greater than one, this operation increases the multiplicative level by two, otherwise by one.
Note: To precompute all required rotation indexes, use init_rotation!
.
See also: SecureArray
, init_rotation!
Base.collect
— Methodcollect(plain_array::PlainArray{<:OpenFHEBackend})
Decode and return the real-valued data contained in plain_array
.
See also: PlainArray
, OpenFHEBackend
Base.collect
— Methodcollect(pa::PlainArray{<:Unencrypted})
Return the real-valued data contained in pa
.
See also: PlainArray
Base.length
— Methodlength(a::Union{PlainArray, SecureArray})
Return the current length of a
, i.e., the number of container elements in use. Note that this might be less than its maximum capacity
.
See also: capacity
, SecureArray
, PlainArray
Base.ndims
— Methodndims(a::Union{PlainArray, SecureArray})
Return the number of dimensions of a
.
See also: SecureArray
, PlainArray
Base.size
— Methodsize(a::Union{PlainArray, SecureArray}, d::Int)
Return the current length of d
th dimension of a
.
See also: SecureArray
, PlainArray
Base.size
— Methodsize(a::Union{PlainArray, SecureArray})
Return the current shape of a
.
See also: SecureArray
, PlainArray
SecureArithmetic.bootstrap!
— Functionbootstrap!(secure_array::SecureArray{<:OpenFHEBackend}, num_iterations = 1,
precision = 0)
Refresh a given secure_array
to increase the multiplication depth. Supported for CKKS only. Please refer to the OpenFHE documentation for details on the arguments num_iterations
and precision
.
See also: SecureArray
, OpenFHEBackend
, init_bootstrapping!
SecureArithmetic.bootstrap!
— Functionbootstrap!(secure_array::SecureArray{<:Unencrypted}, num_iterations = 1,
precision = 0)
An empty duplicate of bootstrap!
for unencrypted data.
See also: SecureArray
, Unencrypted
, bootstrap!
, init_bootstrapping!
SecureArithmetic.capacity
— Methodcapacity(a::Union{PlainArray, SecureArray})
Return the current capacity of a
, i.e., the maximum number of elements the container may hold. Note that this might be more than its current length
.
See also: length
, SecureArray
, PlainArray
SecureArithmetic.decrypt!
— Methoddecrypt!(plain_array::PlainArray, secure_array::SecureArray, private_key::PrivateKey)
Decrypt secure_array
using the private_key
and store the result in the given plain_array
.
See also: PlainArray
, SecureArray
, PrivateKey
, decrypt
SecureArithmetic.decrypt
— Methoddecrypt(secure_array::SecureArray, private_key::PrivateKey)
Decrypt secure_array
using the private_key
and return the resulting PlainArray
.
See also: PlainArray
, SecureArray
, PrivateKey
, decrypt!
SecureArithmetic.disable_multithreading
— Methoddisable_multithreading()
Disable multithreaded execution. To enable multithreading, use enable_multithreading
.
See also: enable_multithreading
SecureArithmetic.enable_multithreading
— Functionenable_multithreading(enabled=true)
Enable multithreaded execution when enabled
is set to true
. To disable multithreading, use disable_multithreading
.
This multithreading capability takes place entirely on the Julia side and parallelizes operations over multiple ciphertexts within a single SecureArray
. That is, it will have no effect if only one ciphertext is sufficient to hold all data. Please be aware that mixing Julia's multithreading with OpenFHE's builtin OpenMP-based multithreading might cause troubles. Thus if in doubt, set the environment variable OMP_NUM_THREADS=1
to avoid potential issues.
Note: By default multithreading is disabled.
See also: disable_multithreading
SecureArithmetic.encrypt
— Methodencrypt(data::Array{<:Real}, public_key::PublicKey, context::SecureContext)
Encrypt data
into a SecureArray
using the public_key
derived for the given context
.
See also: SecureArray
, PublicKey
, SecureContext
, decrypt
SecureArithmetic.encrypt
— Methodencrypt(plain_array::PlainArray, public_key::PublicKey)
Encrypt plain_array
into a SecureArray
using the public_key
.
See also: PlainArray
, SecureArray
, PublicKey
, decrypt
SecureArithmetic.generate_keys
— Methodgenerate_keys(context::SecureContext{<:OpenFHEBackend})
Generate and return public and private keys.
See also: PublicKey
, PrivateKey
, SecureContext
, OpenFHEBackend
SecureArithmetic.generate_keys
— Methodgenerate_keys(context::SecureContext{<:Unencrypted})
Return public and private keys for use with unencrypted data.
See also: PublicKey
, PrivateKey
, SecureContext
, Unencrypted
SecureArithmetic.get_crypto_context
— Methodget_crypto_context(context::SecureContext{<:OpenFHEBackend})
Return a OpenFHE.CryptoContext
object stored in a given context
.
See also: SecureContext
, OpenFHEBackend
SecureArithmetic.get_crypto_context
— Methodget_crypto_context(a::Union{SecureArray{<:OpenFHEBackend},
PlainArray{<:OpenFHEBackend}})
Return a OpenFHE.CryptoContext
object stored in a
.
See also: SecureContext
, SecureArray
, PlainArray
, OpenFHEBackend
SecureArithmetic.init_bootstrapping!
— Methodinit_bootstrapping!(context::SecureContext{<:OpenFHEBackend},
private_key::PrivateKey)
Generate the necessary keys from private_key
to enable bootstrapping for a given context
. Supported for CKKS only.
See also: SecureContext
, OpenFHEBackend
, PrivateKey
, bootstrap!
SecureArithmetic.init_bootstrapping!
— Methodinit_bootstrapping!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey)
An empty duplicate of init_bootstrapping!
for unencrypted data.
See also: SecureContext
, Unencrypted
, PrivateKey
, init_bootstrapping!
SecureArithmetic.init_multiplication!
— Methodinit_multiplication!(context::SecureContext{<:OpenFHEBackend},
private_key::PrivateKey)
Generate relinearization key for use with OpenFHE.EvalMult
using the private_key
, and store it in the given context
.
See also: SecureContext
, OpenFHEBackend
, PrivateKey
SecureArithmetic.init_multiplication!
— Methodinit_multiplication!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey)
An empty duplicate of init_multiplication!
for unencrypted data.
See also: SecureContext
, Unencrypted
, PrivateKey
, init_multiplication!
SecureArithmetic.init_rotation!
— Methodinit_rotation!(context::SecureContext{<:Unencrypted}, private_key::PrivateKey,
shape, shifts...)
An empty duplicate of init_rotation!
for unencrypted data.
See also: SecureContext
, Unencrypted
, PrivateKey
, init_rotation!
SecureArithmetic.init_rotation!
— Methodinit_rotation!(context::SecureContext{<:OpenFHEBackend}, private_key::PrivateKey,
shape::Union{Integer, NTuple{N, Integer}}, shifts...)
Generate all required rotation keys for applying shifts
with circshift
for arrays of the given shape
using the private_key
. The keys are stored in the given context
.
See also: SecureContext
, OpenFHEBackend
, PrivateKey
SecureArithmetic.level
— Methodlevel(a::Union{SecureArray{<:OpenFHEBackend}, PlainArray{<:OpenFHEBackend}})
Return the number of scalings, referred to as the level, performed over a
.
See also: PlainArray
, SecureArray
, OpenFHEBackend
SecureArithmetic.level
— Methodlevel(a::Union{SecureArray{<:Unencrypted}, PlainArray{<:Unencrypted}})
Return the number of scalings, referred to as the level, performed over a
. For data type derived from Unencrypted
, the level is always equal to 0.
See also: PlainArray
, SecureArray
SecureArithmetic.release_context_memory
— Methodrelease_context_memory()
Release all OpenFHE.CryptoContext
s and keys for multiplication, rotation, bootstrapping and OpenFHE.EvalSum
generated in the functions init_multiplication!
, init_rotation!
, init_bootstrapping!
and OpenFHE.EvalSumKeyGen
.
In the source code of OpenFHE C++, all CryptoContext
s and keys are stored in static objects. Without using release_context_memory
, the memory allocated for these contexts and keys will only be freed after restarting the Julia REPL. It is also advisable to call GC.gc()
after a call to release_context_memory
to clean up all memory on the Julia side.
See also: init_multiplication!
, init_rotation!
, init_bootstrapping!