1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! Timing-leak dudect harness for MAC (signature byte) equality compare.
//!
//! Gated behind the `dudect` Cargo feature so default `cargo test -p
//! chio-kernel-core` is unaffected; opt in via:
//!
//! ```bash
//! cargo test -p chio-kernel-core --features dudect --release mac_eq
//! ```
//!
//! # What this harness measures
//!
//! Chio kernel-core's signature-verification path returns `false` from
//! [`chio_core_types::crypto::PublicKey::verify`] when the supplied
//! signature does not match the message. The portable receipt and passport
//! verifiers compare `Signature` blobs by bytes (see
//! `chio_core_types::crypto::Signature`'s `PartialEq` impl, which uses
//! `==` on the underlying `[u8; 64]` for Ed25519). That byte-equality
//! compare is the closest in-tree analogue of an HMAC-tag compare, which
//! is the canonical "MAC eq" surface that any constant-time crypto code
//! has to keep data-independent.
//!
//! The harness drives two input classes through the byte-equality compare:
//!
//! - `Class::Left`: two signatures that differ at the **first** byte.
//! A naive `==` short-circuits early; a constant-time compare runs
//! through every byte.
//! - `Class::Right`: two signatures that differ at the **last** byte.
//! A naive `==` runs through almost every byte before short-circuiting.
//!
//! If the runtime distributions are statistically distinguishable
//! (Welch's t > 4.5 in two consecutive runs), the compare path is a
//! variable-time short-circuit. The CI lane `.github/workflows/dudect.yml`
//! wires this harness into nightly + PR-time runs with the
//! two-consecutive-runs `t < 4.5` pass rule.
//!
//! # Why the trust-boundary surface, not the wrapper
//!
//! `chio-kernel-core` does not expose its own `mac_eq` symbol; the kernel
//! delegates byte-equality to the `Signature` type from `chio-core-types`,
//! which is part of the same trust boundary set. Measuring the underlying
//! `==` directly catches the leak at its source rather than smearing it
//! through a wrapper that would dilute the signal.
use Signature;
use ;
use ;
/// Number of input pairs generated per harness invocation.
const SAMPLES_PER_RUN: usize = 100_000;
/// Build a `Signature` from a raw 64-byte array.
/// Build a `(left, right)` pair of signatures whose underlying byte arrays
/// differ at exactly `flip_position`. The base bytes are random (filled
/// from `rng`); the right-hand byte at `flip_position` is XOR'd with `0xff`
/// so the pair is guaranteed unequal regardless of what `rng` produced.
/// Dudect harness for `Signature` byte equality.
///
/// Class definitions:
///
/// - `Class::Left`: pair `(a, b)` where `b` differs from `a` at byte 0.
/// A short-circuiting `==` returns after the first byte compare.
/// - `Class::Right`: pair `(a, b)` where `b` differs from `a` at byte 63.
/// A short-circuiting `==` returns only after 63 byte compares.
///
/// The two classes have identical input shapes (random 64-byte blobs);
/// the only difference is which byte position carries the inequality.
ctbench_main!;