1
#![cfg_attr(docsrs, feature(doc_cfg))]
2
#![doc = include_str!("../README.md")]
3
// @@ begin lint list maintained by maint/add_warning @@
4
#![allow(renamed_and_removed_lints)] // @@REMOVE_WHEN(ci_arti_stable)
5
#![allow(unknown_lints)] // @@REMOVE_WHEN(ci_arti_nightly)
6
#![warn(missing_docs)]
7
#![warn(noop_method_call)]
8
#![warn(unreachable_pub)]
9
#![warn(clippy::all)]
10
#![deny(clippy::await_holding_lock)]
11
#![deny(clippy::cargo_common_metadata)]
12
#![deny(clippy::cast_lossless)]
13
#![deny(clippy::checked_conversions)]
14
#![allow(clippy::cognitive_complexity)] // See arti#2556
15
#![deny(clippy::debug_assert_with_mut_call)]
16
#![deny(clippy::exhaustive_enums)]
17
#![deny(clippy::exhaustive_structs)]
18
#![deny(clippy::expl_impl_clone_on_copy)]
19
#![deny(clippy::fallible_impl_from)]
20
#![deny(clippy::implicit_clone)]
21
#![deny(clippy::large_stack_arrays)]
22
#![warn(clippy::manual_ok_or)]
23
#![deny(clippy::missing_docs_in_private_items)]
24
#![warn(clippy::needless_borrow)]
25
#![warn(clippy::needless_pass_by_value)]
26
#![warn(clippy::option_option)]
27
#![warn(clippy::or_fun_call)]
28
#![deny(clippy::print_stderr)]
29
#![deny(clippy::print_stdout)]
30
#![warn(clippy::rc_buffer)]
31
#![deny(clippy::ref_option_ref)]
32
#![warn(clippy::semicolon_if_nothing_returned)]
33
#![warn(clippy::trait_duplication_in_bounds)]
34
#![deny(clippy::unchecked_time_subtraction)]
35
#![deny(clippy::unnecessary_wraps)]
36
#![warn(clippy::unseparated_literal_suffix)]
37
#![deny(clippy::unwrap_used)]
38
#![deny(clippy::mod_module_files)]
39
#![allow(clippy::let_unit_value)] // This can reasonably be done for explicitness
40
#![allow(clippy::uninlined_format_args)]
41
#![allow(clippy::significant_drop_in_scrutinee)] // arti/-/merge_requests/588/#note_2812945
42
#![allow(clippy::result_large_err)] // temporary workaround for arti#587
43
#![allow(clippy::needless_raw_string_hashes)] // complained-about code is fine, often best
44
#![allow(clippy::needless_lifetimes)] // See arti#1765
45
#![allow(mismatched_lifetime_syntaxes)] // temporary workaround for arti#2060
46
#![allow(clippy::collapsible_if)] // See arti#2342
47
#![deny(clippy::unused_async)]
48
#![deny(clippy::string_slice)] // See arti#2571
49
#![allow(recursion_depth_exceeding_limit)] // arti#2715, rust/issues/159228
50
//! <!-- @@ end lint list maintained by maint/add_warning @@ -->
51
#![allow(dead_code, unused_variables)]
52

            
53
use rand::RngExt;
54

            
55
mod macros;
56
#[cfg(feature = "ope")]
57
pub mod ope;
58
pub mod ops;
59
pub mod pk;
60
pub mod pow;
61
pub mod time;
62

            
63
use macros::define_bytes;
64

            
65
#[cfg(feature = "memquota-memcost")]
66
use {derive_deftly::Deftly, tor_memquota::derive_deftly_template_HasMemoryCost};
67

            
68
define_bytes! {
69
/// A value to identify an onion service during a given period. (`N_hs_subcred`)
70
///
71
/// This is computed from the onion service's public ID and the blinded ID for
72
/// the current time period.
73
///
74
/// Given this piece of information, the original public ID and blinded ID cannot
75
/// be re-derived.
76
#[derive(Copy, Clone, Debug)]
77
pub struct Subcredential([u8; 32]);
78
}
79

            
80
/// Counts which revision of an onion service descriptor is which, within a
81
/// given time period.
82
///
83
/// There can be gaps in this numbering. A descriptor with a higher-valued
84
/// revision counter supersedes one with a lower revision counter.
85
#[derive(
86
    Copy,
87
    Clone,
88
    Debug,
89
    Ord,
90
    PartialOrd,
91
    Eq,
92
    PartialEq,
93
    derive_more::Deref,
94
    derive_more::From,
95
    derive_more::Into,
96
)]
97
pub struct RevisionCounter(u64);
98

            
99
/// Default number of introduction points a service should establish
100
///
101
/// Default value for `[NUM_INTRO_POINT]`, rend-spec-v3 2.5.4.
102
//
103
// TODO arguably these aren't "crypto" so should be in some currently non-existent tor-hscommon
104
pub const NUM_INTRO_POINT_DEF: usize = 3;
105

            
106
/// Maximum number of introduction points a service should establish and we should tolerate
107
///
108
/// Maximum value for `[NUM_INTRO_POINT]`, rend-spec-v3 2.5.4.
109
pub const NUM_INTRO_POINT_MAX: usize = 20;
110

            
111
/// Length of a `RENDEZVOUS` cookie
112
const REND_COOKIE_LEN: usize = 20;
113

            
114
define_bytes! {
115
/// An opaque value `RENDEZVOUS_COOKIE` used at a rendezvous point to match clients and services.
116
///
117
/// See rend-spec-v3 s4.1.
118
///
119
/// The client includes this value to the rendezvous point in its
120
/// `ESTABLISH_RENDEZVOUS` message; the service later provides the same value in its
121
/// `RENDEZVOUS1` message.
122
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
123
#[cfg_attr(
124
    feature = "memquota-memcost",
125
    derive(Deftly),
126
    derive_deftly(HasMemoryCost),
127
)]
128
pub struct RendCookie([u8; REND_COOKIE_LEN]);
129
}
130

            
131
impl rand::distr::Distribution<RendCookie> for rand::distr::StandardUniform {
132
85
    fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> RendCookie {
133
85
        RendCookie(rng.random::<[u8; REND_COOKIE_LEN]>().into())
134
85
    }
135
}