Skip to content

Commit

Permalink
Add EncodingParams (#30)
Browse files Browse the repository at this point in the history
* Add EncodingParams

* Add module name to unexported symbol
  • Loading branch information
sloede authored Feb 12, 2024
1 parent 8e3a53e commit 96341f8
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/OpenFHE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions src/convenience.jl
Original file line number Diff line number Diff line change
@@ -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}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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...)
Expand All @@ -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)
Expand Down Expand Up @@ -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
end
121 changes: 121 additions & 0 deletions src/documentation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/test_convenience.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 96341f8

Please sign in to comment.