-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial eddsa multisig signer implementation
Integrated EdDSA multisig to conconrd-bft's key generation and to commit path threshold signature collection Added unittests for EdDSA multisig interface
- Loading branch information
1 parent
32a04c1
commit 4d27255
Showing
30 changed files
with
769 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
threshsign/include/threshsign/eddsa/EdDSAMultisigFactory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// Created by yflum on 26/04/2022. | ||
// | ||
#pragma once | ||
|
||
#include "../IThresholdFactory.h" | ||
#include "../IThresholdSigner.h" | ||
#include "../IThresholdVerifier.h" | ||
|
||
class EdDSAMultisigFactory : public IThresholdFactory { | ||
public: | ||
IThresholdVerifier *newVerifier(ShareID reqSigners, | ||
ShareID totalSigners, | ||
const char *publicKeyStr, | ||
const std::vector<std::string> &verifKeysHex) const override; | ||
IThresholdSigner *newSigner(ShareID id, const char *secretKeyStr) const override; | ||
std::tuple<std::vector<IThresholdSigner *>, IThresholdVerifier *> newRandomSigners( | ||
NumSharesType reqSigners, NumSharesType numSigners) const override; | ||
std::pair<std::unique_ptr<IShareSecretKey>, std::unique_ptr<IShareVerificationKey>> newKeyPair() const override; | ||
~EdDSAMultisigFactory() override = default; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Created by yflum on 26/04/2022. | ||
// | ||
#pragma once | ||
|
||
#include "../IThresholdSigner.h" | ||
#include "SSLEdDSAPrivateKey.h" | ||
#include "SSLEdDSAPublicKey.h" | ||
|
||
class EdDSAMultisigSigner : public IThresholdSigner { | ||
public: | ||
EdDSAMultisigSigner(const SSLEdDSAPrivateKey &privateKey, const uint32_t id); | ||
int requiredLengthForSignedData() const override; | ||
|
||
void signData(const char *hash, int hashLen, char *outSig, int outSigLen) override; | ||
const IShareSecretKey &getShareSecretKey() const override; | ||
const IShareVerificationKey &getShareVerificationKey() const override; | ||
~EdDSAMultisigSigner() override = default; | ||
|
||
private: | ||
SSLEdDSAPrivateKey privateKey_; | ||
SSLEdDSAPublicKey publicKey_; | ||
uint32_t id_; | ||
}; |
45 changes: 45 additions & 0 deletions
45
threshsign/include/threshsign/eddsa/EdDSAMultisigVerifier.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// Created by yflum on 27/04/2022. | ||
// | ||
#pragma once | ||
#include "threshsign/IThresholdVerifier.h" | ||
#include "SSLEdDSAPublicKey.h" | ||
#include "SingleEdDSASignature.h" | ||
|
||
class EdDSAMultisigVerifier; | ||
|
||
class EdDSASignatureAccumulator : public IThresholdAccumulator { | ||
public: | ||
EdDSASignatureAccumulator(const EdDSAMultisigVerifier &verifier); | ||
int add(const char *sigShareWithId, int len) override; | ||
void setExpectedDigest(const unsigned char *msg, int len) override; | ||
size_t getFullSignedData(char *outThreshSig, int threshSigLen) override; | ||
bool hasShareVerificationEnabled() const override; | ||
int getNumValidShares() const override; | ||
std::set<ShareID> getInvalidShareIds() const override; | ||
|
||
private: | ||
std::unordered_map<uint32_t, SingleEdDSASignature> signatures_; | ||
std::string msgDigest_; | ||
// const EdDSAMultisigVerifier& verifier_; | ||
}; | ||
|
||
class EdDSAMultisigVerifier : public IThresholdVerifier { | ||
public: | ||
EdDSAMultisigVerifier(const std::vector<SSLEdDSAPublicKey> &publicKeys, | ||
const size_t signersCount, | ||
const size_t threshold); | ||
IThresholdAccumulator *newAccumulator(bool withShareVerification) const override; | ||
|
||
bool verify(const char *msg, int msgLen, const char *sig, int sigLen) const override; | ||
|
||
int requiredLengthForSignedData() const override; | ||
const IPublicKey &getPublicKey() const override; | ||
const IShareVerificationKey &getShareVerificationKey(ShareID signer) const override; | ||
~EdDSAMultisigVerifier() override = default; | ||
|
||
private: | ||
std::vector<SSLEdDSAPublicKey> publicKeys_; | ||
const size_t signersCount_; | ||
const size_t threshold_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Created by yflum on 26/04/2022. | ||
// | ||
|
||
#pragma once | ||
#include "../ISecretKey.h" | ||
#include <array> | ||
|
||
class SSLEdDSAPrivateKey : public IShareSecretKey { | ||
public: | ||
static constexpr const size_t KeyByteSize = 32; | ||
static constexpr const size_t SignatureByteSize = 64; | ||
using EdDSAPrivateKeyBytes = std::array<uint8_t, KeyByteSize>; | ||
using EdDSASignatureBytes = std::array<uint8_t, SignatureByteSize>; | ||
|
||
SSLEdDSAPrivateKey(const EdDSAPrivateKeyBytes& bytes); | ||
~SSLEdDSAPrivateKey() override = default; | ||
|
||
std::string sign(const std::string& message) const; | ||
std::string sign(const uint8_t* msg, size_t len) const; | ||
void sign(const uint8_t* msg, size_t len, uint8_t* signature, size_t& signatureLength) const; | ||
std::string toString() const override; | ||
|
||
static SSLEdDSAPrivateKey fromHexString(const std::string& hexString); | ||
|
||
private: | ||
SSLEdDSAPrivateKey() = default; | ||
|
||
EdDSAPrivateKeyBytes bytes_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// Created by yflum on 26/04/2022. | ||
// | ||
#pragma once | ||
#include "../IPublicKey.h" | ||
#include <array> | ||
|
||
class SSLEdDSAPublicKey : public IShareVerificationKey { | ||
public: | ||
static constexpr const size_t KeyByteSize = 32; | ||
using EdDSAPublicKeyBytes = std::array<uint8_t, KeyByteSize>; | ||
|
||
SSLEdDSAPublicKey(const EdDSAPublicKeyBytes& bytes); | ||
~SSLEdDSAPublicKey() override = default; | ||
|
||
std::string serialize() const; | ||
bool verify(const uint8_t* message, | ||
const size_t messageLen, | ||
const uint8_t* signature, | ||
const size_t signatureLen) const; | ||
bool verify(const std::string& message, const std::string& signature) const; | ||
std::string toString() const override; | ||
|
||
static SSLEdDSAPublicKey fromHexString(const std::string& hexString); | ||
|
||
private: | ||
SSLEdDSAPublicKey() = default; | ||
EdDSAPublicKeyBytes bytes_; | ||
}; |
19 changes: 19 additions & 0 deletions
19
threshsign/include/threshsign/eddsa/SingleEdDSASignature.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Concord | ||
// | ||
// Copyright (c) 2018-2022 VMware, Inc. All Rights Reserved. | ||
// | ||
// This product is licensed to you under the Apache 2.0 license (the "License"). | ||
// You may not use this product except in compliance with the Apache 2.0 License. | ||
// | ||
// This product may include a number of subcomponents with separate copyright | ||
// notices and license terms. Your use of these subcomponents is subject to the | ||
// terms and conditions of the subcomponent's license, as noted in the | ||
// LICENSE file. | ||
#pragma once | ||
#include <array> | ||
#include <cstdint> | ||
|
||
struct SingleEdDSASignature { | ||
uint64_t id; | ||
std::array<uint8_t, 64> signatureBytes; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.