Commit Graph

59 Commits

Author SHA1 Message Date
Jack Grigg 9c76d5789f Render byte slices as hex more often in `Debug` impls
This is more generally useful for debugging purposes than the default
`Debug` impl for `&[u8]`.

We also provide an alternate `Debug` impl for `legacy::Script` that
parses and renders known opcodes. Note that we only parse a subset of
the full opcode set.


Extracted from: c8e2d81f58
2023-08-30 20:41:27 +00:00
Kris Nuttycombe f000a52148 Add comments detailing the checks required prior to calling `check_note_validity`
Extracted from: fe3d0269d1
2023-05-26 10:12:21 -06:00
Kris Nuttycombe 5076943e69 Update `zcash_primitives` to reflect argument changes to `parse_note_plaintext_without_memo_ovk`
Extracted from: 696a9be0a0
2023-05-26 09:43:26 -06:00
Kris Nuttycombe a7fa69c504 Remove `esk` and `ephemeral_key` arguments from `parse_note_plaintext_without_memo_ovk`
Fixes #850


Extracted from: be89e81534
2023-05-26 09:24:22 -06:00
Jack Grigg 81d8f61b0d zcash_note_encryption: Remove `esk` check requirement from `Domain::parse_note_plaintext_without_memo_ovk`
This method is only called from `try_output_recovery_with_ock`, and we
can instead rely on the check performed in `check_note_validity`,
reducing the number of checks that `Domain` implementations need to
perform.

The `esk` and `ephemeral_key` parameters become unused, and will be
removed in a subsequent commit (as this change needs to be synchronized
with the `orchard` crate).


Extracted from: a115a8f00f
2023-05-19 16:30:47 +00:00
Kris Nuttycombe d8885bec55 Update Sapling note encryption for `zcash_note_encryption 0.3.0`
Fixes zcash/librustzcash#455


Extracted from: d6fafa291b
2023-03-21 11:09:38 -06:00
Kris Nuttycombe b060f1c1df Remove the `recipient` parameter from zcash_note_encyption::Domain::note_plaintext_bytes
The `Domain::Note` type is now expected to contain information about the
recipient of the note, eliminating the need to pass this information in
via the encryption context.


Extracted from: c88f3e1b9d
2023-03-20 16:16:00 -06:00
Kris Nuttycombe c06128cf9d Remove `zcash_primitives` as a zcash_note_encryption dev dependency.
This was only used to provide example code for Sapling usage of
the `NoteEncryption` struct; this example code has been moved
to `sapling::note_encryption`.


Extracted from: 29220c716f
2022-09-16 12:52:00 -06:00
Kris Nuttycombe 1ec4b356ad Upgrade chacha20poly1305 dependency to version 0.10
Also upgrade  the `chacha20`, `cipher`, and `subtle` dependency
versions.


Extracted from: 72b5e6dfc3
2022-09-16 12:52:00 -06:00
Daira Hopwood f1d4498da6 zcash_note_encryption: Add API to prepare epk.
Co-authored-by: Jack Grigg <jack@electriccoin.co>
Signed-off-by: Daira Hopwood <daira@jacaranda.org>


Extracted from: 515b0a40ec
2022-09-15 03:22:41 +01:00
Kris Nuttycombe e6483762f2 Remove redundant TryFrom/TryInto imports.
Extracted from: a93f5945ab
2022-09-02 12:05:15 -06:00
Kris Nuttycombe 33b8a037cf Use the new name rustdoc::broken_intra_doc_links
Extracted from: 199c49760b
2022-07-29 15:56:44 -06:00
Kris Nuttycombe 168fd15674 Use batch decryption in wallet scanning.
This modifies wallet scanning to perform per-block batched
decryption. It also alters the structure of the `ScanningKey`
trait to correctly include internal (change) keys in the scan
process.


Extracted from: 73314dc682
2022-07-28 17:28:31 -06:00
Kris Nuttycombe f258e3559e Restructure batch decryption to avoid cartesian product of results.
While it is necessary in the worst case to perform `m * n` decryptions,
where `m` is the number of outputs being decrypted and `n` is the number
of IVKs, it is possible to stop performing trial decryptions when the
first successful decryption is performed. Also, it's inconvenient and
unnecessary to return the full cartesian product of these results, as
only one IVK will decrypt a given output. This commit modifies batch
trial decryption to stop on the first successful decryption, and instead
of returning the cartesian product of results we return the index of the
input IVK along with the output it decrypted. Note that this means that
trial decryption is not constant-time with respect to the number and/or
order of IVKs.


Extracted from: 5873950648
2022-07-28 15:23:21 -06:00
Kris Nuttycombe 8a5c0f8946 Fix Clippy beta linting complaints.
Extracted from: a304c3953b
2022-02-02 16:02:45 -07:00
Kris Nuttycombe 0a7ad528ed Apply suggestions from code review
Co-authored-by: str4d <jack@electriccoin.co>


Extracted from: 3a20176092
2022-01-27 15:00:37 -07:00
Jack Grigg 312472ffbe zcash_note_encryption: Crate documentation
Extracted from: d511a788c4
2021-12-17 15:06:22 +00:00
Jack Grigg b12b4124ed zcash_note_encryption: Document APIs
Extracted from: edc3557e30
2021-12-17 14:12:18 +00:00
Jack Grigg 7b52b15cfa zcash_note_encryption: Add `doc_cfg` annotations
Extracted from: 5409291b0c
2021-12-17 14:12:18 +00:00
Jack Grigg 9994ddc70d zcash_note_encryption: Constrain outgoing ciphertext size
This replaces a length assertion, making the API more predictable.


Extracted from: 76f364593a
2021-12-17 05:23:53 +00:00
Jack Grigg 1ac6d5b8fe zcash_note_encryption: Constrain `ShieldedOutput` ciphertext size
Previously we were returning the ciphertext as a slice, and then
asserting its length within the APIs the caller passed it into. Now
instead we require the caller to define whether or not the output is
compact, to make the API more predictable.

This doesn't place any additional constraints on users of this trait,
because the assertions already prevented a full output from being passed
to a compact trial decryption API.


Extracted from: 4fcd83d74e
2021-12-17 05:23:53 +00:00
Jack Grigg 7ab76d8574 zcash_note_encryption: Remove `Domain::check_epk_bytes`
`Domain::derive_esk` provides sufficient information to determine
whether or not we need to enforce `EphemeralSecretKey`-specific
decryption checks, as it returns `None` for pre-ZIP 212 notes.


Extracted from: d54e1f0bf7
2021-12-17 04:30:57 +00:00
Jack Grigg 34277d4e38 zcash_note_encryption: Use `*PlaintextBytes` structs in `Domain` APIs
`Domain::parse_note_plaintext_without_memo_ivk` is used with both full
note plaintexts and compact notes, so continues to accept a slice. For
all other `Domain` APIs, we constrain the input to `NotePlaintextBytes`
or `OutPlaintextBytes` as appropriate.


Extracted from: 7c1687dcc1
2021-12-17 04:30:57 +00:00
Jack Grigg df05017f1a zcash_note_encryption: Place pre-ZIP 212 APIs behind a feature flag
Extracted from: 01c768dbeb
2021-12-17 04:30:57 +00:00
jarys f79d84fe59 Add `#![no_std]` support for zcash_note_encryption (#450)
Co-authored-by: str4d <thestr4d@gmail.com>

Extracted from: 0ec7f97c97
2021-11-24 13:58:52 +00:00
Jack Grigg df51fbc543 zcash_note_encryption: Move domain batch APIs into a BatchDomain trait
These are the only allocating APIs; this change makes it possible to
make the crate no-std compatible.


Extracted from: 35e7542065
2021-11-17 12:14:26 +00:00
Kris Nuttycombe 943e6f5c20 Fix a couple of broken doc links.
Extracted from: 5541552453
2021-09-01 14:01:47 -06:00
str4d b7a3885b7f Merge pull request #428 from nuttycom/public_compact_size
Move the CompactSize, Vector, Array and Option encodings to a new zcash_encoding crate.

Extracted from: edcde252de
2021-09-01 20:45:28 +01:00
Kris Nuttycombe 1fd5c8d748 Fix stray clippy complaints.
Extracted from: fa092da456
2021-08-31 13:19:24 -06:00
Jack Grigg b0ff1f9914 zcash_note_encryption: Switch to chacha20poly1305 crate
Extracted from: f03f05f251
2021-08-30 15:03:39 +01:00
Jack Grigg 7f3ca6d79d zcash_note_encryption: Add support for batch-parsing `ephemeral_key`
This is useful when the underlying curve requires an inversion to parse
an encoded point (such as for Jubjub).


Extracted from: 4b4dd2ea55
2021-08-10 02:57:11 +01:00
Jack Grigg 2b4a88be36 zcash_note_encryption: Add batched trial decryption APIs
Extracted from: 8a615c4393
2021-08-10 02:17:10 +01:00
Jack Grigg 53e008b278 Use `EphemeralKeyBytes` type in place of `[u8; 32]`
Extracted from: 279a8b6bb6
2021-08-09 21:28:42 +01:00
Jack Grigg 3999630051 zcash_note_encryption: Add `ShieldedOutput::ephemeral_key() -> EphemeralKeyBytes`
This replaces the `ShieldedOutput::epk() -> &Domain::EphemeralPublicKey`
which could not be satisfied by output types that did not parse epk.


Extracted from: c7c79d266e
2021-06-10 18:35:19 +01:00
Jack Grigg a06b406eb4 zcash_note_encryption: Doc fixes
Extracted from: eba6f417fe
2021-05-29 00:15:25 +01:00
Jack Grigg 1385c8cc41 zcash_note_encryption: Fix array size in Domain::extract_{esk, pk_d}
Decrypted output size is `OUT_PLAINTEXT_BYTES`, which the decryptor
can always provide (either by decrypting into the correct size array
as now, or truncating the buffer before passing it to the domain).


Extracted from: 362838c3fa
2021-05-28 23:48:03 +01:00
Jack Grigg 18e290dbc0 zcash_note_encryption: Add ovk recovery API
Extracted from: f6705f23c3
2021-05-28 23:45:23 +01:00
Jack Grigg befb178c61 zcash_note_encryption: Pass cmstar_bytes to Domain::derive_ock
PRF^ock in the spec takes cm* as a byte array.


Extracted from: ae43e6c074
2021-05-28 23:41:13 +01:00
Jack Grigg d94482d5ac zcash_note_encryption: s/TryFrom/From on ExtractedCommitmentBytes bound
This was left over from an earlier refactor where we could call a domain
API to extract cmstar from a note commitment (which could fail for
Orchard). This part of extraction was subsequently refactored into the
domain logic (and is rejected earlier for Orchard). The resulting bound
is wrong because it's always possible to serialize a scalar.


Extracted from: ee2b96c82d
2021-05-28 22:57:48 +01:00
Jack Grigg 22d0991a46 zcash_note_encryption: Enforce ZIP 212 check on esk from outPlaintext
It needs to equal the esk derived from the note (for v2 note plaintexts).


Extracted from: 16627b4569
2021-05-28 22:33:00 +01:00
Jack Grigg dc22102d41 cargo fmt
Extracted from: 28a45028ab
2021-04-16 14:03:55 +12:00
Daira Hopwood 0a4fb8ff34 Update comment about which case is covered by example code
Extracted from: dc0f6e7115
2021-04-16 00:10:05 +01:00
Kris Nuttycombe 9e499c08ca Fix naming cmstar -> cmstar_bytes and cm -> cmstar
Extracted from: b2b3efd4c2
2021-04-15 15:24:45 -06:00
Kris Nuttycombe 5358e678b2 Make cmstar check follow the spec more closely.
Extracted from: 00d04de547
2021-04-14 15:38:58 -06:00
Kris Nuttycombe a14db84fea Minor comment on epk canonicity.
Extracted from: 389e6ca6a3
2021-04-12 18:43:21 -06:00
Kris Nuttycombe c3d0a64fac Update documentation for note encryption traits.
Extracted from: f34e87884a
2021-04-12 17:41:06 -06:00
Kris Nuttycombe 2884d70e29 Use ephemeral_key bytes instead of the epk abstract point where specified.
Extracted from: 6fc1d1d1c0
2021-04-12 16:19:50 -06:00
Kris Nuttycombe 3843f4ba2b Use ShieldedOutput trait for note encryption/decryption.
This change modifies note encryption and decryption functions
to treat a shielded output as a single value instead of handling
the parts of an output as independent arguments.


Extracted from: 324fc36521
2021-04-12 12:59:06 -06:00
Kris Nuttycombe 4903214bfe Apply suggestions from code review
Co-authored-by: Daira Hopwood <daira@jacaranda.org>

Extracted from: 4f22f1d578
2021-04-12 09:18:51 -06:00
Kris Nuttycombe e06b628f19 Use constant-time equality for EphemeralKeyBytes.
Fixes #370


Extracted from: e654cc4ce6
2021-04-12 09:13:04 -06:00