提交 90a6c72a 编辑于 作者: Heng Wang's avatar Heng Wang
浏览文件

Finish the aggregate part.

上级 de6c4e5f
......@@ -42,6 +42,7 @@ BasicSAS::verify(const string& msg, unsigned time, const Integer& signautre)
{
vector<Integer> msg_frag{this->dismantleMsg(msg)};
Integer e_t{this->publicParameters.hashToPrime(time)};
cout << "e_t " << e_t << endl;
Integer left{ma.Exponentiate(signautre, e_t)};
Integer right{this->pk.front()};
for (unsigned i = 1; i <= this->k; ++i) {
......@@ -50,6 +51,43 @@ BasicSAS::verify(const string& msg, unsigned time, const Integer& signautre)
return left == right;
}
Integer
BasicSAS::aggregate(unsigned t, const vector<Integer>& signatures)
{
Integer agg{Integer::One()};
for (auto &s: signatures) {
agg = this->ma.Multiply(agg, s);
}
return agg;
}
bool
BasicSAS::aggregateVerify(unsigned t, const vector<PK>& pks, const vector<string>& messages, const Integer& aggSignatures)
{
assert(pks.size() == messages.size());
if (t <= 0 || t >= this->publicParameters.getT()) return false;
for (int i = 0; i < pks.size(); ++i) {
for (int j = i+1; j < pks.size(); ++j) {
if (pks[i] == pks[j]) return false;
}
}
cout << "Final Steps." << endl;
Integer e_t{this->publicParameters.hashToPrime(t)};
cout << "e_t " << e_t << endl;
Integer left{ma.Exponentiate(aggSignatures, e_t)};
Integer right{Integer::One()};
for (int i = 0; i < pks.size(); ++i) {
vector<Integer> msg_frags{this->dismantleMsg(messages[i])};
right = ma.Multiply(right, pks[i].front());
for (int j = 1; j <= this->k; ++j) {
right = ma.Multiply(right, ma.Exponentiate(pks[i][j], msg_frags[j-1]));
}
}
cout << "Left: " << left << endl;
cout << "Right: " << right << endl;
return left == right;
}
vector<Integer>
BasicSAS::dismantleMsg(const string& msg)
{ // The message is L bits which will be broken into k chunks each of l bits
......@@ -80,21 +118,24 @@ main(int argc, char** argv)
const unsigned timePeriod = 10;
Setup pp{lambda, timePeriod};
BasicSAS sas{pp};
BasicSAS sasOne{pp}, sasTwo{pp}, sasThree{pp};
cout << "Setup Done." << endl;
cout << pp.getN() << endl;
sas.Keygen();
sasOne.Keygen();
sasTwo.Keygen();
sasThree.Keygen();
string msg{"Hello, World."};
string msgOne{"Hello, World."};
string msgTwo{"C++"};
string msgThree{"Python"};
string msgFake{"Hello."};
const unsigned time = 2;
const unsigned timeFake = 3;
Integer s{sas.sign(msg, time)};
cout << "Signature: " << s << endl;
cout << "Verify: " << sas.verify(msg, time, s) << endl;
cout << "False Verify: " << sas.verify(msgFake, time, s) << endl;
cout << "False Verify: " << sas.verify(msg, timeFake, s) << endl;
cout << "False Verify: " << sas.verify(msg, time, Integer::One()) << endl;
Integer sOne{sasOne.sign(msgOne, time)}, sTwo{sasTwo.sign(msgTwo, time)}, sThree{sasThree.sign(msgThree, time)};
Integer aggS{sasOne.aggregate(time, {sOne, sTwo, sThree})};
cout << sasOne.verify(msgOne, time, sOne) << endl;
cout << sasTwo.verify(msgTwo, time, sTwo) << endl;
cout << sasThree.verify(msgThree, time, sThree) << endl;
cout << aggS << endl;
cout << sasTwo.aggregateVerify(time, {sasOne.publicKey(), sasTwo.publicKey(), sasThree.publicKey()}, {msgOne, msgTwo, msgThree}, aggS) << endl;
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ using PP=Setup;
using std::vector;
using std::string;
using CryptoPP::ModularArithmetic;
using PK=vector<Integer>;
class BasicSAS
......@@ -17,11 +18,9 @@ public:
void Keygen();
Integer sign(const string&, unsigned);
bool verify(const string&, unsigned, const Integer&);
inline vector<Integer>
BasicSAS::publicKey()
{
return this->pk;
}
inline PK publicKey();
Integer aggregate(unsigned, const vector<Integer>&);
bool aggregateVerify(unsigned, const vector<PK>&, const vector<string>&, const Integer&);
private:
BasicSAS();
......@@ -30,8 +29,14 @@ private:
AutoSeededRandomPool prng;
PP publicParameters;
vector<Integer> sk;
vector<Integer> pk;
PK pk;
ModularArithmetic ma;
vector<Integer> dismantleMsg(const string&);
};
\ No newline at end of file
};
inline PK
BasicSAS::publicKey()
{
return this->pk;
}
\ No newline at end of file
......@@ -2,9 +2,10 @@
class Setup;
Setup::Setup(const Setup& s):Setup{s.lambda, s.timePeriod} {}
Setup::Setup(const Setup& s):lambda{s.lambda}, e_default{s.e_default}, Ks{s.Ks}, c{s.c}, T{s.T}, Y{s.Y}, N{s.N}, g{s.g}, primes{s.primes} {}
Setup::Setup(unsigned lambda, unsigned timePeriod):lambda{lambda},timePeriod{timePeriod}, rng{}, Ks{this->rng, Integer::Zero(), Integer::Power2(lambda+1).Minus(Integer::One())}, c{this->rng, Integer::Zero(), Integer::Power2(lambda).Minus(Integer::One())}, T{timePeriod} {
Setup::Setup(unsigned lambda, unsigned timePeriod):lambda{lambda}, rng{}, Ks{this->rng, Integer::Zero(), Integer::Power2(lambda+1).Minus(Integer::One())}, c{this->rng, Integer::Zero(), Integer::Power2(lambda).Minus(Integer::One())}, T{timePeriod} {
unsigned primeBits = lambda / 2;
Integer p, q, subp, subq;
while (true) {
......
......@@ -30,7 +30,6 @@ public:
Integer hashToPrime(unsigned&);
private:
unsigned lambda;
unsigned timePeriod;
const int delta = 1;
AutoSeededRandomPool rng;
// The following three form a key for PRF K=(Ks, c, default_prime)
......
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册