예제 #1
0
int testGetSharesForParticipants(PFC &pfc) {
  int errors = 0;

  ENHDEBUG("Creating instances");
  std::string expr = op_OR + "(1, " + op_AND + "(2,3,4), " + op_AND + "(2,5), " + op_AND + "(4,5))";
  shared_ptr<BLAccessPolicy> policy = make_shared<BLAccessPolicy>(expr, 5);
  BLSS testScheme(policy, pfc.order(), pfc);

  ENHDEBUG("Creating shares");
  ShareTuple s1a(1, 0, "1a");
  ShareTuple s1b(1, 0, "1b");
  ShareTuple s2a(2, 0, "2a");
  ShareTuple s3a(3, 0, "3a");
  ShareTuple s3b(3, 0, "3b");
  ShareTuple s3c(3, 0, "3c");
  ShareTuple s4a(4, 0, "4a");
  ShareTuple s5a(5, 0, "5a");

  vector<ShareTuple> shares;

  shares.push_back(s1a);
  shares.push_back(s1b);
  shares.push_back(s2a);
  shares.push_back(s3a);
  shares.push_back(s3b);
  shares.push_back(s3c);
  shares.push_back(s4a);
  shares.push_back(s5a);

  vector<int> parts313;
  vector<int> parts276;
  vector<int> parts45;

  parts313.push_back(3);
  parts313.push_back(1);
  parts313.push_back(3);

  parts276.push_back(2);
  parts276.push_back(7);
  parts276.push_back(6);

  parts45.push_back(4);
  parts45.push_back(5);

  vector<ShareTuple> verif313;
  vector<ShareTuple> verif276;
  vector<ShareTuple> verif45;

  verif313.push_back(s1a);
  verif313.push_back(s1b);
  verif313.push_back(s3a);
  verif313.push_back(s3b);
  verif313.push_back(s3c);

  verif276.push_back(s2a);
  
  verif45.push_back(s4a);
  verif45.push_back(s5a);
  
  std::string base = "testGetSharesForParticipants - ";

  ENHDEBUG("Calling diagnosis");
  DEBUG("call 1");
  vector<ShareTuple> returnedShares = SecretSharing::getSharesForParticipants(parts313, shares);
  test_diagnosis(base + "[313]", returnedShares == verif313, errors);

  DEBUG("call 2");
  returnedShares = SecretSharing::getSharesForParticipants(parts276, shares);
  test_diagnosis(base + "[276]", returnedShares == verif276, errors);

  DEBUG("call 3");
  returnedShares = SecretSharing::getSharesForParticipants(parts45, shares);
  test_diagnosis(base + "[45]", returnedShares == verif45, errors);

  ENHDEBUG("Finished diagnosis");	
  return errors;
}
예제 #2
0
int testDistributeAndReconstruct(PFC &pfc){
  int errors = 0;
  ENHDEBUG("testDistribute and Reconstruct");
  int niter = 5;
  DEBUG("Initting s");
  Big s;
  DEBUG("Initting old_s");
  Big old_s=0;
  DEBUG("Obtaining order");
  Big order = pfc.order();


  DEBUG("Creating instances");

  std::string expr = op_OR + "(1, " + op_AND + "(2,3,4), " + op_AND + "(2,5), " + op_AND + "(4,5))";
  shared_ptr<BLAccessPolicy> policy = make_shared<BLAccessPolicy>(expr, 5);
  BLSS testScheme(policy, pfc.order(), pfc);
  
  std::string base = "testDistributeAndReconstruct ";
  
  vector<int> party1;
  vector<int> party234;
  vector<int> party25;
  vector<int> party45;
  vector<int> badparty23;

  party1.push_back(1);
  
  party234.push_back(2);
  party234.push_back(3);
  party234.push_back(4);

  party25.push_back(2);
  party25.push_back(5);

  party45.push_back(4);
  party45.push_back(5);
  
  badparty23.push_back(2);
  badparty23.push_back(3);
  
  
  old_s = 0;
  for (int j = 0; j < niter; j++){
    OUT(base + "Iteration: " << j);
    pfc.random(s);
    s = s % order;
    
    DEBUG("s: " << s << "\t old s: " << old_s);
    guard("s should be random, and different from the last value or 0", s != old_s); // the probability that s is 0 or the old value should be negligible
    
    vector<ShareTuple> shares = testScheme.distribute_random(s);
    
    test_diagnosis(base + "number of shares:", shares.size() == policy->getNumShares(), errors);
    
    errors += testReconFromShares(party1, base + "[1]", testScheme, shares, true, 1, s);
    errors += testReconFromShares(party234, base + "[234]", testScheme, shares, true, 3, s);
    errors += testReconFromShares(party25, base + "[25]", testScheme, shares, true, 2, s);
    errors += testReconFromShares(party45, base + "[45]", testScheme, shares, true, 2, s);
    errors += testReconFromShares(badparty23, base + "[23]", testScheme, shares, false, 0, s);
    
    
    old_s = s;
  }
    return errors;
}
예제 #3
0
bool extractPrivateKey(ThreadParams *params) {
    PFC *pfc = params->pfc;
    clock_t begin_time, begin_time1;
    float enc_time, enc_time1, dec_time, dec_time1, dec_time2, ext_time;

    G2 P;
    G2 Ppub;
    G1 Qpriv, Qid;
    G1 D;

    Big order = pfc->order();

    // Specify the ids of the dkgs to contact
    //int dkgIds[THRESHOLD] = {1, 2, 3};
    //int dkgIds2[THRESHOLD] = {3, 4, 5};
    int dkgIds[THRESHOLD];
    for(int i = 0; i < THRESHOLD; i++) {
        dkgIds[i] = i+1;
    }
    //TODO: Change this to an id from the scramble extension

    /*
    ifstream infile("test.txt");
    string readoutId;
    if (infile.good())
    {
        getline(infile, readoutId);
        cout << "The read out ID is:" << endl << readoutId << endl;
    }
    infile.close();*/

    const char * id = "-3114599686203605494";
    //const char * id = readoutId.c_str();
    string urls[THRESHOLD];
    for (int i = 0; i < THRESHOLD; i++) {
        stringstream ss;
        ss << DKG_BASE_ADDR << dkgIds[i] << "/";
        urls[i] = ss.str();
    }
    vector <G1> Qprivs;
    vector <G2> Ppubs;
    DkgResult retParams;

    begin_time = clock();
    // Before doing the check, concatenate the expiration date
    string idString = "";
    idString = idString + id;
    idString = mapToDate(idString);
    (*pfc).hash_and_map(Qid, (char*)idString.c_str());

    for (int i = 0; i < THRESHOLD; i++) {
        retParams = scrapeDkg(urls[i], (char*)id);
        // Get Ppub, P and Qpriv from the PKG's XML message
        P = retParams.P;

        Qpriv = retParams.Qpriv;
        Qprivs.push_back(Qpriv);

        Ppub = retParams.Ppub;
        Ppubs.push_back(Ppub);

        // Verify if the DKG are being honest
        GT QprivP = (*pfc).pairing(P, Qpriv);
        GT QidPpub = (*pfc).pairing(Ppub, Qid);
        if (QprivP != QidPpub) {
            cout << "Server " << dkgIds[i] << " is dishonest. Select another DKG to continue the extraction process." << endl;
            return false;
        }
    }

    D = getSecretKey(dkgIds, Qprivs, order, pfc);
    Ppub = getPpub(dkgIds, Ppubs, order, pfc);

    ext_time = getExecutionTime(begin_time);
    cout << "Extraction time was " << ext_time << endl << endl;
    params->P = P;
    params->Ppub = Ppub;
    params->D = D;
    return true;
}