Skip to content

Commit

Permalink
LowMC
Browse files Browse the repository at this point in the history
Reimplemented the graycode for the lowmc example such that the lowmc example can be compiled again.
  • Loading branch information
Martin Kromm authored and oliver-schick committed May 3, 2020
1 parent cfef7f3 commit bae46a0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ add_subdirectory(bench_operations)
add_subdirectory(euclidean_distance)
add_subdirectory(float)
add_subdirectory(innerproduct)
#currently not supported due to dependency to gpl code
#TODO make it work again
#add_subdirectory(lowmc)
add_subdirectory(lowmc)
add_subdirectory(millionaire_prob)
add_subdirectory(min-euclidean-dist)
add_subdirectory(psi_phasing)
Expand Down
36 changes: 31 additions & 5 deletions src/examples/lowmc/common/lowmccircuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
#include <ENCRYPTO_utils/crypto/crypto.h>

static uint32_t m_nRndCtr;
static code* m_tGrayCode;
static uint32_t* m_tGrayCode;
static uint32_t* m_tGrayCodeIncrement;
static uint32_t m_nZeroGate;

//sboxes (m), key-length (k), statesize (n), data (d), rounds (r)
Expand Down Expand Up @@ -91,8 +92,8 @@ share* BuildLowMCCircuit(share* val, share* key, BooleanCircuit* circ, LowMCPara
m_nZeroGate = zerogate;

//Build the GrayCode for the optimal window-size
uint32_t wsize = floor_log2(statesize) - 2;
m_tGrayCode = build_code(wsize);
m_tGrayCode = BuildGrayCode(statesize);
m_tGrayCodeIncrement = BuildGrayCodeIncrement(statesize);

//copy the input to the current state
for (i = 0; i < statesize; i++)
Expand All @@ -117,7 +118,8 @@ share* BuildLowMCCircuit(share* val, share* key, BooleanCircuit* circ, LowMCPara

}

destroy_code(m_tGrayCode);
free(m_tGrayCode);
free(m_tGrayCodeIncrement);

#if PRINT_PERFORMANCE_STATS
std::cout << "Total Number of Boolean Gates: " << circ->GetNumGates() << std::endl;
Expand Down Expand Up @@ -220,7 +222,7 @@ void FourRussiansMatrixMult(std::vector<uint32_t>& state, uint32_t lowmcstatesiz

for (i = 0, bitctr = 0; i < ceil_divide(lowmcstatesize, wsize); i++) { //for each column-window
for (j = 1; j < (1 << wsize); j++) {
lut[m_tGrayCode->ord[j]] = circ->PutXORGate(lut[m_tGrayCode->ord[j - 1]], state_pad[i * wsize + m_tGrayCode->inc[j - 1]]);
lut[m_tGrayCode[j]] = circ->PutXORGate(lut[m_tGrayCode[j - 1]], state_pad[i * wsize + m_tGrayCodeIncrement[j - 1]]);
}

for (j = 0; j < lowmcstatesize; j++, bitctr += wsize) {
Expand Down Expand Up @@ -273,3 +275,27 @@ void CallbackMultiplyAndDestroy4RMatrix(GATE* gate, void* matrix) {
//TODO
}

uint32_t* BuildGrayCode(uint32_t length) {
uint32_t* gray_code = (uint32_t*) malloc(sizeof(uint32_t) * length);
for(uint32_t i = 0; i < length; ++i) {
gray_code[i] = i ^ (i >> 1);
}
return gray_code;
}

uint32_t* BuildGrayCodeIncrement(uint32_t length) {
uint32_t* gray_code_increment = (uint32_t*) malloc(sizeof(uint32_t) * length);
for(uint32_t i = 0; i < length; ++i) {
gray_code_increment[i] = 0;
}
uint32_t length_inc = 2;
while(length_inc < length) {
uint32_t length_count = length_inc - 1;
while(length_count <= length) {
(gray_code_increment[length_count])++;
length_count += length_inc;
}
length_inc <<= 1;
}
return gray_code_increment;
}
5 changes: 3 additions & 2 deletions src/examples/lowmc/common/lowmccircuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "../../../abycore/aby/abyparty.h"
#include <ENCRYPTO_utils/cbitvector.h>
#include <ENCRYPTO_utils/typedefs.h>
//TODO make the graycode functionallity work again, the current graycode implementation depends on gpl code
//#include <ENCRYPTO_utils/graycode.h>
#include <cassert>

static const BYTE mpccseed[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
Expand Down Expand Up @@ -74,4 +72,7 @@ void CallbackMultiplyAndDestroy4RMatrix(GATE* gate, void* matrix);

void FourRussiansMatrixMult(std::vector<uint32_t>& state, uint32_t lowmcstatesize, BooleanCircuit* circ);

uint32_t* BuildGrayCode(uint32_t length);
uint32_t* BuildGrayCodeIncrement(uint32_t length);

#endif /* __LOWMCCIRCUIT_H_ */

0 comments on commit bae46a0

Please sign in to comment.