Skip to content

Instantly share code, notes, and snippets.

@kanzure
Created April 3, 2017 01:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanzure/febf73f132198b639a539c8406460a30 to your computer and use it in GitHub Desktop.
Save kanzure/febf73f132198b639a539c8406460a30 to your computer and use it in GitHub Desktop.
Short attempt at verifying an aggregate signature using BLS and a single pubkey
#include <iostream>
#include "bls.h"
int main() {
std::cout << "Signature aggregation toy attempt\n";
// create instance of Bls class
bls::Bls my_bls = bls::Bls();
// define message
const char *msg = "That's how the cookie crumbles";
// generate public key from seed
const char *seed = "19283492834298123123";
bls::PubKey pubkey = my_bls.genPubKey(seed);
// create signature
bls::Sig sig = my_bls.signMsg(msg, seed, pubkey);
// validate signature
bool verification_result = my_bls.verifySig(pubkey, msg, sig);
if (verification_result == true) {
std::cout << "Verification: success!";
} else {
std::cout << "Verification: failure";
}
std::cout << "\n\n\n----------------\n\n";
// Now on to aggregation.
// create instance of Bls class
bls::Bls my_bls2 = bls::Bls();
// generate two seeds (NOTE: seeds should actually be random)
const char *seed_1 = "11111111111";
const char *seed_2 = "22222222222";
// generate both pubkeys
bls::PubKey pubkey_1 = my_bls2.genPubKey(seed_1);
bls::PubKey pubkey_2 = my_bls2.genPubKey(seed_2);
std::vector<bls::PubKey> pubkeys;
pubkeys.push_back(pubkey_1);
pubkeys.push_back(pubkey_2);
std::vector<bls::PubKey> pubkeys2;
pubkeys2.push_back(pubkey_1);
const char *msg_1 = "message 1";
const char *msg_2 = "message 2";
std::vector<const char *> msgs;
msgs.push_back(msg_1);
msgs.push_back(msg_2);
std::vector<const char *> msgs2;
msgs2.push_back(msg_1);
// sign both messages
bls::Sig sig_1 = my_bls2.signMsg(msg_1, seed_1, pubkey_1);
bls::Sig sig_2 = my_bls2.signMsg(msg_2, seed_2, pubkey_2);
// add signatures to vector
std::vector<bls::Sig> sigs;
sigs.push_back(sig_1);
sigs.push_back(sig_2);
// generate the aggregate signature of all signatures in the vector
bls::Sig agg_sig = my_bls2.aggregateSigs(sigs);
// Check that the signature is valid
// NOTE: using my_bls (the first one) here...
// works: bool temp = my_bls.verifyAggSig(msgs, pubkeys, agg_sig);
// fails: bool temp = my_bls.verifyAggSig(msgs2, pubkeys2, agg_sig);
bool temp = my_bls.verifySig(pubkey_1, msg_1, agg_sig); // also fails
if (temp == true) {
std::cout << "Successfully verified an aggregate signature against a single pubkey.";
} else {
std::cout << "Verification failed for single pubkey and aggregate signature.";
}
std::cout << "\n\n\n";
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment