Skip to content

Commit

Permalink
device: untangle cyclic depenency
Browse files Browse the repository at this point in the history
When #3303 was merged, a cyclic dependency chain was generated:

    libdevice <- libcncrypto <- libringct <- libdevice

This was because libdevice needs access to a set of basic crypto operations
implemented in libringct such as scalarmultBase(), while libringct also needs
access to abstracted crypto operations implemented in libdevice such as
ecdhEncode(). To untangle this cyclic dependency chain, this patch splits libringct
into libringct_basic and libringct, where the basic crypto ops previously in
libringct are moved into libringct_basic. The cyclic dependency is now resolved
thanks to this separation:

    libcncrypto <- libringct_basic <- libdevice <- libcryptonote_basic <- libringct

This eliminates the need for crypto_device.cpp and rctOps_device.cpp.

Also, many abstracted interfaces of hw::device such as encrypt_payment_id() and
get_subaddress_secret_key() were previously implemented in libcryptonote_basic
(cryptonote_format_utils.cpp) and were then called from hw::core::device_default,
which is odd because libdevice is supposed to be independent of libcryptonote_basic.
Therefore, those functions were moved to device_default.cpp.
  • Loading branch information
stoffu committed Mar 14, 2018
1 parent c9b38b4 commit 27a196b
Show file tree
Hide file tree
Showing 25 changed files with 189 additions and 463 deletions.
2 changes: 0 additions & 2 deletions src/crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ set(crypto_sources
crypto-ops-data.c
crypto-ops.c
crypto.cpp
crypto_device.cpp
groestl.c
hash-extra-blake.c
hash-extra-groestl.c
Expand Down Expand Up @@ -78,7 +77,6 @@ monero_add_library(cncrypto
target_link_libraries(cncrypto
PUBLIC
epee
device
${Boost_SYSTEM_LIBRARY}
PRIVATE
${EXTRA_LIBRARIES})
Expand Down
12 changes: 0 additions & 12 deletions src/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include "hex.h"
#include "span.h"
#include "hash.h"
#include "device/device_declare.hpp"
extern "C" {
#include "crypto-ops.h"
}
Expand Down Expand Up @@ -156,17 +155,6 @@ namespace crypto {
const public_key *const *, std::size_t, const signature *);
};

secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover, hw::device &hwdev);
secret_key generate_keys(public_key &pub, secret_key &sec, hw::device &hwdev);
bool secret_key_to_public_key(const secret_key &sec, public_key &pub, hw::device &hwdev);
bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation, hw::device &hwdev);
void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res, hw::device &hwdev) ;
bool derive_public_key(const key_derivation &derivation, size_t output_index, const public_key &base, public_key &derived_key, hw::device &hwdev);
void derive_secret_key(const key_derivation &derivation, size_t output_index, const secret_key &base, secret_key &derived_key, hw::device &hwdev);
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);
void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image, hw::device &hwdev);


/* Generate N random bytes
*/
inline void rand(size_t N, uint8_t *bytes) {
Expand Down
75 changes: 0 additions & 75 deletions src/crypto/crypto_device.cpp

This file was deleted.

1 change: 0 additions & 1 deletion src/cryptonote_basic/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ extern "C"
}
#include "cryptonote_basic_impl.h"
#include "cryptonote_format_utils.h"
#include "device/device.hpp"

#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "account"
Expand Down
1 change: 0 additions & 1 deletion src/cryptonote_basic/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "cryptonote_basic.h"
#include "crypto/crypto.h"
#include "serialization/keyvalue_serialization.h"
#include "device/device_declare.hpp"

namespace cryptonote
{
Expand Down
3 changes: 2 additions & 1 deletion src/cryptonote_basic/cryptonote_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "misc_language.h"
#include "tx_extra.h"
#include "ringct/rctTypes.h"
#include "device/device.hpp"

namespace cryptonote
{
Expand Down Expand Up @@ -437,7 +438,7 @@ namespace cryptonote
static inline keypair generate(hw::device &hwdev)
{
keypair k;
generate_keys(k.pub, k.sec, hwdev);
hwdev.generate_keys(k.pub, k.sec);
return k;
}
};
Expand Down
Loading

0 comments on commit 27a196b

Please sign in to comment.