Template Class CryptoContextFactory

Template Parameter Order

  1. typename Element

Class Documentation

template<typename Element>
class lbcrypto::CryptoContextFactory

CryptoContextFactory.

A class that contains all generated contexts and static methods to access/release them. Contexts are deduplicated: GetContext() returns the already registered context whose crypto parameters and scheme compare equal to the requested ones, so keys and ciphertexts deserialized separately end up sharing a single context instance.

Template Parameters

Element – a ring element.

Public Static Functions

static inline void ReleaseAllContexts()

Releases all registered contexts: clears their CKKS caches and the static evaluation-key maps, empties the registry and returns freed memory to the system.

static inline int GetContextCount()

Returns the number of registered contexts.

Returns

the number of contexts currently held by the factory

static CryptoContext<Element> GetContext(std::shared_ptr<CryptoParametersBase<Element>> params, std::shared_ptr<SchemeBase<Element>> scheme, SCHEME schemeId = SCHEME::INVALID_SCHEME)

Returns the registered context with equal crypto parameters and scheme, creating and registering a new one if none exists yet.

Parameters
  • params – crypto parameters of the context

  • scheme – scheme object of the context

  • schemeId – scheme identifier stored in a newly created context (ignored if an existing one is found)

Returns

the shared context

static CryptoContext<Element> GetFullContextByDeserializedContext(const CryptoContext<Element> context)

Returns the full registered context matching a (partial) context obtained by deserialization, registering the deserialized context itself if no equal one exists. Callers that only include cryptocontext-fwd.h use this instead of GetContext() to avoid circular dependencies.

Parameters

context – the deserialized context

Returns

the registered context with the same crypto parameters, scheme and scheme identifier

static inline const std::vector<CryptoContext<Element>> &GetAllContexts()

Returns all registered contexts.

Returns

reference to the vector of registered contexts

Protected Static Functions

static CryptoContext<Element> FindContext(std::shared_ptr<CryptoParametersBase<Element>> params, std::shared_ptr<SchemeBase<Element>> scheme)

Looks up a registered context with equal crypto parameters and scheme. If found and the context uses packed encoding, the PackedEncoding parameters are (re)initialized for it.

Parameters
  • params – crypto parameters to match (compared by value)

  • scheme – scheme object to match (compared by value)

Returns

the matching registered context, or nullptr if there is none

static void AddContext(CryptoContext<Element>)

Registers the given context and, if it uses packed encoding, initializes the PackedEncoding parameters for it.