当前位置: 首页>>代码示例>>C++>>正文


C++ PRNG::ReSeed方法代码示例

本文整理汇总了C++中PRNG::ReSeed方法的典型用法代码示例。如果您正苦于以下问题:C++ PRNG::ReSeed方法的具体用法?C++ PRNG::ReSeed怎么用?C++ PRNG::ReSeed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PRNG的用法示例。


在下文中一共展示了PRNG::ReSeed方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setup

OTExtensionWithMatrix OTExtensionWithMatrix::setup(TwoPartyPlayer& player,
        int128 delta, OT_ROLE role, bool passive)
{
    BaseOT baseOT(128, 128, &player, INV_ROLE(role));
    PRNG G;
    G.ReSeed();
    baseOT.set_receiver_inputs(delta);
    baseOT.exec_base(false);
    return OTExtensionWithMatrix(baseOT, &player, passive);
}
开发者ID:lance6716,项目名称:SPDZ-2,代码行数:10,代码来源:OTExtensionWithMatrix.cpp

示例2: zero

void PartSetup<FD>::insecure_debug_keys(vector<PartSetup<FD> >& setups, int nplayers, bool simple_pk)
{
    cout << "generating INSECURE keys for debugging" << endl;
    setups.clear();
    Rq_Element zero(params, evaluation, evaluation),
            one(params, evaluation, evaluation);
    zero.assign_zero();
    one.assign_one();
    PRNG G;
    G.ReSeed();
    if (simple_pk)
        pk.assign(zero, zero, zero, zero - one);
    else
        pk.KeyGen(one, G, nplayers);
    setups.resize(nplayers, *this);
    setups[0].sk.assign(one);
    for (int i = 1; i < nplayers; i++)
        setups[i].sk.assign(zero);
}
开发者ID:lance6716,项目名称:SPDZ-2,代码行数:19,代码来源:DataSetup.cpp

示例3: sk

void PartSetup<FD>::fake(vector<FHE_SK>& sks, vector<T>& alphais,
        int nplayers, bool distributed)
{
  insecure("global key generation");
  if (distributed)
      cout << "Faking distributed key generation" << endl;
  else
      cout << "Faking key generation with extra noise" << endl;
  PRNG G;
  G.ReSeed();
  pk = FHE_PK(params, FieldD.get_prime());
  FHE_SK sk(params, FieldD.get_prime());
  calpha = Ciphertext(params);
  sks.resize(nplayers, pk);
  alphais.resize(nplayers);

  if (distributed)
      DistKeyGen::fake(pk, sks, FieldD.get_prime(), nplayers);
  else
  {
      Rq_Element sk = FHE_SK(pk).s();
      for (int i = 0; i < nplayers; i++)
      {
          Rq_Element ski = pk.sample_secret_key(G);
          sks[i].assign(ski);
          sk += ski;
      }
      pk.KeyGen(sk, G, nplayers);
  }

  for (int i = 0; i < nplayers; i++)
    {
      Plaintext_<FD> m(FieldD);
      m.randomize(G,Diagonal);
      Ciphertext calphai = pk.encrypt(m);
      calpha += calphai;
      alphais[i] = m.element(0);
    }
}
开发者ID:lance6716,项目名称:SPDZ-2,代码行数:39,代码来源:DataSetup.cpp

示例4: transfer

void OTExtensionWithMatrix::transfer(int nOTs,
                                     const BitVector& receiverInput)
{
#ifdef OTEXT_TIMER
    timeval totalstartv, totalendv;
    gettimeofday(&totalstartv, NULL);
#endif
    cout << "\tDoing " << nOTs << " extended OTs as " << role_to_str(ot_role) << endl;
    if (nOTs % nbaseOTs != 0)
        throw invalid_length(); //"nOTs must be a multiple of nbaseOTs\n");
    if (nOTs == 0)
        return;
    // add k + s to account for discarding k OTs
    nOTs += 2 * 128;

    int slice = nOTs / nsubloops / 128;
    BitMatrix t1(nOTs), u(nOTs);
    senderOutputMatrices.resize(2, BitMatrix(nOTs));
    // resize to account for extra k OTs that are discarded
    PRNG G;
    G.ReSeed();
    BitVector newReceiverInput(nOTs);
    for (unsigned int i = 0; i < receiverInput.size_bytes(); i++)
    {
        newReceiverInput.set_byte(i, receiverInput.get_byte(i));
    }

    //BitVector newReceiverInput(receiverInput);
    newReceiverInput.resize(nOTs);

    receiverOutputMatrix.resize(nOTs);

    for (int loop = 0; loop < nloops; loop++)
    {
        // randomize last 128 + 128 bits that will be discarded
        for (int i = 0; i < 4; i++)
            newReceiverInput.set_word(nOTs/64 - i, G.get_word());

        // subloop for first part to interleave communication with computation
        for (int start = 0; start < nOTs / 128; start += slice)
        {
            vector<octetStream> os(2);

            BitMatrixSlice receiverOutputSlice(receiverOutputMatrix, start, slice);
            BitMatrixSlice senderOutputSlices[2] = {
                BitMatrixSlice(senderOutputMatrices[0], start, slice),
                BitMatrixSlice(senderOutputMatrices[1], start, slice)
            };
            BitMatrixSlice t1Slice(t1, start, slice);
            BitMatrixSlice uSlice(u, start, slice);

            // expand with PRG and create correlation
            if (ot_role & RECEIVER)
            {
                for (int i = 0; i < nbaseOTs; i++)
                {
                    receiverOutputSlice.randomize(i, G_sender[i][0]);
                    t1Slice.randomize(i, G_sender[i][1]);
                }

                t1Slice ^= receiverOutputSlice;
                t1Slice ^= newReceiverInput;
                t1Slice.pack(os[0]);

//                t1 = receiverOutputMatrix;
//                t1 ^= newReceiverInput;
//                receiverOutputMatrix.print_side_by_side(t1);
            }
#ifdef OTEXT_TIMER
            timeval commst1, commst2;
            gettimeofday(&commst1, NULL);
#endif
            // send t0 + t1 + x
            send_if_ot_receiver(player, os, ot_role);

            // sender adjusts using base receiver bits
            if (ot_role & SENDER)
            {
                for (int i = 0; i < nbaseOTs; i++)
                    // randomize base receiver output
                    senderOutputSlices[0].randomize(i, G_receiver[i]);

                // u = t0 + t1 + x
                uSlice.unpack(os[1]);
                senderOutputSlices[0].conditional_xor(baseReceiverInput, u);
            }
#ifdef OTEXT_TIMER
            gettimeofday(&commst2, NULL);
#ifdef VERBOSE
            double commstime = timeval_diff(&commst1, &commst2);
            cout << "\t\tCommunication took time " << commstime/1000000 << endl << flush;
#endif
            times["Communication"] += timeval_diff(&commst1, &commst2);
#endif

            // transpose t0[i] onto receiverOutput and tmp (q[i]) onto senderOutput[i][0]

#ifdef VERBOSE
            cout << "Starting matrix transpose\n" << flush << endl;
#endif
//.........这里部分代码省略.........
开发者ID:bristolcrypto,项目名称:apricot,代码行数:101,代码来源:OTExtensionWithMatrix.cpp

示例5: main


//.........这里部分代码省略.........
        opt.getUsage(usage);
        cout << usage;
        exit(0);
    }

    cout << "Player 0 host name = " << hostname << endl;
    cout << "Creating " << nOTs << " extended OTs in " << nthreads << " threads\n";
    cout << "Running in mode " << ot_mode << endl;

    if (passive)
        cout << "Running with PASSIVE security only\n";

    if (nbase < 128)
        cout << "WARNING: only using " << nbase << " seed OTs, using these for OT extensions is insecure.\n";

    OT_ROLE ot_role;
    if (ot_mode.compare("s") == 0)
        ot_role = BOTH;
    else if (ot_mode.compare("a") == 0)
    {
        if (my_num == 0)
            ot_role = SENDER;
        else
            ot_role = RECEIVER;
    }
    else
    {
        cerr << "Invalid OT mode argument: " << ot_mode << endl;
        exit(1);
    }

    // PRG for generating inputs etc
    PRNG G;
    G.ReSeed();

    // Several names for multiplexing
    vector<Names> N;
    unsigned int pos = 0;
    while (pos < hostname.length())
    {
        string::size_type new_pos = hostname.find(',', pos);
        if (new_pos == string::npos)
            new_pos = hostname.length();
        int len = new_pos - pos;
        string name = hostname.substr(pos, len);
        pos = new_pos + 1;

        vector<string> names(2);
        names[my_num] = "localhost";
        names[1-my_num] = name;
        N.push_back(Names(my_num, portnum_base, names));
    }

    TwoPartyPlayer* P = new TwoPartyPlayer(N[0], 1 - my_num, 500);

    timeval baseOTstart, baseOTend;
    gettimeofday(&baseOTstart, NULL);
    // swap role for base OTs
    BaseOT baseOT = BaseOT(nbase, 128, 1 - my_num, P, INV_ROLE(ot_role));
    FakeOT fakeOT = FakeOT(nbase, 128, 1 - my_num, P, INV_ROLE(ot_role));
    BaseOT* bot_;
    if (opt.isSet("-f"))
    {
        cout << "WARNING: using fake base OTs, not secure\n";
        bot_ = &fakeOT;
    }
开发者ID:bristolcrypto,项目名称:apricot,代码行数:67,代码来源:OText_main.cpp

示例6: values

void PairwiseGenerator<FD>::run()
{
    PRNG G;
    G.ReSeed();
    MAC_Check<typename FD::T> MC(machine.setup<FD>().alphai);

    while (total < machine.nTriplesPerThread)
    {
        timers["Randomization"].start();
        a.randomize(G);
        b.randomize(G);
        timers["Randomization"].stop();
        size_t prover_memory = EC.generate_proof(C, a, ciphertexts, cleartexts);
        timers["Plaintext multiplication"].start();
        c.mul(a, b);
        timers["Plaintext multiplication"].stop();
        timers["FFT of b"].start();
        for (int i = 0; i < machine.sec; i++)
            b_mod_q.at(i).from_vec(b.at(i).get_poly());
        timers["FFT of b"].stop();
        timers["Proof exchange"].start();
        size_t verifier_memory = EC.create_more(ciphertexts, cleartexts);
        timers["Proof exchange"].stop();
        volatile_memory = max(prover_memory, verifier_memory);

        Rq_Element values({machine.setup<FD>().params, evaluation, evaluation});
        for (int k = 0; k < machine.sec; k++)
        {
            producer.ai = a[k];
            producer.bi = b[k];
            producer.ci = c[k];

            for (int j = 0; j < 3; j++)
            {
                timers["Plaintext multiplication"].start();
                producer.macs[j].mul(machine.setup<FD>().alpha, producer.values[j]);
                timers["Plaintext multiplication"].stop();

                if (j == 1)
                    values = b_mod_q[k];
                else
                {
                    timers["Plaintext conversion"].start();
                    values.from_vec(producer.values[j].get_poly());
                    timers["Plaintext conversion"].stop();
                }

                for (auto m : multipliers)
                    m->multiply_alpha_and_add(producer.macs[j], values);
            }
            producer.reset();
            total += producer.sacrifice(P, MC);
        }

        timers["Checking"].start();
        MC.Check(P);
        timers["Checking"].stop();
    }

    cout << "Could save " << 1e-9 * a.report_size(CAPACITY) << " GB" << endl;
    timers.insert(EC.timers.begin(), EC.timers.end());
    timers.insert(producer.timers.begin(), producer.timers.end());
    timers["Networking"] = P.timer;
}
开发者ID:lance6716,项目名称:SPDZ-2,代码行数:64,代码来源:PairwiseGenerator.cpp


注:本文中的PRNG::ReSeed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。