Skip to content

Commit

Permalink
Implement DHKeyExchange (dashpay#43)
Browse files Browse the repository at this point in the history
* Implement DHKeyExchange

* Call CheckRelicErrors in DHKeyExchange
  • Loading branch information
codablock authored and mariano54 committed Nov 1, 2018
1 parent 523c44e commit bb30628
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/bls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ void BLS::HashPubKeys(bn_t* output, size_t numOutputs,
CheckRelicErrors();
}

PublicKey BLS::DHKeyExchange(const PrivateKey& privKey, const PublicKey& pubKey) {
AssertInitialized();
if (!privKey.keydata) {
throw std::string("keydata not initialized");
}
PublicKey ret = pubKey.Exp(*privKey.keydata);
CheckRelicErrors();
return ret;
}

void BLS::CheckRelicErrors() {
if (!core_get()) {
throw std::string("Library not initialized properly. Call BLS::Init()");
Expand Down
2 changes: 2 additions & 0 deletions src/bls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class BLS {
std::vector<uint8_t*> const &serPubKeys,
std::vector<size_t> const &sortedIndices);

static PublicKey DHKeyExchange(const PrivateKey& privKey, const PublicKey& pubKey);

static void CheckRelicErrors();
};
} // end namespace bls
Expand Down
1 change: 1 addition & 0 deletions src/privatekey.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "signature.hpp"
namespace bls {
class PrivateKey {
friend class BLS;
public:
// Private keys are represented as 32 byte field elements. Note that
// not all 32 byte integers are valid keys, the private key must be
Expand Down
1 change: 1 addition & 0 deletions src/publickey.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PublicKey {
friend class InsecureSignature;
friend class Signature;
friend class ExtendedPublicKey;
friend class BLS;
public:
static const size_t PUBLIC_KEY_SIZE = 48;

Expand Down

0 comments on commit bb30628

Please sign in to comment.