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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_root_url = "https://docs.rs/k256/0.8.1"
)]
#![forbid(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
#[cfg(feature = "arithmetic")]
mod arithmetic;
#[cfg(feature = "ecdh")]
#[cfg_attr(docsrs, doc(cfg(feature = "ecdh")))]
pub mod ecdh;
#[cfg(feature = "ecdsa-core")]
#[cfg_attr(docsrs, doc(cfg(feature = "ecdsa-core")))]
pub mod ecdsa;
#[cfg(any(feature = "test-vectors", test))]
#[cfg_attr(docsrs, doc(cfg(feature = "test-vectors")))]
pub mod test_vectors;
pub use elliptic_curve;
#[cfg(feature = "arithmetic")]
pub use arithmetic::{
affine::AffinePoint,
projective::ProjectivePoint,
scalar::{NonZeroScalar, Scalar, ScalarBits},
};
#[cfg(feature = "expose-field")]
pub use arithmetic::FieldElement;
#[cfg(feature = "pkcs8")]
#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
pub use elliptic_curve::pkcs8;
use elliptic_curve::consts::U32;
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
pub struct Secp256k1;
impl elliptic_curve::Curve for Secp256k1 {
type FieldSize = U32;
}
#[cfg(target_pointer_width = "32")]
impl elliptic_curve::Order for Secp256k1 {
type Limbs = [u32; 8];
const ORDER: Self::Limbs = [
0xD036_4141,
0xBFD2_5E8C,
0xAF48_A03B,
0xBAAE_DCE6,
0xFFFF_FFFE,
0xFFFF_FFFF,
0xFFFF_FFFF,
0xFFFF_FFFF,
];
}
#[cfg(target_pointer_width = "64")]
impl elliptic_curve::Order for Secp256k1 {
type Limbs = [u64; 4];
const ORDER: Self::Limbs = [
0xBFD2_5E8C_D036_4141,
0xBAAE_DCE6_AF48_A03B,
0xFFFF_FFFF_FFFF_FFFE,
0xFFFF_FFFF_FFFF_FFFF,
];
}
impl elliptic_curve::weierstrass::Curve for Secp256k1 {}
impl elliptic_curve::weierstrass::PointCompression for Secp256k1 {
const COMPRESS_POINTS: bool = true;
}
#[cfg(feature = "jwk")]
#[cfg_attr(docsrs, doc(cfg(feature = "jwk")))]
impl elliptic_curve::JwkParameters for Secp256k1 {
const CRV: &'static str = "secp256k1";
}
#[cfg(feature = "pkcs8")]
impl elliptic_curve::AlgorithmParameters for Secp256k1 {
const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new("1.3.132.0.10");
}
pub type CompressedPoint = [u8; 33];
pub type FieldBytes = elliptic_curve::FieldBytes<Secp256k1>;
pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<Secp256k1>;
#[cfg(feature = "arithmetic")]
pub type PublicKey = elliptic_curve::PublicKey<Secp256k1>;
#[cfg(feature = "zeroize")]
#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))]
pub type SecretKey = elliptic_curve::SecretKey<Secp256k1>;
#[cfg(feature = "zeroize")]
#[cfg_attr(docsrs, doc(cfg(feature = "zeroize")))]
pub type SecretBytes = elliptic_curve::SecretBytes<Secp256k1>;
#[cfg(all(not(feature = "arithmetic"), feature = "zeroize"))]
impl elliptic_curve::SecretValue for Secp256k1 {
type Secret = SecretBytes;
fn from_secret_bytes(bytes: &FieldBytes) -> Option<SecretBytes> {
Some(bytes.clone().into())
}
}
#[cfg(all(not(feature = "arithmetic"), feature = "zeroize"))]
impl elliptic_curve::sec1::ValidatePublicKey for Secp256k1 {}