device: untangle cyclic depenency

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.
This commit is contained in:
stoffu 2018-03-05 16:16:30 +09:00
parent c9b38b4765
commit 27a196b126
No known key found for this signature in database
GPG key ID: 41DAB8343A9EC012
25 changed files with 189 additions and 463 deletions

View file

@ -46,7 +46,6 @@
#include "hex.h"
#include "span.h"
#include "hash.h"
#include "device/device_declare.hpp"
extern "C" {
#include "crypto-ops.h"
}
@ -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) {