Commit Graph

7840 Commits

Author SHA1 Message Date
Micah Elizabeth Scott f4939a5fd8 tor-hspow, equix, hashx: Make all error types Clone
This uses an Arc to hold std::io::Error for low-level HashX runtime
errors.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 10b7352c98 hashx: Simplify hash_to_bytes, only support fixed output width
In response to review feedback. The byte output is only needed
for unit tests right now, since Equi-X uses u64 output exclusively.

The optimization for shorter output widths can shave tiny amounts of
time off hash benchmarks, but in this case it's more helpful to avoid
introducing APIs that offer parameters with incomplete compile-time
range checking.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott d17c12b152 hashx: use RngCore for HashX's internal PRNG
This refactors the random number generator used within HashX's program
generator so that it uses the rand::RngCore trait. The basic SipHash
powered u64 generator now implements RngCore, while a buffer layer
wraps this and provides u8 and u32 values as needed by the generator.

Some of this new RngCore layer is now exposed to the hashx crate's
public API. The intent is to allow external code to test, benchmark, or
fuzz the program generator by supplying its own random number stream.

Benchmarks show a small but confusing performance improvement
associated with this patch. About a 2% improvement in generation.
This could be due to the Rng changes. No change in compiled hash
execution performance. Even though this patch only touches program
generation, benchmarks show a 4% speedup in interpreted execution.
This seems most likely explained by instruction cache effects,
but I'm not sure.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 2c20b46921 hashx: Implement Default for RuntimeOption 2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott c5976c6675 equix: Refactoring for bucket_array
This splits up bucket_array into two smaller modules, one for the hash
table behavior and one for the MaybeUninit memory management.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 8a79021f38 Update equix, hashx, tor-hspow for new clippy defaults
Just running maint/add_warning after the rebase
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott fdfe3ce55f hashx: register set optimizations, 20% faster generator
I was hoping most of the program generator would get inlined, so we can
resolve a lot of the edge cases at compile-time. This patch gets us
close to that, adding many inline attrs and rewriting RegisterSet with
explicit unrolling and storage types that are easier for the optimizer
to reason about.

From the disassembly of the program generator, it's now mostly one big
function with a jump table. From callgrind instruction profiles, there
are no longer obvious hotspots in register set scanning loops. It also
looks like we're often keeping per-register schedule information all
loaded into machine registers now.

Keeping the Rng entry points non-inlined for now seems to be slightly
better, by a percent or two.

There's some work left to do in compiled programs, and maybe room for
improvement in the Program representation too. That will be in a future
patch.

Benchmark shows about 20% improvement on my machine,

generate-interp         time:   [75.440 µs 75.551 µs 75.684 µs]
                        change: [-24.083% -23.775% -23.483%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  5 (5.00%) high mild
  6 (6.00%) high severe

generate-x86_64         time:   [96.068 µs 96.273 µs 96.540 µs]
                        change: [-18.699% -18.381% -18.013%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 10 outliers among 100 measurements (10.00%)
  4 (4.00%) high mild
  6 (6.00%) high severe

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 3e8b8d035a Include debug symbols in "bench" profile
Including full debug symbols makes the benchmark builds useful for
profiling too.
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott e7aa1d6b62 Start implementing Proposal 327
This adds a new tor-hspow crate with the first layers of support in
place for onion service client puzzles as described in Proposal 327.

The API here is experimental, and it's currently only implementing
the self-contained parts of the client puzzle. So, it can verify and
solve puzzles, but it has no event loop integration or nonce replay
tracking or prioritization code yet. These things seem like they would
eventually live in the same crate.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott 16c9bdf178 Reimplement Equi-X in Rust
This is a new pure Rust implementation of the Equi-X algorithm
designed by tevador for Tor's onion service proof of work puzzle v1.

Equi-X is an asymmetric puzzle algorithm based on Equihash, with
N=60, K=3, the XOR replaced with modular addition, a 16-bit index
space, and HashX as the inner hash function.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:14 -07:00
Micah Elizabeth Scott a8756f2bce Reimplement HashX in Rust
This is a new pure Rust implementation of the HashX algorithm
designed by tevador for Tor's onion service proof of work puzzle v1.

HashX is a lightweight family of randomly generated hash functions.
A seed, via blake2 and siphash, drives a program generation model
which randomly selects opcodes and registers while following some
constraints that avoid timing stalls or insufficient hash mixing.

The execution of these hash funcions can be done using a pure Rust
interpreter, or about 20x faster using a very simple just in time
compiler based on the dynasm assembler crate. This has been
implemented for x86_64 and aarch64.

Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
2023-07-27 07:20:06 -07:00
Nick Mathewson 3b9cc6b4e7 Merge branch 'circuit-reactor-first-hop' into 'main'
tor-proto: Extract Create message handling from Reactor::run_once()

See merge request tpo/core/arti!1441
2023-07-27 11:56:14 +00:00
gabi-250 d4fff19ec9 Merge branch 'keymgr-api-updates-gen-key' into 'main'
keymgr: Add KeyMgr::generate() for generating new keys.

See merge request tpo/core/arti!1433
2023-07-27 11:12:12 +00:00
Gabriela Moldovan 0fbd96df82
keymgr: Add TODO regarding generate() being racy. 2023-07-27 11:46:38 +01:00
Gabriela Moldovan 74a2a7937b
keymgr: Document the TOCTOU issue with generate(). 2023-07-27 11:45:05 +01:00
Gabriela Moldovan 249149d4ce
keymgr: Make the return value of generate() indicate if a new key was created. 2023-07-27 11:13:24 +01:00
Gabriela Moldovan 44f6d1c827
keymgr: Make Keystore::generate() return a Result. 2023-07-27 11:03:06 +01:00
Gabriela Moldovan ecfec3b827
tor-proto: Rename create_firsthop() to wait_for_create(). 2023-07-27 10:56:18 +01:00
Gabriela Moldovan 6f22c16ecc
tor-proto: Update handle_control docs. 2023-07-26 19:36:54 +01:00
Gabriela Moldovan 331ec1033a
tor-proto: Add functions for handling Shutdown and AddFakeHop messages.
This helps reduce code duplication, as `CtrlMsg::Shutdown` and
`CtrlMsg::AddFakeHop` are now handled in multiple places.
2023-07-26 19:36:50 +01:00
Gabriela Moldovan fee4baa17f
tor-proto: Extract first-hop creation to a separate function.
I think it's safe to handle `ChanMsg::Create` separately, because
there's nothing for the reactor to do until the first hop of the circuit
is created (so blocking on this _should_ be alright).
2023-07-26 19:36:47 +01:00
Gabriela Moldovan 98b9be0f2d
tor-proto: Create a function for handling the initial CREATE cell.
This logic from `create_firsthop()` was extracted (copied) from
`Reactor::run_once()`. A future commit will update `Reactor::run_once()`
to use `create_firsthop()`.
2023-07-26 19:35:04 +01:00
Ian Jackson 86ee2193b1 dev notes: Draft IPT algorithm: Minor clarifications 2023-07-26 16:14:45 +01:00
Ian Jackson 9966627479 Merge branch 'ipts' into 'main'
dev notes: Draft IPT algorithm: note re intro pt verification (followup)

See merge request tpo/core/arti!1438
2023-07-26 15:14:18 +00:00
Ian Jackson 869df2817a dev notes: Draft IPT algorithm: Added TODO re previous descriptor semantics
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924491
2023-07-26 12:21:34 +01:00
Ian Jackson be31effcae dev notes: Draft IPT algorithm: Added TODO/xref re tuning
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924530
2023-07-26 12:21:34 +01:00
Ian Jackson 98e3d7ac56 dev notes: Draft IPT algorithm: Possible fixed descriptor lifetimes
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924501
2023-07-26 12:21:34 +01:00
Ian Jackson 36cf899dd9 dev notes: Draft IPT algorithm: Add a publication rate limit
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924499
2023-07-26 12:21:34 +01:00
Ian Jackson 0b928f8a5b dev notes: Draft IPT algorithm: Add a TODO re selecting from >N IPTs
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924498
2023-07-26 12:21:34 +01:00
Ian Jackson 348aab8166 dev notes: Draft IPT algorithm: Added 2N IPT limit to tuning params
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924496
2023-07-26 12:21:34 +01:00
Ian Jackson a0d0a90b2b dev notes: Draft IPT algorithm: Delay IPT replacement
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924497
2023-07-26 12:21:34 +01:00
Ian Jackson 360bf843ae dev notes: Draft IPT algorithm: Early descriptor publish timing
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924494
2023-07-26 12:21:34 +01:00
Ian Jackson f050309c60 dev notes: Draft IPT algorithm: Retire IPTs - note re Onion Balance
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924487
2023-07-26 12:21:34 +01:00
Ian Jackson e9935ce2bc dev notes: Draft IPT algorithm: Retire IPTs - timing question
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924485
2023-07-26 12:21:34 +01:00
Ian Jackson 3807b43791 dev notes: Draft IPT algorithm: Retire IPTs after N introductions
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924485
2023-07-26 12:21:34 +01:00
Ian Jackson 75cc7ccf22 dev notes: Draft IPT algorithm: note re unpublished IPT
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924483
2023-07-26 12:21:34 +01:00
Ian Jackson 35a1e269c4 dev notes: Draft IPT algorithm: note re intro pt verification
Discussions here:
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924481
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/1429#note_2924495
2023-07-26 12:21:34 +01:00
Ian Jackson 30e25af0a0 Merge branch 'typos' into 'main'
Fix typos

See merge request tpo/core/arti!1436
2023-07-26 10:21:27 +00:00
Ian Jackson 86e76c1100 Merge branch 'sw1tch/fix_reconfigure_deadlock' into 'main'
fixes deadlock in TorClient::reconfigure

See merge request tpo/core/arti!1432
2023-07-26 10:20:49 +00:00
Dimitris Apostolou c466edaa07
Fix typos 2023-07-25 21:17:18 +03:00
sw1tch b6873a9b84 pass reconfigure_lock guard into TorClient::reconfigure_inner 2023-07-25 19:31:36 +02:00
Nick Mathewson 2833648bfb Merge branch 'ipts' into 'main'
dev notes: Draft IPT algorithm

See merge request tpo/core/arti!1429
2023-07-25 16:29:38 +00:00
Nick Mathewson 6f841d0fb8 Merge branch 'onion-service-notes-v1' into 'main'
Initial notes about onion service structs and APIs

See merge request tpo/core/arti!1422
2023-07-25 16:29:28 +00:00
gabi-250 e3d2e12624 Merge branch 'keymgr-keygen-key-list' into 'main'
keymgr-doc: Document the list of keys the keymgr needs to generate.

See merge request tpo/core/arti!1413
2023-07-25 10:51:01 +00:00
Ian Jackson 965aab96b9 Merge branch 'safer_build' into 'main'
Add `doc/safer_build.md` to explain path anonymization

Closes #957

See merge request tpo/core/arti!1435
2023-07-25 10:44:51 +00:00
Nick Mathewson 7347a25ab1 Change keyid to nickname 2023-07-24 12:22:46 -04:00
Nick Mathewson 4f5fb5c011 Mention anti-DOS options. 2023-07-24 12:19:43 -04:00
Nick Mathewson 75038d8348 Mention ob_config. Not sure we will want to build it like this. 2023-07-24 12:18:21 -04:00
Nick Mathewson 7166c9e5b5 Add `doc/safer_build.md` to explain path anonymization
Otherwise our default build instructions will lead people
to build binaries that include their home directory.

Closes #957 for now.
2023-07-24 09:34:40 -04:00
Nick Mathewson f400ba2925 Merge branch 'fmt' into 'main'
Run cargo +nightly fmt to format many let ... else ...

See merge request tpo/core/arti!1434
2023-07-24 13:19:36 +00:00