Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GetCryptoContext #18

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/OpenFHE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export SetMultiplicativeDepth, SetScalingModSize, SetBatchSize, SetSecretKeyDist
# FHECKKSRNS
export GetBootstrapDepth

# CryptoObject
export GetCryptoContext

# CryptoContext
export CryptoContext, GenCryptoContext, Enable, GetRingDimension, KeyGen, EvalMultKeyGen,
EvalRotateKeyGen, MakeCKKSPackedPlaintext, Encrypt, EvalAdd, EvalSub, EvalMult,
Expand Down
19 changes: 19 additions & 0 deletions src/convenience.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ function EvalBootstrap(context::CxxWrap.CxxWrapCore.CxxRef{OpenFHE.CryptoContext
EvalBootstrap(context, ciphertext, num_iterations, precision)
end

"""
GetCryptoContext(object::Union{Ciphertext})

Return a the crypto context for a an `object` that is is a subtype of `CryptoObject`.

Currently, this is only implemented for [`Ciphertext`](@ref).

See also: [`CryptoContext`](@ref), [`Ciphertext`](@ref)
"""
function GetCryptoContext(object::Union{Ciphertext})
# Note: Due to limitations of CxxWrap.jl when wrapping mutually dependent template
# types, openfhe-julia introduces a non-template proxy type as an additional level of
# indirection.
# We thus need to first dereference `Ciphertext` to get to the `CiphertextImpl`, then
# call the proxy method to get the `CryptoContextProxy`, and finally obtain the actual
# `CryptoContext` from it
GetCryptoContext(GetCryptoContextProxy(object[]))
end

"""
Decrypt(crypto_context::CryptoContext, ciphertext::Ciphertext, private_key::PrivateKey, plaintext::Plaintext)
Decrypt(crypto_context::CryptoContext, private_key::PrivateKey, ciphertext::Ciphertext, plaintext::Plaintext)
Expand Down
4 changes: 4 additions & 0 deletions test/test_ckks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ end
@test GetRealPackedValue(result_dec) ≈ circshift(x1, -shift)
end

@testset verbose=true showtiming=true "GetCryptoContext" begin
@test GetCryptoContext(c1) isa CryptoContext
end

end # @testset "test_ckks.jl"

end # module
Loading