1#![no_std]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3#![doc(
4 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
5 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
6)]
7#![forbid(unsafe_code)]
8#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
9#![doc = include_str!("../README.md")]
10
11#[cfg(feature = "arithmetic")]
23mod arithmetic;
24
25#[cfg(feature = "ecdh")]
26#[cfg_attr(docsrs, doc(cfg(feature = "ecdh")))]
27pub mod ecdh;
28
29#[cfg(feature = "ecdsa-core")]
30#[cfg_attr(docsrs, doc(cfg(feature = "ecdsa-core")))]
31pub mod ecdsa;
32
33#[cfg(any(feature = "test-vectors", test))]
34#[cfg_attr(docsrs, doc(cfg(feature = "test-vectors")))]
35pub mod test_vectors;
36
37pub use elliptic_curve::{self, bigint::U256};
38
39#[cfg(feature = "arithmetic")]
40pub use arithmetic::{
41 affine::AffinePoint,
42 projective::ProjectivePoint,
43 scalar::{blinded::BlindedScalar, Scalar},
44};
45
46#[cfg(feature = "expose-field")]
47pub use arithmetic::field::FieldElement;
48
49#[cfg(feature = "pkcs8")]
50#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
51pub use elliptic_curve::pkcs8;
52
53use elliptic_curve::{consts::U33, generic_array::GenericArray};
54
55#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
75pub struct NistP256;
76
77impl elliptic_curve::Curve for NistP256 {
78 type UInt = U256;
80
81 const ORDER: U256 =
99 U256::from_be_hex("ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551");
100}
101
102impl elliptic_curve::PrimeCurve for NistP256 {}
103
104impl elliptic_curve::PointCompression for NistP256 {
105 const COMPRESS_POINTS: bool = false;
107}
108
109impl elliptic_curve::PointCompaction for NistP256 {
110 const COMPACT_POINTS: bool = false;
112}
113
114#[cfg(feature = "jwk")]
115#[cfg_attr(docsrs, doc(cfg(feature = "jwk")))]
116impl elliptic_curve::JwkParameters for NistP256 {
117 const CRV: &'static str = "P-256";
118}
119
120#[cfg(feature = "pkcs8")]
121impl pkcs8::AssociatedOid for NistP256 {
122 const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.2.840.10045.3.1.7");
123}
124
125pub type CompressedPoint = GenericArray<u8, U33>;
127
128pub type FieldBytes = elliptic_curve::FieldBytes<NistP256>;
132
133pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP256>;
135
136#[cfg(feature = "arithmetic")]
138pub type NonZeroScalar = elliptic_curve::NonZeroScalar<NistP256>;
139
140#[cfg(feature = "arithmetic")]
142pub type PublicKey = elliptic_curve::PublicKey<NistP256>;
143
144pub type SecretKey = elliptic_curve::SecretKey<NistP256>;
146
147#[cfg(not(feature = "arithmetic"))]
148impl elliptic_curve::sec1::ValidatePublicKey for NistP256 {}
149
150#[cfg(feature = "bits")]
152#[cfg_attr(docsrs, doc(cfg(feature = "bits")))]
153pub type ScalarBits = elliptic_curve::ScalarBits<NistP256>;
154
155#[cfg(feature = "voprf")]
156#[cfg_attr(docsrs, doc(cfg(feature = "voprf")))]
157impl elliptic_curve::VoprfParameters for NistP256 {
158 const ID: u16 = 0x0003;
160
161 type Hash = sha2::Sha256;
163}