2015-03-10 20:13:06 +00:00
|
|
|
#include <fc/crypto/elliptic.hpp>
|
|
|
|
|
|
|
|
|
|
#include <fc/crypto/base58.hpp>
|
|
|
|
|
#include <fc/crypto/openssl.hpp>
|
|
|
|
|
|
|
|
|
|
#include <fc/fwd_impl.hpp>
|
|
|
|
|
#include <fc/exception/exception.hpp>
|
|
|
|
|
#include <fc/log/logger.hpp>
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <secp256k1.h>
|
|
|
|
|
|
2015-03-13 17:47:31 +00:00
|
|
|
#include "_elliptic_impl_priv.hpp"
|
|
|
|
|
#include "_elliptic_impl_pub.hpp"
|
|
|
|
|
|
2015-03-10 20:13:06 +00:00
|
|
|
namespace fc { namespace ecc {
|
|
|
|
|
namespace detail
|
|
|
|
|
{
|
2022-06-30 17:43:56 +00:00
|
|
|
const secp256k1_context* _get_context() {
|
|
|
|
|
static secp256k1_context* ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN);
|
2015-05-07 13:59:21 +00:00
|
|
|
return ctx;
|
2015-03-13 17:47:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _init_lib() {
|
2022-06-30 17:43:56 +00:00
|
|
|
static const secp256k1_context* ctx = _get_context();
|
2015-03-13 17:47:31 +00:00
|
|
|
static int init_o = init_openssl();
|
|
|
|
|
}
|
2015-03-10 20:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-13 17:47:31 +00:00
|
|
|
static const private_key_secret empty_priv;
|
2015-03-10 20:15:55 +00:00
|
|
|
fc::sha512 private_key::get_shared_secret( const public_key& other )const
|
|
|
|
|
{
|
2015-03-13 17:47:31 +00:00
|
|
|
FC_ASSERT( my->_key != empty_priv );
|
2015-03-10 20:15:55 +00:00
|
|
|
FC_ASSERT( other.my->_key != nullptr );
|
2015-03-13 17:47:31 +00:00
|
|
|
public_key_data pub(other.serialize());
|
2015-05-07 13:59:21 +00:00
|
|
|
FC_ASSERT( secp256k1_ec_pubkey_tweak_mul( detail::_get_context(), (unsigned char*) pub.begin(), pub.size(), (unsigned char*) my->_key.data() ) );
|
2015-03-13 17:47:31 +00:00
|
|
|
return fc::sha512::hash( pub.begin() + 1, pub.size() - 1 );
|
2015-03-10 20:15:55 +00:00
|
|
|
}
|
|
|
|
|
|
2015-03-10 20:56:20 +00:00
|
|
|
} }
|