Commit graph

49 commits

Author SHA1 Message Date
Jason Rhinelander 13409ad00e
run clang format 2023-04-13 17:15:12 -03:00
Jason Rhinelander 6aa9db9538
Overhaul and fix crypto::{public_key,ec_point,etc.} types
- Remove implicit `operator bool` from ec_point/public_key/etc. which
  was causing all sorts of implicit conversion mess and bugs.
- Change ec_point/public_key/etc. to use a `std::array<unsigned char,
  32>` (via a base type) rather than a C-array of char that has to be
  reinterpret_cast<>'ed all over the place.
- Add methods to ec_point/public_key/etc. that make it work more like a
  container of bytes (`.data()`, `.size()`, `operator[]`, `begin()`,
  `end()`).
- Make a generic `crypto::null<T>` that is a constexpr all-0 `T`, rather
  than the mishmash `crypto::null_hash`, crypto::null_pkey,
  crypto:#️⃣:null(), and so on.
- Replace three metric tons of `crypto::hash blahblah =
  crypto::null_hash;` with the much simpler `crypto::hash blahblah{};`,
  because there's no need to make a copy of a null hash in all these
  cases.  (Likewise for a few other null_whatevers).
- Remove a whole bunch of `if (blahblah == crypto::null_hash)` and `if
  (blahblah != crypto::null_hash)` with the more concise `if
  (!blahblah)` and `if (blahblah)` (which are fine via the newly
  *explicit* bool conversion operators).
- `crypto::signature` becomes a 64-byte container (as above) but with
  `c()` and `r()` to get the c() and r() data pointers.  (Previously
  `.c` and `.r` were `ec_scalar`s).
- Delete with great prejudice CRYPTO_MAKE_COMPARABLE and
  CRYPTO_MAKE_HASHABLE and all the other utter trash in
  `crypto/generic-ops.h`.
- De-inline functions in very common crypto/*.h files so that they don't
  have to get compiled 300 times.
- Remove the disgusting include-a-C-header-inside-a-C++-namespace
  garbage from some crypto headers trying to be both a C and *different*
  C++ header at once.
- Remove the toxic, disgusting, shameful `operator&` on ec_scalar, etc.
  that replace `&x` with `reinterpret_cast x into an unsigned char*`.
  This was pure toxic waste.
- changed some `<<` outputs to fmt
- Random other small changes encountered while fixing everything that
  cascaded out of the above changes.
2022-10-17 22:20:54 -03:00
Thomas Winget 1311a20e9f merge dev branch with RPC/wallet3 changes
Incomplete, many things to fix, some annotated with
a comment MERGEFIX
2022-07-11 20:40:50 -04:00
Jason Rhinelander dfe566480b
Remove cryptonote_config macros
- Replace all cryptonote_config macros with constexpr variables.  Some
  become integer types, some become chrono types.
  - generally this involved removing a "CRYPTONOTE_" prefix since the
    values are now in the `cryptonote` namespace
  - some constants are grouped into sub-namespaces (e.g.
    cryptonote::p2p)
  - deprecated constants (i.e. for old HFs) are in the `cryptonote::old`
    namespace.
  - all the magic hash key domain separating strings are now in
    cryptonote::hashkey::WHATEVER.
- Move some economy-related constants to oxen_economy.h instead
- Replaced the BLOCKS_EXPECTED_IN_DAYS constexpr functions with more
  straightforward `BLOCKS_PER_DAY` value (i.e.  old
  `BLOCKS_EXPECTED_IN_DAYS(10)` is now `BLOCKS_PER_DAY * 10`.
- Replaced `network_version` unscoped enum with a scoped enum
  `cryptonote::hf`, replacing all the raw uint8_t values where it was
  currently accepted with the new `hf` type.
- Made `network_type` a scoped enum so that it now has to be qualified
  (network_type::TESTNET) and can't be arbitrarily/unintentionally
  converted to/from an int.
- HARDFORK_WHATEVER macros have become cryptonote::feature::WHATEVER
  constexpr hf values.
- Add `revision` to rpc hard_fork_info response
- Don't build trezor code at all (previously we were pointlessly
  building an empty dummy lib).
2022-05-16 20:37:07 -03:00
Thomas Winget ecb62e8fab Wallet3 squashed initial commit
tx scanning for basic transactions working
  - TODO: subadresses.  The scanning code is there, but it does not
  currently know/care about any subaddresses.

daemon comms for basic syncing working

(multi-)wallet sync more or less working properly
  - seem to have a dangling shared_ptr somewhere when removing a wallet from
  daemon comms, so not working perfectly yet.

Lots of TODOs and cleanup needed, as well as further features of course.
2021-11-30 16:31:54 -05:00
Jason Rhinelander b8ecb6724c device: C++ cleanups and modernization
- Clean up a bunch of not very nice C and older C++ code in the
`device/` tree.

- Rename device/device_io_* source files to io_*, and remove their `_io`
suffix from the class names (since they are *already* inside an `io`
namespace).
2021-11-04 01:35:44 -03:00
Sean Darcy 8023b59867 rebrand lns -> ons 2021-04-12 10:27:57 +10:00
Jason Rhinelander 438f403c01 Don't invoke cryptonote_core functions from device code
We can't call cryptonote::add_tx_secret_key_to_tx_extra from `device`
code because that isn't necessarily available in `device` (though for
some odd reason this only actually showed up on the i386 build).

This amends the call to just get the secret key, leaving the actual job
of adding it to tx.extra to the caller (which is a cleaner way to do it
anyway).
2020-12-14 11:51:29 -04:00
Jason Rhinelander 33242dff47 Replace keypair::generate with a keypair constructor taking a hwdev
This makes it a bit nicer, and allows in-place construction rather than
needing to construct-and-copy.
2020-12-08 22:31:54 -04:00
Jason Rhinelander 46b25d5ef4 Move LNS signature generation into device code
Includes Ledger implementation.
2020-12-06 23:21:24 -04:00
Jason Rhinelander 4104244576 Fix extracted txversion/txtype 2020-12-06 23:19:20 -04:00
Jason Rhinelander 07aad36120 Ledger: Add stake unlock signature support 2020-12-06 23:17:07 -04:00
Jason Rhinelander ff26b83b45 Add tx secret key via device layer
We add the tx secret key to the tx_extra in staking transactions so that
values can be decoded, but the tx secret key value that we have on hand
is encrypted and so we can't access it.

This moves the call that adds the secret key into the device code so
that devices can provide this.  It also adds the tx version/type earlier
in the process (into `open_tx`) so that the device can know early on
that this is a stake transaction and therefore that leaking the tx
secret key is okay (and can also apply other stake-specific behaviour).
2020-12-04 11:56:46 -04:00
Jason Rhinelander 052d012745 Move key image signature generation into device
We don't have access to output private keys, so without this we can't
generate staking transactions.
2020-12-04 11:54:33 -04:00
Jason Rhinelander 540d097810 Improve crappy ledger C++ code
Fixes lots of crappy C++ code.  I strongly get the impression from these
changes that whoever wrote this code was a C programmer with very little
C++ experience.  Sadly no one in the upstream Monero PR review tried to
help or seemed to care about the code quality.

- Get rid of superfluous `this->` throughout the ledger code.
- DRY: abstract away sending sequences of bytes, replacing:
    memmove(buffer, this->buffer_send+offset, 32);
    offset += 32
  with:
    send_bytes(buffer, 32, offset);
- DRY: abstract sending/receiving u32
- DRY: abstract receiving bytes/u32
- properly prefix memcpy/memmove with std::
- use std::string_view and std::string for setting/retrieving name
- rename `this->controle_device` to `debug_device`
- replace `f(void)` -> `f()` (on C++ methods, FFS!)
- DRY: replace set-length-then-exchange dance with a function
- DRY: merge nearly-identical exchange() and exchange_wait_for_input()
- remove never-used ok/mask arguments from exchange()
- Remove ASSERT_SW macro used only in one place
- Replace dumb ASSERT_X macro that was just an alias for another macro
- remove ASSERT_T0 macro that isn't used anywhere
2020-11-30 00:47:12 -04:00
Jason Rhinelander 4a9767ead3 Reformat length function signatures
Function signatures (especially in headers) should be readable!

Also removes useless "const" on pass-by-value parameters from headers,
and pass the bool argument by value instead of by const lvalue
reference.
2020-11-30 00:47:12 -04:00
Jason Rhinelander d39afe00ea Remove mlsag generation
The blockchain doesn't accept MLSAG txes anymore (since HF16 + 10
blocks), so there is no need to keep the generation code around.

Also renames mlsag_prehash to clsag_prehash since that is where it is
primarily used now.
2020-11-30 00:47:12 -04:00
Jason Rhinelander b627b3b4bb Move epee includes under "epee/..."
This ends epee's include pollution.
2020-10-24 12:46:27 -03:00
Sarang Noether 534346656a CLSAG device support 2020-09-16 20:43:12 -03:00
Jason Rhinelander 06f5f3ee82 cryptonote_config.h: use inline constexpr
Currently all the variables in here need to be added into every
compilation unit; C++17 inline constexpr avoids that by throwing away
the duplicates at link time, plus lets the compiler optimize things
away.

Also eliminates a side effect in `get_config()` that mutated the
variable (so that one `get_config()` would end up changing the data of a
previous `get_config()`).  Instead `get_config()` is now always constant
and doesn't care about the hard fork version; instead there is a
convenience method to get the governance wallet_address which takes the
hf version.
2020-07-21 21:53:27 -03:00
Jason Rhinelander 96354a0e0f boost::optional -> std::optional 2020-07-02 12:52:12 -03:00
Doyle a5e21b3c24 Merge commit '688a3e87e712123d182ae6715610c461988f9e74' into MergeUpstream3 2020-05-29 10:50:19 +10:00
Doyle abb8dfc48e Merge commit 'c4f75fe' into MergeUpstream3 2020-05-28 15:29:00 +10:00
cslashm 688a3e87e7 Add timelock verification on device 2020-04-08 11:12:32 +02:00
Sarang Noether 80d5320fff Hash domain separation 2020-04-01 08:31:00 -04:00
Doyle 9d1df98f37 Merge commit '4308a2e' into LokiMergeUpstream 2019-04-12 18:00:11 +10:00
Doyle 892469ded1 Update monero copyright to 2019 pre-emptively to make merge simpler 2019-04-12 14:36:43 +10:00
cslashm 7c44091541 Add get_tx_proof support, needed for new sanity check
Enhance debug info
2019-03-28 18:26:15 +01:00
cslashm 98fdcb2aa5 Add support for V11 protocol with BulletProofV2 and short amount.
New scheme key destination contrfol
Fix dummy decryption in debug mode
2019-03-28 18:26:15 +01:00
binaryFate 1f2930ce0b Update 2019 copyright 2019-03-05 22:05:34 +01:00
cslashm d0e0e89651 New scheme key destination contrfol
Implies protocol version management.
2019-02-20 17:09:16 +11:00
cslashm 460da140ec New scheme key destination contrfol
Implies protocol version management.
2019-02-08 17:02:44 +01:00
moneromooo-monero 99d946e619
ringct: encode 8 byte amount, saving 24 bytes per output
Found by knaccc
2019-01-22 23:17:31 +00:00
moneromooo-monero ec1a62b50d
move int-util.h to epee 2018-12-04 15:14:29 +00:00
Dusan Klinec 29ffb6bba8
device/trezor: trezor support added 2018-11-02 21:36:39 +01:00
moneromooo-monero d6937e373b
ringct: use dummy bulletproofs when in fake mode, for speed 2018-10-23 21:03:18 +00:00
moneromooo-monero ab74dc277a
crypto: make secret_key automatically mlock 2018-08-16 11:57:49 +00:00
stoffu bcab579864
wallet: allow adjusting number of rounds for the key derivation function 2018-08-08 01:56:54 +09:00
cslashm 2c274e05fe Fix sub-address tx scan.
When additional keys was needed, the TX scan failed because the
derivation data was always recomputed with the main tx_key and not
the corresponding additional one.

Moreover this patch avoid perf decreasing when not using HW device.
2018-04-12 13:58:57 +02:00
Riccardo Spagni 3a9290ba6f
Merge pull request #3511
0beb94f3 device: fix endianess dependence on subaddress secret key generation (moneromooo-monero)
2018-04-12 11:15:27 +02:00
cslashm c77d2bfaa0 Add the possibility to export private view key for fast scan.
On client startup the device asks for authorization to export the private view key.
If user agree, the client hold the private view key allowing a fast blockchain scan.
If the user does not agree, the blockchain scan is fully done via the device.
2018-03-31 18:00:33 +02:00
cslashm 100b7bc10d Change mutex lock model to avoid dead lock and ensure locks are always released.
Additional cosmetic fixes:
 move 'name' as protected
 remove unnecessary local var
 Fix debug log
2018-03-31 18:00:33 +02:00
moneromooo-monero 0beb94f323
device: fix endianess dependence on subaddress secret key generation
We now force little endianness
2018-03-28 11:14:25 +01:00
stoffu 8705beaf51
keypair::generate: always require hw::device to avoid possible mistake 2018-03-14 21:00:16 +09:00
stoffu 27a196b126
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.
2018-03-14 21:00:15 +09:00
stoffu c9b38b4765
device: made function prototypes consistent with pre-#3303 codebase 2018-03-14 21:00:06 +09:00
Cédric 73dd883d51 Ledger HW Bug fixes
Fix the way the REAL mode is handle:
  Let create_transactions_2 and create_transactions_from construct the vector of transactions.
  Then iterate on it and resign.
  We just need to add 'outs' list in the TX struct for that.

Fix default secret keys value when DEBUG_HWDEVICE mode is off
  The magic value (00...00 for view key and FF..FF for spend key) was not correctly set
  when DEBUG_HWDEVICE was off. Both was set to 00...00.

Add sub-address info in ABP map in order to correctly display destination sub-address on device

Fix DEBUG_HWDEVICE mode:
   - Fix compilation errors.
   - Fix control device init in ledger device.
   - Add more log.

Fix sub addr control

Fix debug Info
2018-03-12 10:43:06 +01:00
MoroccanMalinois 25ea307d67
Fix invalid device unique_ptr cast 2018-03-04 18:56:48 +00:00
cslashm e745c1e38d Code modifications to integrate Ledger HW device into monero-wallet-cli.
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.
2018-03-04 12:54:53 +01:00