1#![no_std]
13#![cfg_attr(docsrs, feature(doc_cfg))]
14#![forbid(unsafe_code, clippy::unwrap_used)]
15#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
16#![doc(
17 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
18 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
19 html_root_url = "https://docs.rs/elliptic-curve/0.10.4"
20)]
21
22#[cfg(feature = "alloc")]
23#[allow(unused_imports)]
24#[macro_use]
25extern crate alloc;
26
27#[cfg(feature = "std")]
28extern crate std;
29
30#[cfg(feature = "rand_core")]
31#[cfg_attr(docsrs, doc(cfg(feature = "rand_core")))]
32pub use rand_core;
33
34pub mod ops;
35pub mod sec1;
36pub mod weierstrass;
37
38mod error;
39mod scalar;
40
41#[cfg(feature = "arithmetic")]
42mod arithmetic;
43#[cfg(feature = "arithmetic")]
44mod public_key;
45
46#[cfg(feature = "dev")]
47#[cfg_attr(docsrs, doc(cfg(feature = "dev")))]
48pub mod dev;
49
50#[cfg(feature = "ecdh")]
51#[cfg_attr(docsrs, doc(cfg(feature = "ecdh")))]
52pub mod ecdh;
53
54#[cfg(feature = "jwk")]
55mod jwk;
56
57#[cfg(feature = "zeroize")]
58mod secret_key;
59
60pub use self::{
61 error::{Error, Result},
62 scalar::bytes::ScalarBytes,
63};
64pub use crypto_bigint as bigint;
65pub use generic_array::{self, typenum::consts};
66pub use rand_core;
67pub use subtle;
68
69#[cfg(feature = "arithmetic")]
70pub use {
71 crate::{
72 arithmetic::{AffineArithmetic, ProjectiveArithmetic, ScalarArithmetic},
73 public_key::PublicKey,
74 scalar::{non_zero::NonZeroScalar, Scalar},
75 },
76 ff::Field,
77 group::{self, Group},
78};
79
80#[cfg(feature = "bits")]
81pub use crate::scalar::ScalarBits;
82
83#[cfg(feature = "jwk")]
84pub use crate::jwk::{JwkEcKey, JwkParameters};
85
86#[cfg(feature = "pkcs8")]
87pub use pkcs8;
88
89#[cfg(feature = "zeroize")]
90pub use secret_key::SecretKey;
91#[cfg(feature = "zeroize")]
92pub use zeroize;
93
94use core::fmt::Debug;
95use generic_array::GenericArray;
96use subtle::{ConstantTimeEq, ConstantTimeGreater, ConstantTimeLess};
97
98#[cfg(feature = "pkcs8")]
103#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
104pub const ALGORITHM_OID: pkcs8::ObjectIdentifier =
105 pkcs8::ObjectIdentifier::new("1.2.840.10045.2.1");
106
107pub trait Curve: Clone + Debug + Default + Eq + Ord + Send + Sync {
116 type UInt: AsRef<[bigint::Limb]>
120 + bigint::ArrayEncoding
121 + bigint::Encoding
122 + Copy
123 + Debug
124 + Default
125 + ConstantTimeEq
126 + ConstantTimeGreater
127 + ConstantTimeLess;
128
129 const ORDER: Self::UInt;
134}
135
136pub type FieldSize<C> = <<C as Curve>::UInt as bigint::ArrayEncoding>::ByteSize;
138
139pub type FieldBytes<C> = GenericArray<u8, FieldSize<C>>;
141
142#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
145#[cfg(feature = "arithmetic")]
146pub type AffinePoint<C> = <C as AffineArithmetic>::AffinePoint;
147
148#[cfg(feature = "arithmetic")]
151#[cfg_attr(docsrs, doc(cfg(feature = "arithmetic")))]
152pub type ProjectivePoint<C> = <C as ProjectiveArithmetic>::ProjectivePoint;
153
154#[cfg(feature = "pkcs8")]
161#[cfg_attr(docsrs, doc(cfg(feature = "pkcs8")))]
162pub trait AlgorithmParameters: Curve {
163 const OID: pkcs8::ObjectIdentifier;
165
166 fn algorithm_identifier() -> pkcs8::AlgorithmIdentifier<'static> {
168 pkcs8::AlgorithmIdentifier {
169 oid: ALGORITHM_OID,
170 parameters: Some((&Self::OID).into()),
171 }
172 }
173}