Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IF: Use bls12_381::pop_prove to generate POP and add get_pop_str method to libfc #1625

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libraries/libfc/include/fc/crypto/bls_private_key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace fc::crypto::blslib {

bls_public_key get_public_key() const;
bls_signature sign( const std::vector<uint8_t>& message ) const;
bls_signature proof_of_possession() const;

static bls_private_key generate();

Expand All @@ -45,4 +46,4 @@ namespace fc {
void from_variant(const variant& var, crypto::blslib::bls_private_key& vo);
} // namespace fc

FC_REFLECT(crypto::blslib::bls_private_key, (_sk) )
FC_REFLECT(crypto::blslib::bls_private_key, (_sk) )
2 changes: 1 addition & 1 deletion libraries/libfc/libraries/bls12-381
Submodule bls12-381 updated 1 files
+2 −2 src/signatures.cpp
6 changes: 6 additions & 0 deletions libraries/libfc/src/crypto/bls_private_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace fc::crypto::blslib {
return bls_public_key(pk);
}

bls_signature bls_private_key::proof_of_possession() const
{
bls12_381::g2 proof = bls12_381::pop_prove(_sk);
arhag marked this conversation as resolved.
Show resolved Hide resolved
return bls_signature(proof);
}

bls_signature bls_private_key::sign( const std::vector<uint8_t>& message ) const
{
bls12_381::g2 sig = bls12_381::sign(_sk, message);
Expand Down
20 changes: 5 additions & 15 deletions programs/leap-util/actions/bls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ int bls_actions::create_key() {
const bls_private_key private_key = bls_private_key::generate();
const bls_public_key public_key = private_key.get_public_key();

// generate pop
const std::string pop_str = generate_pop_str(private_key);
// generate proof of possession
const bls_signature pop = private_key.proof_of_possession();

// prepare output
std::string out_str = "Private key: " + private_key.to_string({}) + "\n";
out_str += "Public key: " + public_key.to_string({}) + "\n";
out_str += "Proof of Possession: " + pop_str + "\n";
out_str += "Proof of Possession: " + pop.to_string({}) + "\n";
if (opt->print_console) {
std::cout << out_str;
} else {
Expand Down Expand Up @@ -106,20 +106,10 @@ int bls_actions::create_pop() {
// create private key object using input private key string
const bls_private_key private_key = bls_private_key(private_key_str);
const bls_public_key public_key = private_key.get_public_key();
std::string pop_str = generate_pop_str(private_key);
const bls_signature pop = private_key.proof_of_possession();

std::cout << "Proof of Possession: " << pop_str << "\n";
std::cout << "Proof of Possession: " << pop.to_string({})<< "\n";
std::cout << "Public key: " << public_key.to_string({}) << "\n";

return 0;
}

std::string bls_actions::generate_pop_str(const bls_private_key& private_key) {
const bls_public_key public_key = private_key.get_public_key();

const std::array<uint8_t, 96> msg = public_key._pkey.toAffineBytesLE(true); // true means raw
const std::vector<uint8_t> msg_vector = std::vector<uint8_t>(msg.begin(), msg.end());
const bls_signature pop = private_key.sign(msg_vector);

return pop.to_string({});
}
2 changes: 1 addition & 1 deletion tests/leap_util_bls_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def get_results(rslts):
# sample output looks like
# Private key: PVT_BLS_kRhJJ2MsM+/CddO...
# Public key: PUB_BLS_lbUE8922wUfX0Iy5...
# Proof of Possession: SIG_BLS_olZfcFw...
# Proof of Possession: SIG_BLS_3jwkVUUYahHgsnmnEA...
pattern = r'(\w+[^:]*): ([^\n]+)'
matched= re.findall(pattern, rslts)

Expand Down