From 96341f8547f0e80bc089500c83b343c89d9ffe1d Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Mon, 12 Feb 2024 07:12:58 +0100 Subject: [PATCH] Add EncodingParams (#30) * Add EncodingParams * Add module name to unexported symbol --- src/OpenFHE.jl | 22 ++++--- src/convenience.jl | 27 ++++++++- src/documentation.jl | 121 +++++++++++++++++++++++++++++++++++++++ test/test_convenience.jl | 6 ++ 4 files changed, 167 insertions(+), 9 deletions(-) diff --git a/src/OpenFHE.jl b/src/OpenFHE.jl index 483c5e6..1944f34 100644 --- a/src/OpenFHE.jl +++ b/src/OpenFHE.jl @@ -31,18 +31,26 @@ export SetMultiplicativeDepth, SetScalingModSize, SetBatchSize, SetSecretKeyDist # FHECKKSRNS export GetBootstrapDepth +# EncodingParams +export EncodingParams +export GetPlaintextModulus, SetPlaintextModulus, GetPlaintextRootOfUnity, + SetPlaintextRootOfUnity, GetPlaintextBigModulus, SetPlaintextBigModulus, + GetPlaintextBigRootOfUnity, SetPlaintextBigRootOfUnity, GetPlaintextGenerator, + SetPlaintextGenerator, GetBatchSize, SetBatchSize + # CryptoObject export GetCryptoContext # CryptoContext export CryptoContext -export GenCryptoContext, Enable, GetKeyGenLevel, SetKeyGenLevel, GetCyclotomicOrder, - GetModulus, GetRingDimension, GetRootOfUnity, KeyGen, MakeCKKSPackedPlaintext, - Encrypt, Decrypt, EvalNegate, EvalAdd, EvalSub, EvalMultKeyGen, EvalMult, EvalSquare, - EvalMultNoRelin, Relinearize, RelinearizeInPlace, EvalRotate, EvalRotateKeyGen, - ComposedEvalMult, Rescale, RescaleInPlace, ModReduce, ModReduceInPlace, EvalSin, - EvalCos, EvalLogistic, EvalDivide, EvalSumKeyGen, EvalSum, EvalBootstrapSetup, - EvalBootstrapKeyGen, EvalBootstrap +export GenCryptoContext, Enable, GetKeyGenLevel, SetKeyGenLevel, GetEncodingParams, + GetCyclotomicOrder, GetModulus, GetRingDimension, GetRootOfUnity, KeyGen, + MakeCKKSPackedPlaintext, Encrypt, Decrypt, EvalNegate, EvalAdd, EvalSub, + EvalMultKeyGen, EvalMult, EvalSquare, EvalMultNoRelin, Relinearize, + RelinearizeInPlace, EvalRotate, EvalRotateKeyGen, ComposedEvalMult, Rescale, + RescaleInPlace, ModReduce, ModReduceInPlace, EvalSin, EvalCos, EvalLogistic, + EvalDivide, EvalSumKeyGen, EvalSum, EvalBootstrapSetup, EvalBootstrapKeyGen, + EvalBootstrap # Plaintext export Plaintext diff --git a/src/convenience.jl b/src/convenience.jl index e15efd6..08c37e9 100644 --- a/src/convenience.jl +++ b/src/convenience.jl @@ -1,4 +1,13 @@ -# Define CryptoContext for convenience +""" + EncodingParams + +Type alias for `CxxWrap.StdLib.SharedPtr{EncodingParamsImpl}`. + +The `EncodingParams` store the parameters for encoding. These parameters are kept with +multiple OpenFHE objects and are continually reused during the encoding of new values. +""" +const EncodingParams = CxxWrap.StdLib.SharedPtr{EncodingParamsImpl} + """ CryptoContext{T} @@ -88,6 +97,7 @@ for (WrappedT, fun) in [ :(CryptoContext{DCRTPoly}) => :Enable, :(CryptoContext{DCRTPoly}) => :GetKeyGenLevel, :(CryptoContext{DCRTPoly}) => :SetKeyGenLevel, + :(CryptoContext{DCRTPoly}) => :GetEncodingParams, :(CryptoContext{DCRTPoly}) => :GetCyclotomicOrder, :(CryptoContext{DCRTPoly}) => :GetModulus, :(CryptoContext{DCRTPoly}) => :GetRingDimension, @@ -139,6 +149,18 @@ for (WrappedT, fun) in [ :(Plaintext) => :GetCoefPackedValue, :(Plaintext) => :GetPackedValue, :(Plaintext) => :GetRealPackedValue, + :(EncodingParams) => :GetPlaintextModulus, + :(EncodingParams) => :SetPlaintextModulus, + :(EncodingParams) => :GetPlaintextRootOfUnity, + :(EncodingParams) => :SetPlaintextRootOfUnity, + :(EncodingParams) => :GetPlaintextBigModulus, + :(EncodingParams) => :SetPlaintextBigModulus, + :(EncodingParams) => :GetPlaintextBigRootOfUnity, + :(EncodingParams) => :SetPlaintextBigRootOfUnity, + :(EncodingParams) => :GetPlaintextGenerator, + :(EncodingParams) => :SetPlaintextGenerator, + :(EncodingParams) => :GetBatchSize, + :(EncodingParams) => :SetBatchSize, ] @eval function $fun(arg::$WrappedT, args...; kwargs...) $fun(arg[], args...; kwargs...) @@ -157,6 +179,7 @@ for (T, str) in [ :(PublicKey{DCRTPoly}) => "PublicKey{DCRTPoly}()", :(PrivateKey{DCRTPoly}) => "PrivateKey{DCRTPoly}()", :(DecryptResult) => "DecryptResult()", + :(EncodingParams) => "EncodingParams()", ] @eval function Base.show(io::IO, ::$T) print(io, $str) @@ -323,4 +346,4 @@ function EvalSumKeyGen(context::CxxWrap.CxxWrapCore.CxxRef{OpenFHE.CryptoContext privateKey; publicKey = OpenFHE.CxxWrap.StdLib.SharedPtr{OpenFHE.PublicKeyImpl{OpenFHE.DCRTPoly}}()) EvalSumKeyGen(context, privateKey, publicKey) -end \ No newline at end of file +end diff --git a/src/documentation.jl b/src/documentation.jl index 499fe2d..2e6b7f4 100644 --- a/src/documentation.jl +++ b/src/documentation.jl @@ -115,6 +115,118 @@ SetKeySwitchTechnique # FHECKKSRNS # `GetBootstrapDepth` is documented in `src/convenience.jl` + +# EncodingParams +""" + GetPlaintextModulus(parameters::EncodingParams) + +FIXME! + +See also: [`EncodingParams`](@ref), [`SetPlaintextModulus`](@ref) +""" +GetPlaintextModulus + +""" + SetPlaintextModulus(parameters::EncodingParams, FIXME::Integer) + +FIXME! + +See also: [`EncodingParams`](@ref), [`GetPlaintextModulus`](@ref) +""" +SetPlaintextModulus + +""" + GetPlaintextRootOfUnity(parameters::EncodingParams) + +FIXME! + +See also: [`EncodingParams`](@ref), [`SetPlaintextRootOfUnity`](@ref) +""" +GetPlaintextRootOfUnity + +""" + SetPlaintextRootOfUnity(parameters::EncodingParams, FIXME::Integer) + +FIXME! + +See also: [`EncodingParams`](@ref), [`GetPlaintextRootOfUnity`](@ref) +""" +SetPlaintextRootOfUnity + +""" + GetPlaintextBigModulus(parameters::EncodingParams) + +FIXME! + +See also: [`EncodingParams`](@ref), [`SetPlaintextBigModulus`](@ref) +""" +GetPlaintextBigModulus + +""" + SetPlaintextBigModulus(parameters::EncodingParams, FIXME::Integer) + +FIXME! + +See also: [`EncodingParams`](@ref), [`GetPlaintextBigModulus`](@ref) +""" +SetPlaintextBigModulus + +""" + GetPlaintextBigRootOfUnity(parameters::EncodingParams) + +FIXME! + +See also: [`EncodingParams`](@ref), [`SetPlaintextBigRootOfUnity`](@ref) +""" +GetPlaintextBigRootOfUnity + +""" + SetPlaintextBigRootOfUnity(parameters::EncodingParams, FIXME::Integer) + +FIXME! + +See also: [`EncodingParams`](@ref), [`GetPlaintextBigRootOfUnity`](@ref) +""" +SetPlaintextBigRootOfUnity + +""" + GetPlaintextGenerator(parameters::EncodingParams) + +FIXME! + +See also: [`EncodingParams`](@ref), [`SetPlaintextGenerator`](@ref) +""" +GetPlaintextGenerator + +""" + SetPlaintextGenerator(parameters::EncodingParams, FIXME::Integer) + +FIXME! + +See also: [`EncodingParams`](@ref), [`GetPlaintextGenerator`](@ref) +""" +SetPlaintextGenerator + +""" + GetBatchSize(parameters::EncodingParams) + +FIXME! + +See also: [`EncodingParams`](@ref), [`SetBatchSize`](@ref) +""" +GetBatchSize + +""" + SetBatchSize(parameters::EncodingParams, FIXME::Integer) + +FIXME! + +See also: [`EncodingParams`](@ref), [`GetBatchSize`](@ref) +""" +SetBatchSize + + + # CryptoContext """ GenCryptoContext(parameters::CCParams)::CryptoContext @@ -156,6 +268,15 @@ See also: [`CryptoContext`](@ref), [`GetKeyGenLevel`](@ref) """ SetKeyGenLevel +""" + GetEncodingParams(crypto_context::CryptoContext) + +Return the [`EncodingParams`](@ref) used by a given `crypto_context`. + +See also: [`CryptoContext`](@ref), [`EncodingParams`](@ref) +""" +GetEncodingParams + """ GetCyclotomicOrder(crypto_context::CryptoContext)::UInt32 diff --git a/test/test_convenience.jl b/test/test_convenience.jl index a2428ef..5f586de 100644 --- a/test/test_convenience.jl +++ b/test/test_convenience.jl @@ -26,6 +26,12 @@ using OpenFHE @test_nowarn show(PrivateKey{DCRTPoly}()) println() + + @test_nowarn show(OpenFHE.DecryptResult()) + println() + + @test_nowarn show(EncodingParams()) + println() end end # @testset "test_convenience.jl"