Skip to content

Commit

Permalink
Add GetCryptoContext (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
sloede authored Jan 16, 2024
1 parent 5e15410 commit f4ec6ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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

0 comments on commit f4ec6ab

Please sign in to comment.