1#![no_std]
2#![cfg_attr(docsrs, feature(doc_auto_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")]
26pub mod ecdh;
27
28#[cfg(feature = "ecdsa-core")]
29pub mod ecdsa;
30
31#[cfg(any(feature = "test-vectors", test))]
32pub mod test_vectors;
33
34pub use elliptic_curve::{self, bigint::U384, consts::U48};
35
36#[cfg(feature = "arithmetic")]
37pub use arithmetic::{scalar::Scalar, AffinePoint, ProjectivePoint};
38
39#[cfg(feature = "expose-field")]
40pub use arithmetic::field::FieldElement;
41
42#[cfg(feature = "pkcs8")]
43pub use elliptic_curve::pkcs8;
44
45use elliptic_curve::{
46 bigint::ArrayEncoding, consts::U49, generic_array::GenericArray, FieldBytesEncoding,
47};
48
49const ORDER_HEX: &str = "ffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973";
51
52#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, PartialOrd, Ord)]
54pub struct NistP384;
55
56impl elliptic_curve::Curve for NistP384 {
57 type FieldBytesSize = U48;
59
60 type Uint = U384;
62
63 const ORDER: U384 = U384::from_be_hex(ORDER_HEX);
65}
66
67impl elliptic_curve::PrimeCurve for NistP384 {}
68
69impl elliptic_curve::point::PointCompression for NistP384 {
70 const COMPRESS_POINTS: bool = false;
72}
73
74impl elliptic_curve::point::PointCompaction for NistP384 {
75 const COMPACT_POINTS: bool = false;
77}
78
79#[cfg(feature = "jwk")]
80impl elliptic_curve::JwkParameters for NistP384 {
81 const CRV: &'static str = "P-384";
82}
83
84#[cfg(feature = "pkcs8")]
85impl pkcs8::AssociatedOid for NistP384 {
86 const OID: pkcs8::ObjectIdentifier = pkcs8::ObjectIdentifier::new_unwrap("1.3.132.0.34");
87}
88
89pub type CompressedPoint = GenericArray<u8, U49>;
91
92pub type EncodedPoint = elliptic_curve::sec1::EncodedPoint<NistP384>;
94
95pub type FieldBytes = elliptic_curve::FieldBytes<NistP384>;
100
101impl FieldBytesEncoding<NistP384> for U384 {
102 fn decode_field_bytes(field_bytes: &FieldBytes) -> Self {
103 U384::from_be_byte_array(*field_bytes)
104 }
105
106 fn encode_field_bytes(&self) -> FieldBytes {
107 self.to_be_byte_array()
108 }
109}
110
111#[cfg(feature = "arithmetic")]
113pub type NonZeroScalar = elliptic_curve::NonZeroScalar<NistP384>;
114
115#[cfg(feature = "arithmetic")]
117pub type PublicKey = elliptic_curve::PublicKey<NistP384>;
118
119pub type SecretKey = elliptic_curve::SecretKey<NistP384>;
121
122#[cfg(not(feature = "arithmetic"))]
123impl elliptic_curve::sec1::ValidatePublicKey for NistP384 {}
124
125#[cfg(feature = "bits")]
127pub type ScalarBits = elliptic_curve::scalar::ScalarBits<NistP384>;
128
129#[cfg(feature = "voprf")]
130impl elliptic_curve::VoprfParameters for NistP384 {
131 const ID: &'static str = "P384-SHA384";
133
134 type Hash = sha2::Sha384;
136}