Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[submodule "extern/ENCRYPTO_utils"]
path = extern/ENCRYPTO_utils
url = ../ENCRYPTO_utils.git
url = https://github.com/encryptogroup/ENCRYPTO_utils.git
branch = feature-cmake
[submodule "extern/OTExtension"]
path = extern/OTExtension
url = ../OTExtension.git
url = https://github.com/encryptogroup/OTExtension.git
branch = feature-cmake
103 changes: 103 additions & 0 deletions MATRIX/MatrixMeasurement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// Created by liork on 8/22/18.
//

#ifndef ABY_MATRIXMEASUREMENT_H
#define ABY_MATRIXMEASUREMENT_H

#include <string>
#include <chrono>
#include <fstream>
#include <iostream>


using namespace std;
using namespace std::chrono;

class MatrixMeasurement
{
private:
string getcwdStr()
{
char* buff;//automatically cleaned when it exits scope
return string(getcwd(buff,255));
}

int getTaskIdx(string name)
{
auto it = std::find(m_tasksNames.begin(), m_tasksNames.end(), name);
auto idx = distance(m_tasksNames.begin(), it);
return idx;
}

vector<vector<long>> m_cpuStartTimes;
vector<vector<long>> m_cpuEndTimes;
string m_arguments = "";
vector<string> m_tasksNames;

public:
MatrixMeasurement(size_t argc, char* argv[], vector<string> tasksNames, int numberOfIterations):
m_cpuStartTimes(vector<vector<long>>(tasksNames.size(), vector<long>(numberOfIterations))),
m_cpuEndTimes(vector<vector<long>>(tasksNames.size(), vector<long>(numberOfIterations)))
{

for(size_t idx = 0; idx < argc; ++idx)
{
string s(argv[idx]);
if (idx < argc - 1)
m_arguments += s + "*";
else
m_arguments += s;
}

m_tasksNames = tasksNames;
}

void startSubTask(string taskName, int currentIterationNumber)
{
int taskIdx = getTaskIdx(taskName);
auto now = system_clock::now();

//Cast the time point to ms, then get its duration, then get the duration's count.
auto ms = time_point_cast<milliseconds>(now).time_since_epoch().count();
m_cpuStartTimes[taskIdx][currentIterationNumber] = ms;
}

void endSubTask(string taskName, int currentIterationNumber)
{
int taskIdx = getTaskIdx(taskName);
auto now = system_clock::now();

//Cast the time point to ms, then get its duration, then get the duration's count.
auto ms = time_point_cast<milliseconds>(now).time_since_epoch().count();
m_cpuEndTimes[taskIdx][currentIterationNumber] = ms;

// if this is the last task and last iteration write the data to file
if (taskIdx == m_tasksNames.size() - 1 && currentIterationNumber == m_cpuEndTimes[0].size() - 1)
{
string logFileName = getcwdStr() + "/../../MATRIX/logs/" + m_arguments + ".log";
ofstream logFile(logFileName);
if (logFile.is_open())
{
//write to file
int numberOfIterations = m_cpuEndTimes[0].size();
for (size_t idx = 0; idx < m_tasksNames.size(); ++idx)
{
logFile << m_tasksNames[idx] + ":";
cout << "taskName : " << m_tasksNames[idx] << endl;
for (size_t idx2 = 0; idx2 < numberOfIterations; ++idx2)
{
cout << "value : " << m_cpuEndTimes[idx][idx2] << endl;
logFile << to_string(m_cpuEndTimes[idx][idx2]- m_cpuStartTimes[taskIdx][currentIterationNumber])
+ ",";
}

logFile << "\n";
}
logFile.close();
}
}
}
};

#endif //ABY_MATRIXMEASUREMENT_H
6 changes: 6 additions & 0 deletions MATRIX/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

cd ..
mkdir -p build && cd build
cmake .. -DABY_BUILD_EXE=On
make
Empty file added MATRIX/logs/dummylog
Empty file.
25 changes: 25 additions & 0 deletions MATRIX/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# read the arguments without party id

argc=$#
argv=($@)
values=""

for (( j=1; j<argc; j++ )); do
values+=`echo ${argv[j]}`
values+=' '
done

# read parties file
parties=()
while IFS= read -r line || [[ -n "${line}" ]]; do
l=`echo ${line} | cut -d'=' -f2`
parties+=(${l})
done < parties.conf

idx=${1}
addr=${parties[0]}

cd ../build/bin
./innerproduct_test -r ${idx} -a ${addr} ${values}
40 changes: 38 additions & 2 deletions src/abycore/sharing/boolsharing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
*/
#include "boolsharing.h"
#include "../aby/abysetup.h"
#if _GNUC_ >= 8
#include <filesystem>

#else
#include <experimental/filesystem>
#endif

void BoolSharing::Init() {

Expand Down Expand Up @@ -1604,18 +1607,31 @@ void BoolSharing::Reset() {

/**Checking the role and and deciding upon the file to be deleted if the precomputation values are
completely used up in a Precomputation READ mode.*/
#if _GNUC_ >= 8
std::filesystem::path precomputation_file;
#else
std::experimental::filesystem::path precomputation_file;
#endif
if(m_eRole == SERVER) {
precomputation_file = "pre_comp_server.dump";
} else {
precomputation_file = "pre_comp_client.dump";
}
#if _GNUC_ >= 8
if (std::filesystem::exists(precomputation_file)
&& (m_nFilePos >= std::filesystem::file_size(precomputation_file))
&& (GetPreCompPhaseValue() == ePreCompRead)) {
std::filesystem::remove(precomputation_file);
m_nFilePos = -1; // FIXME: m_nFilePos is unsigned ...
}
#else
if (std::experimental::filesystem::exists(precomputation_file)
&& (m_nFilePos >= std::experimental::filesystem::file_size(precomputation_file))
&& (GetPreCompPhaseValue() == ePreCompRead)) {
std::experimental::filesystem::remove(precomputation_file);
m_nFilePos = -1; // FIXME: m_nFilePos is unsigned ...
}
#endif

}

Expand All @@ -1626,7 +1642,11 @@ void BoolSharing::PreComputationPhase() {
ePreCompPhase phase_value = GetPreCompPhaseValue();

/**Decision of the precomputation file based on the role of executor.*/
#if _GNUC_ >= 8
std::filesystem::path filename;
#else
std::experimental::filesystem::path filename;
#endif
if(m_eRole == SERVER) {
filename = "pre_comp_server.dump";
} else {
Expand All @@ -1638,7 +1658,11 @@ void BoolSharing::PreComputationPhase() {
return;
}
/**Check if the execution is non-Read mode or if the file to be used in READ mode doesn't exist*/
#if _GNUC_ >= 8
else if((phase_value != ePreCompRead)||(!std::filesystem::exists(filename))) {
#else
else if((phase_value != ePreCompRead)||(!std::experimental::filesystem::exists(filename))) {
#endif
/**Compute the MTs normally*/
ComputeMTs();
/**Check if the mode of precomputation is store. If so store it to respective file.*/
Expand Down Expand Up @@ -1668,7 +1692,11 @@ void BoolSharing::StoreMTsToFile(const char *filename) {
Condition to check if the file already exists. If so then, the mode of write would
be file append.
*/
#if _GNUC_ >= 8
if(std::filesystem::exists(filename)) {
#else
if(std::experimental::filesystem::exists(filename)) {
#endif
fp = fopen(filename, "a+b");
}
else {
Expand Down Expand Up @@ -1696,7 +1724,11 @@ void BoolSharing::ReadMTsFromFile(const char *filename) {

FILE *fp;
/**Calculate the file size*/
#if __GNUC_ >= 8
uint64_t file_size = std::filesystem::file_size(filename);
#else
uint64_t file_size = std::experimental::filesystem::file_size(filename);
#endif

/**Variable for the storing the NUMANDSizes value from the file.*/
uint32_t num_and_sizes;
Expand Down Expand Up @@ -1766,7 +1798,11 @@ void BoolSharing::ReadMTsFromFile(const char *filename) {
BOOL BoolSharing::isCircuitSizeLessThanOrEqualWithValueFromFile(char *filename, uint32_t in_circ_size) {

/**Check if the file already exists and if the existing is empty. If so, return false.*/
if(!std::filesystem::exists(filename)||std::filesystem::is_empty(filename)) {
#if __GNUC_ >= 8
if(!std::experimental::filesystem::exists(filename)||std::filesystem::is_empty(filename)) {
#else
if(!std::experimental::filesystem::exists(filename)||std::experimental::filesystem::is_empty(filename)) {
#endif
/**Returning false and reverting the precomputation mode to default.*/
return FALSE;
}
Expand Down
26 changes: 25 additions & 1 deletion src/abycore/sharing/sharing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
#include <ENCRYPTO_utils/crypto/crypto.h>
#include <cassert>
#include <cstring>
#if _GNUC_ >= 8
#include <filesystem>
#else
#include <experimental/filesystem>
#endif
#include <iostream>
#include <iomanip>

Expand Down Expand Up @@ -65,13 +69,17 @@ ePreCompPhase Sharing::GetPreCompPhaseValue() {
}
void Sharing::PreCompFileDelete() {
uint64_t truncation_size;
#if __GNUC_ >= 8
std::filesystem::path filename;
#else
std::experimental::filesystem::path filename;
#endif
if(m_eRole == SERVER) {
filename = "pre_comp_server.dump";
} else {
filename = "pre_comp_client.dump";
}

#if __GNUC_ >= 8
if((std::filesystem::exists(filename))&&(GetPreCompPhaseValue() == ePreCompRead)) {

if(m_nFilePos >= std::filesystem::file_size(filename)) {
Expand All @@ -86,6 +94,22 @@ void Sharing::PreCompFileDelete() {
}
}
}
#else
if((std::experimental::filesystem::exists(filename))&&(GetPreCompPhaseValue() == ePreCompRead)) {

if(m_nFilePos >= std::experimental::filesystem::file_size(filename)) {
std::experimental::filesystem::remove(filename);
}
else {
truncation_size = std::experimental::filesystem::file_size(filename) - m_nFilePos;
std::error_code ec;
std::experimental::filesystem::resize_file(filename, truncation_size, ec);
if(ec) {
std::cout << "Error occured in truncate:" << ec.message() << std::endl;
}
}
}
#endif
}


Expand Down
22 changes: 22 additions & 0 deletions src/examples/innerproduct/common/innerproduct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,28 @@

#include "innerproduct.h"
#include "../../../abycore/sharing/sharing.h"
#include "../../../../MATRIX/MatrixMeasurement.h"

int32_t test_inner_product_circuit(e_role role, const std::string& address, uint16_t port, seclvl seclvl,
uint32_t nvals, uint32_t bitlen, uint32_t nthreads, e_mt_gen_alg mt_alg,
e_sharing sharing, uint32_t num) {

/**
Step 0: Init logger.
*/
char * argv[4];
argv[0] = (char*)"innerproduct";
argv[1] = (char*)malloc(16);
sprintf(argv[1], "%d", role);
argv[2] = (char*)malloc(16);
sprintf(argv[2], "%d", bitlen);
argv[3] = (char*)malloc(16);
sprintf(argv[3], "%d", seclvl.symbits);

vector<string> subTaskNames{"BuildInnerProductCircuit", "ExecCircuit"};

MatrixMeasurement log(4, argv, subTaskNames, 1);

/**
Step 1: Create the ABYParty object which defines the basis of all the
operations which are happening. Operations performed are on the
Expand All @@ -31,6 +48,7 @@ int32_t test_inner_product_circuit(e_role role, const std::string& address, uint
ABYParty* party = new ABYParty(role, address, port, seclvl, bitlen, nthreads,
mt_alg);


/**
Step 2: Get to know all the sharing types available in the program.
*/
Expand Down Expand Up @@ -92,8 +110,10 @@ int32_t test_inner_product_circuit(e_role role, const std::string& address, uint
problem by passing the shared objects and circuit object.
Don't forget to type cast the circuit object to type of share
*/
log.startSubTask("BuildInnerProductCircuit", 0);
s_out = BuildInnerProductCircuit(s_x_vec, s_y_vec, num,
(ArithmeticCircuit*) circ);
log.endSubTask("BuildInnerProductCircuit", 0);

/**
Step 8: Output the value of s_out (the computation result) to both parties
Expand All @@ -104,7 +124,9 @@ int32_t test_inner_product_circuit(e_role role, const std::string& address, uint
Step 9: Executing the circuit using the ABYParty object evaluate the
problem.
*/
log.startSubTask("ExecCircuit", 0);
party->ExecCircuit();
log.endSubTask("ExecCircuit", 0);

/**
Step 10: Type caste the plaintext output to 16 bit unsigned integer.
Expand Down