forked from wownero/wownero
The basic approach it to delegate all sensitive data (master key, secret ephemeral key, key derivation, ....) and related operations to the device. As device has low memory, it does not keep itself the values (except for view/spend keys) but once computed there are encrypted (with AES are equivalent) and return back to monero-wallet-cli. When they need to be manipulated by the device, they are decrypted on receive. Moreover, using the client for storing the value in encrypted form limits the modification in the client code. Those values are transfered from one C-structure to another one as previously. The code modification has been done with the wishes to be open to any other hardware wallet. To achieve that a C++ class hw::Device has been introduced. Two initial implementations are provided: the "default", which remaps all calls to initial Monero code, and the "Ledger", which delegates all calls to Ledger device.release-v0.4.0.1
parent
421ab3119c
commit
e745c1e38d
@ -0,0 +1,44 @@
|
||||
# - Find PCSC
|
||||
# Find the native PCSC includes and library
|
||||
#
|
||||
# PCSC_INCLUDE_DIR - where to find winscard.h, wintypes.h, etc.
|
||||
# PCSC_LIBRARIES - List of libraries when using PCSC.
|
||||
# PCSC_FOUND - True if PCSC found.
|
||||
|
||||
|
||||
IF (PCSC_INCLUDE_DIR AND PCSC_LIBRARIES)
|
||||
# Already in cache, be silent
|
||||
SET(PCSC_FIND_QUIETLY TRUE)
|
||||
ENDIF (PCSC_INCLUDE_DIR AND PCSC_LIBRARIES)
|
||||
|
||||
IF (NOT WIN32)
|
||||
FIND_PACKAGE(PkgConfig)
|
||||
PKG_CHECK_MODULES(PC_PCSC libpcsclite)
|
||||
ENDIF (NOT WIN32)
|
||||
|
||||
FIND_PATH(PCSC_INCLUDE_DIR winscard.h
|
||||
HINTS
|
||||
/usr/include/PCSC
|
||||
${PC_PCSC_INCLUDEDIR}
|
||||
${PC_PCSC_INCLUDE_DIRS}
|
||||
PATH_SUFFIXES PCSC
|
||||
)
|
||||
|
||||
FIND_LIBRARY(PCSC_LIBRARY NAMES pcsclite libpcsclite WinSCard PCSC
|
||||
HINTS
|
||||
${PC_PCSC_LIBDIR}
|
||||
${PC_PCSC_LIBRARY_DIRS}
|
||||
)
|
||||
|
||||
# handle the QUIETLY and REQUIRED arguments and set PCSC_FOUND to TRUE if
|
||||
# all listed variables are TRUE
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCSC DEFAULT_MSG PCSC_LIBRARY PCSC_INCLUDE_DIR)
|
||||
|
||||
IF(PCSC_FOUND)
|
||||
SET( PCSC_LIBRARIES ${PCSC_LIBRARY} )
|
||||
ELSE(PCSC_FOUND)
|
||||
SET( PCSC_LIBRARIES )
|
||||
ENDIF(PCSC_FOUND)
|
||||
|
||||
MARK_AS_ADVANCED( PCSC_LIBRARY PCSC_INCLUDE_DIR )
|
@ -0,0 +1,79 @@
|
||||
// Copyright (c) 2014-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
#include "crypto.h"
|
||||
#include "device/device.hpp"
|
||||
#include "device/log.hpp"
|
||||
|
||||
namespace crypto {
|
||||
|
||||
secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover, hw::device &hwdev) {
|
||||
secret_key rng;
|
||||
hwdev.generate_keys(pub, sec, recovery_key, recover, rng);
|
||||
return rng;
|
||||
}
|
||||
|
||||
secret_key generate_keys(public_key &pub, secret_key &sec, hw::device &hwdev) {
|
||||
secret_key rng;
|
||||
hwdev.generate_keys(pub, sec, secret_key(), false, rng);
|
||||
return rng;
|
||||
}
|
||||
|
||||
|
||||
bool secret_key_to_public_key(const secret_key &sec, public_key &pub, hw::device &hwdev) {
|
||||
return hwdev.secret_key_to_public_key(sec, pub);
|
||||
}
|
||||
|
||||
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation, hw::device &hwdev) {
|
||||
return hwdev.generate_key_derivation(key1, key2, derivation);
|
||||
}
|
||||
|
||||
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res, hw::device &hwdev) {
|
||||
hwdev.derivation_to_scalar(derivation, output_index, res);
|
||||
}
|
||||
|
||||
bool derive_public_key(const key_derivation &derivation, size_t output_index,
|
||||
const public_key &base, public_key &derived_key, hw::device &hwdev) {
|
||||
return hwdev.derive_public_key(derivation, output_index, base, derived_key);
|
||||
}
|
||||
|
||||
void derive_secret_key(const key_derivation &derivation, size_t output_index,
|
||||
const secret_key &base, secret_key &derived_key, hw::device &hwdev) {
|
||||
hwdev.derive_secret_key(derivation, output_index, base, derived_key);
|
||||
}
|
||||
|
||||
bool derive_subaddress_public_key(const public_key &out_key, const key_derivation &derivation, std::size_t output_index, public_key &derived_key, hw::device &hwdev) {
|
||||
return hwdev.derive_subaddress_public_key(out_key, derivation, output_index, derived_key);
|
||||
}
|
||||
|
||||
void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image, hw::device &hwdev) {
|
||||
hwdev.generate_key_image(pub,sec,image);
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
# Copyright (c) 2014-2017, The Monero Project
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are
|
||||
# permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
# conditions and the following disclaimer.
|
||||
#
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
# of conditions and the following disclaimer in the documentation and/or other
|
||||
# materials provided with the distribution.
|
||||
#
|
||||
# 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software without specific
|
||||
# prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
set(device_sources
|
||||
device.cpp
|
||||
device_default.cpp
|
||||
log.cpp
|
||||
)
|
||||
|
||||
if(PCSC_FOUND)
|
||||
set(device_sources ${device_sources} device_ledger.cpp)
|
||||
endif()
|
||||
|
||||
set(device_headers
|
||||
device_declare.hpp
|
||||
device.hpp
|
||||
device_default.hpp
|
||||
log.hpp
|
||||
)
|
||||
|
||||
if(PCSC_FOUND)
|
||||
set(device_headers ${device_headers} device_ledger.hpp)
|
||||
endif()
|
||||
|
||||
set(device_private_headers)
|
||||
|
||||
|
||||
if(PER_BLOCK_CHECKPOINT)
|
||||
set(Blocks "blocks")
|
||||
else()
|
||||
set(Blocks "")
|
||||
endif()
|
||||
|
||||
monero_private_headers(device
|
||||
${device_private_headers})
|
||||
|
||||
monero_add_library(device
|
||||
${device_sources}
|
||||
${device_headers}
|
||||
${device_private_headers})
|
||||
|
||||
target_link_libraries(device
|
||||
PUBLIC
|
||||
${PCSC_LIBRARIES}
|
||||
cncrypto
|
||||
ringct
|
||||
${OPENSSL_CRYPTO_LIBRARIES}
|
||||
${GNU_READLINE_LIBRARY}
|
||||
${EPEE_READLINE}
|
||||
PRIVATE
|
||||
${Blocks}
|
||||
${EXTRA_LIBRARIES})
|
@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "device.hpp"
|
||||
#include "device_default.hpp"
|
||||
#ifdef HAVE_PCSC
|
||||
#include "device_ledger.hpp"
|
||||
#endif
|
||||
#include "common/scoped_message_writer.h"
|
||||
|
||||
|
||||
namespace hw {
|
||||
|
||||
/* ======================================================================= */
|
||||
/* SETUP */
|
||||
/* ======================================================================= */
|
||||
device& get_device(const std::string device_descriptor) {
|
||||
|
||||
struct s_devices {
|
||||
std::map<std::string, std::unique_ptr<device>> registry;
|
||||
s_devices() : registry() {
|
||||
hw::core::register_all(registry);
|
||||
#ifdef HAVE_PCSC
|
||||
hw::ledger::register_all(registry);
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
static const s_devices devices;
|
||||
|
||||
auto device = devices.registry.find(device_descriptor);
|
||||
if (device == devices.registry.end()) {
|
||||
auto logger = tools::fail_msg_writer();
|
||||
logger << "device not found in registry '"<<device_descriptor<<"'\n" <<
|
||||
"known devices:"<<device_descriptor<<"'";
|
||||
|
||||
for( const auto& sm_pair : devices.registry ) {
|
||||
logger<< " - " << sm_pair.first ;
|
||||
}
|
||||
throw std::runtime_error("device not found: "+ device_descriptor);
|
||||
}
|
||||
return *device->second;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cryptonote_basic/cryptonote_basic.h"
|
||||
#include "cryptonote_basic/account.h"
|
||||
#include "cryptonote_basic/subaddress_index.h"
|
||||
|
||||
#ifndef USE_DEVICE_LEDGER
|
||||
#define USE_DEVICE_LEDGER 1
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_PCSC)
|
||||
#undef USE_DEVICE_LEDGER
|
||||
#define USE_DEVICE_LEDGER 0
|
||||
#endif
|
||||
|
||||
#if USE_DEVICE_LEDGER
|
||||
#define WITH_DEVICE_LEDGER
|
||||
#endif
|
||||
|
||||
namespace hw {
|
||||
namespace {
|
||||
//device funcion not supported
|
||||
#define dfns() \
|
||||
throw std::runtime_error(std::string("device function not supported: ")+ std::string(__FUNCTION__) + \
|
||||
std::string(" (device.hpp line ")+std::to_string(__LINE__)+std::string(").")); \
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
class device {
|
||||
public:
|
||||
|
||||
device() {}
|
||||
device(const device &hwdev) {}
|
||||
virtual ~device() {}
|
||||
|
||||
explicit virtual operator bool() const = 0;
|
||||
|
||||
static const int SIGNATURE_REAL = 0;
|
||||
static const int SIGNATURE_FAKE = 1;
|
||||
|
||||
|
||||
std::string name;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* SETUP/TEARDOWN */
|
||||
/* ======================================================================= */
|
||||
virtual bool set_name(const std::string &name) = 0;
|
||||
virtual const std::string get_name() const = 0;
|
||||
|
||||
virtual bool init(void) = 0;
|
||||
virtual bool release() = 0;
|
||||
|
||||
virtual bool connect(void) = 0;
|
||||
virtual bool disconnect() = 0;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* WALLET & ADDRESS */
|
||||
/* ======================================================================= */
|
||||
virtual bool get_public_address(cryptonote::account_public_address &pubkey) = 0;
|
||||
virtual bool get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) = 0;
|
||||
virtual bool generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) = 0;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* SUB ADDRESS */
|
||||
/* ======================================================================= */
|
||||
virtual bool derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub) = 0;
|
||||
virtual bool get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index, crypto::public_key &D) = 0;
|
||||
virtual bool get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) = 0;
|
||||
virtual bool get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) = 0;
|
||||
virtual bool get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index, crypto::secret_key &sub_sec) = 0;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* DERIVATION & KEY */
|
||||
/* ======================================================================= */
|
||||
virtual bool verify_keys(const crypto::secret_key &secret_key, const crypto::public_key &public_key) = 0;
|
||||
virtual bool scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) = 0;
|
||||
virtual bool scalarmultBase(rct::key &aG, const rct::key &a) = 0;
|
||||
virtual bool sc_secret_add( crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) = 0;
|
||||
virtual bool generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) = 0;
|
||||
virtual bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) = 0;
|
||||
virtual bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) = 0;
|
||||
virtual bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) = 0;
|
||||
virtual bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) = 0;
|
||||
virtual bool secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) = 0;
|
||||
virtual bool generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image) = 0;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* TRANSACTION */
|
||||
/* ======================================================================= */
|
||||
|
||||
virtual bool open_tx(crypto::secret_key &tx_key) = 0;
|
||||
|
||||
virtual bool set_signature_mode(unsigned int sig_mode) = 0;
|
||||
|
||||
virtual bool encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id ) = 0;
|
||||
|
||||
virtual bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec) = 0;
|
||||
virtual bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec) = 0;
|
||||
|
||||
virtual bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
|
||||
const rct::key &amount_key, const crypto::public_key &out_eph_public_key) = 0;
|
||||
|
||||
|
||||
virtual bool mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) = 0;
|
||||
virtual bool mlsag_prepare(const rct::key &H, const rct::key &xx, rct::key &a, rct::key &aG, rct::key &aHP, rct::key &rvII) = 0;
|
||||
virtual bool mlsag_prepare(rct::key &a, rct::key &aG) = 0;
|
||||
virtual bool mlsag_hash(const rct::keyV &long_message, rct::key &c) = 0;
|
||||
virtual bool mlsag_sign(const rct::key &c, const rct::keyV &xx, const rct::keyV &alpha, const size_t rows, const size_t dsRows, rct::keyV &ss) = 0;
|
||||
|
||||
virtual bool close_tx(void) = 0;
|
||||
} ;
|
||||
|
||||
device& get_device(const std::string device_descriptor) ;
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
//#define DEBUG_HWDEVICE
|
||||
//#define IODUMMYCRYPT 1
|
||||
//#define IONOCRYPT 1
|
||||
|
||||
namespace hw {
|
||||
class device;
|
||||
|
||||
device& get_device(std::string device_descriptor);
|
||||
}
|
||||
|
@ -0,0 +1,263 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
#include "device_default.hpp"
|
||||
|
||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||
#include "ringct/rctOps.h"
|
||||
|
||||
namespace hw {
|
||||
|
||||
namespace core {
|
||||
|
||||
device_default::device_default() { }
|
||||
|
||||
device_default::~device_default() { }
|
||||
|
||||
/* ===================================================================== */
|
||||
/* === Misc ==== */
|
||||
/* ===================================================================== */
|
||||
static inline unsigned char *operator &(crypto::ec_scalar &scalar) {
|
||||
return &reinterpret_cast<unsigned char &>(scalar);
|
||||
}
|
||||
static inline const unsigned char *operator &(const crypto::ec_scalar &scalar) {
|
||||
return &reinterpret_cast<const unsigned char &>(scalar);
|
||||
}
|
||||
|
||||
/* ======================================================================= */
|
||||
/* SETUP/TEARDOWN */
|
||||
/* ======================================================================= */
|
||||
bool device_default::set_name(const std::string &name) {
|
||||
this->name = name;
|
||||
return true;
|
||||
}
|
||||
const std::string device_default::get_name() const {
|
||||
return this->name;
|
||||
}
|
||||
|
||||
bool device_default::init(void) {
|
||||
dfns();
|
||||
}
|
||||
bool device_default::release() {
|
||||
dfns();
|
||||
}
|
||||
|
||||
bool device_default::connect(void) {
|
||||
dfns();
|
||||
}
|
||||
bool device_default::disconnect() {
|
||||
dfns();
|
||||
}
|
||||
|
||||
/* ======================================================================= */
|
||||
/* WALLET & ADDRESS */
|
||||
/* ======================================================================= */
|
||||
|
||||
bool device_default::generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) {
|
||||
return cryptonote::generate_chacha_key_from_secret_keys(keys, key);
|
||||
}
|
||||
bool device_default::get_public_address(cryptonote::account_public_address &pubkey) {
|
||||
dfns();
|
||||
}
|
||||
bool device_default::get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) {
|
||||
dfns();
|
||||
}
|
||||
/* ======================================================================= */
|
||||
/* SUB ADDRESS */
|
||||
/* ======================================================================= */
|
||||
|
||||
bool device_default::derive_subaddress_public_key(const crypto::public_key &out_key, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_key) {
|
||||
return crypto::derive_subaddress_public_key(out_key, derivation, output_index,derived_key);
|
||||
}
|
||||
|
||||
bool device_default::get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, crypto::public_key &D) {
|
||||
D = cryptonote::get_subaddress_spend_public_key(keys,index);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) {
|
||||
pkeys = cryptonote::get_subaddress_spend_public_keys(keys, account, begin, end);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) {
|
||||
address = cryptonote::get_subaddress(keys,index);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::get_subaddress_secret_key(const crypto::secret_key &a, const cryptonote::subaddress_index &index, crypto::secret_key &m) {
|
||||
m = cryptonote::get_subaddress_secret_key(a,index);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ======================================================================= */
|
||||
/* DERIVATION & KEY */
|
||||
/* ======================================================================= */
|
||||
|
||||
bool device_default::verify_keys(const crypto::secret_key &secret_key, const crypto::public_key &public_key) {
|
||||
return cryptonote::verify_keys(secret_key, public_key);
|
||||
}
|
||||
|
||||
bool device_default::scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) {
|
||||
rct::scalarmultKey(aP, P,a);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::scalarmultBase(rct::key &aG, const rct::key &a) {
|
||||
rct::scalarmultBase(aG,a);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) {
|
||||
sc_add(&r, &a, &b);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) {
|
||||
rng = crypto::generate_keys(pub, sec, recovery_key, recover);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::generate_key_derivation(const crypto::public_key &key1, const crypto::secret_key &key2, crypto::key_derivation &derivation) {
|
||||
return crypto::generate_key_derivation(key1, key2, derivation);
|
||||
}
|
||||
|
||||
bool device_default::derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res){
|
||||
crypto::derivation_to_scalar(derivation,output_index, res);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &base, crypto::secret_key &derived_key){
|
||||
crypto::derive_secret_key(derivation, output_index, base, derived_key);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &base, crypto::public_key &derived_key){
|
||||
return crypto::derive_public_key(derivation, output_index, base, derived_key);
|
||||
}
|
||||
|
||||
bool device_default::secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) {
|
||||
return crypto::secret_key_to_public_key(sec,pub);
|
||||
}
|
||||
|
||||
bool device_default::generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image){
|
||||
crypto::generate_key_image(pub, sec,image);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ======================================================================= */
|
||||
/* TRANSACTION */
|
||||
/* ======================================================================= */
|
||||
|
||||
bool device_default::open_tx(crypto::secret_key &tx_key) {
|
||||
cryptonote::keypair txkey = cryptonote::keypair::generate();
|
||||
tx_key = txkey.sec;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool device_default::add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
|
||||
const rct::key &amount_key, const crypto::public_key &out_eph_public_key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::set_signature_mode(unsigned int sig_mode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id ) {
|
||||
return cryptonote::encrypt_payment_id(payment_id, public_key, secret_key);
|
||||
}
|
||||
|
||||
bool device_default::ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec) {
|
||||
rct::ecdhEncode(unmasked, sharedSec);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec) {
|
||||
rct::ecdhDecode(masked, sharedSec);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::mlsag_prepare(const rct::key &H, const rct::key &xx,
|
||||
rct::key &a, rct::key &aG, rct::key &aHP, rct::key &II) {
|
||||
rct::skpkGen(a, aG);
|
||||
rct::scalarmultKey(aHP, H, a);
|
||||
rct::scalarmultKey(II, H, xx);
|
||||
return true;
|
||||
}
|
||||
bool device_default::mlsag_prepare(rct::key &a, rct::key &aG) {
|
||||
rct::skpkGen(a, aG);
|
||||
return true;
|
||||
}
|
||||
bool device_default::mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) {
|
||||
prehash = rct::cn_fast_hash(hashes);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool device_default::mlsag_hash(const rct::keyV &toHash, rct::key &c_old) {
|
||||
c_old = rct::hash_to_scalar(toHash);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::mlsag_sign(const rct::key &c, const rct::keyV &xx, const rct::keyV &alpha, const size_t rows, const size_t dsRows, rct::keyV &ss ) {
|
||||
CHECK_AND_ASSERT_THROW_MES(dsRows<=rows, "dsRows greater than rows");
|
||||
CHECK_AND_ASSERT_THROW_MES(xx.size() == rows, "xx size does not match rows");
|
||||
CHECK_AND_ASSERT_THROW_MES(alpha.size() == rows, "alpha size does not match rows");
|
||||
CHECK_AND_ASSERT_THROW_MES(ss.size() == rows, "ss size does not match rows");
|
||||
for (size_t j = 0; j < rows; j++) {
|
||||
sc_mulsub(ss[j].bytes, c.bytes, xx[j].bytes, alpha[j].bytes);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool device_default::close_tx() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------------------------------- */
|
||||
static device_default *default_core_device = NULL;
|
||||
void register_all(std::map<std::string, std::unique_ptr<device>> ®istry) {
|
||||
if (!default_core_device) {
|
||||
default_core_device = new device_default();
|
||||
default_core_device->set_name("default_core_device");
|
||||
|
||||
}
|
||||
registry.insert(std::make_pair("default",default_core_device));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "device.hpp"
|
||||
|
||||
namespace hw {
|
||||
|
||||
namespace core {
|
||||
|
||||
void register_all(std::map<std::string, std::unique_ptr<device>> ®istry);
|
||||
|
||||
class device_default : public hw::device {
|
||||
public:
|
||||
device_default();
|
||||
~device_default();
|
||||
|
||||
device_default(const device_default &device) = delete;
|
||||
device_default& operator=(const device_default &device) = delete;
|
||||
|
||||
explicit operator bool() const override { return false; };
|
||||
|
||||
/* ======================================================================= */
|
||||
/* SETUP/TEARDOWN */
|
||||
/* ======================================================================= */
|
||||
bool set_name(const std::string &name) override;
|
||||
const std::string get_name() const override;
|
||||
|
||||
bool init(void) override;
|
||||
bool release() override;
|
||||
|
||||
bool connect(void) override;
|
||||
bool disconnect() override;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* WALLET & ADDRESS */
|
||||
/* ======================================================================= */
|
||||
bool get_public_address(cryptonote::account_public_address &pubkey) override;
|
||||
bool get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) override;
|
||||
bool generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) override;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* SUB ADDRESS */
|
||||
/* ======================================================================= */
|
||||
bool derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub) override;
|
||||
bool get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index, crypto::public_key &D) override;
|
||||
bool get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) override;
|
||||
bool get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) override;
|
||||
bool get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index, crypto::secret_key &sub_sec) override;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* DERIVATION & KEY */
|
||||
/* ======================================================================= */
|
||||
bool verify_keys(const crypto::secret_key &secret_key, const crypto::public_key &public_key) override;
|
||||
bool scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) override;
|
||||
bool scalarmultBase(rct::key &aG, const rct::key &a) override;
|
||||
bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override;
|
||||
bool generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) override;
|
||||
bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override;
|
||||
bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override;
|
||||
bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) override;
|
||||
bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) override;
|
||||
bool secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) override;
|
||||
bool generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image) override;
|
||||
|
||||
|
||||
/* ======================================================================= */
|
||||
/* TRANSACTION */
|
||||
/* ======================================================================= */
|
||||
|
||||
bool open_tx(crypto::secret_key &tx_key) override;
|
||||
|
||||
//bool get_additional_key(const bool subaddr, cryptonote::keypair &additional_txkey) override;
|
||||
bool set_signature_mode(unsigned int sig_mode) override;
|
||||
|
||||
bool encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id ) override;
|
||||
|
||||
bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec) override;
|
||||
bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec) override;
|
||||
|
||||
bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
|
||||
const rct::key &amount_key, const crypto::public_key &out_eph_public_key) override;
|
||||
|
||||
|
||||
bool mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) override;
|
||||
bool mlsag_prepare(const rct::key &H, const rct::key &xx, rct::key &a, rct::key &aG, rct::key &aHP, rct::key &rvII) override;
|
||||
bool mlsag_prepare(rct::key &a, rct::key &aG) override;
|
||||
bool mlsag_hash(const rct::keyV &long_message, rct::key &c) override;
|
||||
bool mlsag_sign(const rct::key &c, const rct::keyV &xx, const rct::keyV &alpha, const size_t rows, const size_t dsRows, rct::keyV &ss) override;
|
||||
|
||||
bool close_tx(void) override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,202 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include "device.hpp"
|
||||
#include <PCSC/winscard.h>
|
||||
#include <PCSC/wintypes.h>
|
||||
|
||||
|
||||
namespace hw {
|
||||
|
||||
namespace ledger {
|
||||
|
||||
void register_all(std::map<std::string, std::unique_ptr<device>> ®istry);
|
||||
|
||||
#ifdef WITH_DEVICE_LEDGER
|
||||
|
||||
namespace {
|
||||
bool apdu_verbose =true;
|
||||
}
|
||||
|
||||
void set_apdu_verbose(bool verbose);
|
||||
|
||||
class ABPkeys {
|
||||
public:
|
||||
rct::key Aout;
|
||||
rct::key Bout;
|
||||
size_t index;
|
||||
rct::key Pout;
|
||||
rct::key AKout;
|
||||
ABPkeys(const rct::key& A, const rct::key& B, size_t index, const rct::key& P,const rct::key& AK);
|
||||
ABPkeys(const ABPkeys& keys) ;
|
||||
ABPkeys() {index=0;}
|
||||
};
|
||||
|
||||
class Keymap {
|
||||
public:
|
||||
std::vector<ABPkeys> ABP;
|
||||
|
||||
bool find(const rct::key& P, ABPkeys& keys) const;
|
||||
void add(const ABPkeys& keys);
|
||||
void clear();
|
||||
void log();
|
||||
};
|
||||
|
||||
#define BUFFER_SEND_SIZE 262
|
||||
#define BUFFER_RECV_SIZE 262
|
||||
|
||||
class device_ledger : public hw::device {
|
||||
private:
|
||||
mutable std::mutex device_locker;
|
||||
mutable std::mutex tx_locker;
|
||||
void lock_device() ;
|
||||
void unlock_device() ;
|
||||
void lock_tx() ;
|
||||
void unlock_tx() ;
|
||||
|
||||
std::string full_name;
|
||||
SCARDCONTEXT hContext;
|
||||
SCARDHANDLE hCard;
|
||||
DWORD length_send;
|
||||
BYTE buffer_send[BUFFER_SEND_SIZE];
|
||||
DWORD length_recv;
|
||||
BYTE buffer_recv[BUFFER_RECV_SIZE];
|
||||
unsigned int id;
|
||||
|
||||
Keymap key_map;
|
||||
|
||||
|
||||
void logCMD(void);
|
||||
void logRESP(void);
|
||||
unsigned int exchange(unsigned int ok=0x9000, unsigned int mask=0xFFFF);
|
||||
void reset_buffer(void);
|
||||
|
||||
#ifdef DEBUGLEDGER
|
||||
Device &controle_device;
|
||||
#endif
|
||||
|
||||
public:
|
||||
device_ledger();
|
||||
~device_ledger();
|
||||
|
||||
device_ledger(const device_ledger &device) = delete ;
|
||||
device_ledger& operator=(const device_ledger &device) = delete;
|
||||
|
||||
explicit operator bool() const override {return this->hContext != 0;}
|
||||
|
||||
bool reset(void);
|
||||
|
||||
/* ======================================================================= */
|
||||
/* SETUP/TEARDOWN */
|
||||
/* ======================================================================= */
|
||||
bool set_name(const std::string &name) override;
|
||||
|
||||
const std::string get_name() const override;
|
||||
bool init(void) override;
|
||||
bool release() override;
|
||||
bool connect(void) override;
|
||||
bool disconnect() override;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* WALLET & ADDRESS */
|
||||
/* ======================================================================= */
|
||||
bool get_public_address(cryptonote::account_public_address &pubkey) override;
|
||||
bool get_secret_keys(crypto::secret_key &viewkey , crypto::secret_key &spendkey) override;
|
||||
bool generate_chacha_key(const cryptonote::account_keys &keys, crypto::chacha_key &key) override;
|
||||
|
||||
|
||||
/* ======================================================================= */
|
||||
/* SUB ADDRESS */
|
||||
/* ======================================================================= */
|
||||
bool derive_subaddress_public_key(const crypto::public_key &pub, const crypto::key_derivation &derivation, const std::size_t output_index, crypto::public_key &derived_pub) override;
|
||||
bool get_subaddress_spend_public_key(const cryptonote::account_keys& keys, const cryptonote::subaddress_index& index, crypto::public_key &D) override;
|
||||
bool get_subaddress_spend_public_keys(const cryptonote::account_keys &keys, uint32_t account, uint32_t begin, uint32_t end, std::vector<crypto::public_key> &pkeys) override;
|
||||
bool get_subaddress(const cryptonote::account_keys& keys, const cryptonote::subaddress_index &index, cryptonote::account_public_address &address) override;
|
||||
bool get_subaddress_secret_key(const crypto::secret_key &sec, const cryptonote::subaddress_index &index, crypto::secret_key &sub_sec) override;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* DERIVATION & KEY */
|
||||
/* ======================================================================= */
|
||||
bool verify_keys(const crypto::secret_key &secret_key, const crypto::public_key &public_key) override;
|
||||
bool scalarmultKey(rct::key & aP, const rct::key &P, const rct::key &a) override;
|
||||
bool scalarmultBase(rct::key &aG, const rct::key &a) override;
|
||||
bool sc_secret_add(crypto::secret_key &r, const crypto::secret_key &a, const crypto::secret_key &b) override;
|
||||
bool generate_keys(crypto::public_key &pub, crypto::secret_key &sec, const crypto::secret_key& recovery_key, bool recover, crypto::secret_key &rng) override;
|
||||
bool generate_key_derivation(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_derivation &derivation) override;
|
||||
bool derivation_to_scalar(const crypto::key_derivation &derivation, const size_t output_index, crypto::ec_scalar &res) override;
|
||||
bool derive_secret_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::secret_key &sec, crypto::secret_key &derived_sec) override;
|
||||
bool derive_public_key(const crypto::key_derivation &derivation, const std::size_t output_index, const crypto::public_key &pub, crypto::public_key &derived_pub) override;
|
||||
bool secret_key_to_public_key(const crypto::secret_key &sec, crypto::public_key &pub) override;
|
||||
bool generate_key_image(const crypto::public_key &pub, const crypto::secret_key &sec, crypto::key_image &image) override;
|
||||
|
||||
/* ======================================================================= */
|
||||
/* TRANSACTION */
|
||||
/* ======================================================================= */
|
||||
|
||||
bool open_tx(crypto::secret_key &tx_key) override;
|
||||
|
||||
bool set_signature_mode(unsigned int sig_mode) override;
|
||||
|
||||
bool encrypt_payment_id(const crypto::public_key &public_key, const crypto::secret_key &secret_key, crypto::hash8 &payment_id ) override;
|
||||
|
||||
bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec) override;
|
||||
bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec) override;
|
||||
|
||||
bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, size_t real_output_index,
|
||||
const rct::key &amount_key, const crypto::public_key &out_eph_public_key) override;
|
||||
|
||||
|
||||
bool mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) override;
|
||||
bool mlsag_prepare(const rct::key &H, const rct::key &xx, rct::key &a, rct::key &aG, rct::key &aHP, rct::key &rvII) override;
|
||||
bool mlsag_prepare(rct::key &a, rct::key &aG) override;
|
||||
bool mlsag_hash(const rct::keyV &long_message, rct::key &c) override;
|
||||
bool mlsag_sign( const rct::key &c, const rct::keyV &xx, const rct::keyV &alpha, const size_t rows, const size_t dsRows, rct::keyV &ss) override;
|
||||
|
||||
bool close_tx(void) override;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef DEBUGLEDGER
|
||||
extern crypto::secret_key viewkey;
|
||||
extern crypto::secret_key spendkey;
|
||||
#endif
|
||||
|
||||
#endif //WITH_DEVICE_LEDGER
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,164 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "misc_log_ex.h"
|
||||
#include "log.hpp"
|
||||
|
||||
namespace hw {
|
||||
|
||||
#ifdef WITH_DEVICE_LEDGER
|
||||
namespace ledger {
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "device.ledger"
|
||||
|
||||
void buffer_to_str(char *to_buff, size_t to_len, const char *buff, size_t len) {
|
||||
CHECK_AND_ASSERT_THROW_MES(to_len > (len*2), "destination buffer too short. At least" << (len*2+1) << " bytes required");
|
||||
for (size_t i=0; i<len; i++) {
|
||||
sprintf(to_buff+2*i, "%.02x", (unsigned char)buff[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void log_hexbuffer(std::string msg, const char* buff, size_t len) {
|
||||
char logstr[1025];
|
||||
buffer_to_str(logstr, sizeof(logstr), buff, len);
|
||||
MDEBUG(msg<< ": " << logstr);
|
||||
}
|
||||
|
||||
void log_message(std::string msg, std::string info ) {
|
||||
MDEBUG(msg << ": " << info);
|
||||
}
|
||||
|
||||
#ifdef DEBUGLEDGER
|
||||
extern crypto::secret_key viewkey;
|
||||
extern crypto::secret_key spendkey;
|
||||
|
||||
|
||||
void decrypt(char* buf, size_t len) {
|
||||
#ifdef IODUMMYCRYPT
|
||||
int i;
|
||||
if (len == 32) {
|
||||
//view key?
|
||||
for (i = 0; i<32; i++) {
|
||||
if (buf[i] != 0) break;
|
||||
}
|
||||
if (i == 32) {
|
||||
memmove(buf, hw::ledger::viewkey.data, 32);
|
||||
return;
|
||||
}
|
||||
//spend key?
|
||||
for (i = 0; i<32; i++) {
|
||||
if (buf[i] != (char)0xff) break;
|
||||
}
|
||||
if (i == 32) {
|
||||
memmove(buf, hw::ledger::spendkey.data, 32);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//std decrypt: XOR.55h
|
||||
for (i = 0; i<len;i++) {
|
||||
buf[i] ^= 0x55;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
crypto::key_derivation decrypt(const crypto::key_derivation &derivation) {
|
||||
crypto::key_derivation x = derivation;
|
||||
decrypt(x.data, 32);
|
||||
return x;
|
||||
}
|
||||
|
||||
cryptonote::account_keys decrypt(const cryptonote::account_keys& keys) {
|
||||
cryptonote::account_keys x = keys;
|
||||
decrypt(x.m_view_secret_key.data, 32);
|
||||
decrypt(x.m_spend_secret_key.data, 32);
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
crypto::secret_key decrypt(const crypto::secret_key &sec) {
|
||||
crypto::secret_key x = sec;
|
||||
decrypt(x.data, 32);
|
||||
return x;
|
||||
}
|
||||
|
||||
rct::key decrypt(const rct::key &sec) {
|
||||
rct::key x = sec;
|
||||
decrypt((char*)x.bytes, 32);
|
||||
return x;
|
||||
}
|
||||
|
||||
crypto::ec_scalar decrypt(const crypto::ec_scalar &res) {
|
||||
crypto::ec_scalar x = res;
|
||||
decrypt((char*)x.data, 32);
|
||||
return x;
|
||||
}
|
||||
|
||||
rct::keyV decrypt(const rct::keyV &keys) {
|
||||
rct::keyV x ;
|
||||
for (unsigned int j = 0; j<keys.size(); j++) {
|
||||
x.push_back(decrypt(keys[j]));
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
static void check(std::string msg, std::string info, const char *h, const char *d, int len, bool crypted) {
|
||||
char dd[32];
|
||||
char logstr[128];
|
||||
|
||||
memmove(dd,d,len);
|
||||
if (crypted) {
|
||||
CHECK_AND_ASSERT_THROW_MES(len<=32, "encrypted data greater than 32");
|
||||
decrypt(dd,len);
|
||||
}
|
||||
|
||||
if (memcmp(h,dd,len)) {
|
||||
log_message("ASSERT EQ FAIL", msg + ": "+ info );
|
||||
log_hexbuffer(" host ", h, len);
|
||||
log_hexbuffer(" device", dd, len);
|
||||
|
||||
} else {
|
||||
buffer_to_str(logstr, dd, len);
|
||||
log_message("ASSERT EQ OK", msg + ": "+ info + ": "+ std::string(logstr) );
|
||||
}
|
||||
}
|
||||
|
||||
void check32(std::string msg, std::string info, const char *h, const char *d, bool crypted) {
|
||||
check(msg, info, h, d, 32, crypted);
|
||||
}
|
||||
|
||||
void check8(std::string msg, std::string info, const char *h, const char *d, bool crypted) {
|
||||
check(msg, info, h, d, 8, crypted);
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif //WITH_DEVICE_LEDGER
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
#include "ringct/rctOps.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "cryptonote_basic/account.h"
|
||||
|
||||
#include "device.hpp"
|
||||
|
||||
namespace hw {
|
||||
|
||||
#ifdef WITH_DEVICE_LEDGER
|
||||
namespace ledger {
|
||||
|
||||
void buffer_to_str(char *to_buff, size_t to_len, const char *buff, size_t len) ;
|
||||
void log_hexbuffer(std::string msg, const char* buff, size_t len);
|
||||
void log_message(std::string msg, std::string info );
|
||||
#ifdef DEBUG_HWDEVICE
|
||||
#define TRACK printf("file %s:%d\n",__FILE__, __LINE__)
|
||||
//#define TRACK MCDEBUG("ledger"," At file " << __FILE__ << ":" << __LINE__)
|
||||
//#define TRACK while(0);
|
||||
|
||||
void decrypt(char* buf, size_t len) ;
|
||||
crypto::key_derivation decrypt(const crypto::key_derivation &derivation) ;
|
||||
cryptonote::account_keys decrypt(const cryptonote::account_keys& keys) ;
|
||||
crypto::secret_key decrypt(const crypto::secret_key &sec) ;
|
||||
rct::key decrypt(const rct::key &sec);
|
||||
crypto::ec_scalar decrypt(const crypto::ec_scalar &res);
|
||||
rct::keyV decrypt(const rct::keyV &keys);
|
||||
|
||||
void check32(std::string msg, std::string info, const char *h, const char *d, bool crypted=false);
|
||||
void check8(std::string msg, std::string info, const char *h, const char *d, bool crypted=false);
|
||||
|
||||
void set_check_verbose(bool verbose);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
// Copyright (c) 2017-2018, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
#include "misc_log_ex.h"
|
||||
#include "rctOps.h"
|
||||
#include "device/device.hpp"
|
||||
using namespace crypto;
|
||||
using namespace std;
|
||||
|
||||
|
||||
namespace rct
|
||||
{
|
||||
void scalarmultKey(key & aP, const key &P, const key &a, hw::device &hwdev) {
|
||||
hwdev.scalarmultKey(aP, P, a);
|
||||
}
|
||||
|
||||
key scalarmultKey(const key & P, const key & a, hw::device &hwdev) {
|
||||
key aP;
|
||||
hwdev.scalarmultKey(aP, P, a);
|
||||
return aP;
|
||||
}
|
||||
|
||||
void scalarmultBase(key &aG, const key &a, hw::device &hwdev) {
|
||||
hwdev.scalarmultBase(aG, a);
|
||||
}
|
||||
|
||||
key scalarmultBase(const key & a, hw::device &hwdev) {
|
||||
key aG;
|
||||
hwdev.scalarmultBase(aG, a);
|
||||
return aG;
|
||||
}
|
||||
|
||||
void ecdhDecode(ecdhTuple & masked, const key & sharedSec, hw::device &hwdev) {
|
||||
hwdev.ecdhDecode(masked, sharedSec);
|
||||
}
|
||||
|
||||
void ecdhEncode(ecdhTuple & unmasked, const key & sharedSec, hw::device &hwdev) {
|
||||
hwdev.ecdhEncode(unmasked, sharedSec);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue