Design and Implementation of a Homomorphic ... - Researcher
Design and Implementation of a Homomorphic ... - Researcher
Design and Implementation of a Homomorphic ... - Researcher
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
2.6.2 The IndexMap class<br />
The class template IndexMap implements a map <strong>of</strong> elements <strong>of</strong> type T, indexed by a dynamic<br />
IndexSet. Additionally, it allows new elements <strong>of</strong> the map to be initialized in a flexible manner,<br />
by providing an initialization function which is called whenever a new element (indexed by a new<br />
index j) is added to the map.<br />
Specifically, we have a helper class template IndexMapInit that stores a pointer to an<br />
initialization function, <strong>and</strong> possibly also other parameters that the initialization function needs.<br />
We then provide a constructor IndexMap(IndexMapInit* initObject=NULL) that associates<br />
the given initialization object with the new IndexMap object. Thereafter, When a new index j is<br />
added to the index set, an object t <strong>of</strong> type T is created using the default constructor for T, after<br />
which the function initObject->init(t) is called.<br />
In our library, we use an IndexMap to store the rows <strong>of</strong> the matrix <strong>of</strong> a Double-CRT object.<br />
For these objects we have an initialization object that stores the value <strong>of</strong> φ(m), <strong>and</strong> the initialization<br />
function, which is called whenever we add a new row, ensures that all the rows have length<br />
exactly φ(m).<br />
After initialization an IndexMap object provides the operator map[i] to access the type-T object<br />
indexed by i (if i currently belongs to the IndexSet), as well as the methods map.insert(i) <strong>and</strong><br />
map.remove(i) to insert or delete a single data item indexed by i, <strong>and</strong> also map.insert(s) <strong>and</strong><br />
map.remove(s) to insert or delete a collection <strong>of</strong> data items indexed by the IndexSet s.<br />
2.7 FHEcontext: Keeping the parameters<br />
Objects in higher layers <strong>of</strong> our library are defined relative to some parameters, such as the integer<br />
parameter m (that defines the groups Z ∗ m <strong>and</strong> Z ∗ m/ 〈2〉 <strong>and</strong> the ring A = Z[X]/Φ m (X)) <strong>and</strong> the<br />
sequence <strong>of</strong> small primes that determine our modulus-chain. To allow convenient access to these<br />
parameters, we define the class FHEcontext that keeps them all <strong>and</strong> provides access methods <strong>and</strong><br />
some utility functions.<br />
One thing that’s included in FHEcontext is a vector <strong>of</strong> Cmodulus objects, holding the small<br />
primes that define our modulus chain:<br />
vector moduli;<br />
// Cmodulus objects for the different primes<br />
We provide access to the Cmodulus objects via context.ithModulus(i) (that returns a reference<br />
<strong>of</strong> type const Cmodulus&), <strong>and</strong> to the small primes themselves via context.ithPrime(i)<br />
(that returns a long). The FHEcontext includes also the various algebraic structures for plaintext<br />
arithmetic, specifically we have the three data members:<br />
PAlgebra zMstar; // The structure <strong>of</strong> Zm<br />
∗<br />
PAlgebraModTwo modTwo; // The structure <strong>of</strong> Z[X]/(Φ m (X), 2)<br />
PAlgebraMod2r mod2r; // The structure <strong>of</strong> Z[X]/(Φ m (X), 2 r )<br />
In addition to the above, the FHEcontext contains a few IndexSet objects, describing various<br />
partitions <strong>of</strong> the index-set in the vector <strong>of</strong> moduli. These partitions are used when generating the<br />
key-switching matrices in the public key, <strong>and</strong> when using them to actually perform key-switching<br />
on ciphertexts.<br />
One such partition is “ciphertext” vs. “special” primes: Freshly encrypted ciphertexts are<br />
encrypted relative to a subset <strong>of</strong> the small primes, called the ciphertext primes. All other primes<br />
are only used during key-switching, these are called the special primes. The ciphertext primes, in<br />
9