1#![no_std]
2#![cfg_attr(docsrs, feature(doc_auto_cfg))]
3#![doc = include_str!("../README.md")]
4#![doc(
5 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
6 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
7)]
8#![forbid(unsafe_code)]
9#![warn(
10 clippy::mod_module_files,
11 clippy::unwrap_used,
12 missing_docs,
13 rust_2018_idioms,
14 unused_lifetimes,
15 unused_qualifications
16)]
17
18#[cfg(feature = "arithmetic")]
30mod arithmetic;
31
32#[cfg(feature = "ecdh")]
33pub mod ecdh;
34
35#[cfg(feature = "ecdsa-core")]
36pub mod ecdsa;
37
38#[cfg(any(feature = "test-vectors", test))]
39pub mod test_vectors;
40
41pub use elliptic_curve::{self, bigint::U256, consts::U32};
42
43#[cfg(feature = "arithmetic")]
44pub use arithmetic::{scalar::Scalar, AffinePoint, ProjectivePoint};
45
46#[cfg(feature = "expose-field")]
47pub use arithmetic::field::FieldElement;
48
49#[cfg(feature = "pkcs8")]
50pub use elliptic_curve::pkcs8;
51
52use elliptic_curve::{
53 bigint::ArrayEncoding, consts::U33, generic_array::GenericArray, FieldBytesEncoding,
54};
55
56const ORDER_HEX: &str = "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551";
75
76#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
98pub struct NistP256;
99
100impl elliptic_curve::Curve for NistP256 {
101 type FieldBytesSize = U32;
103
104 type Uint = U256;
106
107 const ORDER: U256 = U256::from_be_hex(ORDER_HEX);
109}
110
111impl elliptic_curve::PrimeCurve for NistP256 {}
112
113impl elliptic_curve::point::PointCompression for NistP256 {
114 const COMPRESS_POINTS: bool = false;
116}
117
118impl elliptic_curve::point::PointCompaction for NistP256 {
119 const COMPACT_POINTS: bool = false;
121}
122
123#[cfg(feature = "jwk")]
124impl elliptic_curve::JwkParameters for NistP256 {
125 const CRV: &'static str = "P-256";
126}
127
128#[cfg(feature = "pkcs8")]
129impl pkcs8::AssociatedOid for NistP256 {
130 const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.2.840.10045.3.1.7");
131}
132
133#[cfg(feature = "arithmetic")]
135pub type BlindedScalar = elliptic_curve::scalar::BlindedScalar<NistP256>;
136
137pub type CompressedPoint = GenericArray<u8, U33>;
139
140pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP256>;
142
143pub type FieldBytes = elliptic_curve::FieldBytes<NistP256>;
147
148impl FieldBytesEncoding<NistP256> for U256 {
149 fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
150 U256::from_be_byte_array(*field_bytes)
151 }
152
153 fn encode_field_bytes(&self) -> FieldBytes {
154 self.to_be_byte_array()
155 }
156}
157
158#[cfg(feature = "arithmetic")]
160pub type NonZeroScalar = elliptic_curve::NonZeroScalar<NistP256>;
161
162#[cfg(feature = "arithmetic")]
164pub type PublicKey = elliptic_curve::PublicKey<NistP256>;
165
166pub type SecretKey = elliptic_curve::SecretKey<NistP256>;
168
169#[cfg(not(feature = "arithmetic"))]
170impl elliptic_curve::sec1::ValidatePublicKey for NistP256 {}
171
172#[cfg(feature = "bits")]
174pub type ScalarBits = elliptic_curve::scalar::ScalarBits<NistP256>;
175
176#[cfg(feature = "voprf")]
177impl elliptic_curve::VoprfParameters for NistP256 {
178 const ID: &'static str = "P256-SHA256";
180
181 type Hash = sha2::Sha256;
183}