22.04.2014 Views

a590003

a590003

a590003

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.1 Homomorphic Operations over GF (2 8 )<br />

/*** Determine the parameters (cf. [5, Appendix C]) ***/<br />

long ptxtSpace = 2;<br />

long nDigits = 2; // # of digits/# of columns in key-switching matrices<br />

long k = 80; // security parameter<br />

long weight = 64; // Hamming weight of secret keys<br />

long lvls = 3; // number of ciphertext-primes in the modulus chain<br />

long m = 11441; // the parameter m, defining Zm^* and Phi_m(X)<br />

/*** Setup the various tables, and choose the keys ***/<br />

FHEcontext context(m); // initialize a new context for the parameter m<br />

buildModChain(context, lvls, nDigits); // build the modulus chain<br />

FHESecKey secretKey(context);<br />

const FHEPubKey& publicKey = secretKey;<br />

secretKey.GenSecKey(weight,ptxtSpace);<br />

// initialize a secret-key object<br />

// use the same object as a public-key<br />

// draw a random secret key<br />

addSome1DMatrices(secretKey);<br />

// compute some key-switching matrices<br />

// We could also use add1DMatrices instead of addSome1DMatrices<br />

GF2X G; // G is the AES polynomial, G(X)= X^8 +X^4 +X^3 +X +1<br />

SetCoeff(G,8); SetCoeff(G,4); SetCoeff(G,3); SetCoeff(G,1); SetCoeff(G,0);<br />

EncryptedArray ea(context, G); // An EncryptedArray object, encoding wrt G<br />

long nslots = ea.size(); // number of plaintext slots<br />

/*** Encrypt random arrays over GF(2^8) ***/<br />

vector p0, p1, p2, p3;<br />

ea.random(p0);<br />

ea.random(p1);<br />

ea.random(p2);<br />

ea.random(p3);<br />

vector const1, const2;<br />

ea.random(const1);<br />

ea.random(const2);<br />

// Choose random arrays<br />

// two more random "constants"<br />

ZZX const1_poly, const2_poly; // encode constants as polynomials<br />

ea.encode(const1_poly, const1);<br />

ea.encode(const2_poly, const2);<br />

// Encrypt the random arrays<br />

Ctxt c0(publicKey), c1(publicKey), c2(publicKey), c3(publicKey);<br />

ea.encrypt(c0, publicKey, p0);<br />

ea.encrypt(c1, publicKey, p1);<br />

ea.encrypt(c2, publicKey, p2);<br />

ea.encrypt(c3, publicKey, p3);<br />

34<br />

16. Design and Implementation of a Homomorphic-Encryption Library

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!