forked from elibensasson/libSTARK
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
confidential-input program of starkdpm
- Loading branch information
Showing
20 changed files
with
5,695 additions
and
95 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <regex> | ||
#include <protocols/protocol.hpp> | ||
#include "LOCI_AES160hashchain.hpp" | ||
|
||
using namespace stark_dpm; | ||
using namespace stark_dpm::ACSP_FOR_AES160LOCIhashchain; | ||
using std::cout; | ||
using std::endl; | ||
using std::string; | ||
using std::stoul; | ||
using AES160LOCIhashchain::dpmpair_t; | ||
using AES160LOCIhashchain::fingerprint_t; | ||
using AES160LOCIhashchain::database_t; | ||
|
||
const string securityPrefix = "-s"; | ||
|
||
|
||
void printHelp(const string exeName){ | ||
cout<<"Usage:"<<endl; | ||
cout<<"$>"<<exeName<<" <database file path> <fingerprint file path> [" + securityPrefix + "<security parameter>]"<<endl; | ||
cout<<endl<<"Example:"<<endl; | ||
cout<<"$>"<<exeName<<" examples-dpm/database.txt examples-dpm/fp_no_match.txt "+securityPrefix+"120"<<std::endl; | ||
cout<<endl<<"The above execution results in execution of STARK simulation over the DPM blacklist program, with the database represented by examples-dpm/database.txt,"; | ||
cout<<" the suspects fingerprint in examples-dpm/fp_nomatch.txt, with soundness error at most 2^-120. The prover generates in this case a proof for the claim that the fingerprint does not perfectly match any entry in the database."<<endl; | ||
cout<<endl<<"A single fingerprint is represented by a single line, each line contains 20 pairs delimited by spaces, each pair contains two 8 bit numbers in hexadecimal basis, separated by a single period. A database is a file where each line represents a fingerprint."<<endl; | ||
cout<<endl<<"In the simulation the Prover and Verify interact, the Prover generates a proof and the Verifier verifies it. During the executions the specifications of generated BAIR and APR, measurements, and Verifiers decision, are printed to the standard output."<<endl; | ||
|
||
} | ||
|
||
void execute(const fingerprint_t& fprint,const database_t& db, const unsigned int securityParameter){ | ||
AES160LOCIhashcCommonParams params; | ||
params.length = db.size()*2; | ||
params.seed = 127; | ||
|
||
libstark::BairInstance bair_instance = buildBairInstance(params); | ||
|
||
std::vector<std::vector<Algebra::FieldElement>> hashC; | ||
std::vector<Algebra::FieldElement> Result = AES160LOCIhashchain::genHashchain(hashC, db); | ||
AES160LOCIhashchain::evalp::setParams(Result, Algebra::power(xFE(), params.length), fprint); | ||
libstark::BairWitness bair_witness = buildBairWitness(params, hashC, fprint); | ||
|
||
libstark::Protocols::executeProtocol(bair_instance, bair_witness,securityParameter,false,false,true); | ||
} | ||
|
||
dpmpair_t readPair(const string pairStr){ | ||
std::regex regex{R"([.]+)"}; // split on period | ||
std::sregex_token_iterator it{pairStr.begin(), pairStr.end(), regex, -1}; | ||
std::vector<std::string> words{it, {}}; | ||
|
||
if(words.size() != 2){ | ||
cout<<"Each pair must contain 2 elements"<<std::endl; | ||
throw("bad format of DPM file"); | ||
} | ||
|
||
dpmpair_t res; | ||
for(int i=0; i<2; i++){ | ||
res[i] = std::stoul(words[i],0,16); | ||
} | ||
|
||
return res; | ||
} | ||
|
||
fingerprint_t readEntry(const string line){ | ||
std::regex regex{R"([\s]+)"}; // split on space | ||
std::sregex_token_iterator it{line.begin(), line.end(), regex, -1}; | ||
std::vector<std::string> words{it, {}}; | ||
|
||
if(words.size() != 20){ | ||
cout<<"Each line must contain 20 pairs"<<std::endl; | ||
throw("bad format of DPM file"); | ||
} | ||
|
||
fingerprint_t fprint; | ||
for(unsigned int i=0; i<20; i++){ | ||
fprint[i] = readPair(words[i]); | ||
} | ||
return fprint; | ||
} | ||
|
||
database_t readDatabaseFromFile(const string filename){ | ||
std::ifstream ifs(filename); | ||
std::string content((std::istreambuf_iterator<char>(ifs)),std::istreambuf_iterator<char>()); | ||
|
||
std::regex regex{R"([\n]+)"}; // split to lines | ||
std::sregex_token_iterator it{content.begin(), content.end(), regex, -1}; | ||
std::vector<std::string> lines{it, {}}; | ||
|
||
database_t db(lines.size()); | ||
|
||
for(unsigned int i=0; i<lines.size() ;i++){ | ||
db[i] = readEntry(lines[i]); | ||
} | ||
|
||
return db; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
if(argc < 3){ | ||
printHelp(argv[0]); | ||
return 0; | ||
} | ||
|
||
database_t db = readDatabaseFromFile(argv[1]); | ||
fingerprint_t fprint; | ||
{ | ||
database_t tmp = readDatabaseFromFile(argv[2]); | ||
if(tmp.size() <1){ | ||
cout<<"bad format of fingerprint file, at least one fingerprint expected"<<endl; | ||
throw("bad format of fingerprint file"); | ||
} | ||
fprint = tmp[0]; | ||
} | ||
|
||
unsigned int securityParameter = 60; | ||
for(int i=3; i< argc; i++){ | ||
const string currArg(argv[i]); | ||
if(currArg.length()<3){ | ||
continue; | ||
} | ||
|
||
const string prefix = currArg.substr(0,2); | ||
const unsigned int num(stoul(currArg.substr(2))); | ||
|
||
if(prefix == securityPrefix){ | ||
securityParameter = num; | ||
} | ||
} | ||
|
||
if(securityParameter == 0){ | ||
printHelp(argv[0]); | ||
return 0; | ||
} | ||
|
||
|
||
execute(fprint,db, securityParameter); | ||
|
||
return 0; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
#ifndef __ACSP_FOR_AES160hashcLOCI_HPP__ | ||
#define __ACSP_FOR_AES160hashcLOCI_HPP__ | ||
|
||
#include "languages/Bair/BairInstance.hpp" | ||
#include "languages/Bair/BairWitness.hpp" | ||
|
||
#include <algebraLib/BitExtract.hpp> | ||
|
||
#define PRNMSG(str) do { std::cout << str << std::endl; } while( false ) | ||
//#define DBGMSG(str) do { std::cout << str << std::endl; } while( false ) | ||
#define DBGMSG(str) do { } while ( false ) | ||
|
||
#define EXTDIM 64 | ||
|
||
using namespace Algebra; | ||
|
||
namespace AES160hashcLOCI { | ||
|
||
//FieldElement eval(const std::vector<FieldElement>& vars, const std::vector<FieldElement> RootHash, const FieldElement values[][2], FieldElement lastPow); | ||
FieldElement evalCPoly(const std::vector<FieldElement> & vars, | ||
const std::vector<FieldElement> & RootHash, const FieldElement& gN); | ||
|
||
|
||
class evalp | ||
{ | ||
public: | ||
static void setParams(const std::vector<FieldElement>&, const FieldElement&, const int); | ||
static FieldElement ep(const std::vector<FieldElement>&); | ||
private: | ||
static std::vector<FieldElement> rHash; | ||
static FieldElement last_leaf_index; | ||
}; | ||
|
||
const short NUMREGS = 81; | ||
|
||
namespace reg { | ||
typedef enum RegType{ | ||
|
||
B00 = 0, B01, B02, B03, B04, | ||
B10, B11, B12, B13, B14, | ||
B20, B21, B22, B23, B24, | ||
B30, B31, B32, B33, B34, | ||
|
||
K00, K01, K02, K03, K04, | ||
K10, K11, K12, K13, K14, | ||
K20, K21, K22, K23, K24, | ||
K30, K31, K32, K33, K34, | ||
|
||
inv1, inv2, inv3, inv4, inv5, | ||
W11, W12, W13, | ||
W21, W22, W23, | ||
W31, W32, W33, | ||
W41, W42, W43, | ||
W51, W52, W53, | ||
|
||
FLAG1, FLAG2, RC, invRC, | ||
|
||
A, B, C, STATE, | ||
K, | ||
MATCH, isSecondPhaseComparingLOCI, PartialMATCH, PHASE, | ||
L1, L2, L3, L4, L5, L6, | ||
ST2, ST3, | ||
} RegType; | ||
} | ||
|
||
typedef std::vector< std::vector<FieldElement> > & witnessType; | ||
short getDim(long long); | ||
std::vector<FieldElement> genHashchain(witnessType, int, int); | ||
void genWitnessLOCIHashcAES160WithPadding(witnessType, const witnessType, int, const int); | ||
|
||
namespace consts { | ||
#define zFE (mapIntegerToFieldElement(0, EXTDIM, 0)) | ||
|
||
const short ROUNDS = 10; | ||
const FieldElement xFEinv = xFE().inverse(); | ||
const FieldElement minus1 = mapIntegerToFieldElement(0, EXTDIM, 0xfffff); | ||
const FieldElement oneTransformed = mapIntegerToFieldElement(0, EXTDIM, 0x1); | ||
const FieldElement xFETransformed = mapIntegerToFieldElement(0, EXTDIM, 0x33CE8BEDDC8A656); | ||
const FieldElement xFEAndOneTransformed = mapIntegerToFieldElement(0, EXTDIM, 0x33CE8BEDDC8A657); | ||
const FieldElement B_Transformed = mapIntegerToFieldElement(0, EXTDIM, 0xFF6C97771E353011); | ||
|
||
|
||
const FieldElement Rcon_round11 = xFETransformed *xFETransformed*xFETransformed*xFETransformed* | ||
xFETransformed*xFETransformed*xFETransformed*xFETransformed*xFETransformed*xFETransformed;// | ||
|
||
const FieldElement xFE_4 = mapIntegerToFieldElement(0, EXTDIM, size_t(1) << 4); | ||
const FieldElement xFE_8 = mapIntegerToFieldElement(0, EXTDIM, size_t(1) << 8); | ||
const FieldElement xFE_minus4 = xFE_4.inverse(); | ||
const FieldElement xFE_minus8 = xFE_minus4*xFE_minus4; | ||
|
||
const FieldElement Transformator[8] = { | ||
|
||
mapIntegerToFieldElement(0, EXTDIM, 0x1), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x33CE8BEDDC8A656), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x512620375ED2A108), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xC9E636090AAFC01), | ||
|
||
|
||
mapIntegerToFieldElement(0, EXTDIM, 0xBA4F3CD82801769C), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xBA26E7904ADB4A47), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x467698598926DC01), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x4418AE808B28BDD0) | ||
|
||
}; | ||
|
||
/*const FieldElement Transformator[8] = { | ||
mapIntegerToFieldElement(0, EXTDIM, 0x4418AE808B28BDD0), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x467698598926DC01), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xBA26E7904ADB4A47), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xBA4F3CD82801769C), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xC9E636090AAFC01), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x512620375ED2A108), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x33CE8BEDDC8A656), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x1) | ||
};*/ | ||
|
||
const FieldElement MixColMat[4][4] = { | ||
{ xFETransformed, xFEAndOneTransformed, oneTransformed, oneTransformed }, | ||
{ oneTransformed, xFETransformed, xFEAndOneTransformed, oneTransformed }, | ||
{ oneTransformed, oneTransformed, xFETransformed, xFEAndOneTransformed }, | ||
{ xFEAndOneTransformed, oneTransformed, oneTransformed, xFETransformed } | ||
}; | ||
|
||
const FieldElement invTransformator[14] = { | ||
mapIntegerToFieldElement(0, EXTDIM, 0x1), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xFD), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x7F), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x4C), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x2A), | ||
zFE, | ||
mapIntegerToFieldElement(0, EXTDIM, 0xA3), | ||
zFE, zFE, zFE, | ||
mapIntegerToFieldElement(0, EXTDIM, 0x41), | ||
zFE, zFE, | ||
mapIntegerToFieldElement(0, EXTDIM, 0x48) | ||
}; | ||
|
||
const FieldElement polyFromMatrix[8] = { | ||
mapIntegerToFieldElement(0, EXTDIM, 0x512620375ED2A109), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xC9E636090AAFC00), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xE998EF1F07EA10A), | ||
mapIntegerToFieldElement(0, EXTDIM, 0xEB00C7A71409EB4E), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x5321CDA63E06FC02), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x1), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x155755FFB7202002), | ||
mapIntegerToFieldElement(0, EXTDIM, 0x1A9C05699898468E) | ||
}; | ||
} | ||
} | ||
|
||
namespace stark_dpm{ | ||
namespace ACSP_FOR_AES160hashcLOCI{ | ||
typedef struct{ | ||
long long length; | ||
int seed; | ||
std::vector<Algebra::FieldElement> head; | ||
}AES160hashcLOCICommonParams; | ||
|
||
libstark::BairInstance buildBairInstance(const AES160hashcLOCICommonParams&); | ||
libstark::BairWitness buildBairWitness(const AES160hashcLOCICommonParams&, const AES160hashcLOCI::witnessType&); | ||
} | ||
} | ||
|
||
#endif // __ACSP_FOR_AES160hashcLOCI_HPP__ |
Oops, something went wrong.