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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! Elliptic curve traits, types, and implementations.
//!
//! # Curve trait
//!
//! The [`Curve`] trait defines an elliptic curve at the type level —
//! its name, key sizes, and the concrete types for public keys,
//! signatures, and shared secrets. Marker types (e.g. [`p256::P256`])
//! implement it so that generic code can be parameterised over curves
//! without runtime dispatch.
//!
//! # Providers
//!
//! *How* a curve's operations are performed lives in [`crate::provider`]:
//! the [`DhProvider`](crate::provider::DhProvider) /
//! [`DhProviderAsync`](crate::provider::DhProviderAsync) trait
//! family, and the backends that implement it — pure software, or
//! hardware such as the Apple Secure Enclave.
//!
//! # P-256 backends
//!
//! Two implementations of the P-256 private key exist:
//!
//! * **Software** ([`p256::P256r1PrivateKey`], always available) —
//! pure-Rust implementation using `eccoxide`. Suitable for tests,
//! WASM, and any platform without hardware key storage.
//!
//! * **Apple Secure Enclave**
//! (`AppleSecureEnclave`,
//! `cfg(any(target_os = "macos", target_os = "ios"))`) — delegates to
//! Apple's Security framework. Private keys never leave the Secure
//! Enclave; signing and ECDH are performed in hardware.
//!
//! Both backends share the same [`p256::P256r1PublicKey`] and
//! [`p256::P256Signature`] types, and their DH results are compatible —
//! the raw 32-byte x-coordinate of the shared point, as the Noise spec
//! requires (no KDF).
// ── Curve trait ─────────────────────────────────────────────────
/// An elliptic curve identity: its name, key sizes, and public-key type.
///
/// Implemented by zero-sized marker types (e.g. [`p256::P256`]). This is
/// the common denominator every curve provides regardless of which
/// operations it supports; the *capabilities* a curve has — Diffie–Hellman
/// ([`DhCurve`]) and/or digital signatures ([`SigningCurve`]) — are layered
/// on top as separate traits, so a DH-only curve need not pretend to sign.
/// A [`Curve`] that supports Diffie–Hellman key agreement.
///
/// Separated from [`Curve`] so a DH-only curve (e.g. X25519) is a full
/// participant in the Noise handshake — which is built entirely on this
/// capability — without having to name a signature type it cannot produce.
/// A [`Curve`] that supports digital signatures.
///
/// Independent of [`DhCurve`]: a curve may agree, sign, or both. The Noise
/// handshake never signs — this capability exists for callers who want
/// signatures alongside the channel.
/// Shared secret derived from an ECDH key exchange.
///
/// Holds the raw `DHLEN`-byte output of the curve's DH function, as
/// required by the Noise protocol specification: `N = 32` for the 32-byte
/// curves (P-256's shared-point x-coordinate, X25519) and `N = 56` for
/// X448. The bytes are zeroed on drop.
;