mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 19:42:46 +01:00
730efde109
795660db76 chore: bump version to 1.3.0 (#84) e8743b0139 Merge pull request #83 from UdjinM6/bp_370_371 72f0ad2d37 fix: add missing destructor for CoreMPL and final for nested classes (#371) 2f05059c60 Fix a typo in class PrivateKey testcase. (#370) 851c2c8f68 fix: reading unitialized memory from Util::HasOnlyZeros in G2Element deserialization (#77) 4dd28e9016 fix: js bindings build (#82) 3697c51521 fix: dash is no more pretending being a 'libdashbls' (#76) 37c53141d3 feat: implement memory-copy only of G1Element and G2Element (#74) 97ac99e8e6 build(bls-dash-sys): ignore wasm32 target arch (#70) 2d494d351e Merge pull request #71 from dashpay/feat/threshold_bindings 67fb70d40b chore: revert permission changes in bcce0b214876c0d9e668baaa30a48542b496cda2 5a58fce0ea fix: resolve rust-bindings compilation failure 8604e03761 build: fix cmake build error c25957edf0 Merge remote-tracking branch 'dash/develop' into feat/threshold_bindings2 198e246f07 added a helper for verifying a message a4b8a5dd6e added a helper for verifying a message 2d783c985e added a helper for signing from the private key 16f7873d6a changed to using a slice for recovery a23d9708c0 feat: clone 0cf8a8eb96 feat: serde 47829e3e75 threshold_recovery functions a5589e6fc8 fix: bls extended private key size 1ceaab56e3 [add cpp targts] 86eb28e2d7 [fix linker path for cpp] 85debcab29 [include 'src' into build] f956c66b90 [switch into cc] 9ecb59bf9b [test linker] 3651a0fd79 [linker change] d8564679eb [fix: iossim] c829d4b6f1 [fix: aarch64-apple-darwin trigger] fc3509e901 [chore: silence warning] 79ce6ded50 [feat: apple build for single platform+arch] e580cb76db [feat: build for apple target] 17b2168955 feat: verifySecure method for BasicSchemeMPL in js bindings (#69) 4613425b60 chore: silence rust warnings 136d762607 [fix: target_arch] 0d8c8e9d41 [try to use ios.toolchain] bd441623df [back] 8137f48897 [change relic src] bdcba81d41 test: check patched relic 32b7f56d94 Merge pull request #1 from dashevo/rust-bindings-enhancement 6d359c6201 chore: test for extended private key from short seed 1cbeffe159 chore: add binding dace793a1a fix: same as previous: BIP32ExtendedPrivateKeyFromSeed with len 65c84d063c fix: ok now add second blank line 24b25bac2d fix: now try from typing import Union fe16287182 fix: try Union[Fq2, None] 3ffc96d409 fix: None 2d669a2cf8 chore: up version fbb5a43b19 fix: pass length PrivateKeyFromSeedBIP32 5822076d1a chore: cargo:fmt a8d3a7e956 test: add keys multiplication test 4b85f08937 fix: exchange keys when multiply 0bcefc68cb chore: add imports 7380332123 [chore: add binding for G1ElementMul] 881e6d7676 patch relic to be compatible with wasm bcce0b2148 chore: fix mode 02801cf973 add deeper checks to example project 6d25c60ee5 compilation fixes a4cebb4025 refactor: remove "C" prefix 995ef3796f refactor: bip32 feature 7ea0c34938 style: remove `get` prefix from getters e316c00f7b add VerifySecure da5536e1c5 feat: introduce PrivateKey::from_bip32_seed 4f03a1a1ae export legacy scheme 5c19e314d4 add extended private key cc081c0956 feat: add G1 element's fingerprint and generate methods f3e85b46d0 refactor: move back re-exports e8155b4bdb refactor: move legacy code to submodule f6e173242e add extendedpublickey 4f823249fb feat: legacy serialize and deserialize methods 90fd9f9c2c fix: comparison int with size_t 57237e5e87 Merge branch 'rust-bindings' of github.com:dashevo/bls-signatures into rust-bindings a1f862480b refactor: implement Deref trait for SecureBox 0b6f94e41f add LegacySchemeMPL aa19a77a40 refactor: small refactoring dae8b31042 make schemes public 827d1ed162 add hdkeys 7b4ffae5ec improve agg sig test 18057687be add basic scheme 3e4fdda2bd aggregates 61a4d791c9 elements ser/de 8b5b6301f3 wip 126b7becea wip c49514176e chore: remove autocxx variant 477c014bb7 refactor: increase `c_err_to_result` readability 5d52d0e59d Merge remote-tracking branch 'dashevo/rust-bindings' into rust-bindings 31724b39d1 chore: add example crate c04c2941db safe wrappers for simple case 844779cd81 chore: remove cdylib from bls-signatures d622625de4 chore: move all rust stuff into one 0d3c51106a Merge remote-tracking branch 'dashevo/rust-bindings' into rust-bindings ecf0271950 revert: bring back necessary c binding files :) 20e1cfe37b wip 654fc5e6a6 chore: remove unnecessary files from c binding 92ffd63c28 refactor: cargo build script 1d4d76fb05 chore: remove wrapper.h 20cc668708 qfix abb38804c7 Merge remote-tracking branch 'dashevo/rust-bindings' into rust-bindings 760a267ab7 build: fix mac related issues 8b083794a4 add destructors to bls-dash-sys basic test 6c54f0a01a Merge remote-tracking branch 'dashevo/rust-bindings' into rust-bindings fd526ab0db build: pass gmp lib path to build.rs a8aaccb510 rust-bindings sign and verify test simple 8447c1c112 wip bindings test 9390162e3c wip add rust-bindings tests 26ab7216c0 revert: bls header path db55e40cb0 rename to sys 96188a6d52 build qfix 965ac58df4 build: automate build process part 2 05636207a0 build: automate build process part 1 73b146a961 experiment cross compiling with autocxx and bindgen 969e5e2102 experiment cross compiling with autocxx and bindgen 88ee9d0519 chore: WIP 525b4d49d9 feat: rust bindings git-subtree-dir: src/dashbls git-subtree-split: 795660db76636c92bea3bfccfee621f1aba371a3
275 lines
11 KiB
C++
275 lines
11 KiB
C++
// Copyright 2020 Chia Network Inc
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in coiance with the License.
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or iied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef SRC_BLSSCHEMES_HPP_
|
|
#define SRC_BLSSCHEMES_HPP_
|
|
|
|
#include <iostream>
|
|
#include <vector>
|
|
|
|
#include "relic_conf.h"
|
|
|
|
#if defined GMP && ARITH == GMP
|
|
#include <gmp.h>
|
|
#endif
|
|
|
|
#include "elements.hpp"
|
|
#include "privatekey.hpp"
|
|
|
|
using std::vector;
|
|
|
|
// These are all MPL schemes
|
|
namespace bls {
|
|
|
|
class Bytes;
|
|
|
|
class CoreMPL {
|
|
|
|
public:
|
|
CoreMPL() = delete;
|
|
CoreMPL(const std::string& strId) : strCiphersuiteId(strId) {}
|
|
virtual ~CoreMPL() {}
|
|
// Generates a private key from a seed, similar to HD key generation
|
|
// (hashes the seed), and reduces it mod the group order
|
|
virtual PrivateKey KeyGen(const vector<uint8_t>& seed);
|
|
virtual PrivateKey KeyGen(const Bytes& seed);
|
|
|
|
// Generates a public key from a secret key
|
|
virtual vector<uint8_t> SkToPk(const PrivateKey &seckey);
|
|
|
|
virtual G1Element SkToG1(const PrivateKey &seckey);
|
|
|
|
virtual G2Element Sign(const PrivateKey &seckey, const vector<uint8_t> &message);
|
|
virtual G2Element Sign(const PrivateKey& seckey, const Bytes& message);
|
|
|
|
virtual bool Verify(const vector<uint8_t> &pubkey,
|
|
const vector<uint8_t> &message,
|
|
const vector<uint8_t> &signature);
|
|
|
|
virtual bool Verify(const Bytes& pubkey, const Bytes& message, const Bytes& signature);
|
|
|
|
virtual bool Verify(const G1Element &pubkey,
|
|
const vector<uint8_t> &message,
|
|
const G2Element &signature);
|
|
|
|
virtual bool Verify(const G1Element& pubkey, const Bytes& message, const G2Element& signature);
|
|
|
|
virtual vector<uint8_t> Aggregate(const vector<vector<uint8_t>> &signatures);
|
|
virtual vector<uint8_t> Aggregate(const vector<Bytes>& signatures);
|
|
|
|
virtual G2Element Aggregate(const vector<G2Element> &signatures);
|
|
|
|
virtual G1Element Aggregate(const vector<G1Element> &publicKeys);
|
|
|
|
virtual G2Element AggregateSecure(const std::vector<G1Element>& vecPublicKeys,
|
|
const std::vector<G2Element>& vecSignatures,
|
|
const Bytes& message);
|
|
|
|
virtual bool VerifySecure(const std::vector<G1Element>& vecPublicKeys,
|
|
const G2Element& signature,
|
|
const Bytes& message);
|
|
|
|
virtual bool AggregateVerify(const vector<vector<uint8_t>> &pubkeys,
|
|
const vector<vector<uint8_t>> &messages,
|
|
const vector<uint8_t> &signature);
|
|
|
|
virtual bool AggregateVerify(const vector<Bytes>& pubkeys,
|
|
const vector<Bytes>& messages,
|
|
const Bytes& signature);
|
|
|
|
virtual bool AggregateVerify(const vector<G1Element> &pubkeys,
|
|
const vector<vector<uint8_t>> &messages,
|
|
const G2Element &signature);
|
|
|
|
virtual bool AggregateVerify(const vector<G1Element>& pubkeys,
|
|
const vector<Bytes>& messages,
|
|
const G2Element& signature);
|
|
|
|
PrivateKey DeriveChildSk(const PrivateKey& sk, uint32_t index);
|
|
PrivateKey DeriveChildSkUnhardened(const PrivateKey& sk, uint32_t index);
|
|
G1Element DeriveChildPkUnhardened(const G1Element& sk, uint32_t index);
|
|
|
|
protected:
|
|
const std::string& strCiphersuiteId;
|
|
bool NativeVerify(g1_t *pubKeys, g2_t *mappedHashes, size_t length);
|
|
G2Element AggregateSecure(std::vector<G1Element> const &vecPublicKeys,
|
|
std::vector<G2Element> const &vecSignatures,
|
|
const Bytes& message,
|
|
bool fLegacy);
|
|
bool VerifySecure(const std::vector<G1Element>& vecPublicKeys,
|
|
const G2Element& signature,
|
|
const Bytes& message,
|
|
bool fLegacy);
|
|
};
|
|
|
|
class BasicSchemeMPL final : public CoreMPL {
|
|
public:
|
|
static const std::string CIPHERSUITE_ID;
|
|
BasicSchemeMPL() : CoreMPL(BasicSchemeMPL::CIPHERSUITE_ID) {}
|
|
bool AggregateVerify(const vector<vector<uint8_t>> &pubkeys,
|
|
const vector<vector<uint8_t>> &messages,
|
|
const vector<uint8_t> &signature) override;
|
|
|
|
bool AggregateVerify(const vector<Bytes>& pubkeys,
|
|
const vector<Bytes>& messages,
|
|
const Bytes& signature) override;
|
|
|
|
bool AggregateVerify(const vector<G1Element> &pubkeys,
|
|
const vector<vector<uint8_t>> &messages,
|
|
const G2Element &signature) override;
|
|
|
|
bool AggregateVerify(const vector<G1Element>& pubkeys,
|
|
const vector<Bytes>& messages,
|
|
const G2Element& signature) override;
|
|
};
|
|
|
|
class AugSchemeMPL final : public CoreMPL {
|
|
|
|
public:
|
|
static const std::string CIPHERSUITE_ID;
|
|
AugSchemeMPL() : CoreMPL(AugSchemeMPL::CIPHERSUITE_ID) {}
|
|
|
|
G2Element Sign(const PrivateKey &seckey, const vector<uint8_t> &message) override;
|
|
|
|
G2Element Sign(const PrivateKey& seckey, const Bytes& message) override;
|
|
|
|
// Used for prepending different augMessage
|
|
G2Element Sign(const PrivateKey &seckey,
|
|
const vector<uint8_t> &message,
|
|
const G1Element &prepend_pk);
|
|
|
|
// Used for prepending different augMessage
|
|
G2Element Sign(const PrivateKey& seckey,
|
|
const Bytes& message,
|
|
const G1Element& prepend_pk);
|
|
|
|
bool Verify(const vector<uint8_t> &pubkey,
|
|
const vector<uint8_t> &message,
|
|
const vector<uint8_t> &signature) override;
|
|
|
|
bool Verify(const Bytes& pubkey,
|
|
const Bytes& message,
|
|
const Bytes& signature) override;
|
|
|
|
bool Verify(const G1Element &pubkey,
|
|
const vector<uint8_t> &message,
|
|
const G2Element &signature) override;
|
|
|
|
bool Verify(const G1Element& pubkey,
|
|
const Bytes& message,
|
|
const G2Element& signature) override;
|
|
|
|
bool AggregateVerify(const vector<vector<uint8_t>> &pubkeys,
|
|
const vector<vector<uint8_t>> &messages,
|
|
const vector<uint8_t> &signature) override;
|
|
|
|
bool AggregateVerify(const vector<Bytes>& pubkeys,
|
|
const vector<Bytes>& messages,
|
|
const Bytes& signature) override;
|
|
|
|
bool AggregateVerify(const vector<G1Element> &pubkeys,
|
|
const vector<vector<uint8_t>> &messages,
|
|
const G2Element &signature) override;
|
|
|
|
bool AggregateVerify(const vector<G1Element>& pubkeys,
|
|
const vector<Bytes>& messages,
|
|
const G2Element& signature) override;
|
|
};
|
|
|
|
class PopSchemeMPL final : public CoreMPL {
|
|
|
|
public:
|
|
static const std::string CIPHERSUITE_ID;
|
|
static const std::string POP_CIPHERSUITE_ID;
|
|
PopSchemeMPL() : CoreMPL(PopSchemeMPL::CIPHERSUITE_ID) {}
|
|
|
|
G2Element PopProve(const PrivateKey &seckey);
|
|
|
|
bool PopVerify(const G1Element &pubkey, const G2Element &signature_proof);
|
|
|
|
bool PopVerify(const vector<uint8_t> &pubkey, const vector<uint8_t> &proof);
|
|
|
|
bool PopVerify(const Bytes& pubkey, const Bytes& proof);
|
|
|
|
bool FastAggregateVerify(const vector<G1Element> &pubkeys,
|
|
const vector<uint8_t> &message,
|
|
const G2Element &signature);
|
|
|
|
bool FastAggregateVerify(const vector<G1Element>& pubkeys,
|
|
const Bytes& message,
|
|
const G2Element& signature);
|
|
|
|
bool FastAggregateVerify(const vector<vector<uint8_t>> &pubkeys,
|
|
const vector<uint8_t> &message,
|
|
const vector<uint8_t> &signature);
|
|
|
|
bool FastAggregateVerify(const vector<Bytes>& pubkeys,
|
|
const Bytes& message,
|
|
const Bytes& signature);
|
|
};
|
|
|
|
/**
|
|
* This scheme reflects the Sign/Verify behaviour of older bls-signatures library versions (<0.1.29).
|
|
*/
|
|
class LegacySchemeMPL final : public CoreMPL {
|
|
|
|
public:
|
|
LegacySchemeMPL() : CoreMPL(std::string{}) {}
|
|
|
|
virtual vector<uint8_t> SkToPk(const PrivateKey &seckey) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
|
|
G2Element Sign(const PrivateKey &seckey, const vector<uint8_t> &message) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
G2Element Sign(const PrivateKey &seckey, const Bytes& message) final;
|
|
|
|
bool Verify(const vector<uint8_t>& pubkey,
|
|
const vector<uint8_t>& message,
|
|
const vector<uint8_t>& signature) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
|
|
bool Verify(const G1Element& pubkey,
|
|
const vector<uint8_t>& message,
|
|
const G2Element& signature) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
|
|
bool Verify(const Bytes& pubkey, const Bytes& message, const Bytes& signature) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
bool Verify(const G1Element &pubkey, const Bytes& message, const G2Element &signature) final;
|
|
|
|
vector<uint8_t> Aggregate(const vector<vector<uint8_t>> &signatures) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
|
|
G2Element AggregateSecure(const std::vector<G1Element>& vecPublicKeys,
|
|
const std::vector<G2Element>& vecSignatures,
|
|
const Bytes& message) final;
|
|
|
|
bool VerifySecure(const std::vector<G1Element>& vecPublicKeys,
|
|
const G2Element& signature,
|
|
const Bytes& message) final;
|
|
|
|
bool AggregateVerify(const vector<vector<uint8_t>> &pubkeys,
|
|
const vector<vector<uint8_t>> &messages,
|
|
const vector<uint8_t> &signature) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
|
|
bool AggregateVerify(const vector<Bytes> &pubkeys,
|
|
const vector<Bytes> &messages,
|
|
const Bytes &signature) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
|
|
bool AggregateVerify(const vector<G1Element> &pubkeys,
|
|
const vector<vector<uint8_t>> &messages,
|
|
const G2Element &signature) final { throw std::runtime_error("Not supported in LegacySchemeMPL"); }
|
|
|
|
bool AggregateVerify(const vector<G1Element> &pubkeys,
|
|
const vector<Bytes> &messages,
|
|
const G2Element &signature) final;
|
|
};
|
|
} // end namespace bls
|
|
|
|
#endif // SRC_BLSSCHEMES_HPP_
|