Commit Graph

145 Commits

Author SHA1 Message Date
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
Jason Rhinelander 463590ad5c
Eliminate most << output operators
Replace (nearly) everything with fmt formatting.  Some crap in wallet2
remains that I'm not going to bother with.
2022-10-17 13:45:24 -03:00
Jason Rhinelander c9934b9f5f
Change most oxen::log::whatever to log::whatever
oxen::log::info(...), etc. are a bit too verbose; this simplifies them
to just `log::info(...)`, etc. by aliasing the `oxen::log` namespace
into most of the common namespaces we use in core.

This result is usage that is shorter but also reads better:

    oxen::log::info(logcat, "blah: {}", 42);

    log::info(logcat, "blah: {}", 42);
2022-10-17 13:41:43 -03:00
Sean Darcy d7992b5940
Logging Refactor
This replaces the current epee logging system with our oxen::log
library. It replaces the easylogging library with spdlog, removes the
macros and replaces with functions and standardises how we call the
logs.
2022-10-17 13:41:10 -03:00
Thomas Winget d4b6f967fd Merge most recent dev and wallet3 branches
Fixes a few merge conflicts, several compilation errors, and
some behavioral incorrectness.  Still a few bugs with wallet3
but as far as I can tell wallet2 and daemon etc. should be working
correctly.
2022-08-22 19:25:49 -04: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
Sean Darcy 8566f8b973 nano s plus HID pid 2022-06-29 15:27:22 +10:00
Jason Rhinelander 636ee3f622
Replace boost::endian conversion with oxenc 1.0.3
1.0.3 got some endian fixes that lets us avoid boost::endian everywhere.
2022-05-24 17:35:59 -03:00
Jason Rhinelander 6fcfd0b8ba
Update oxenmq to latest oxen-mq+oxen-encoding
All the encoding parts move to oxen-encoding recently; this updates to
the latest version of oxen-mq, adds oxen-encoding, and converts
everything to use oxenc headers rather than the oxenmq compatibility
shims.
2022-04-14 14:32:01 -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
Sean Darcy f549e3ffad Add entire range of udev rules 2021-11-05 09:39:16 +11:00
Jason Rhinelander 972fe0de73 Stop using legacy ledger usb product id 2021-11-04 01:35:46 -03:00
Jason Rhinelander 06a9251f15 Add LedgerTCP hardware wallet support
This communicates with the Ledger over TCP, which is what the ledger
emulator requires.

To use, specify:

    --hw-device LedgerTCP --hw-device-address localhost:9999

to the wallet command-line arguments.
2021-11-04 01:35:46 -03: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 466a1317d2 Rename lokimq -> oxenmq 2021-01-14 19:35:00 -04:00
Sean Darcy 432dc319a9 executable names changed 2021-01-04 14:19:42 +11:00
Sean Darcy 0396698ee7 initial loki -> oxen pass 2021-01-04 11:09:45 +11: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 b717d34557 Cleanups
- rename INS_STEALTH to INS_ENCRYPT_PAYMENT_ID
- remove no-longer-valid (and unused) INS_MANAGE_SEEDWORDS
- hard-code CLSAG rct type prehashing and remove pre-CLSAG code paths
- remove unused decrypt(rct key vector)
- use a constexpr rather than memset & loop for dummy view/spend key
values
- fix speeling mistacks
- fix shitty code formatting
2020-12-08 16:00:07 -04:00
Jason Rhinelander 338d017b3d Properly display SW_WRONG_LENGTH errors
SW_WRONG_LENGTH is a range of errors: the least significant two bytes
carry the failed length.
2020-12-08 15:34:57 -04:00
Jason Rhinelander 2e18a905fb Revert wallet-side clsag c generation
Being able to pass the hash to the Ledger might be abusable (e.g. if it
passed a different hash, with a different secret key to try to sign
something else using the device's secret keys).
2020-12-06 23:22:00 -04:00
Jason Rhinelander 200be25574 Fix key image signature instruction code 2020-12-06 23:21:46 -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 8297b051f7 Use send_u32 2020-11-30 00:47:12 -04:00
Jason Rhinelander 343687dd6e Fix buggy, wrong command IDs
Monero's codes are extremely broken (relative to Monero's own ledger app
code) with wrong codes, omissions, and status codes that don't exist at
all.
2020-11-30 00:47:12 -04:00
Jason Rhinelander 7ecab90008 Clean up how options get set with VALIDATE 2020-11-30 00:47:12 -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 1b97f37e35 Ledger: don't send nulls for no reason
don't send 32 null bytes for no reason in INS_GEN_TXOUT_KEYS when there
is no additional txkey    (this doesn't even match the case when there
is one since we send it encrypted, requiring 64 bytes).
2020-11-30 00:47:12 -04:00
Jason Rhinelander 3eeb295f16 Code cleanups 2020-11-30 00:47:12 -04:00
Jason Rhinelander 591c828aa2 Improve CMD debugging
- Show the instruction name (in debug builds)
- annotate the byte values
2020-11-30 00:47:12 -04:00
Jason Rhinelander 7214a29211 Clean up more nasty C code 2020-11-30 00:47:12 -04:00
Jason Rhinelander f6ba1a465e Add cmd response time to debugging log output 2020-11-30 00:47:12 -04:00
Jason Rhinelander 87fe444303 Don't calculate CLSAG `c` on the device
It's slow and unnecessary and depends on no keys in the hardware wallet
(c is public info in CLSAG).  If the wallet was to provide a changed c
value then verification would simply fail.
2020-11-30 00:47:12 -04:00
Jason Rhinelander d87a91bfc8 Revert protocol version to 1 2020-11-30 00:47:12 -04:00
Jason Rhinelander e408a3c991 Clean up HW debug code
The hard wallet debug code had no way to enable it, and if you did
manually add the define, didn't compile.  It was also nasty, gross,
disgusting code that someone slopped into the file.

This fixes it, adds a cmake option for it, and significantly cleans it
up--just because code is for debugging doesn't mean it should be nasty
and broken.
2020-11-30 00:47:12 -04:00
Jason Rhinelander 2525ab4d0d Ledger: Revise/fix/optimize data chunk transmission
- Sending one 32-byte key at a time is noticeably slower than sending in
  larger chunks.
- Sending in 256-byte chunks was broken because the size field is only
  254 bytes.  Since we are actually sending these for Keccak, it makes
  some sense to chunk it at 136 bytes (i.e. keccak block size).
- Change how multipart works to send as parts 1->2->...->0.  Previously
  0xff (rather than 0) marked the last chunk.
- Allow multi-part chunks to wrap by wrapping the part after 255 to 1
  (skipping 0 since that now means "last").
- Use multi-part chunk scheme for CLSAG in addition to prefix hashing.
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 b810732058 Ledger: Remove obsolete MLSAG instruction 2020-11-30 00:47:12 -04:00
Jason Rhinelander 67f4e990d2 Remove MLSAG generation
The blockchain only accepts CLSAG txes now, so no need to keep the MLSAG
generation code around.  (MLSAG verification stays, of course).
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 ca64e46e86 Compilation fixes 2020-11-30 00:47:12 -04:00
Jason Rhinelander ad7e63a04f Overhaul tx prefix comms; rename some overloaded methods
Tx prefix communication was missing some needed information on the tx
type, and was a little inefficient.  This redoes the protocol to send
the tx type info and then the entire prefix (rather than starting from a
few bytes in).  It also changes how we number requests and signal the
final piece of a multi-piece transmission.
2020-11-30 00:47:12 -04:00
Jason Rhinelander 754a9c12cf Ledger support updates
Loki-side updates for Ledger Nano S support:

- Add a get-network command (and bump protocol version) so that we can
verify that the Ledger is set to the correct network type (i.e. mainnet
or testnet).  Previously there was no check at all, so you could have a
testnet wallet on desktop using mainnet keys on the Ledger.  Now they
get checked and an error occurs on mismatch.

- Reset required version to 0.9.0
2020-11-30 00:47:12 -04:00
François Colas 059ad205a9 Fix send scalar z in plaintext
The scalar z has not been generated on the HW thus it can't be sent
encrypted. The value is derived from the exported private view key.
2020-09-16 20:43:12 -03:00
cslashm 5f920bb5b0 draft support of clsag 2020-09-16 20:43:12 -03:00