From bb30628de1b1eb7f208e143488b61a1980224050 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Thu, 1 Nov 2018 17:18:24 +0100 Subject: [PATCH] Implement DHKeyExchange (#43) * Implement DHKeyExchange * Call CheckRelicErrors in DHKeyExchange --- src/bls.cpp | 10 ++++++++++ src/bls.hpp | 2 ++ src/privatekey.hpp | 1 + src/publickey.hpp | 1 + 4 files changed, 14 insertions(+) diff --git a/src/bls.cpp b/src/bls.cpp index d2375baf015ff0..2ec05ae2e4e21b 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -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()"); diff --git a/src/bls.hpp b/src/bls.hpp index d100eeee90e385..a58cbf2f1dea65 100644 --- a/src/bls.hpp +++ b/src/bls.hpp @@ -63,6 +63,8 @@ class BLS { std::vector const &serPubKeys, std::vector const &sortedIndices); + static PublicKey DHKeyExchange(const PrivateKey& privKey, const PublicKey& pubKey); + static void CheckRelicErrors(); }; } // end namespace bls diff --git a/src/privatekey.hpp b/src/privatekey.hpp index 7ecb09f6a37def..91133eb2e884f0 100644 --- a/src/privatekey.hpp +++ b/src/privatekey.hpp @@ -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 diff --git a/src/publickey.hpp b/src/publickey.hpp index 5b77605051f5e5..8909294775c853 100644 --- a/src/publickey.hpp +++ b/src/publickey.hpp @@ -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;