Skip to content

Commit

Permalink
Resolved merge conflicts.
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbeast committed Apr 28, 2016
2 parents 80c17fb + e43b309 commit 73fd19a
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 77 deletions.
Binary file modified krypto-api/src/main/resources/libmain.so
Binary file not shown.
2 changes: 1 addition & 1 deletion krypto-lib/src/main/cpp/BitMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ class BitMatrix {
* Function: copy(m)
* Copies a given matrix to the current one
*/
void copy(const BitMatrix<ROWS, COLS> &m) {
void copy(const BitMatrix<ROWS, COLS> &m) const {
for (size_t i = 0; i < ROWS; ++i)
(_rows[i]).copy(m.getRow(i));
}
Expand Down
2 changes: 1 addition & 1 deletion krypto-lib/src/main/cpp/BitVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class BitVector {
* Function: copy(rhs)
* Copies a given vector into the current one
*/
void copy(const BitVector<NUM_BITS> & v) {
void copy(const BitVector<NUM_BITS> & v) const {
memcpy(this->elements(), v.elements(), sizeof(v));
}

Expand Down
75 changes: 23 additions & 52 deletions krypto-lib/src/main/cpp/BridgeKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ class BridgeKey{
_Cu1(pk.getUnaryObf1()),
_Cu2(pk.getUnaryObf2()),
_Cb1(pk.getBinaryObf1()),
_Cb2(pk.getBinaryObf2()),
_Ai(pk.getA().inv()),
_Bi(pk.getB().inv()),
_ARAi(pk.getA() * _R * _Ai),
_AiM2(_Ai.template pMult<2*N, 2*N>(_M.inv(), N))
_Cb2(pk.getBinaryObf2())
{}

/* Unary unified code */
Expand All @@ -50,7 +46,7 @@ class BridgeKey{
const MultiQuadTuple<2*N, 2*N> getUnaryG1() const{
const MultiQuadTupleChain<N,2> & f = _pk.getf();

const BitMatrix<N, 2*N> & matTop = _AiM2;
const BitMatrix<N, 2*N> & matTop = _M.inv().splitV2(1);
const BitMatrix<N, 2*N> & matBot = _R * matTop;

const MultiQuadTuple<2*N, N> & top = f.get(0) * matTop;
Expand Down Expand Up @@ -88,16 +84,12 @@ class BridgeKey{
*/
const BitMatrix<2*N, 4*N> getLMMZ(const BitMatrix<N> & K) const{
const BitMatrix<N> & zeroN = BitMatrix<N>::zeroMatrix();
const BitMatrix<N> & RAi = _R * _Ai;

const BitMatrix<N> & _BKBi = _pk.getB() * K * _Bi;
const BitMatrix<N> & _BKBiAi = _BKBi * _Ai;

const BitMatrix<N, 2*N> & XTop = BitMatrix<N, 2*N>::augH(_BKBi, _BKBiAi ^ RAi);
const BitMatrix<N, 2*N> & XBot = BitMatrix<N, 2*N>::augH(zeroN, _ARAi);
const BitMatrix<N, 2*N> & XTop = BitMatrix<N, 2*N>::augH(K, zeroN);
const BitMatrix<N, 2*N> & XBot = BitMatrix<N, 2*N>::augH(zeroN, _R);
const BitMatrix<2*N> & X = _M * BitMatrix<2*N>::augV(XTop, XBot) * _M.inv();

const BitMatrix<N, 2*N> & YTop = BitMatrix<N, 2*N>::augH(_BKBi, BitMatrix<N>::identityMatrix());
const BitMatrix<N, 2*N> & YTop = BitMatrix<N, 2*N>::augH(K, BitMatrix<N>::identityMatrix());
const BitMatrix<N, 2*N> & YBot = BitMatrix<N, 2*N>::augH(zeroN, zeroN);
const BitMatrix<2*N> & Y = _M * BitMatrix<2*N>::augV(YTop, YBot) * _Cu2.inv();
return BitMatrix<2*N, 4*N>::augH(X, Y);
Expand Down Expand Up @@ -150,17 +142,13 @@ class BridgeKey{
const MultiQuadTupleChain<N,2> & f = _pk.getf();

const BitMatrix<N, 2*N> & M2 = _M.inv().splitV2(1);
const BitMatrix<N, 4*N> & M2ProjX = BitMatrix<N, 4*N>::augH(M2, BitMatrix<N, 2*N>::zeroMatrix());
const BitMatrix<N, 4*N> & M2ProjY = BitMatrix<N, 4*N>::augH(BitMatrix<N, 2*N>::zeroMatrix(), M2);

const BitMatrix<N, 4*N> & matTop = _Ai * M2ProjX;
const BitMatrix<N, 4*N> & matMid = _Ai * M2ProjY;
const BitMatrix<N, 4*N> & matBotX = _Rx * matTop;
const BitMatrix<N, 4*N> & matBotY = _Ry * matMid;
const BitMatrix<N, 4*N> & matTop = BitMatrix<N, 4*N>::augH(M2, BitMatrix<N, 2*N>::zeroMatrix());
const BitMatrix<N, 4*N> & matMid = BitMatrix<N, 4*N>::augH(BitMatrix<N, 2*N>::zeroMatrix(), M2);
const BitMatrix<N, 4*N> & matBot = (_Rx * matTop) ^ (_Ry * matMid);

const MultiQuadTuple<4*N, N> & top = f.get(0) * matTop;
const MultiQuadTuple<4*N, N> & mid = f.get(0) * matMid;
const MultiQuadTuple<4*N, N> & bot = f.get(0) * (matBotX ^ matBotY);
const MultiQuadTuple<4*N, N> & bot = f.get(0) * matBot;
MultiQuadTuple<4*N, 3*N> aug;
aug.augV(top, mid, bot);
return aug.template rMult<3*N>(_Cb1);
Expand Down Expand Up @@ -241,7 +229,7 @@ class BridgeKey{
const H_AND getAND() const{
H_AND result;
refreshParam();
const BitMatrix<2*N, N> & MB = _M.template pMult(_pk.getB(), 0, 0, N);
const BitMatrix<2*N, N> & MB = _M.splitH2(0); // is this a possible security vulnerability??
const BitMatrix<2*N, 3*N> & MY3 = _M * BitMatrix<2*N, 3*N>::augV(_Cb2.inv().splitV3(2), BitMatrix<N, 3*N>::zeroMatrix());
result.initialize(MB, MY3, getANDz(), getANDZ1(), getANDZ2(), getBinaryG1(), getBinaryG2());
return result;
Expand All @@ -257,29 +245,17 @@ class BridgeKey{
const BitMatrix<2*N> _Cu2;
const BitMatrix<3*N> _Cb1;
const BitMatrix<3*N> _Cb2;
const BitMatrix<N> _Ai;
const BitMatrix<N> _Bi;
const BitMatrix<N> _ARAi;
BitMatrix<N> _ARxAi;
BitMatrix<N> _ARyAi;
const BitMatrix<N, 2*N> _AiM2;
static const unsigned int twoN = N << 1;
static const unsigned int threeN = 3 * N;

/*
* Function: Refresh and re-randomise Rx, Ry and all associated variables
* Returns void
*/
void refreshParam() {
void refreshParam() const {
// re-randomise Rx, Ry
_Rx.copy(BitMatrix<N>::randomInvertibleMatrix());
_Ry.copy(BitMatrix<N>::randomInvertibleMatrix());

// carry out all necessary modifications
const BitMatrix<N> & conjugateRx = _pk.getA() * _Rx * _Ai;
const BitMatrix<N> & conjugateRy = _pk.getA() * _Ry * _Ai;
_ARxAi.copy(conjugateRx);
_ARyAi.copy(conjugateRy);
}

/* Helper Functions for getXOR */
Expand All @@ -289,10 +265,8 @@ class BridgeKey{
* Returns matrix Xx used for homomorphic XOR
*/
const BitMatrix<2*N> getXORXx() const{
const BitMatrix<N> & idN = BitMatrix<N>::identityMatrix();

const BitMatrix<N, 2*N> & XTop = BitMatrix<N, 2*N>::augH(idN, (idN ^ _Rx) * _Ai);
const BitMatrix<N, 2*N> & XBot = BitMatrix<N, 2*N>::augH(BitMatrix<N>::zeroMatrix(), _ARxAi);
const BitMatrix<N, 2*N> & XTop = BitMatrix<N, 2*N>::augH(BitMatrix<N>::identityMatrix(), BitMatrix<N>::zeroMatrix());
const BitMatrix<N, 2*N> & XBot = BitMatrix<N, 2*N>::augH(BitMatrix<N>::zeroMatrix(), _Rx);
return _M * BitMatrix<2*N>::augV(XTop, XBot) * _M.inv();
}

Expand All @@ -301,10 +275,8 @@ class BridgeKey{
* Returns matrix Xy used for homomorphic XOR
*/
const BitMatrix<2*N> getXORXy() const{
const BitMatrix<N> idN = BitMatrix<N>::identityMatrix();

const BitMatrix<N, 2*N> XTop = BitMatrix<N, 2*N>::augH(idN, (idN ^ _Ry) * _Ai);
const BitMatrix<N, 2*N> XBot = BitMatrix<N, 2*N>::augH(BitMatrix<N>::zeroMatrix(), _ARyAi);
const BitMatrix<N, 2*N> XTop = BitMatrix<N, 2*N>::augH(BitMatrix<N>::identityMatrix(), BitMatrix<N>::zeroMatrix());
const BitMatrix<N, 2*N> XBot = BitMatrix<N, 2*N>::augH(BitMatrix<N>::zeroMatrix(), _Ry);
return _M * BitMatrix<2*N>::augV(XTop, XBot) * _M.inv();
}

Expand All @@ -326,8 +298,8 @@ class BridgeKey{
* Returns matrix X used to compute z for homomorphic AND
*/
const BitMatrix<N, 2*N> getANDX() const{
const BitMatrix<N, 2*N> & inner = BitMatrix<N, 2*N>::augH(BitMatrix<N>::identityMatrix(), _Ai);
return _Bi * inner * _M.inv();
const BitMatrix<N, 2*N> & inner = BitMatrix<N, 2*N>::augH(BitMatrix<N>::identityMatrix(), BitMatrix<N>::zeroMatrix());
return inner * _M.inv();
}

/*
Expand Down Expand Up @@ -513,9 +485,8 @@ class BridgeKey{
const MultiQuadTuple<7*N, N> getANDz() const{
const BitMatrix<N, 2*N> & X = getANDX();
const BitMatrix<3*N> & Cb2i = _Cb2.inv();
const BitMatrix<N, 3*N> & Y1 = _Bi.pMult(Cb2i, 0);
const BitMatrix<N, 3*N> & Y2 = _Bi.pMult(Cb2i, N);
const BitMatrix<N, 3*N> & Y3 = Cb2i.splitV3(2);
const BitMatrix<N, 3*N> & Y1 = Cb2i.splitV3(0);
const BitMatrix<N, 3*N> & Y2 = Cb2i.splitV3(1);
const BitMatrix<((7*N * (7*N + 1)) >> 1), N> & contrib = BitMatrix<((7*N * (7*N + 1)) >> 1), N>::augV(getANDP(X, Y2), getANDQ(X, Y1), getANDS(Y1, Y2));
MultiQuadTuple<7*N, N> z;
z.setContributions(contrib, BitVector<N>::zeroVector());
Expand All @@ -527,8 +498,8 @@ class BridgeKey{
* Returns matrix Z1 used for homomorphic AND
*/
const BitMatrix<2*N> getANDZ1() const{
const BitMatrix<N, 2*N> & top = _Rx * _AiM2;
const BitMatrix<N, 2*N> & bottom = _pk.getA() * top;
const BitMatrix<N, 2*N> & top = BitMatrix<N, 2*N>::zeroMatrix();
const BitMatrix<N, 2*N> & bottom = _Rx * _M.inv().splitV2(1);
return _M * BitMatrix<2*N>::augV(top, bottom);
}

Expand All @@ -538,8 +509,8 @@ class BridgeKey{
* Dimension of Z2: 2*(N * 2^6) by 2*(N * 2^6)
*/
const BitMatrix<2*N> getANDZ2() const{
const BitMatrix<N, 2*N> & top = _Ry * _AiM2;
const BitMatrix<N, 2*N> & bottom = _pk.getA() * top;
const BitMatrix<N, 2*N> & top = BitMatrix<N, 2*N>::zeroMatrix();
const BitMatrix<N, 2*N> & bottom = _Ry * _M.inv().splitV2(1);
return _M * BitMatrix<2*N>::augV(top, bottom);
}

Expand Down
8 changes: 3 additions & 5 deletions krypto-lib/src/main/cpp/ClientHashFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ struct ClientHashFunction
void generateHashMatrix(const BitMatrix<N, 2*N> & K, const PrivateKey<N> & pk){
const BitMatrix<2*N> & Mi = pk.getM().inv();
const BitMatrix<N, 2*N> & Mi1 = Mi.splitV2(0);
const BitMatrix<N, 2*N> & Mi2 = Mi.splitV2(1);

const BitMatrix<N, 2*N> & decryptMatrix = pk.getB().inv() * (Mi1 ^ pk.getA().inv() * Mi2);
const BitMatrix<N, 2*N> & decryptMatrix = Mi1;

const BitMatrix<N, 2*N> & zero = BitMatrix<N, 2*N>::zeroMatrix();
const BitMatrix<N, 4*N> & top = BitMatrix<N, 4*N>::augH(decryptMatrix, zero);
Expand All @@ -64,7 +63,7 @@ struct ClientHashFunction
*/
const MultiQuadTuple<2*N, N> generateAugmentedF2(const BitMatrix<N> & C, const BitMatrix<N, 2*N> & K, const PrivateKey<N> & pk) const{
MultiQuadTuple<N, N> f2 = pk.getf().get(1);
MultiQuadTuple<N, N> topBot = (f2 * C).rMult(pk.getB().inv());
MultiQuadTuple<N, N> topBot = f2 * C;

const BitMatrix<N> & I = BitMatrix<N>::identityMatrix();
const BitMatrix<N> & O = BitMatrix<N>::zeroMatrix();
Expand All @@ -83,8 +82,7 @@ struct ClientHashFunction
*/
const MultiQuadTuple<2*N, N> generateConcealedF1(const BitMatrix<N> & C, const PrivateKey<N> & pk) const{
MultiQuadTuple<N, N> f1 = pk.getf().get(0);
const BitMatrix<N, 2*N> & Mi2 = pk.getM().inv().splitV2(1);
const BitMatrix<N, 2*N> & inner = pk.getA().inv() * Mi2;
const BitMatrix<N, 2*N> & inner = pk.getM().inv().splitV2(1);
return (f1 * inner).rMult(C.inv());
}

Expand Down
20 changes: 4 additions & 16 deletions krypto-lib/src/main/cpp/PrivateKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ template<unsigned int N4> friend class KryptnosticClient;
* Constructs a PrivateKey with randomly initialized private variables
*/
PrivateKey():
_A(BitMatrix<N>::randomInvertibleMatrix()),
_B(BitMatrix<N>::randomInvertibleMatrix()),
_M(BitMatrix<2*N>::randomInvertibleMatrix()),
_f(MultiQuadTupleChain<N,2>::randomMultiQuadTupleChain()){
generateObfuscationMatrixChains();
Expand All @@ -46,8 +44,8 @@ template<unsigned int N4> friend class KryptnosticClient;
*/
const BitVector<2*N> encrypt(const BitVector<N> &m) const{//returns x = E(m, r) given a plaintext m
const BitVector<N> & r = BitVector<N>::randomVector();
const BitVector<N> & top = (_B * m) ^ (r ^ _f(r));
const BitVector<N> & bottom = _A * r;
const BitVector<N> & top = m ^ _f(r);
const BitVector<N> & bottom = r;
return _M * BitVector<N>::vCat(top, bottom);
}

Expand All @@ -59,20 +57,11 @@ template<unsigned int N4> friend class KryptnosticClient;
const BitVector<2*N> & mix = _M.solve(x);
BitVector<N> x1, x2;
mix.proj(x1, x2);
const BitVector<N> & Aix2 = _A.solve(x2);
const BitVector<N> & fAix2 = _f(Aix2);
return _B.solve(x1 ^ (Aix2 ^ fAix2));
const BitVector<N> & fx2 = _f(x2);
return x1 ^ fx2;
}

protected:
const BitMatrix<N> getA() const{
return _A;
}

const BitMatrix<N> getB() const{
return _B;
}

const BitMatrix<2*N> getM() const{
return _M;
}
Expand All @@ -98,7 +87,6 @@ template<unsigned int N4> friend class KryptnosticClient;
}

private:
const BitMatrix<N> _A, _B; //SL_n(F_2)
const BitMatrix<2*N> _M; //SL_{2n}(F_2)
MultiQuadTupleChain<N,2> _f; //{f_1,...,f_L} random quadratic function tuples
BitMatrix<2*N> _Cu[2]; //chain of obfuscation matrix for unary operations
Expand Down
4 changes: 2 additions & 2 deletions krypto-lib/src/main/cpp/PublicKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class PublicKey{
const BitMatrix<2*N, 4*N> _lc;
const MultiQuadTuple<2*N, 2*N> _gu1;
const MultiQuadTuple<2*N, 2*N> _gu2;
const typename BridgeKey<N>::H_XOR _XOR;
const typename BridgeKey<N>::H_AND _AND;
typename BridgeKey<N>::H_XOR _XOR;
typename BridgeKey<N>::H_AND _AND;
};

#endif

0 comments on commit 73fd19a

Please sign in to comment.